Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
AbsPtr.cpp
Go to the documentation of this file.
2/*
3Copyright (c) 1999-2004 I. B. Smirnov
4
5The file can be used, copied, modified, and distributed
6according to the terms of GNU Lesser General Public License version 2.1
7as published by the Free Software Foundation,
8and provided that the above copyright notice, this permission notice,
9and notices about any modifications of the original text
10appear in all copies and in supporting documentation.
11The file is provided "as is" without express or implied warranty.
12*/
13
14RegPassivePtr::RegPassivePtr(const RegPassivePtr& f)
15 :
16#ifdef USE_BIT_OPERA
17 control_word(f.control_word),
18#elif defined(USE_BIT_FIELDS)
19 conparam(f.conparam),
20//#ifdef USE_DELETE_AT_ZERO_COUNT
21// conparam(fs_ban_del, fs_ban_sub, fs_ban_cop, s_allow_del_at_zero_count ),
22//#else
23// conparam(fs_ban_del, fs_ban_sub, fs_ban_cop ),
24//#endif
25#else
26 s_ban_del(f.s_ban_del),
27 s_ban_sub(f.s_ban_sub),
28 s_ban_cop(f.s_ban_cop),
30 s_allow_del_at_zero_count(f.s_allow_del_at_zero_count),
31#endif
32#endif
33 cpp(NULL) {
34//mcout<<"RegPassivePtr::RegPassivePtr(...) is started\n";
35#ifdef USE_BIT_OPERA
36 if (f.get_s_ban_cop() == 2)
37#elif defined(USE_BIT_FIELDS)
38 if (f.conparam.s_ban_cop == 2)
39#else
40 if (f.s_ban_cop == 2)
41#endif
42 {
43 mcerr << "Error in "
44 << "RegPassivePtr::RegPassivePtr(const RegPassivePtr& f):\n"
45 << "attempt to copy object whose s_ban_cop == 2.\n";
47 }
48#ifdef USE_BIT_OPERA
49 else if (f.get_s_ban_cop() == 1 && f.cpp->get_number_of_booked() > 0)
50#elif defined(USE_BIT_FIELDS)
51 else if (f.conparam.s_ban_cop == 1 && f.cpp->get_number_of_booked() > 0)
52#else
53 else if (f.s_ban_cop == 1 && f.cpp->get_number_of_booked() > 0)
54#endif
55 {
56 mcerr << "Error in "
57 << "RegPassivePtr::RegPassivePtr(const RegPassivePtr& f):\n"
58 << "attempt to copy referred object whose s_ban_cop == 1.\n"
59 << "f.cpp->get_number_of_booked()="
60 << f.cpp->get_number_of_booked() << '\n';
62 }
63}
64
65RegPassivePtr& RegPassivePtr::operator=(const RegPassivePtr& f) {
66//mcout<<"RegPassivePtr::operator= is started\n";
67#ifdef USE_BIT_OPERA
68 if (f.get_s_ban_cop() == 2)
69#elif defined(USE_BIT_FIELDS)
70 if (f.conparam.s_ban_cop == 2)
71#else
72 if (f.s_ban_cop == 2)
73#endif
74 {
75 mcerr << "Error in "
76 << "RegPassivePtr& RegPassivePtr::operator=(const RegPassivePtr& "
77 "f):\n"
78 << "attempt to copy object whose s_ban_cop == 2.\n";
80 }
81#ifdef USE_BIT_OPERA
82 else if (f.get_s_ban_cop() == 1 && f.cpp->get_number_of_booked() > 0)
83#elif defined(USE_BIT_FIELDS)
84 else if (f.conparam.s_ban_cop == 1 && f.cpp->get_number_of_booked() > 0)
85#else
86 else if (f.s_ban_cop == 1 && f.cpp->get_number_of_booked() > 0)
87#endif
88 {
89 mcerr << "Error in "
90 << "RegPassivePtr& RegPassivePtr::operator=(const "
91 "RegPassivePtr& f):\n"
92 << "attempt to copy referred object whose s_ban_cop == 1.\n"
93 << "f.cpp->get_number_of_booked()="
94 << f.cpp->get_number_of_booked() << '\n';
96 }
97#ifdef USE_BIT_OPERA
98 set_s_ban_cop(f.get_s_ban_cop());
99#ifdef USE_DELETE_AT_ZERO_COUNT
100 set_s_allow_del_at_zero_count(f.get_s_allow_del_at_zero_count());
101#endif
102 set_s_ban_del(f.get_s_ban_del());
103 if (get_s_ban_sub() == 1)
104#elif defined(USE_BIT_FIELDS)
105 conparam.s_ban_cop = f.conparam.s_ban_cop;
106#ifdef USE_DELETE_AT_ZERO_COUNT
107 conparam.s_allow_del_at_zero_count = f.conparam.s_allow_del_at_zero_count;
108#endif
109 conparam.s_ban_del = f.conparam.s_ban_del;
110 if (conparam.s_ban_sub == 1)
111#else
112 s_ban_cop = f.s_ban_cop;
113#ifdef USE_DELETE_AT_ZERO_COUNT
114 s_allow_del_at_zero_count = f.s_allow_del_at_zero_count;
115#endif
116 s_ban_del = f.s_ban_del;
117 if (s_ban_sub == 1)
118#endif
119 {
120 if (this == &f && // self-assignment
121 cpp != NULL && cpp->get_number_of_booked() > 0) {
122 mcerr << "Error in "
123 << "RegPassivePtr& RegPassivePtr::operator=(const RegPassivePtr& "
124 "f):\n"
125 << "self-assignment, s_ban_sub == 1, but the object is addressed.\n"
126 << "This can lead to loss of pointers to copied object, not only "
127 "to this one.\n";
128 spexit(mcerr);
129 }
130 clear_pointers();
131 }
132#ifdef USE_BIT_OPERA
133 else if (get_s_ban_sub() == 2 && cpp != NULL &&
134 cpp->get_number_of_booked() > 0)
135#elif defined(USE_BIT_FIELDS)
136 else if (conparam.s_ban_sub == 2 && cpp != NULL &&
137 cpp->get_number_of_booked() > 0)
138#else
139 else if (s_ban_sub == 2 && cpp != NULL &&
140 cpp->get_number_of_booked() > 0)
141#endif
142 {
143 mcerr << "Error in "
144 << "RegPassivePtr& RegPassivePtr::operator=(const RegPassivePtr& "
145 "f):\n"
146 << "s_ban_sub == 2, but the object is addressed.\n";
147 spexit(mcerr);
148 }
149#ifdef USE_BIT_OPERA
150 set_s_ban_sub(f.get_s_ban_sub());
151#elif defined(USE_BIT_FIELDS)
152 conparam.s_ban_sub = f.conparam.s_ban_sub;
153#else
154 s_ban_sub = f.s_ban_sub;
155#endif
156 return *this;
157}
158
159int RegPassivePtr::s_print_adr_cpp = 0;
160
161void RegPassivePtr::print(std::ostream& file, int l) const {
162 if (l > 0) file << (*this);
163}
164
165std::ostream& operator<<(std::ostream& file, const RegPassivePtr& f) {
166#ifdef USE_BIT_OPERA
167#ifdef USE_CHAR_GETSETTERS_PARAMETERS
168 Ifile << "RegPassivePtr<X>: s_ban_del/sub/cop=" << int(f.get_s_ban_del())
169 << "/" << int(f.get_s_ban_sub()) << "/" << int(f.get_s_ban_cop());
170#else
171 Ifile << "RegPassivePtr<X>: s_ban_del/sub/cop=" << f.get_s_ban_del() << "/"
172 << f.get_s_ban_sub() << "/" << f.get_s_ban_cop();
173#endif
174#elif defined USE_BIT_FIELDS
175 Ifile << "RegPassivePtr<X>: s_ban_del/sub/cop=" << f.conparam.s_ban_del << "/"
176 << f.conparam.s_ban_sub << "/" << f.conparam.s_ban_cop;
177#else
178#ifdef USE_CHAR_CONTROL_VARIABLES
179 Ifile << "RegPassivePtr<X>: s_ban_del/sub/cop=" << int(f.s_ban_del) << "/"
180 << int(f.s_ban_sub) << "/" << int(f.s_ban_cop);
181#else
182 Ifile << "RegPassivePtr<X>: s_ban_del/sub/cop=" << f.s_ban_del << "/"
183 << f.s_ban_sub << "/" << f.s_ban_cop;
184#endif
185#endif
186 /*
187 Ifile<<"RegPassivePtr<X>: s_ban_del="<<f.s_ban_del
188 <<" s_ban_sub="<<f.s_ban_sub
189 <<" s_ban_cop="<<f.s_ban_cop;
190 */
191 if (RegPassivePtr::s_print_adr_cpp == 0) {
192 if (f.cpp == NULL) {
193 file << " cpp=NULL\n";
194 } else {
195 file << " cpp!=NULL\n";
196 }
197 } else {
198 file << " cpp=" << f.cpp << '\n';
199 }
200 if (f.cpp != NULL) {
201 indn.n += 2;
202 Ifile << "cpp->number_of_registered=" << f.cpp->get_number_of_booked()
203 << '\n';
204 indn.n -= 2;
205 }
206#ifdef USE_DELETE_AT_ZERO_COUNT
207 indn.n += 2;
208#ifdef USE_BIT_OPERA
209 Ifile << "s_allow_del_at_zero_count="
210#ifdef USE_CHAR_GETSETTERS_PARAMETERS
211 << int(f.get_s_allow_del_at_zero_count()) << '\n';
212#else
213 << f.get_s_allow_del_at_zero_count() << '\n';
214#endif
215#elif defined(USE_BIT_FIELDS)
216 Ifile << "s_allow_del_at_zero_count=" << f.conparam.s_allow_del_at_zero_count
217 << '\n';
218#else
219#ifdef USE_CHAR_CONTROL_VARIABLES
220 Ifile << "s_allow_del_at_zero_count=" << int(f.s_allow_del_at_zero_count)
221 << '\n';
222#else
223 Ifile << "s_allow_del_at_zero_count=" << f.s_allow_del_at_zero_count << '\n';
224#endif
225#endif
226 indn.n -= 2;
227#endif
228 return file;
229}
230
231long RegPassivePtr::get_total_number_of_references(void) const {
232 if (cpp == NULL)
233 return 0;
234 else
235 return cpp->get_number_of_booked();
236}
237
238int RegPassivePtr::s_ban_del_ignore = 0;
239
240RegPassivePtr::~RegPassivePtr() {
241 //mcout<<"~RegPassivePtr(): *this="<<(*this)<<'\n';
242 if (cpp != NULL) {
243 cpp->change_rpp(NULL);
244 if (cpp->get_number_of_booked() == 0) {
245 delete cpp;
246 cpp = NULL;
247 } else {
248#ifdef USE_BIT_OPERA
249 if (s_ban_del_ignore == 0 && get_s_ban_del() == 1)
250#elif defined(USE_BIT_FIELDS)
251 if (s_ban_del_ignore == 0 && conparam.s_ban_del == 1)
252#else
253 if (s_ban_del_ignore == 0 && s_ban_del == 1)
254#endif
255 {
256 mcerr << "Error in RegPassivePtr::~RegPassivePtr() "
257 << "s_ban_del == 1, but there are pointers to this class.\n";
258 mcerr << "cpp->number_of_registered=" << cpp->get_number_of_booked()
259 << '\n';
260 s_ban_del_ignore = 1;
261 spexit(mcerr);
262 }
263 }
264 }
265 //mcout<<"~RegPassivePtr(): *this="<<(*this)<<'\n';
266}
267
268std::ostream& operator<<(std::ostream& file,
269 const DoubleReg&
270 f) { // make output similar to ordinary double
271 file << f.val;
272 return file;
273}
std::ostream & operator<<(std::ostream &file, const RegPassivePtr &f)
Definition: AbsPtr.cpp:165
#define USE_DELETE_AT_ZERO_COUNT
Definition: AbsPtr.h:50
#define spexit(stream)
Definition: FunNameStack.h:536
double val
Definition: AbsPtr.h:2398
indentation indn
Definition: prstream.cpp:13
#define Ifile
Definition: prstream.h:207
#define mcerr
Definition: prstream.h:135