ATLAS Offline Software
Loading...
Searching...
No Matches
TestClass.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5//
9
10#ifndef SERIALIZER_TC
11#define SERIALIZER_TC
12
13#include <iostream>
14#include <vector>
15
16class TestClass {
17
18 public:
19 std::string key;
21
22 virtual ~TestClass(){}
23 virtual void print() const = 0;
24 virtual bool isEqual(const TestClass *otherobj) const = 0;
25 virtual std::string getKey() const {
26 return key;
27 }
28};
29
30
31
32class TestClass11 : public TestClass {
33 public:
34 int ai;
35
36 public:
38 TestClass11(const int i){
39 Set(i);
40 }
41 void Set(const int i){
42 ai=i;
43 }
44
46 void print() const { std::cout << "Output::TC11:Class of one integer = "<<"\t"
47 << ai << std:: endl;
48 }
49
50 std::string getKey() const {
51 return("TestClass11");
52 }
53
54 bool isEqual(const TestClass *otherobj) const {
55 TestClass11 *tc = (TestClass11 *)otherobj;
56 if(ai==tc->ai){
57 return true;
58 }
59 else{
60 return false;
61 }
62
63 }
64
65};
66
67
68class TestClass12 : public TestClass {
69 public:
70 int size;
71 int *p; //[size]
72
73 public:
75 p=NULL;}
76
77 TestClass12(const int i,const int s){
78 size=s;
79 p=new int[size];
80
81 for(int j=0;j<size;j++){
82 p[j]=10+i*j;
83 }
84 }
85
87 delete p;
88 }
89
90 void print() const {
91 std::cout << "Output::TC12 class of dynamic array of integers"<<std::endl;
92 for(int j=0; j<size; j++) {
93
94 std::cout<< p[j]<< "\t";
95
96 }
97 std::cout << std::endl;
98 }
99
100
101 std::string getKey() const {
102 return("TestClass12");
103 }
104
105 bool isEqual(const TestClass *otherobj) const {
106 TestClass12 *tc = (TestClass12 *)otherobj;
107 for(int j=0; j<size; j++){
108 if(p[j]==tc->p[j]){
109
110
111 }
112 else{
113 return false;
114 }
115
116 }
117 return true;
118 }
119 };
120
121class TestClass13 : public TestClass {
122 public:
123 int ai[3];
124
125 public:
127 TestClass13(const int i){ Set(i);
128 }
129 void Set(const int i){
130 for(int j=0;j<3;j++){
131 ai[j]=i+j;
132 }
133
134 }
135
136
138 void print() const { std::cout << "Output::TC13: array of integers "<<"\t"
139 << ai[0] <<"\t"
140 <<ai[1]<<"\t"
141 <<ai[2]<<std:: endl;
142 }
143
144 std::string getKey() const {
145 return("TestClass13");
146
147 }
148
149 bool isEqual(const TestClass *otherobj) const {
150 TestClass13 *tc = (TestClass13 *)otherobj;
151 for(int k=0;k<3;k++){
152 if(ai[k]==tc->ai[k]){
153
154
155 }
156 else{
157 return false;
158 }
159
160 }
161 return true;
162 }
163
164};
165
166
167class TestClass14 : public TestClass {
168 public:
170 std::string key;
171
172 public:
174 p=new TestClass11;
175 }
176 TestClass14(const int i){
177
178 p=new TestClass11(i);
179
180 }
181
182 ~TestClass14(){delete p;}
183 void print() const {
184 std::cout << "Output::TC14: Pointer to TestClass11(integer) "<<std::endl;
185 p->print();
186 }
187
188 bool isEqual(const TestClass *otherobj) const {
189 TestClass14 *tc = (TestClass14 *)otherobj;
190 return p->isEqual(tc->p);
191
192 }
193
194 std::string getKey() const {
195 return("TestClass14");
196 }
197
198};
199
200class TestClassA;
201
202class TestClassB: public TestClass{
203 public:
205
206 void SetA(TestClassA *ptr);
207 public:
208 TestClassB();
209 ~TestClassB();
210
211 void print()const{std::cout<<"TCB:" << this << " aa: " << aa <<std::endl;
212 }
213
214 std::string getKey() const {
215 return("TestClassB");
216 }
217
218 bool isEqual(const TestClass */*otherobj*/)const {
219 return false ;}
220};
221
222
223class TestClassA: public TestClass {
224 public:
226 int a;
227
228 public:
229 TestClassA();
230 ~TestClassA();
231
232 void print()const{
233 std::cout<<"TCA:"<<"\t"
234 << "bb: " << bb << " and this: " << this <<std::endl;
235
236 }
237
238 std::string getKey() const {
239 return("TestClassA");
240 }
241
242 bool isEqual(const TestClass */*otherobj*/) const {
243
244 return false;}
245};
246
248 aa=ptr;
249 ptr->print();
250
251}
252
253
255
256 bb=new TestClassB();
257 bb->SetA(this);
258 bb->print();
259}
260
261
263 delete bb;
264}
265
267 std::cout << "TestClassB::TestClassB()" << std::endl;
268}
269
270
272 std::cout << "TestClassB::~TestClassB()" << std::endl;
273}
274
275
276class TCBase : public TestClass {
277 public:
278 int ai;
279
280 public:
282 TCBase(const int i){Set(i);}
283 void Set(const int i){
284 ai=i;
285 }
286
287 virtual ~TCBase(){}
288
289 void print() const {
290 std::cout<<"Output:base class member:"<<ai<<std::endl;
291 }
292
293 bool isEqual(const TestClass *otherobj) const {
294 TCBase *tc=(TCBase *)otherobj;
295 if(ai==tc->ai){
296 }
297 else{
298 return false;
299 }
300 return true;
301 }
302 std::string getKey() const {
303 return("TCBase");
304 }
305
306};
307
308class TCIn :public TCBase {
309 public:
310 int ai;
311
312 public:
314 TCIn(const int i):TCBase((i-1)){Set(i);
315 }
316 void Set(const int i){
317 ai=i;
318
319 }
320
321 virtual ~TCIn(){}
322
323 void print() const {
324 std::cout<<"Output::inherited class member from TCBase:"<<ai<<std::endl;
325 }
326
327 bool isEqual(const TestClass *otherobj) const {
328 TCIn *tc=(TCIn *)otherobj;
329 if(ai==tc->ai){
330 }
331 else{
332 return false;
333 }
334 return true;
335 }
336
337 std::string getKey() const {
338 return("TCIn");
339 }
340
341};
342
343
344class TCIn1 :public TCBase {
345 public:
346
347 public:
349 TCIn1(const int i):TCBase(i){}
350
351 virtual ~TCIn1(){}
352
353 bool isEqual(const TestClass *otherobj) const {
354 TCIn1 *tc=(TCIn1 *)otherobj;
355 if(ai==tc->ai){
356
357 }
358 else{
359 return false;
360 }
361
362 return true;
363 }
364
365 std::string getKey() const {
366 return("TCIn1");
367
368 }
369};
370
371
372class TestClass2 : public TestClass{
373 public:
374 int a;
375 double b;
376 float c;
377
378 public:
380
381 TestClass2(const int i){Set(i);}
382 void Set(const int i){
383 a=i;}
384
385 TestClass2(const double i){Set(i);}
386 void Set(const double i){
387 b=i;}
388
389 TestClass2(const float i){Set(i);}
390 void Set(const float i){
391 c=i;}
392
394 void print()const{std::cout<< "TC2 "<<"\t"
395 << a <<"\t"
396 << b <<"\t"
397 << c <<std::endl;
398 }
399 std::string getKey() const {
400 return("TestClass2");
401
402 }
403 bool isEqual(const TestClass *otherobj) const {
404 TestClass2 *tc=(TestClass2 *)otherobj;
405 if(a){
406 if(a==tc->a){
407 return true;
408 }
409 else{
410 return false;
411 }
412 }
413 else if(b){
414 if(b==tc->b){
415 return true;
416 }
417 else{
418 return false;
419 }
420 }
421 else if(c){
422 if(c==tc->c){
423 return true;
424 }
425 else{
426 return false;
427 }
428 }
429 else{ return false;}
430 }
431};
432
433
434class TCvec : public TestClass {
435 public:
436 std::vector<int> my_integers;
437
438
439
440 public:
441 TCvec() {}
442 TCvec(const int i){ Set(i);
443
444 }
445 void Set(const int i){
446 for (int j=0; j<i; j++){
447 my_integers.push_back(j+i*2);
448 }
449
450 }
451
452
453
455 void print() const {
456 std::cout << "Output::"<< getKey() << " vector of integers: ";
457 const int maxsiz = (my_integers.size()<5 ? my_integers.size() : 5);
458 for (int i=0; i<maxsiz; i++){
459 std::cout << my_integers.at(i) << "\t";
460 }
461 std::cout << std::endl;
462
463 }
464
465
466
467
468 std::string getKey() const {
469 return("TCvec");
470
471 }
472
473 bool isEqual(const TestClass *otherobj) const {
474 TCvec *tc = (TCvec *)otherobj;
475 if(tc->my_integers.size()==my_integers.size()){
476 std::cout << "Output vectors same size" << std::endl;
477 for(int j=0; j<10; j++){
478 if(my_integers.at(j)==tc->my_integers.at(j)){
479 }
480 else{
481 return false;
482 }
483 }
484 return true;
485 }
486 else{
487 return false;
488 }
489 }
490
491};
492
493class TCvecPtr : public TestClass {
494public:
495 std::vector<int*> my_ptrint;
496
497public:
499 TCvecPtr(const int i){ Set(i);
500
501 }
502
503 void Set(const int i){
504 for (int j=0; j<i; j++){
505 my_ptrint.push_back(new int(j+i*10));
506 }
507 }
508
510 const int siz = my_ptrint.size();
511 for (int j=0; j<siz; j++) delete my_ptrint.at(j);
512 }
513
514 void print() const {
515 std::cout <<"Output::"<< getKey() << " vector of pointer to integers: ";
516 const int maxsiz = (my_ptrint.size()<5 ? my_ptrint.size() : 5);
517 // std::cout << "maxsiz=" << maxsiz "\t";
518 for (int i=0; i<maxsiz; i++)
519 std::cout << *(my_ptrint.at(i)) << "\t";
520 std::cout << std::endl;
521 }
522
523 std::string getKey() const {
524 return("TCvecPtr");
525
526 }
527
528 bool isEqual(const TestClass *otherobj) const {
529
530 TCvecPtr *tc = (TCvecPtr *)otherobj;
531 for(unsigned int j=0; j<my_ptrint.size(); j++){
532 if(tc->my_ptrint.at(j)){
533
534 }
535 else{
536 return false;
537 }
538 }
539 return true;
540 }
541
542};
543
544
545
546class TCvec1 : public TestClass {
547public:
548 std::vector<class TestClass11> my_TC;
549
550public:
552 /* TCvec1(const int i){ Set(i); */
553
554 /* } */
555 /* /\* void Set(const int i){ *\/ */
556 /* /\* for (int j=0; j<i; j++){ *\/ */
557 /* /\* my_TC.push_back(j); *\/ */
558 /* /\* } *\/ */
559
560 /* } */
561
562
563
565 void print() const { std::cout << "TCvec1 "<<std::endl;
566
567 }
568
569 std::string getKey() const {
570 return("TCvec1");
571
572 }
573
574 bool isEqual(const TestClass */*otherobj*/) const {
575 //TCvec1 *tc = (TCvec1 *)otherobj;
576 /* for(int j=0; j<10; j++){ */
577/* if(tc->my_TC.at(j)){ */
578
579/* std::cout << "true for int"<< "\t" */
580/* << my_TC.at(j)<<std::endl; */
581/* //return true; */
582/* } */
583/* else{ */
584/* //return false; */
585/* std::cout << "false for int"<<"\t" */
586/* << my_TC.at(j)<<std::endl; */
587/* // return false; */
588/* } */
589/* } */
590 return false;
591 }
592
593};
594
595#endif
596
static Double_t tc
int ai
Definition TestClass.h:278
void print() const
Definition TestClass.h:289
TCBase(const int i)
Definition TestClass.h:282
bool isEqual(const TestClass *otherobj) const
Definition TestClass.h:293
std::string getKey() const
Definition TestClass.h:302
void Set(const int i)
Definition TestClass.h:283
virtual ~TCBase()
Definition TestClass.h:287
virtual ~TCIn1()
Definition TestClass.h:351
bool isEqual(const TestClass *otherobj) const
Definition TestClass.h:353
TCIn1()
Definition TestClass.h:348
TCIn1(const int i)
Definition TestClass.h:349
std::string getKey() const
Definition TestClass.h:365
TCIn()
Definition TestClass.h:313
TCIn(const int i)
Definition TestClass.h:314
std::string getKey() const
Definition TestClass.h:337
virtual ~TCIn()
Definition TestClass.h:321
void print() const
Definition TestClass.h:323
int ai
Definition TestClass.h:310
bool isEqual(const TestClass *otherobj) const
Definition TestClass.h:327
void Set(const int i)
Definition TestClass.h:316
void print() const
Definition TestClass.h:565
std::string getKey() const
Definition TestClass.h:569
bool isEqual(const TestClass *) const
Definition TestClass.h:574
std::vector< class TestClass11 > my_TC
Definition TestClass.h:548
~TCvec1()
Definition TestClass.h:564
bool isEqual(const TestClass *otherobj) const
Definition TestClass.h:528
void print() const
Definition TestClass.h:514
void Set(const int i)
Definition TestClass.h:503
std::string getKey() const
Definition TestClass.h:523
TCvecPtr(const int i)
Definition TestClass.h:499
std::vector< int * > my_ptrint
Definition TestClass.h:495
std::string getKey() const
Definition TestClass.h:468
std::vector< int > my_integers
Definition TestClass.h:436
TCvec(const int i)
Definition TestClass.h:442
void Set(const int i)
Definition TestClass.h:445
bool isEqual(const TestClass *otherobj) const
Definition TestClass.h:473
TCvec()
Definition TestClass.h:441
void print() const
Definition TestClass.h:455
~TCvec()
Definition TestClass.h:454
std::string getKey() const
Definition TestClass.h:50
TestClass11(const int i)
Definition TestClass.h:38
bool isEqual(const TestClass *otherobj) const
Definition TestClass.h:54
void Set(const int i)
Definition TestClass.h:41
void print() const
Definition TestClass.h:46
void print() const
Definition TestClass.h:90
bool isEqual(const TestClass *otherobj) const
Definition TestClass.h:105
TestClass12(const int i, const int s)
Definition TestClass.h:77
std::string getKey() const
Definition TestClass.h:101
std::string getKey() const
Definition TestClass.h:144
void Set(const int i)
Definition TestClass.h:129
void print() const
Definition TestClass.h:138
int ai[3]
Definition TestClass.h:123
TestClass13(const int i)
Definition TestClass.h:127
bool isEqual(const TestClass *otherobj) const
Definition TestClass.h:149
bool isEqual(const TestClass *otherobj) const
Definition TestClass.h:188
std::string getKey() const
Definition TestClass.h:194
TestClass11 * p
Definition TestClass.h:169
void print() const
Definition TestClass.h:183
std::string key
Definition TestClass.h:170
TestClass14(const int i)
Definition TestClass.h:176
TestClass2(const int i)
Definition TestClass.h:381
double b
Definition TestClass.h:375
void Set(const int i)
Definition TestClass.h:382
TestClass2(const double i)
Definition TestClass.h:385
std::string getKey() const
Definition TestClass.h:399
bool isEqual(const TestClass *otherobj) const
Definition TestClass.h:403
TestClass2(const float i)
Definition TestClass.h:389
void Set(const float i)
Definition TestClass.h:390
void Set(const double i)
Definition TestClass.h:386
void print() const
Definition TestClass.h:394
std::string getKey() const
Definition TestClass.h:238
TestClassB * bb
Definition TestClass.h:225
void print() const
Definition TestClass.h:232
bool isEqual(const TestClass *) const
Definition TestClass.h:242
std::string getKey() const
Definition TestClass.h:214
void SetA(TestClassA *ptr)
Definition TestClass.h:247
TestClassA * aa
Definition TestClass.h:204
void print() const
Definition TestClass.h:211
bool isEqual(const TestClass *) const
Definition TestClass.h:218
Test classes for the Serializer 2006/07 Sara.Maguerite.Traynor@cern.ch.
Definition TestClass.h:16
virtual ~TestClass()
Definition TestClass.h:22
virtual void print() const =0
std::string key
Definition TestClass.h:19
virtual bool isEqual(const TestClass *otherobj) const =0
virtual std::string getKey() const
Definition TestClass.h:25
struct _Set Set
Represents a set of values.
Definition set.h:59