Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
rw_value.h
Go to the documentation of this file.
1
29#ifndef RW_VALUE_H_INCLUDED
30#define RW_VALUE_H_INCLUDED
31
32#include <rw_testdefs.h>
33#include <rw_alg_test.h> // for conv_to_bool
34
35
38{
39 int val_; // object's value
40};
41
42
45{
47
48 static UserPOD
49 from_char (char c)
50 {
51 UserPOD x;
52 x.data_.val_ = c;
53 return x;
54 }
55
56 // construct an array of objects of type UserPOD each initialized
57 // from the corresponding element of the character array
58 // when the last argument is true and the character array
59 // is not sorted in ascending order the function fails by
60 // returning 0
61 static UserPOD*
62 from_char (const char*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX,
63 bool = false);
64
65 // returns a pointer to the first element in the sequence of UserClass
66 // whose value is not equal to the corresponding element of
67 // the character string or 0 when no such element exists
68 static const UserPOD* mismatch (const UserPOD*, const char*,
69 _RWSTD_SIZE_T /* len */ = _RWSTD_SIZE_MAX);
70};
71
72
74// objects of class UserClass maintain a count of their instances in existence,
75// the number of defaut and copy ctor calls, assignment operators, and
76// the number of calls to operator==() and operator<()
78{
80
81 const int id_; // a unique non-zero id of the object
82 int origin_; // id of the original object that this
83 // is a (perhaps indirect) copy of (id_
84 // when this is the original)
85 int src_id_; // id of the object that this is a direct
86 // copy of (id_ when this the original)
87
88 // number of times the object has been copied into another object,
89 // regardless of whether the operation threw an exception or not
90 _RWSTD_SIZE_T n_copy_ctor_;
91
92 // number of times the object's assignment operator has been invoked,
93 // regardless of whether the operation threw an exception or not
94 _RWSTD_SIZE_T n_op_assign_;
95
96 // number of times the object's operator+=() has been invoked,
97 // regardless of whether the operation threw an exception or not
98 _RWSTD_SIZE_T n_op_plus_assign_;
99
100 // number of times the object's operator-=() has been invoked,
101 // regardless of whether the operation threw an exception or not
102 _RWSTD_SIZE_T n_op_minus_assign_;
103
104 // number of times the object's operator*=() has been invoked,
105 // regardless of whether the operation threw an exception or not
106 _RWSTD_SIZE_T n_op_times_assign_;
107
108 // number of times the object's operator/=() has been invoked,
109 // regardless of whether the operation threw an exception or not
110 _RWSTD_SIZE_T n_op_div_assign_;
111
112 // number of times the object's operator== was invoked
113 // regardless of whether the operation threw an exception
114 _RWSTD_SIZE_T n_op_eq_;
115
116 // number of times the object's operator< was invoked
117 // regardless of whether the operation threw an exception
118 _RWSTD_SIZE_T n_op_lt_;
119
120 static _RWSTD_SIZE_T count_; // number of objects in existence (>= 0)
121 static int id_gen_; // generates a unique non-zero id
122 static int (*gen_)(); // extern "C++" int (*)()
123
124 static _RWSTD_SIZE_T n_total_def_ctor_; // number of default ctor calls
125 static _RWSTD_SIZE_T n_total_copy_ctor_; // ... copy ctors ...
126 static _RWSTD_SIZE_T n_total_dtor_; // ... dtors ...
127 static _RWSTD_SIZE_T n_total_op_assign_; // ... assignment operators ...
128 static _RWSTD_SIZE_T n_total_op_plus_assign_; // ... operator+=
129 static _RWSTD_SIZE_T n_total_op_minus_assign_; // ... operator-=
130 static _RWSTD_SIZE_T n_total_op_times_assign_; // ... operator*=
131 static _RWSTD_SIZE_T n_total_op_div_assign_; // ... operator/=
132 static _RWSTD_SIZE_T n_total_op_eq_; // ... equality operators ...
133 static _RWSTD_SIZE_T n_total_op_lt_; // ... operators <= ...
134
135 // classes thrown from the respective functions
136 struct Exception { int id_; };
137 struct DefCtor: Exception { };
138 struct CopyCtor: Exception { };
139 struct Dtor: Exception { };
140 struct OpAssign: Exception { };
145 struct OpEq: Exception { };
146 struct OpLt: Exception { };
147
148 // throw object's `id' wrapped in the appropriate struct when the
149 // corresponding n_total_xxx_ counter reaches the value pointed to
150 // by the respective pointer below
151 static _RWSTD_SIZE_T* def_ctor_throw_ptr_;
152 static _RWSTD_SIZE_T* copy_ctor_throw_ptr_;
153 static _RWSTD_SIZE_T* dtor_throw_ptr_;
154 static _RWSTD_SIZE_T* op_assign_throw_ptr_;
155 static _RWSTD_SIZE_T* op_plus_assign_throw_ptr_;
156 static _RWSTD_SIZE_T* op_minus_assign_throw_ptr_;
157 static _RWSTD_SIZE_T* op_times_assign_throw_ptr_;
158 static _RWSTD_SIZE_T* op_div_assign_throw_ptr_;
159 static _RWSTD_SIZE_T* op_eq_throw_ptr_;
160 static _RWSTD_SIZE_T* op_lt_throw_ptr_;
161
162 // objects to which the pointers above initally point
163 static _RWSTD_SIZE_T def_ctor_throw_count_;
164 static _RWSTD_SIZE_T copy_ctor_throw_count_;
165 static _RWSTD_SIZE_T dtor_throw_count_;
166 static _RWSTD_SIZE_T op_assign_throw_count_;
167 static _RWSTD_SIZE_T op_plus_assign_throw_count_;
168 static _RWSTD_SIZE_T op_minus_assign_throw_count_;
169 static _RWSTD_SIZE_T op_times_assign_throw_count_;
170 static _RWSTD_SIZE_T op_div_assign_throw_count_;
171 static _RWSTD_SIZE_T op_eq_throw_count_;
172 static _RWSTD_SIZE_T op_lt_throw_count_;
173
174 UserClass ();
175
176 UserClass (const UserClass&);
177
178 ~UserClass ();
179
180 UserClass& operator= (const UserClass&);
181 UserClass& operator+= (const UserClass&);
182 UserClass& operator-= (const UserClass&);
183 UserClass& operator*= (const UserClass&);
184 UserClass& operator/= (const UserClass&);
185
186 bool operator== (const UserClass&) const;
187 bool operator< (const UserClass&) const;
188
189 // the following operators are not declared or defined in order
190 // to detect any unwarranted assumptions made in algorithms
191 // bool operator!= (const UserClass &rhs) const;
192 // bool operator> (const UserClass &rhs) const;
193 // bool operator>= (const UserClass &rhs) const;
194 // bool operator<= (const UserClass &rhs) const;
195 // UserClass operator- () const;
196 // UserClass operator+ () const;
197
198 bool
199 is_count (_RWSTD_SIZE_T copy_ctor,
200 _RWSTD_SIZE_T op_assign,
201 _RWSTD_SIZE_T op_eq,
202 _RWSTD_SIZE_T op_lt) const;
203
204 static bool
205 is_total (_RWSTD_SIZE_T count,
206 _RWSTD_SIZE_T n_def_ctor,
207 _RWSTD_SIZE_T n_copy_ctor,
208 _RWSTD_SIZE_T n_op_assign,
209 _RWSTD_SIZE_T n_op_eq,
210 _RWSTD_SIZE_T n_op_lt);
211
212 // returns a pointer to the first element in the sequence whose value
213 // is less than the value of the immediately preceding element, or 0
214 // when no such element exists
215 static const UserClass*
216 first_less (const UserClass*, _RWSTD_SIZE_T);
217
218 static void reset_totals ();
219
220 static UserClass
222 {
223 UserClass x;
224 x.data_.val_ = c;
225 return x;
226 }
227
228 // construct an array of objects of type UserClass each initialized
229 // from the corresponding element of the character array
230 // when the last argument is true and the character array
231 // is not sorted in ascending order the function fails by
232 // returning 0
233 static UserClass*
234 from_char (const char*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX,
235 bool = false);
236
237 // returns -1 when less, 0 when same, or +1 when the array
238 // of UserClass objects is greater than the character string
239 static int compare (const UserClass*, const char*,
240 _RWSTD_SIZE_T = _RWSTD_SIZE_MAX);
241 static int compare (const char*, const UserClass*,
242 _RWSTD_SIZE_T = _RWSTD_SIZE_MAX);
243
244 // returns -1 when less, 0 when same, or +1 when the first
245 // array of UserClass objects is greater than the second array
246 static int compare (const UserClass*, const UserClass*, _RWSTD_SIZE_T);
247
248 // returns a pointer to the first element in the sequence of UserClass
249 // whose value is not equal to the corresponding element of
250 // the character string or 0 when no such element exists
251 static const UserClass* mismatch (const UserClass*, const char*,
252 _RWSTD_SIZE_T);
253
254 struct Less;
255
256private:
257
258 enum assign_op {
259 op_assign, op_plus_assign, op_minus_assign,
260 op_times_assign, op_div_assign
261 };
262
263 void assign (assign_op, const UserClass&);
264};
265
266
269{
270 // total number of times operator() was invoked
271 static _RWSTD_SIZE_T n_total_op_fcall_;
272
274
276
277 UnaryPredicate& operator= (const UnaryPredicate&);
278
279 virtual ~UnaryPredicate ();
280
281 virtual conv_to_bool operator()(const UserClass&) const;
282};
283
284
286{
287 // total number of times operator() was invoked
288 static _RWSTD_SIZE_T n_total_op_fcall_;
289
296 op_greater_equal
297 };
298
299 BinaryPredicate (binary_op);
300
301 virtual ~BinaryPredicate ();
302
303 virtual conv_to_bool operator()(const UserClass&,
304 const UserClass&) /* non-const */;
305
306private:
307
308 // not assignable
309 void operator= (const BinaryPredicate&);
310
311 binary_op op_;
312};
313
314
316{
317 // dummy arguments provided to prevent the class from being
318 // default constructible and implicit conversion from int
319 Less (int /* dummy */, int /* dummy */)
320 : BinaryPredicate (BinaryPredicate::op_less) { /* no-op */ }
321};
322
323
324static const struct _TEST_EXPORT UserClassFmatInit {
325 UserClassFmatInit ();
326} _rw_user_class_fmat_init;
327
328
329#endif // RW_VALUE_H_INCLUDED
void count(T, T, const U &,...)
#define BinaryPredicate
Definition 17.names.cpp:451
#define x
Definition 17.names.cpp:140
#define c
Definition 17.names.cpp:111
bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14737
bool operator<(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14787
#define _TEST_EXPORT
Definition rw_testdefs.h:55
static _RWSTD_SIZE_T n_total_op_fcall_
Definition rw_value.h:288
static _RWSTD_SIZE_T n_total_op_fcall_
Definition rw_value.h:271
Less(int, int)
Definition rw_value.h:319
int origin_
Definition rw_value.h:82
_RWSTD_SIZE_T n_copy_ctor_
Definition rw_value.h:90
_RWSTD_SIZE_T n_op_minus_assign_
Definition rw_value.h:102
static _RWSTD_SIZE_T n_total_op_eq_
Definition rw_value.h:132
static _RWSTD_SIZE_T n_total_op_times_assign_
Definition rw_value.h:130
static _RWSTD_SIZE_T * op_minus_assign_throw_ptr_
Definition rw_value.h:156
static _RWSTD_SIZE_T * op_lt_throw_ptr_
Definition rw_value.h:160
static _RWSTD_SIZE_T n_total_dtor_
Definition rw_value.h:126
_RWSTD_SIZE_T n_op_eq_
Definition rw_value.h:114
static _RWSTD_SIZE_T dtor_throw_count_
Definition rw_value.h:165
static _RWSTD_SIZE_T * op_eq_throw_ptr_
Definition rw_value.h:159
static _RWSTD_SIZE_T n_total_op_assign_
Definition rw_value.h:127
const int id_
Definition rw_value.h:81
static _RWSTD_SIZE_T * op_div_assign_throw_ptr_
Definition rw_value.h:158
_RWSTD_SIZE_T n_op_times_assign_
Definition rw_value.h:106
_RWSTD_SIZE_T n_op_assign_
Definition rw_value.h:94
static _RWSTD_SIZE_T * def_ctor_throw_ptr_
Definition rw_value.h:151
static _RWSTD_SIZE_T * op_plus_assign_throw_ptr_
Definition rw_value.h:155
static UserClass from_char(char c)
Definition rw_value.h:221
int src_id_
Definition rw_value.h:85
static _RWSTD_SIZE_T * copy_ctor_throw_ptr_
Definition rw_value.h:152
_RWSTD_SIZE_T n_op_lt_
Definition rw_value.h:118
static UserClass * from_char(const char *, _RWSTD_SIZE_T=_RWSTD_SIZE_MAX, bool=false)
static _RWSTD_SIZE_T def_ctor_throw_count_
Definition rw_value.h:163
UserData data_
Definition rw_value.h:79
static _RWSTD_SIZE_T * dtor_throw_ptr_
Definition rw_value.h:153
static _RWSTD_SIZE_T copy_ctor_throw_count_
Definition rw_value.h:164
_RWSTD_SIZE_T n_op_div_assign_
Definition rw_value.h:110
static _RWSTD_SIZE_T n_total_op_minus_assign_
Definition rw_value.h:129
static _RWSTD_SIZE_T op_eq_throw_count_
Definition rw_value.h:171
static _RWSTD_SIZE_T op_times_assign_throw_count_
Definition rw_value.h:169
static _RWSTD_SIZE_T op_plus_assign_throw_count_
Definition rw_value.h:167
static _RWSTD_SIZE_T count_
Definition rw_value.h:120
static _RWSTD_SIZE_T n_total_op_div_assign_
Definition rw_value.h:131
static int id_gen_
Definition rw_value.h:121
static int compare(const UserClass *, const UserClass *, _RWSTD_SIZE_T)
static _RWSTD_SIZE_T op_lt_throw_count_
Definition rw_value.h:172
static _RWSTD_SIZE_T n_total_op_plus_assign_
Definition rw_value.h:128
static _RWSTD_SIZE_T n_total_op_lt_
Definition rw_value.h:133
static int compare(const char *, const UserClass *, _RWSTD_SIZE_T=_RWSTD_SIZE_MAX)
_RWSTD_SIZE_T n_op_plus_assign_
Definition rw_value.h:98
static int compare(const UserClass *, const char *, _RWSTD_SIZE_T=_RWSTD_SIZE_MAX)
static _RWSTD_SIZE_T * op_assign_throw_ptr_
Definition rw_value.h:154
static _RWSTD_SIZE_T op_assign_throw_count_
Definition rw_value.h:166
static _RWSTD_SIZE_T op_minus_assign_throw_count_
Definition rw_value.h:168
static _RWSTD_SIZE_T * op_times_assign_throw_ptr_
Definition rw_value.h:157
static _RWSTD_SIZE_T n_total_def_ctor_
Definition rw_value.h:124
static _RWSTD_SIZE_T n_total_copy_ctor_
Definition rw_value.h:125
static _RWSTD_SIZE_T op_div_assign_throw_count_
Definition rw_value.h:170
int val_
Definition rw_value.h:39
static UserPOD from_char(char c)
Definition rw_value.h:49
UserData data_
Definition rw_value.h:46
static UserPOD * from_char(const char *, _RWSTD_SIZE_T=_RWSTD_SIZE_MAX, bool=false)