source: Sophya/trunk/Eval/COS/consopeg.cc@ 3744

Last change on this file since 3744 was 989, checked in by ansari, 25 years ago

Creation du module Eval/COS - Tests compilos/OS - Reza 2/5/2000

File size: 3.3 KB
Line 
1#include<stdlib.h>
2#include<stdio.h>
3#include<string.h>
4
5/* Tout est public dans cette classe */
6
7class BToto
8{
9public:
10static int nb;
11static int cons, dest, conscpy, opeg;
12
13 static void InfoCons();
14
15 float px,py;
16 int id;
17
18 BToto(int oid=0, float x=1., float y=2.);
19 BToto(BToto const & bt);
20 ~BToto(void);
21
22
23/* Les methodes virtuelles sont la pour pouvoir etre utilisees */
24/* par les classes derivees de celle la par defaut. */
25 void Set(float a=0., float b=0.);
26 BToto& operator=(const BToto& bt);
27 virtual BToto Scale(float sc);
28 virtual int GetId() { return id; } ;
29 virtual void Display();
30 virtual char * ClassNom() { return "BToto"; } ;
31
32};
33
34int BToto::nb = 0;
35int BToto::cons = 0;
36int BToto::dest = 0;
37int BToto::conscpy = 0;
38int BToto::opeg = 0;
39
40void BToto::InfoCons()
41{
42 printf("BToto::InfoCons() NbConsCall= %d NbCopyConsCall= %d NbDestCall= %d NbOpegal=%d \n", cons, conscpy, dest, opeg);
43}
44
45BToto::BToto(int oid, float x, float y)
46{
47 cons++;
48nb += 10;
49 if (oid == 0) oid = nb;
50printf("BToto::BToto(int oid) : %d -Pointer= %lx\n", oid,(long)this);
51px = x; py = y;
52id = oid;
53}
54
55BToto::BToto(BToto const & b)
56{
57 conscpy++;
58printf("BToto::BToto(BToto const & : %d -Pointer= %lx ) Pointer= %lx\n",
59 b.id,(long)(&b),(long)this);
60id = b.id;
61px = b.px;
62py = b.py;
63}
64
65BToto::~BToto(void)
66{
67 dest++;
68printf("BToto::~BToto: %d \n", id);
69return;
70}
71
72void BToto::Set(float a, float b)
73{
74px = a; py = b;
75return;
76}
77
78BToto BToto::Scale(float sc)
79{
80printf("BToto::Scale : %d -Pointer= %lx\n", id,(long)this);
81
82 BToto ret(*this);
83 ret.px *= sc;
84 ret.py *= sc;
85 return(ret);
86}
87
88BToto& BToto::operator=(const BToto& b)
89{
90 opeg++;
91printf("BToto::Operateur= (BToto const & : %d -Pointer= %lx ) Pointer= %lx\n",
92 b.id,(long)(&b),(long)this);
93id = b.id;
94px = b.px;
95py = b.py;
96return(*this);
97}
98
99
100void BToto::Display()
101{
102printf("BToto::Display() %g %g (Id= %d) Point=%lx\n", px, py, id,(long)this);
103return;
104}
105
106
107class PointBToto
108{
109public:
110static int num;
111 PointBToto();
112 virtual ~PointBToto();
113 operator BToto ();
114
115 BToto * bt;
116};
117
118
119int PointBToto::num = 0;
120PointBToto::PointBToto()
121{
122 num++;
123 bt = new BToto(10000*num, num*3., num*6.);
124}
125
126PointBToto::~PointBToto()
127{
128 delete bt;
129}
130
131PointBToto::operator BToto ()
132{
133 printf("PointBToto::operator BToto %d \n", bt->GetId());
134 return(*bt);
135}
136
137void test_cons();
138
139main(int narg, char *arg[])
140{
141 printf(" ---- Programme test constructeur et operateur egal ----- \n");
142 test_cons();
143 printf("> BToto::InfoCons() \n");
144 BToto::InfoCons();
145}
146
147void test_cons()
148{
149 printf("> BToto b1; b1.Display(); \n");
150 BToto b1;
151 b1.Display();
152 printf("> BToto b2(344, 5, 15.); b2.Display(); b1 = b2; b1.Display(); \n");
153 BToto b2(344, 5, 15.);
154 b2.Display();
155 b1 = b2;
156 b1.Display();
157 printf("> BToto b3(666, 8., 16.); BToto b4 = b3.Scale(2.); b4.Display(); \n");
158 BToto b3(666, 8., 16.);
159 BToto b4 = b3.Scale(2.);
160 b4.Display();
161 printf("> BToto b5(788, 10., 20.); BToto b6; b6 = b5.Scale(3.); b6.Display(); \n");
162 BToto b5(788, 10., 20.);
163 BToto b6;
164 b6 = b5.Scale(3.);
165 b6.Display();
166 printf("> PointBToto pb1; ((BToto)pb1).Display(); \n");
167 PointBToto pb1;
168 ((BToto)pb1).Display();
169 printf("> PointBToto pb2; BToto bb1 = pb1; bb1.Display(); \n");
170 PointBToto pb2;
171 BToto bb1 = pb1;
172 bb1.Display();
173}
174
175
176
177
178
Note: See TracBrowser for help on using the repository browser.