Garfield++ 5.0
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
14namespace Heed {
15
17 :
18#ifdef USE_BIT_OPERA
19 control_word(f.control_word),
20#elif defined(USE_BIT_FIELDS)
21 conparam(f.conparam),
22#else
23 s_ban_del(f.s_ban_del),
24 s_ban_sub(f.s_ban_sub),
25 s_ban_cop(f.s_ban_cop),
27 s_allow_del_at_zero_count(f.s_allow_del_at_zero_count),
28#endif
29#endif
30 cpp(NULL) {
31// mcout<<"RegPassivePtr::RegPassivePtr(...) is started\n";
32#ifdef USE_BIT_OPERA
33 if (f.get_s_ban_cop() == 2) {
34#elif defined(USE_BIT_FIELDS)
35 if (f.conparam.s_ban_cop == 2) {
36#else
37 if (f.s_ban_cop == 2) {
38#endif
39 mcerr << "Error in "
40 << "RegPassivePtr::RegPassivePtr(const RegPassivePtr& f):\n"
41 << "attempt to copy object whose s_ban_cop == 2.\n";
42 spexit(mcerr);
43 }
44#ifdef USE_BIT_OPERA
45 else if (f.get_s_ban_cop() == 1 && f.cpp->get_number_of_booked() > 0) {
46#elif defined(USE_BIT_FIELDS)
47 else if (f.conparam.s_ban_cop == 1 && f.cpp->get_number_of_booked() > 0) {
48#else
49 else if (f.s_ban_cop == 1 && f.cpp->get_number_of_booked() > 0) {
50#endif
51 mcerr << "Error in "
52 << "RegPassivePtr::RegPassivePtr(const RegPassivePtr& f):\n"
53 << "attempt to copy referred object whose s_ban_cop == 1.\n"
54 << "f.cpp->get_number_of_booked()=" << f.cpp->get_number_of_booked()
55 << '\n';
56 spexit(mcerr);
57 }
58}
59
60RegPassivePtr& RegPassivePtr::operator=(const RegPassivePtr& f) {
61// mcout<<"RegPassivePtr::operator= is started\n";
62#ifdef USE_BIT_OPERA
63 if (f.get_s_ban_cop() == 2) {
64#elif defined(USE_BIT_FIELDS)
65 if (f.conparam.s_ban_cop == 2) {
66#else
67 if (f.s_ban_cop == 2) {
68#endif
69 mcerr << "Error in "
70 << "RegPassivePtr& RegPassivePtr::operator=(const RegPassivePtr& "
71 "f):\n"
72 << "attempt to copy object whose s_ban_cop == 2.\n";
73 spexit(mcerr);
74#ifdef USE_BIT_OPERA
75 } else if (f.get_s_ban_cop() == 1 && f.cpp->get_number_of_booked() > 0) {
76#elif defined(USE_BIT_FIELDS)
77 } else if (f.conparam.s_ban_cop == 1 && f.cpp->get_number_of_booked() > 0) {
78#else
79 } else if (f.s_ban_cop == 1 && f.cpp->get_number_of_booked() > 0) {
80#endif
81 mcerr << "Error in "
82 << "RegPassivePtr& RegPassivePtr::operator=(const "
83 "RegPassivePtr& f):\n"
84 << "attempt to copy referred object whose s_ban_cop == 1.\n"
85 << "f.cpp->get_number_of_booked()=" << f.cpp->get_number_of_booked()
86 << '\n';
87 spexit(mcerr);
88 }
89#ifdef USE_BIT_OPERA
90 set_s_ban_cop(f.get_s_ban_cop());
91#ifdef USE_DELETE_AT_ZERO_COUNT
92 set_s_allow_del_at_zero_count(f.get_s_allow_del_at_zero_count());
93#endif
94 set_s_ban_del(f.get_s_ban_del());
95 if (get_s_ban_sub() == 1)
96#elif defined(USE_BIT_FIELDS)
97 conparam.s_ban_cop = f.conparam.s_ban_cop;
98#ifdef USE_DELETE_AT_ZERO_COUNT
99 conparam.s_allow_del_at_zero_count = f.conparam.s_allow_del_at_zero_count;
100#endif
101 conparam.s_ban_del = f.conparam.s_ban_del;
102 if (conparam.s_ban_sub == 1)
103#else
104 s_ban_cop = f.s_ban_cop;
105#ifdef USE_DELETE_AT_ZERO_COUNT
106 s_allow_del_at_zero_count = f.s_allow_del_at_zero_count;
107#endif
108 s_ban_del = f.s_ban_del;
109 if (s_ban_sub == 1)
110#endif
111 {
112 if (this == &f && // self-assignment
113 cpp != NULL && cpp->get_number_of_booked() > 0) {
114 mcerr << "Error in "
115 << "RegPassivePtr& RegPassivePtr::operator=(const RegPassivePtr& "
116 "f):\n"
117 << "self-assignment, s_ban_sub == 1, but the object is addressed.\n"
118 << "This can lead to loss of pointers to copied object, not only "
119 "to this one.\n";
120 spexit(mcerr);
121 }
122 clear_pointers();
123 }
124#ifdef USE_BIT_OPERA
125 else if (get_s_ban_sub() == 2 && cpp != NULL &&
126 cpp->get_number_of_booked() > 0)
127#elif defined(USE_BIT_FIELDS)
128 else if (conparam.s_ban_sub == 2 && cpp != NULL &&
129 cpp->get_number_of_booked() > 0)
130#else
131 else if (s_ban_sub == 2 && cpp != NULL && cpp->get_number_of_booked() > 0)
132#endif
133 {
134 mcerr << "Error in "
135 << "RegPassivePtr& RegPassivePtr::operator=(const RegPassivePtr& "
136 "f):\n"
137 << "s_ban_sub == 2, but the object is addressed.\n";
138 spexit(mcerr);
139 }
140#ifdef USE_BIT_OPERA
141 set_s_ban_sub(f.get_s_ban_sub());
142#elif defined(USE_BIT_FIELDS)
143 conparam.s_ban_sub = f.conparam.s_ban_sub;
144#else
145 s_ban_sub = f.s_ban_sub;
146#endif
147 return *this;
148}
149
150int RegPassivePtr::s_print_adr_cpp = 0;
151
152void RegPassivePtr::print(std::ostream& file, int l) const {
153 if (l > 0) file << (*this);
154}
155
156std::ostream& operator<<(std::ostream& file, const RegPassivePtr& f) {
157#ifdef USE_BIT_OPERA
158#ifdef USE_CHAR_GETSETTERS_PARAMETERS
159 Ifile << "RegPassivePtr<X>: s_ban_del/sub/cop=" << int(f.get_s_ban_del())
160 << "/" << int(f.get_s_ban_sub()) << "/" << int(f.get_s_ban_cop());
161#else
162 Ifile << "RegPassivePtr<X>: s_ban_del/sub/cop=" << f.get_s_ban_del() << "/"
163 << f.get_s_ban_sub() << "/" << f.get_s_ban_cop();
164#endif
165#elif defined USE_BIT_FIELDS
166 Ifile << "RegPassivePtr<X>: s_ban_del/sub/cop=" << f.conparam.s_ban_del << "/"
167 << f.conparam.s_ban_sub << "/" << f.conparam.s_ban_cop;
168#else
169#ifdef USE_CHAR_CONTROL_VARIABLES
170 Ifile << "RegPassivePtr<X>: s_ban_del/sub/cop=" << int(f.s_ban_del) << "/"
171 << int(f.s_ban_sub) << "/" << int(f.s_ban_cop);
172#else
173 Ifile << "RegPassivePtr<X>: s_ban_del/sub/cop=" << f.s_ban_del << "/"
174 << f.s_ban_sub << "/" << f.s_ban_cop;
175#endif
176#endif
177 /*
178 Ifile<<"RegPassivePtr<X>: s_ban_del="<<f.s_ban_del
179 <<" s_ban_sub="<<f.s_ban_sub
180 <<" s_ban_cop="<<f.s_ban_cop;
181 */
182 if (RegPassivePtr::s_print_adr_cpp == 0) {
183 if (f.cpp == NULL) {
184 file << " cpp=NULL\n";
185 } else {
186 file << " cpp!=NULL\n";
187 }
188 } else {
189 file << " cpp=" << f.cpp << '\n';
190 }
191 if (f.cpp != NULL) {
192 indn.n += 2;
193 Ifile << "cpp->number_of_registered=" << f.cpp->get_number_of_booked()
194 << '\n';
195 indn.n -= 2;
196 }
197#ifdef USE_DELETE_AT_ZERO_COUNT
198 indn.n += 2;
199#ifdef USE_BIT_OPERA
200 Ifile << "s_allow_del_at_zero_count="
201#ifdef USE_CHAR_GETSETTERS_PARAMETERS
202 << int(f.get_s_allow_del_at_zero_count()) << '\n';
203#else
204 << f.get_s_allow_del_at_zero_count() << '\n';
205#endif
206#elif defined(USE_BIT_FIELDS)
207 Ifile << "s_allow_del_at_zero_count=" << f.conparam.s_allow_del_at_zero_count
208 << '\n';
209#else
210#ifdef USE_CHAR_CONTROL_VARIABLES
211 Ifile << "s_allow_del_at_zero_count=" << int(f.s_allow_del_at_zero_count)
212 << '\n';
213#else
214 Ifile << "s_allow_del_at_zero_count=" << f.s_allow_del_at_zero_count << '\n';
215#endif
216#endif
217 indn.n -= 2;
218#endif
219 return file;
220}
221
222long RegPassivePtr::get_total_number_of_references(void) const {
223 if (cpp == NULL)
224 return 0;
225 else
226 return cpp->get_number_of_booked();
227}
228
229int RegPassivePtr::s_ban_del_ignore = 0;
230
231RegPassivePtr::~RegPassivePtr() {
232 // mcout<<"~RegPassivePtr(): *this="<<(*this)<<'\n';
233 if (cpp != NULL) {
234 cpp->change_rpp(NULL);
235 if (cpp->get_number_of_booked() == 0) {
236 delete cpp;
237 cpp = NULL;
238 } else {
239#ifdef USE_BIT_OPERA
240 if (s_ban_del_ignore == 0 && get_s_ban_del() == 1)
241#elif defined(USE_BIT_FIELDS)
242 if (s_ban_del_ignore == 0 && conparam.s_ban_del == 1)
243#else
244 if (s_ban_del_ignore == 0 && s_ban_del == 1)
245#endif
246 {
247 mcerr << "Error in RegPassivePtr::~RegPassivePtr() "
248 << "s_ban_del == 1, but there are pointers to this class.\n";
249 mcerr << "cpp->number_of_registered=" << cpp->get_number_of_booked()
250 << '\n';
251 s_ban_del_ignore = 1;
252 spexit(mcerr);
253 }
254 }
255 }
256}
257
258}
#define USE_DELETE_AT_ZERO_COUNT
Definition AbsPtr.h:33
char get_s_ban_cop(void) const
Definition AbsPtr.h:704
Definition BGMesh.cpp:6