Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
revision_counter.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3 * Author: Andreas Vogel
4 *
5 * This file is part of UG4.
6 *
7 * UG4 is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License version 3 (as published by the
9 * Free Software Foundation) with the following additional attribution
10 * requirements (according to LGPL/GPL v3 §7):
11 *
12 * (1) The following notice must be displayed in the Appropriate Legal Notices
13 * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 *
15 * (2) The following notice must be displayed at a prominent place in the
16 * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 *
18 * (3) The following bibliography is recommended for citation and must be
19 * preserved in all covered files:
20 * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 * parallel geometric multigrid solver on hierarchically distributed grids.
22 * Computing and visualization in science 16, 4 (2013), 151-164"
23 * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 * flexible software system for simulating pde based models on high performance
25 * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 */
32
33#ifndef __H__UG__LIB_DISC__COMMON__REVISION_COUNTER__
34#define __H__UG__LIB_DISC__COMMON__REVISION_COUNTER__
35
36#include "common/common.h"
37
38namespace ug{
39
41
56{
57 public:
60
62 RevisionCounter(const void* pObj) : m_pObj(pObj), m_cnt(1) {}
63
65 template <typename T>
66 RevisionCounter(const T* pObj) : m_pObj(static_cast<const void*>(pObj)), m_cnt(1) {}
67
70 if(invalid())
71 UG_THROW("AdaptState: increasing invalid state not admissible.")
72
73 ++m_cnt;
74
75 if(invalid())
76 UG_THROW("AdaptState: counter overflow. Alter implementation.")
77 return *this;
78 }
79
82 RevisionCounter tmp(*this);
83 ++(*this);
84 return tmp;
85 }
86
88 bool operator==(const RevisionCounter& rhs) const{
89 if(invalid() || rhs.invalid()) return false;
90 if(m_pObj != rhs.m_pObj) return false;
91 return (m_cnt == rhs.m_cnt);
92 }
93
95 bool operator!=(const RevisionCounter& rhs) const{
96 return !((*this) == rhs);
97 }
98
100 bool operator<(const RevisionCounter& rhs) const{
101 if(m_pObj != rhs.m_pObj) return m_pObj < rhs.m_pObj;
102 if(m_cnt != rhs.m_cnt) return m_cnt < rhs.m_cnt;
103 return false;
104 }
105
107 bool operator>(const RevisionCounter& rhs) const{
108 if(m_pObj != rhs.m_pObj) return m_pObj > rhs.m_pObj;
109 if(m_cnt != rhs.m_cnt) return m_cnt > rhs.m_cnt;
110 return false;
111 }
112
114 bool valid() const {return m_pObj != 0 && m_cnt != 0;}
115
117 bool invalid() const {return !valid();}
118
120 void invalidate() {m_pObj = 0; m_cnt = 0;}
121
123 const void* obj() const {return m_pObj;}
124
125 protected:
126 const void* m_pObj;
128};
129
130} // end namespace ug
131
132#endif /* __H__UG__LIB_DISC__COMMON__REVISION_COUNTER__ */
Class used to identify a state of adaption of a grid, approx-space, ...
Definition revision_counter.h:56
bool invalid() const
returns if state is invalid
Definition revision_counter.h:117
const void * obj() const
returns the associated object
Definition revision_counter.h:123
RevisionCounter & operator++()
increase state (prefix)
Definition revision_counter.h:69
RevisionCounter(const T *pObj)
constructor (with valid state initialization)
Definition revision_counter.h:66
bool operator>(const RevisionCounter &rhs) const
compare two states
Definition revision_counter.h:107
RevisionCounter operator++(int)
increase state (postfix)
Definition revision_counter.h:81
RevisionCounter()
constructor (with invalid state initialization)
Definition revision_counter.h:59
const void * m_pObj
associated object
Definition revision_counter.h:126
bool operator!=(const RevisionCounter &rhs) const
compare two states
Definition revision_counter.h:95
uint64 m_cnt
state counter (0 = invalid)
Definition revision_counter.h:127
RevisionCounter(const void *pObj)
constructor (with valid state initialization)
Definition revision_counter.h:62
bool operator<(const RevisionCounter &rhs) const
compare two states
Definition revision_counter.h:100
void invalidate()
invalidates state
Definition revision_counter.h:120
bool valid() const
returns if state is valid
Definition revision_counter.h:114
bool operator==(const RevisionCounter &rhs) const
compare two states
Definition revision_counter.h:88
#define UG_THROW(msg)
Definition error.h:57
ugtypes::uint64_t uint64
Definition types.h:117
the ug namespace