ATLAS Offline Software
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 
16 class 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 
32 class 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 
68 class 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 
121 class 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 
167 class 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 
200 class TestClassA;
201 
202 class 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 
223 class 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 
276 class TCBase : public TestClass {
277  public:
278  int ai;
279 
280  public:
281  TCBase(){}
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 
308 class TCIn :public TCBase {
309  public:
310  int ai;
311 
312  public:
313  TCIn(){}
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 
344 class TCIn1 :public TCBase {
345  public:
346 
347  public:
348  TCIn1(){}
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 
372 class 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 
434 class 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 
454  ~TCvec(){}
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 
493 class TCvecPtr : public TestClass {
494 public:
495  std::vector<int*> my_ptrint;
496 
497 public:
498  TCvecPtr() {}
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 
546 class TCvec1 : public TestClass {
547 public:
548  std::vector<class TestClass11> my_TC;
549 
550 public:
551  TCvec1() {}
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 
TCvec::print
void print() const
Definition: TestClass.h:455
TCvec1::isEqual
bool isEqual(const TestClass *) const
Definition: TestClass.h:574
TestClass14::p
TestClass11 * p
Definition: TestClass.h:169
TCBase::TCBase
TCBase(const int i)
Definition: TestClass.h:282
TestClassA::TestClassA
TestClassA()
Definition: TestClass.h:254
TCIn1::~TCIn1
virtual ~TCIn1()
Definition: TestClass.h:351
TCIn::Set
void Set(const int i)
Definition: TestClass.h:316
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
TCvecPtr::~TCvecPtr
~TCvecPtr()
Definition: TestClass.h:509
TestClass2::print
void print() const
Definition: TestClass.h:394
TestClass2::a
int a
Definition: TestClass.h:374
TestClass14::~TestClass14
~TestClass14()
Definition: TestClass.h:182
TestClassB::~TestClassB
~TestClassB()
Definition: TestClass.h:271
TestClassA::getKey
std::string getKey() const
Definition: TestClass.h:238
TestClass14::key
std::string key
Definition: TestClass.h:170
TCIn::~TCIn
virtual ~TCIn()
Definition: TestClass.h:321
TCvec::TCvec
TCvec(const int i)
Definition: TestClass.h:442
TestClass2::Set
void Set(const float i)
Definition: TestClass.h:390
TestClass13::TestClass13
TestClass13()
Definition: TestClass.h:126
TCvec::isEqual
bool isEqual(const TestClass *otherobj) const
Definition: TestClass.h:473
TCvec1::~TCvec1
~TCvec1()
Definition: TestClass.h:564
TestClass2
Definition: TestClass.h:372
TCIn1::TCIn1
TCIn1(const int i)
Definition: TestClass.h:349
TCvec1::print
void print() const
Definition: TestClass.h:565
TestClass13::TestClass13
TestClass13(const int i)
Definition: TestClass.h:127
TestClass2::getKey
std::string getKey() const
Definition: TestClass.h:399
TestClass2::Set
void Set(const double i)
Definition: TestClass.h:386
TestClassB::aa
TestClassA * aa
Definition: TestClass.h:204
TestClass11::~TestClass11
~TestClass11()
Definition: TestClass.h:45
TestClass13::ai
int ai[3]
Definition: TestClass.h:123
TestClass14::TestClass14
TestClass14()
Definition: TestClass.h:173
TestClass14::print
void print() const
Definition: TestClass.h:183
TestClass2::TestClass2
TestClass2()
Definition: TestClass.h:379
TCIn1::isEqual
bool isEqual(const TestClass *otherobj) const
Definition: TestClass.h:353
TestClass12::~TestClass12
~TestClass12()
Definition: TestClass.h:86
TCBase::ai
int ai
Definition: TestClass.h:278
TestClass::getKey
virtual std::string getKey() const
Definition: TestClass.h:25
TCIn::isEqual
bool isEqual(const TestClass *otherobj) const
Definition: TestClass.h:327
TCIn1::getKey
std::string getKey() const
Definition: TestClass.h:365
TCvecPtr::getKey
std::string getKey() const
Definition: TestClass.h:523
TestClass11::isEqual
bool isEqual(const TestClass *otherobj) const
Definition: TestClass.h:54
TCIn1::TCIn1
TCIn1()
Definition: TestClass.h:348
TestClass2::c
float c
Definition: TestClass.h:376
TestClassA::isEqual
bool isEqual(const TestClass *) const
Definition: TestClass.h:242
TestClass13::~TestClass13
~TestClass13()
Definition: TestClass.h:137
TCvec
Definition: TestClass.h:434
TCvecPtr::print
void print() const
Definition: TestClass.h:514
TestClass12::size
int size
Definition: TestClass.h:70
TestClassB::isEqual
bool isEqual(const TestClass *) const
Definition: TestClass.h:218
TCvec1::TCvec1
TCvec1()
Definition: TestClass.h:551
TCIn1
Definition: TestClass.h:344
TCvec1
Definition: TestClass.h:546
TestClass14
Definition: TestClass.h:167
TCBase::Set
void Set(const int i)
Definition: TestClass.h:283
TestClass2::Set
void Set(const int i)
Definition: TestClass.h:382
TCIn::ai
int ai
Definition: TestClass.h:310
TestClass2::~TestClass2
~TestClass2()
Definition: TestClass.h:393
TCBase::print
void print() const
Definition: TestClass.h:289
TestClass14::TestClass14
TestClass14(const int i)
Definition: TestClass.h:176
lumiFormat.i
int i
Definition: lumiFormat.py:92
TestClass13::Set
void Set(const int i)
Definition: TestClass.h:129
TestClassA::a
int a
Definition: TestClass.h:226
TestClass14::isEqual
bool isEqual(const TestClass *otherobj) const
Definition: TestClass.h:188
TCvec::Set
void Set(const int i)
Definition: TestClass.h:445
TCBase::isEqual
bool isEqual(const TestClass *otherobj) const
Definition: TestClass.h:293
TestClass11::TestClass11
TestClass11(const int i)
Definition: TestClass.h:38
TCBase::~TCBase
virtual ~TCBase()
Definition: TestClass.h:287
TCvec1::my_TC
std::vector< class TestClass11 > my_TC
Definition: TestClass.h:548
TestClass::key
std::string key
Definition: TestClass.h:19
TestClass12
Definition: TestClass.h:68
TestClassB::print
void print() const
Definition: TestClass.h:211
TestClass13::print
void print() const
Definition: TestClass.h:138
TestClass13::getKey
std::string getKey() const
Definition: TestClass.h:144
TestClass2::b
double b
Definition: TestClass.h:375
TCvec1::getKey
std::string getKey() const
Definition: TestClass.h:569
TestClass2::isEqual
bool isEqual(const TestClass *otherobj) const
Definition: TestClass.h:403
TCIn::TCIn
TCIn()
Definition: TestClass.h:313
TestClass13
Definition: TestClass.h:121
TestClass12::TestClass12
TestClass12(const int i, const int s)
Definition: TestClass.h:77
TestClass12::print
void print() const
Definition: TestClass.h:90
TCvecPtr
Definition: TestClass.h:493
TCBase::getKey
std::string getKey() const
Definition: TestClass.h:302
TCIn::print
void print() const
Definition: TestClass.h:323
TestClass12::TestClass12
TestClass12()
Definition: TestClass.h:74
TCvecPtr::TCvecPtr
TCvecPtr(const int i)
Definition: TestClass.h:499
TestClass12::isEqual
bool isEqual(const TestClass *otherobj) const
Definition: TestClass.h:105
TestClassB
Definition: TestClass.h:202
TCBase::TCBase
TCBase()
Definition: TestClass.h:281
TestClass2::TestClass2
TestClass2(const double i)
Definition: TestClass.h:385
TCIn::getKey
std::string getKey() const
Definition: TestClass.h:337
TestClass::print
virtual void print() const =0
TestClass12::getKey
std::string getKey() const
Definition: TestClass.h:101
TestClass11::ai
int ai
Definition: TestClass.h:34
TCvecPtr::TCvecPtr
TCvecPtr()
Definition: TestClass.h:498
TestClass11
Definition: TestClass.h:32
TestClass
Test classes for the Serializer 2006/07 Sara.Maguerite.Traynor@cern.ch.
Definition: TestClass.h:16
TCvecPtr::Set
void Set(const int i)
Definition: TestClass.h:503
TCvec::~TCvec
~TCvec()
Definition: TestClass.h:454
TestClass11::TestClass11
TestClass11()
Definition: TestClass.h:37
TCvecPtr::my_ptrint
std::vector< int * > my_ptrint
Definition: TestClass.h:495
TestClass12::p
int * p
Definition: TestClass.h:71
TCvec::my_integers
std::vector< int > my_integers
Definition: TestClass.h:436
TestClassA::~TestClassA
~TestClassA()
Definition: TestClass.h:262
TestClass::~TestClass
virtual ~TestClass()
Definition: TestClass.h:22
TestClass11::getKey
std::string getKey() const
Definition: TestClass.h:50
TestClass2::TestClass2
TestClass2(const int i)
Definition: TestClass.h:381
TestClassA::print
void print() const
Definition: TestClass.h:232
TestClass::TestClass
TestClass()
Definition: TestClass.h:20
TestClass13::isEqual
bool isEqual(const TestClass *otherobj) const
Definition: TestClass.h:149
TestClass14::getKey
std::string getKey() const
Definition: TestClass.h:194
TCvec::TCvec
TCvec()
Definition: TestClass.h:441
TCIn
Definition: TestClass.h:308
TCBase
Definition: TestClass.h:276
TestClass11::print
void print() const
Definition: TestClass.h:46
TestClassA
Definition: TestClass.h:223
TCIn::TCIn
TCIn(const int i)
Definition: TestClass.h:314
TestClassB::getKey
std::string getKey() const
Definition: TestClass.h:214
TCvecPtr::isEqual
bool isEqual(const TestClass *otherobj) const
Definition: TestClass.h:528
TestClass::isEqual
virtual bool isEqual(const TestClass *otherobj) const =0
fitman.k
k
Definition: fitman.py:528
TestClass11::Set
void Set(const int i)
Definition: TestClass.h:41
TestClassB::TestClassB
TestClassB()
Definition: TestClass.h:266
TestClass2::TestClass2
TestClass2(const float i)
Definition: TestClass.h:389
TestClassA::bb
TestClassB * bb
Definition: TestClass.h:225
TestClassB::SetA
void SetA(TestClassA *ptr)
Definition: TestClass.h:247
TCvec::getKey
std::string getKey() const
Definition: TestClass.h:468