Nektar++
CountedObject.h
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: CountedObject.h
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description:
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#ifndef NEKTAR_UNIT_TESTS_COUNTED_OBJECT_H
36#define NEKTAR_UNIT_TESTS_COUNTED_OBJECT_H
37
38#include <boost/test/unit_test.hpp>
39#include <iostream>
40
41namespace Nektar
42{
43
44template <typename DerivedType> class CountedObject
45{
46public:
48 {
50 }
51
52 explicit CountedObject(unsigned int v) : value(v)
53 {
56 }
57
58 CountedObject(unsigned int a1, unsigned int a2) : value(a1 + a2)
59 {
61 }
62
63 CountedObject(unsigned int a1, unsigned int a2, unsigned int a3)
64 : value(a1 + a2 + a3)
65 {
67 }
68
70 {
72 }
73
75 {
77 }
78
80 {
82 value = rhs.value;
83 return *this;
84 }
85
87 {
88 return value == rhs.value;
89 }
90
92 {
93 return !(*this == rhs);
94 }
95
97 {
99 return new CountedObject<DerivedType>(*this);
100 }
101
102 static void ClearCounters()
103 {
106 numberDestroyed = 0;
107 numberCopied = 0;
108 numberAssigned = 0;
109 numberCloned = 0;
115 }
116
117 static void Check(unsigned int expectedDefaultConstructed,
118 unsigned int expectedConstructedFromInt,
119 unsigned int expectedDestroyed,
120 unsigned int expectedCopied, unsigned int expectedCloned,
121 unsigned int expectedAssigned)
122 {
123 BOOST_CHECK_EQUAL(numberDefaultConstructed, expectedDefaultConstructed);
124 BOOST_CHECK_EQUAL(numberConstructedFromInt, expectedConstructedFromInt);
125 BOOST_CHECK_EQUAL(numberDestroyed, expectedDestroyed);
126 BOOST_CHECK_EQUAL(numberCopied, expectedCopied);
127 BOOST_CHECK_EQUAL(numberAssigned, expectedAssigned);
128 BOOST_CHECK_EQUAL(numberCloned, expectedCloned);
129 }
130
131 unsigned int GetValue() const
132 {
133 return value;
134 }
135 operator unsigned int() const
136 {
137 return value;
138 }
139 unsigned int value;
140
141 static unsigned int numberDefaultConstructed;
142 static unsigned int numberConstructedFromInt;
143 static unsigned int numberDestroyed;
144 static unsigned int numberCopied;
145 static unsigned int numberAssigned;
146 static unsigned int numberCloned;
151 static unsigned int numberOfExpressionAssignments;
152};
153
154template <typename T>
155std::ostream &operator<<(std::ostream &os, const CountedObject<T> &lhs)
156{
157 os << lhs.GetValue();
158 return os;
159}
160
161template <typename DerivedType>
163
164template <typename DerivedType>
166
167template <typename DerivedType>
169
170template <typename DerivedType>
172
173template <typename DerivedType>
175
176template <typename DerivedType>
178
179template <typename DerivedType>
181
182template <typename DerivedType>
184
185template <typename DerivedType>
187
188template <typename DerivedType>
190
191template <typename DerivedType>
193} // namespace Nektar
194
195#endif // NEKTAR_UNIT_TESTS_COUNTED_OBJECT_H
static unsigned int numberConstructedFromInt
static unsigned int numberDestroyed
static unsigned int numberCopied
bool operator==(const CountedObject< DerivedType > &rhs) const
Definition: CountedObject.h:86
CountedObject< DerivedType > * clone() const
Definition: CountedObject.h:96
static unsigned int numberOfExpressionConstructions
static unsigned int numberOf3ParameterConstructions
static unsigned int numberOf1ParameterConstructions
static unsigned int numberAssigned
static void Check(unsigned int expectedDefaultConstructed, unsigned int expectedConstructedFromInt, unsigned int expectedDestroyed, unsigned int expectedCopied, unsigned int expectedCloned, unsigned int expectedAssigned)
CountedObject(unsigned int a1, unsigned int a2, unsigned int a3)
Definition: CountedObject.h:63
static void ClearCounters()
unsigned int GetValue() const
static unsigned int numberDefaultConstructed
CountedObject(const CountedObject< DerivedType > &rhs)
Definition: CountedObject.h:69
static unsigned int numberOfExpressionAssignments
bool operator!=(const CountedObject< DerivedType > &rhs) const
Definition: CountedObject.h:91
CountedObject(unsigned int a1, unsigned int a2)
Definition: CountedObject.h:58
CountedObject< DerivedType > & operator=(const CountedObject< DerivedType > &rhs)
Definition: CountedObject.h:79
CountedObject(unsigned int v)
Definition: CountedObject.h:52
static unsigned int numberCloned
static unsigned int numberOf2ParameterConstructions
std::ostream & operator<<(std::ostream &os, const NekMatrix< DataType, FormType > &rhs)
Definition: NekMatrix.hpp:49