source: ThirdParty/mpqc_open/src/lib/util/class/classtest.cc@ 398fcd

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 398fcd was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 4.6 KB
Line 
1//
2// classtest.cc
3//
4// Copyright (C) 1996 Limit Point Systems, Inc.
5//
6// Author: Curtis Janssen <cljanss@limitpt.com>
7// Maintainer: LPS
8//
9// This file is part of the SC Toolkit.
10//
11// The SC Toolkit is free software; you can redistribute it and/or modify
12// it under the terms of the GNU Library General Public License as published by
13// the Free Software Foundation; either version 2, or (at your option)
14// any later version.
15//
16// The SC Toolkit is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Library General Public License for more details.
20//
21// You should have received a copy of the GNU Library General Public License
22// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24//
25// The U.S. Government is granted a limited license as per AL 91-7.
26//
27
28// a simple program to test the class stuff
29
30#include <iostream>
31
32#include <util/misc/formio.h>
33#include <util/class/class.h>
34
35using namespace std;
36using namespace sc;
37
38#undef SIMPLE_TEST
39
40class A: virtual public DescribedClass {
41 private:
42 int i;
43 public:
44 A():i(1) {};
45 ~A() { cout << "A dtor\n"; };
46};
47
48static ClassDesc A_cd(typeid(A),"A",1,"virtual public DescribedClass");
49
50#ifndef SIMPLE_TEST
51
52class B: public A {
53 private:
54 int ib;
55 public:
56 B():ib(2) {};
57 ~B() { cout << "B dtor\n"; };
58};
59
60static ClassDesc B_cd(typeid(B),"B",1,"public A");
61
62class C: virtual public DescribedClass {
63 private:
64 int i;
65 public:
66 C():i(3) {};
67 ~C() { cout << "C dtor\n"; };
68};
69
70static ClassDesc C_cd(typeid(C),"C",1,"virtual public DescribedClass");
71
72class D: public B, public C {
73 private:
74 int id;
75 A* atst;
76 public:
77 D():id(4),atst(new A) {};
78 ~D() { delete atst; cout << "D dtor\n"; };
79};
80
81static ClassDesc D_cd(typeid(D),"D",1,"public B, public C",create<D>);
82
83#endif /* ! SIMPLE_TEST */
84
85main()
86{
87 ClassDesc::list_all_classes();
88
89 cout << indent << "using 0" << endl;
90 const Ref<DescribedClass> descl2(0);
91 Ref<A> aaa;
92 cout << "getting aaaa" << endl;
93 A* aaaa = 0; //aaa.pointer();
94 cout << "using aaaa" << endl;
95 const Ref<DescribedClass> descl((aaaa==(A*)0)?(DescribedClass*)0:aaaa);
96 cout << "using aaa.pointer()" << endl;
97 const Ref<DescribedClass> descl3((aaa.pointer()==(A*)0)?(DescribedClass*)0:aaa.pointer());
98
99 A a;
100 cout << "A name:" << a.class_name() << '\n';
101
102 D* dtst = dynamic_cast<D*>(ClassDesc::name_to_class_desc("D")->create());
103 delete dtst;
104
105 // check the compiler's handling of virtual inheritance
106 D* dt = new D;
107 C* ct = dt;
108 B* bt = dt;
109 cout << "virtual inheritance test:" << endl;
110 dt->reference();
111 cout << "The following three numbers should be equal:" << endl;
112 cout << ' ' << dt->nreference()
113 << ' ' << ct->nreference()
114 << ' ' << bt->nreference() << endl;
115 ct->reference();
116 cout << "The following three numbers should be equal:" << endl;
117 cout << ' ' << dt->nreference()
118 << ' ' << ct->nreference()
119 << ' ' << bt->nreference() << endl;
120 bt->reference();
121 cout << "The following three numbers should be equal:" << endl;
122 cout << ' ' << dt->nreference()
123 << ' ' << ct->nreference()
124 << ' ' << bt->nreference() << endl;
125 cout << "done with virtual inheritance test:" << endl;
126 dt->dereference();
127 if (dt->nreference() == 0) delete dt;
128 ct->dereference();
129 if (ct->nreference() == 0) delete ct;
130 bt->dereference();
131 if (bt->nreference() == 0) delete bt;
132
133#ifndef SIMPLE_TEST
134 D d;
135 cout << "D name:" << d.class_name() << '\n';
136
137 cout << "&d = " << (void*) &d << '\n';
138 cout << "dynamic_cast<D*>(&d) = " << (void*) dynamic_cast<D*>(&d) << '\n';
139 cout << "dynamic_cast<B*>(&d) = " << (void*) dynamic_cast<B*>(&d) << '\n';
140 cout << "dynamic_cast<A*>(&d) = " << (void*) dynamic_cast<A*>(&d) << '\n';
141 cout << "dynamic_cast<C*>(&d) = " << (void*) dynamic_cast<C*>(&d) << '\n';
142 cout << "dynamic_cast<DescribedClass*>(&d) = "
143 << (void*) dynamic_cast<DescribedClass*>(&d) << '\n';
144
145 Ref<D> dref(new D);
146 Ref<A> aref(dref);
147
148 cout << "aref.pointer() is " << aref.pointer() << '\n';
149 cout << "dref.pointer() is " << dref.pointer() << '\n';
150 cout << "aref == dref gives " << (aref == dref) << '\n';
151
152 dref << aref;
153
154 cout << "aref.pointer() is " << aref.pointer() << '\n';
155 cout << "dref.pointer() is " << dref.pointer() << '\n';
156 cout << "aref == dref gives " << (aref == dref) << '\n';
157#endif /* ! SIMPLE_TEST */
158
159}
160
161/////////////////////////////////////////////////////////////////////////////
162
163// Local Variables:
164// mode: c++
165// c-file-style: "CLJ"
166// End:
Note: See TracBrowser for help on using the repository browser.