distortos  v0.4.0
object-oriented C++ RTOS for microcontrollers
OperationCountingType.hpp
Go to the documentation of this file.
1 
12 #ifndef TEST_OPERATIONCOUNTINGTYPE_HPP_
13 #define TEST_OPERATIONCOUNTINGTYPE_HPP_
14 
15 #include <utility>
16 
17 #include <cstddef>
18 
19 namespace distortos
20 {
21 
22 namespace test
23 {
24 
28 {
29 public:
30 
32  using Value = unsigned int;
33 
40  explicit OperationCountingType(const Value value = {}) :
41  value_{value}
42  {
43  ++constructed_;
44  }
45 
53  value_{other.value_}
54  {
56  }
57 
65  value_{other.value_}
66  {
67  other.value_ = {};
69  }
70 
76  {
77  value_ = {};
78  ++destructed_;
79  }
80 
90  {
91  value_ = other.value_;
92  ++copyAssigned_;
93  return *this;
94  }
95 
105  {
106  value_ = other.value_;
107  other.value_ = {};
108  ++moveAssigned_;
109  return *this;
110  }
111 
120  {
121  using std::swap;
122  swap(left.value_, right.value_);
123  ++swapped_;
124  }
125 
135  friend bool operator==(const OperationCountingType& left, const OperationCountingType& right)
136  {
137  return left.value_ == right.value_;
138  }
139 
144  Value getValue() const
145  {
146  return value_;
147  }
148 
163  static bool checkCounters(size_t constructed, size_t copyConstructed, size_t moveConstructed, size_t destructed,
164  size_t copyAssigned, size_t moveAssigned, size_t swapped);
165 
170  static void resetCounters();
171 
172 private:
173 
176 
178  static size_t constructed_;
179 
181  static size_t copyConstructed_;
182 
184  static size_t moveConstructed_;
185 
187  static size_t destructed_;
188 
190  static size_t copyAssigned_;
191 
193  static size_t moveAssigned_;
194 
196  static size_t swapped_;
197 };
198 
208 inline bool operator!=(const OperationCountingType& left, const OperationCountingType& right)
209 {
210  return (left == right) == false;
211 }
212 
213 } // namespace test
214 
215 } // namespace distortos
216 
217 #endif // TEST_OPERATIONCOUNTINGTYPE_HPP_
static size_t swapped_
counter of swap calls since last resetCounters() call
Definition: OperationCountingType.hpp:196
OperationCountingType(const Value value={})
OperationCountingType&#39;s constructor.
Definition: OperationCountingType.hpp:40
Value getValue() const
Definition: OperationCountingType.hpp:144
OperationCountingType(const OperationCountingType &other)
OperationCountingType&#39;s copy constructor.
Definition: OperationCountingType.hpp:52
Value value_
value held by object
Definition: OperationCountingType.hpp:175
static size_t copyAssigned_
counter of copy assignment calls since last resetCounters() call
Definition: OperationCountingType.hpp:190
Definition: OperationCountingType.hpp:27
OperationCountingType & operator=(OperationCountingType &&other)
OperationCountingType&#39;s move assignment.
Definition: OperationCountingType.hpp:104
static size_t constructed_
counter of constructor calls since last resetCounters() call
Definition: OperationCountingType.hpp:178
friend bool operator==(const OperationCountingType &left, const OperationCountingType &right)
Equality comparison operator for OperationCountingType.
Definition: OperationCountingType.hpp:135
friend void swap(OperationCountingType &left, OperationCountingType &right)
OperationCountingType&#39;s swap overload.
Definition: OperationCountingType.hpp:119
static void resetCounters()
Resets value of all counters.
Definition: OperationCountingType.cpp:33
static size_t moveAssigned_
counter of move assignment calls since last resetCounters() call
Definition: OperationCountingType.hpp:193
Top-level namespace of distortos project.
bool operator!=(const OperationCountingType &left, const OperationCountingType &right)
Inequality comparison operator for OperationCountingType.
Definition: OperationCountingType.hpp:208
~OperationCountingType()
OperationCountingType&#39;s destructor.
Definition: OperationCountingType.hpp:75
void swap(IntrusiveForwardListNode &left, IntrusiveForwardListNode &right)
Swaps contents of two nodes.
Definition: IntrusiveForwardList.hpp:172
static bool checkCounters(size_t constructed, size_t copyConstructed, size_t moveConstructed, size_t destructed, size_t copyAssigned, size_t moveAssigned, size_t swapped)
Checks value of counters.
Definition: OperationCountingType.cpp:24
static size_t destructed_
counter of destructor calls since last resetCounters() call
Definition: OperationCountingType.hpp:187
OperationCountingType(OperationCountingType &&other)
OperationCountingType&#39;s move constructor.
Definition: OperationCountingType.hpp:64
static size_t copyConstructed_
counter of copy constructor calls since last resetCounters() call
Definition: OperationCountingType.hpp:181
static size_t moveConstructed_
counter of move constructor calls since last resetCounters() call
Definition: OperationCountingType.hpp:184
OperationCountingType & operator=(const OperationCountingType &other)
OperationCountingType&#39;s copy assignment.
Definition: OperationCountingType.hpp:89
unsigned int Value
type used for OperationCountingType&#39;s "value"
Definition: OperationCountingType.hpp:32