Garfield++ v2r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
Heed::ActivePtr< X, C > Class Template Reference

Active pointer or automatic container or controlling pointer. More...

#include <AbsPtr.h>

Public Member Functions

X * operator-> (void) const
 
X & operator* (void) const
 
X * getver (void) const
 
X * get (void) const
 
void put (const X *fptr)
 
void pass (X *fptr)
 
X * extract (void)
 
void clear (void)
 
void pilfer (const ActivePtr< X, C > &f)
 
void print (std::ostream &file, int l=1) const
 
 ActivePtr (void)
 
 ActivePtr (const X *fptr, Clone)
 
 ActivePtr (const ActivePtr< X, C > &f)
 
 ActivePtr (const ActivePtr< X, C > &f, Pilfer)
 
 ActivePtr (X *fptr, Pass)
 
ActivePtroperator= (const ActivePtr< X, C > &f)
 
virtual ActivePtrcopy () const
 
virtual ~ActivePtr ()
 

Detailed Description

template<class X, class C = StandardCopyDefinition<X>>
class Heed::ActivePtr< X, C >

Active pointer or automatic container or controlling pointer.

Definition at line 199 of file AbsPtr.h.

Constructor & Destructor Documentation

◆ ActivePtr() [1/5]

template<class X , class C = StandardCopyDefinition<X>>
Heed::ActivePtr< X, C >::ActivePtr ( void  )
inline

Definition at line 317 of file AbsPtr.h.

317: ptr(NULL) {}

Referenced by Heed::ActivePtr< X, C >::copy().

◆ ActivePtr() [2/5]

template<class X , class C = StandardCopyDefinition<X>>
Heed::ActivePtr< X, C >::ActivePtr ( const X *  fptr,
Clone   
)
inline

Definition at line 319 of file AbsPtr.h.

320 : ptr(fptr != NULL ? C::copy(fptr) : ((X*)NULL))
321#ifndef DEBUG_ACTIVEPTR
322 {
323 } // normal case

◆ ActivePtr() [3/5]

template<class X , class C = StandardCopyDefinition<X>>
Heed::ActivePtr< X, C >::ActivePtr ( const ActivePtr< X, C > &  f)
inline

Definition at line 334 of file AbsPtr.h.

335 : ptr(f.ptr != NULL ? C::copy(f.ptr) : f.ptr)
336#ifndef DEBUG_ACTIVEPTR
337 {
338 }

◆ ActivePtr() [4/5]

template<class X , class C = StandardCopyDefinition<X>>
Heed::ActivePtr< X, C >::ActivePtr ( const ActivePtr< X, C > &  f,
Pilfer   
)
inline

Attention: actually not const

Definition at line 346 of file AbsPtr.h.

347 : ptr(f.ptr) { //!Attention: actually not const
348#ifdef DEBUG_ACTIVEPTR
349 mcout << "ActivePtr(const ActivePtr<X,C>& f, Pilfer) is run\n";
350#endif
351 f.ptr = NULL;
352 } // debug
#define mcout
Definition: prstream.h:126

◆ ActivePtr() [5/5]

template<class X , class C = StandardCopyDefinition<X>>
Heed::ActivePtr< X, C >::ActivePtr ( X *  fptr,
Pass   
)
inline

Definition at line 355 of file AbsPtr.h.

355: ptr(fptr) {}

◆ ~ActivePtr()

template<class X , class C = StandardCopyDefinition<X>>
virtual Heed::ActivePtr< X, C >::~ActivePtr ( )
inlinevirtual

Definition at line 366 of file AbsPtr.h.

366 {
367 // unfortunately it should be virtual
368 // in order to avoid some rare (not met in practice but
369 // in principle possible) problems with ActivePtrReg.
370 // Therefore (if there is a virtual member)
371 // we can also include virtual copy (see above),
372 // although there is no obvious application for it
373 // (multiple indirection depth, but for what?).
374 if (ptr != NULL) {
375 delete ptr;
376 ptr = NULL;
377 }
378 }

Member Function Documentation

◆ clear()

template<class X , class C = StandardCopyDefinition<X>>
void Heed::ActivePtr< X, C >::clear ( void  )
inline

Definition at line 281 of file AbsPtr.h.

281 {
282#ifdef DEBUG_ACTIVEPTR
283 mcout << "ActivePtr::clear is called, ptr =" << ptr << '\n';
284#endif
285 if (ptr) {
286 delete ptr;
287 ptr = NULL;
288 }
289 }

Referenced by Heed::operator>>().

◆ copy()

template<class X , class C = StandardCopyDefinition<X>>
virtual ActivePtr * Heed::ActivePtr< X, C >::copy ( ) const
inlinevirtual

Definition at line 365 of file AbsPtr.h.

365{ return new ActivePtr(*this); }
ActivePtr(void)
Definition: AbsPtr.h:317

◆ extract()

template<class X , class C = StandardCopyDefinition<X>>
X * Heed::ActivePtr< X, C >::extract ( void  )
inline

Definition at line 276 of file AbsPtr.h.

276 {
277 X* ret = ptr;
278 ptr = NULL;
279 return ret;
280 }

Referenced by Heed::exchange().

◆ get()

template<class X , class C = StandardCopyDefinition<X>>
X * Heed::ActivePtr< X, C >::get ( void  ) const
inline

Definition at line 215 of file AbsPtr.h.

215{ return ptr; }

Referenced by Heed::ExAtomPhotoAbsCS::ExAtomPhotoAbsCS(), and Heed::operator<<().

◆ getver()

template<class X , class C >
X * Heed::ActivePtr< X, C >::getver ( void  ) const
inline

Definition at line 465 of file AbsPtr.h.

465 {
466#ifdef SKIP_CHECKS_NULL
467 return ptr;
468#else
469 if (ptr) return ptr;
470 mcerr << "Error in X* ActivePtr<X,C>::getver(void) const: "
471 << " ptr == NULL\n";
472 mcerr << "Type of X is (in internal notations) " << typeid(X).name() << '\n';
473 spexit(mcerr);
474 return ptr;
475#endif
476}
#define spexit(stream)
Definition: FunNameStack.h:256
#define mcerr
Definition: prstream.h:128

◆ operator*()

template<class X , class C >
X & Heed::ActivePtr< X, C >::operator* ( void  ) const
inline

Definition at line 452 of file AbsPtr.h.

452 {
453#ifdef SKIP_CHECKS_NULL
454 return *ptr;
455#else
456 if (ptr) return *ptr;
457 mcerr << "Error in X& ActivePtr<X,C>::operator*(void) const: "
458 << " ptr == NULL\n";
459 mcerr << "Type of X is (in internal notations) " << typeid(X).name() << '\n';
460 spexit(mcerr);
461 return *ptr;
462#endif
463}

◆ operator->()

template<class X , class C >
X * Heed::ActivePtr< X, C >::operator-> ( void  ) const
inline

Definition at line 438 of file AbsPtr.h.

438 {
439#ifdef SKIP_CHECKS_NULL
440 return ptr;
441#else
442 if (ptr) return ptr;
443 mcerr << "Error in X* ActivePtr<X,C>::operator->(void) const: "
444 << " ptr == NULL\n";
445 mcerr << "Type of X is (in internal notations) " << typeid(X).name() << '\n';
446 // mcerr<<"Type of ptr is "<<typeid(ptr).name()<<'\n';
447 spexit(mcerr);
448 return ptr;
449#endif
450}

◆ operator=()

template<class X , class C = StandardCopyDefinition<X>>
ActivePtr & Heed::ActivePtr< X, C >::operator= ( const ActivePtr< X, C > &  f)
inline

Definition at line 357 of file AbsPtr.h.

357 {
358#ifdef DEBUG_ACTIVEPTR
359 mcout << "inline ActivePtr& operator=(const ActivePtr<X,C>& f)\n";
360#endif
361 if (this != &f) put(f.ptr);
362 return *this;
363 }
void put(const X *fptr)
Definition: AbsPtr.h:225

◆ pass()

template<class X , class C = StandardCopyDefinition<X>>
void Heed::ActivePtr< X, C >::pass ( X *  fptr)
inline

Definition at line 247 of file AbsPtr.h.

247 {
248 // delete old owned object and
249 // pass address of object fptr to ownership of this
250 // without copying.
251 // At fptr==NULL old object is deleted and new one is not copyed.
252 // In general this is dengerous operation.
253 // In particular if object pointed by fptr is direct or indirect part
254 // of object pointed by ptr, it will be destroyed, which would probably
255 // cause error.
256 // But it is more efficient since does not require copying.
257
258 if (ptr) {
259 if (fptr) {
260 mcerr << "ERROR in ActivePtr::pass(X* fptr):\n";
261 mcerr << "Both the destination and source pointers are not empty\n";
262 // if f belongs to *ptr, deletion of *ptr would lead to
263 // deletion of f. In order to avoid this unexpected behaviour,
264 // we interprete non-zero ptr as error.
265 // The user should clear ptr first and then use this function.
266 spexit(mcerr);
267 } else {
268 delete ptr;
269 }
270 }
271 ptr = fptr;
272 }

Referenced by Heed::exchange(), Heed::circumf::get_components(), Heed::plane::get_components(), Heed::polyline::get_components(), Heed::polyline_pl::get_components(), Heed::rectangle::get_components(), Heed::spquadr::get_components(), Heed::straight::get_components(), Heed::splane::get_components(), Heed::ulsvolume::get_components(), Heed::trajestep::get_components(), Heed::basis::get_components(), Heed::fixsyscoor::get_components(), and Heed::sh_manip_absvol::get_components().

◆ pilfer()

template<class X , class C = StandardCopyDefinition<X>>
void Heed::ActivePtr< X, C >::pilfer ( const ActivePtr< X, C > &  f)
inline

Attention: actually not const

Definition at line 291 of file AbsPtr.h.

291 {
292 //!Attention: actually not const
293#ifdef DEBUG_ACTIVEPTR
294 mcout << "ActivePtr::pilfer is called\n";
295#endif
296 if (this != &f) {
297 if (ptr) {
298 if (f.ptr) {
299 mcerr << "ERROR in ActivePtr::pilfer(...):\n";
300 mcerr << "Both the destination and source pointers are not empty\n";
301 // if f belongs to *ptr, deletion of *ptr would lead to
302 // deletion of f. In order to avoid this unexpected behaviour,
303 // we interprete non-zero ptr as error.
304 // The user should clear ptr first and then use this function.
305 spexit(mcerr);
306 } else {
307 delete ptr;
308 }
309 }
310 ptr = f.ptr;
311 f.ptr = NULL;
312 }
313 return;
314 }

◆ print()

template<class X , class C >
void Heed::ActivePtr< X, C >::print ( std::ostream &  file,
int  l = 1 
) const

Definition at line 391 of file AbsPtr.h.

391 {
392 Ifile << "ActivePtr<X,C>: ";
393 if (ptr == NULL)
394 file << " ptr==NULL. \n"; // optimized to provide automatic reading
395 else {
396 file << " ptr!=NULL: ";
397 file << noindent;
398 ptr->print(file, l);
399 file << yesindent;
400 }
401}
std::ostream & noindent(std::ostream &f)
Definition: prstream.cpp:17
std::ostream & yesindent(std::ostream &f)
Definition: prstream.cpp:21
#define Ifile
Definition: prstream.h:196

◆ put()

template<class X , class C = StandardCopyDefinition<X>>
void Heed::ActivePtr< X, C >::put ( const X *  fptr)
inline

Definition at line 225 of file AbsPtr.h.

225 {
226 // delete old owned object and copy object fptr to ownership of this.
227 // At fptr == NULL old object is deleted and new one is not copied.
228#ifdef DEBUG_ACTIVEPTR
229 mcout << "inline void put(const X* fptr)\n";
230 Iprintn(mcout, ptr);
231 mcout << "Type of X is (in internal notations) " << typeid(X).name()
232 << '\n';
233 mcout << "Type of *fptr is (in internal notations) " << typeid(*fptr).name()
234 << '\n';
235#endif
236 // Initialization of copy should go ahead, since
237 // object *fptr could be dependant or part of *this,
238 // and could be deleted prior to copying at the reverse order.
239 X* ptr_temp = (fptr != NULL ? C::copy(fptr) : (X*)(NULL));
240 if (ptr) delete ptr;
241 ptr = ptr_temp;
242#ifdef DEBUG_ACTIVEPTR
243 mcout << "finishing inline void put(const X* fptr):\n";
244 Iprintn(mcout, ptr);
245#endif
246 }
#define Iprintn(file, name)
Definition: prstream.h:205

Referenced by Heed::ActivePtr< X, C >::operator=(), and Heed::operator>>().


The documentation for this class was generated from the following file: