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

#include <AbsPtr.h>

Public Member Functions

X * get (void) const
 
void put (X *fptr)
 
 PassivePtr (void)
 
 PassivePtr (X *fptr)
 
 PassivePtr (X &fptr)
 
 PassivePtr (const PassivePtr< X > &f)
 
PassivePtr< X > & operator= (const PassivePtr< X > &f)
 
PassivePtr< X > & operator= (X *f)
 
template<class Y >
 PassivePtr (const PassivePtr< Y > &f)
 
void move_pointer (PassivePtr< X > &f)
 
X * operator-> (void) const
 
X & operator* (void) const
 
X * getver (void) const
 
long get_total_number_of_references (void) const
 
void print (std::ostream &file, int l=1) const
 
virtual PassivePtrcopy () const
 
virtual ~PassivePtr ()
 

Friends

class RegPassivePtr
 

Detailed Description

template<class X>
class Heed::PassivePtr< X >

Definition at line 1138 of file AbsPtr.h.

Constructor & Destructor Documentation

◆ PassivePtr() [1/5]

template<class X >
Heed::PassivePtr< X >::PassivePtr ( void  )
inline

Definition at line 1174 of file AbsPtr.h.

1175 : cpp(NULL)
1176#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1177 ,
1178 ptr(NULL)
1179#endif
1180 {
1181 }

◆ PassivePtr() [2/5]

template<class X >
Heed::PassivePtr< X >::PassivePtr ( X *  fptr)
inline

Definition at line 1182 of file AbsPtr.h.

1182 {
1183 if (fptr != NULL)
1184 cpp = fptr->book();
1185 else
1186 cpp = NULL;
1187#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1188 ptr = fptr;
1189#endif
1190 }

◆ PassivePtr() [3/5]

template<class X >
Heed::PassivePtr< X >::PassivePtr ( X &  fptr)
inline

Definition at line 1191 of file AbsPtr.h.

1191 {
1192 cpp = fptr.book();
1193#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1194 ptr = &fptr;
1195#endif
1196 }

◆ PassivePtr() [4/5]

template<class X >
Heed::PassivePtr< X >::PassivePtr ( const PassivePtr< X > &  f)
inline

Definition at line 1305 of file AbsPtr.h.

1305 {
1306 if (f.cpp != NULL) {
1307 f.cpp->book();
1308 cpp = f.cpp;
1309 } else
1310 cpp = NULL;
1311#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1312 ptr = f.ptr;
1313#endif
1314}

◆ PassivePtr() [5/5]

template<class X >
template<class Y >
Heed::PassivePtr< X >::PassivePtr ( const PassivePtr< Y > &  f)

Definition at line 1236 of file AbsPtr.h.

1237 : cpp(NULL) {
1238 put((f.get()));
1239}
void put(X *fptr)
Definition: AbsPtr.h:1275

◆ ~PassivePtr()

template<class X >
Heed::PassivePtr< X >::~PassivePtr
virtual

Definition at line 1614 of file AbsPtr.h.

1614 {
1615 if (cpp) {
1616#ifdef USE_DELETE_AT_ZERO_COUNT
1617 const RegPassivePtr* arptr;
1618 if ((arptr = cpp->get_rpp()) != NULL &&
1620 arptr->get_s_allow_del_at_zero_count() == 1 &&
1621#else
1622 arptr->s_allow_del_at_zero_count == 1 &&
1623#endif
1624 cpp->get_number_of_booked() == 1)
1625 delete arptr;
1626#endif
1627 cpp->unbook();
1628 // mcout<<"PassivePtr<X>::~PassivePtr(): &ptr="<<&ptr<<" *ptr="<<*ptr<<'\n';
1629 if (cpp->get_rpp() == NULL && cpp->get_number_of_booked() == 0) {
1630 delete cpp;
1631 cpp = NULL;
1632 }
1633 }
1634}
#define USE_PRIVATE_PARAM_IN_PASSIVEPTR
Definition: AbsPtr.h:76
const RegPassivePtr * get_rpp(void)
Definition: AbsPtr.h:515
friend class RegPassivePtr
Definition: AbsPtr.h:1140

Member Function Documentation

◆ copy()

template<class X >
virtual PassivePtr * Heed::PassivePtr< X >::copy ( ) const
inlinevirtual

Definition at line 1224 of file AbsPtr.h.

1224{ return new PassivePtr(*this); }
PassivePtr(void)
Definition: AbsPtr.h:1174

◆ get()

template<class X >
X * Heed::PassivePtr< X >::get ( void  ) const
inline

Definition at line 1142 of file AbsPtr.h.

1142 {
1143 if (cpp == NULL) return NULL;
1144#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1145
1146 if (cpp->get_rpp() == NULL) return NULL;
1147#ifdef USE_CHECK_DOUBLE_PTR_IN_PASSIVEPTR
1148 X* temp_ptr = dynamic_cast<X*>(const_cast<RegPassivePtr*>(cpp->get_rpp()));
1149 if (ptr != temp_ptr) {
1150 mcerr << "Error in inline X* PassivePtr::get(void):\n";
1151 mcerr << "ptr != temp_ptr\n";
1152 spexit(mcerr);
1153 }
1154#endif
1155 return ptr;
1156#else // for ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1157 else
1158 return (X*)(cpp->get_rpp());
1159#endif // for ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1160 }
#define spexit(stream)
Definition: FunNameStack.h:256
#define mcerr
Definition: prstream.h:128

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

◆ get_total_number_of_references()

template<class X >
long Heed::PassivePtr< X >::get_total_number_of_references ( void  ) const
inline

Definition at line 1217 of file AbsPtr.h.

1217 {
1218 if (cpp == NULL)
1219 return 0;
1220 else
1221 return cpp->get_number_of_booked();
1222 }

Referenced by Heed::operator<<().

◆ getver()

template<class X >
X * Heed::PassivePtr< X >::getver ( void  ) const
inline

Definition at line 1486 of file AbsPtr.h.

1486 {
1487#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1488#ifdef SKIP_CHECKS_NULL
1489 return ptr;
1490#else
1491 if (cpp == NULL) {
1492 mcerr << "Error in X* PassivePtr<X>::getver(void) const: cpp == NULL\n";
1493 mcerr << "This means that the pointer is emtpy, "
1494 << "there is no addressed object.\n";
1495 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1496 << '\n';
1497 spexit(mcerr);
1498 }
1499 if (cpp->get_rpp() == NULL) {
1500 mcerr << "Error in X* PassivePtr<X>::getver(void) const: cpp->get_rpp() == "
1501 "NULL\n";
1502 mcerr << "This means that the pointer is emtpy, "
1503 << "there is no addressed object.\n";
1504 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1505 << '\n';
1506 spexit(mcerr);
1507 }
1508#ifdef USE_CHECK_DOUBLE_PTR_IN_PASSIVEPTR
1509 X* temp_ptr = dynamic_cast<X*>(const_cast<RegPassivePtr*>(cpp->get_rpp()));
1510 if (ptr != temp_ptr) {
1511 mcerr << "Error in inline X* PassivePtr::getver(void):\n";
1512 mcerr << "ptr != temp_ptr\n";
1513 spexit(mcerr);
1514 }
1515#endif
1516 return ptr;
1517#endif // for ifdef SKIP_CHECKS_NULL
1518#else // for ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1519#ifdef SKIP_CHECKS_NULL
1520 const RegPassivePtr* rpp = cpp->get_rpp();
1521#else
1522 if (cpp == NULL) {
1523 mcerr << "Error in X* PassivePtr<X>::getver(void) const: cpp == NULL\n";
1524 mcerr << "This means that the pointer is emtpy, "
1525 << "there is no addressed object.\n";
1526 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1527 << '\n';
1528 spexit(mcerr);
1529 }
1530 const RegPassivePtr* rpp;
1531 if ((rpp = cpp->get_rpp()) == NULL) {
1532 mcerr << "Error in X* PassivePtr<X>::getver(void) const: cpp->get_rpp() == "
1533 "NULL\n";
1534 mcerr << "This means that the pointer is emtpy, "
1535 << "there is no addressed object.\n";
1536 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1537 << '\n';
1538 spexit(mcerr);
1539 }
1540#endif
1541 return (X*)(rpp);
1542#endif // for ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1543}

◆ move_pointer()

template<class X >
void Heed::PassivePtr< X >::move_pointer ( PassivePtr< X > &  f)
inline

Definition at line 1328 of file AbsPtr.h.

1328 {
1329 if (cpp != NULL) {
1330#ifdef USE_DELETE_AT_ZERO_COUNT
1331 const RegPassivePtr* arptr;
1332 if ((arptr = cpp->get_rpp()) != NULL &&
1334 arptr->get_s_allow_del_at_zero_count() == 1 &&
1335#else
1336 arptr->s_allow_del_at_zero_count == 1 &&
1337#endif
1338 cpp->get_number_of_booked() == 1)
1339 delete arptr;
1340// fptr should not be part of old object!
1341#endif
1342 cpp->unbook();
1343 if (cpp->get_rpp() == NULL && cpp->get_number_of_booked() == 0) {
1344 delete cpp;
1345 cpp = NULL;
1346 }
1347 }
1348 cpp = f.cpp;
1349 if (cpp != NULL) cpp->book();
1350#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1351 ptr = f.ptr;
1352#endif
1353 f.put(NULL);
1354}

◆ operator*()

template<class X >
X & Heed::PassivePtr< X >::operator* ( void  ) const
inline

Definition at line 1417 of file AbsPtr.h.

1417 {
1418#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1419#ifdef SKIP_CHECKS_NULL
1420 return *ptr;
1421#else
1422 if (cpp == NULL) {
1423 mcerr << "Error in X& PassivePtr<X>::operator*(void) const: cpp == NULL\n";
1424 mcerr << "This means that the pointer is emtpy, "
1425 << "there is no addressed object.\n";
1426 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1427 << '\n';
1428 spexit(mcerr);
1429 }
1430 if (cpp->get_rpp() == NULL) {
1431 mcerr << "Error in X& PassivePtr<X>::operator*(void) const: cpp->get_rpp() "
1432 "== NULL\n";
1433 mcerr << "This means that the pointer is emtpy, "
1434 << "there is no addressed object.\n";
1435 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1436 << '\n';
1437 spexit(mcerr);
1438 }
1439#ifdef USE_CHECK_DOUBLE_PTR_IN_PASSIVEPTR
1440 X* temp_ptr = dynamic_cast<X*>(const_cast<RegPassivePtr*>(cpp->get_rpp()));
1441 if (ptr != temp_ptr) {
1442 mcerr << "Error in inline X& PassivePtr::operator*(void):\n";
1443 mcerr << "ptr != temp_ptr\n";
1444 spexit(mcerr);
1445 }
1446#endif
1447 return *ptr;
1448#endif // for ifdef SKIP_CHECKS_NULL
1449#else // for ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1450#ifdef SKIP_CHECKS_NULL
1451 static const RegPassivePtr* rpp = cpp->get_rpp();
1452#else
1453 if (cpp == NULL) {
1454 mcerr << "Error in X& PassivePtr<X>::operator*(void) const: cpp == NULL\n";
1455 mcerr << "This means that the pointer is emtpy, "
1456 << "there is no addressed object.\n";
1457 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1458 << '\n';
1459 spexit(mcerr);
1460 }
1461 static const RegPassivePtr* rpp;
1462 // I have put static here only to avoid
1463 // perhaps erroneous warning which appear
1464 // in compiler : gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
1465 // This is old compiler. At newer ones there is no problems.
1466 // The message is
1467 // AbsPtr.h:997: warning: reference to local variable `rpp' returned
1468 // This is in fact wrong statement, but so as not to make users thinking
1469 // about it, I made this variable static.
1470
1471 if ((rpp = cpp->get_rpp()) == NULL) {
1472 mcerr << "Error in X& PassivePtr<X>::operator*(void) const: cpp->get_rpp() "
1473 "== NULL\n";
1474 mcerr << "This means that the pointer is emtpy, "
1475 << "there is no addressed object.\n";
1476 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1477 << '\n';
1478 spexit(mcerr);
1479 }
1480#endif
1481 return *((X*)(rpp));
1482#endif // for ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1483}

◆ operator->()

template<class X >
X * Heed::PassivePtr< X >::operator-> ( void  ) const
inline

Definition at line 1357 of file AbsPtr.h.

1357 {
1358#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1359#ifdef SKIP_CHECKS_NULL
1360 return ptr;
1361#else
1362 if (cpp == NULL) {
1363 mcerr << "Error in X* PassivePtr<X>::operator->(void) const: cpp == NULL\n";
1364 mcerr << "This means that the pointer is emtpy, "
1365 << "there is no addressed object.\n";
1366 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1367 << '\n';
1368 spexit(mcerr);
1369 }
1370 if (cpp->get_rpp() == NULL) {
1371 mcerr << "Error in X* PassivePtr<X>::operator->(void) const: "
1372 "cpp->get_rpp() == NULL\n";
1373 mcerr << "This means that the pointer is emtpy, "
1374 << "there is no addressed object.\n";
1375 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1376 << '\n';
1377 spexit(mcerr);
1378 }
1379#ifdef USE_CHECK_DOUBLE_PTR_IN_PASSIVEPTR
1380 X* temp_ptr = dynamic_cast<X*>(const_cast<RegPassivePtr*>(cpp->get_rpp()));
1381 if (ptr != temp_ptr) {
1382 mcerr << "Error in inline X* PassivePtr::operator->(void):\n";
1383 mcerr << "ptr != temp_ptr\n";
1384 spexit(mcerr);
1385 }
1386#endif
1387 return ptr;
1388#endif // for ifdef SKIP_CHECKS_NULL
1389#else // for ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1390#ifdef SKIP_CHECKS_NULL
1391 const RegPassivePtr* rpp = cpp->get_rpp();
1392#else
1393 if (cpp == NULL) {
1394 mcerr << "Error in X* PassivePtr<X>::operator->(void) const: cpp == NULL\n";
1395 mcerr << "This means that the pointer is emtpy, "
1396 << "there is no addressed object.\n";
1397 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1398 << '\n';
1399 spexit(mcerr);
1400 }
1401 const RegPassivePtr* rpp;
1402 if ((rpp = cpp->get_rpp()) == NULL) {
1403 mcerr << "Error in X* PassivePtr<X>::operator->(void) const: "
1404 "cpp->get_rpp() == NULL\n";
1405 mcerr << "This means that the pointer is emtpy, "
1406 << "there is no addressed object.\n";
1407 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1408 << '\n';
1409 spexit(mcerr);
1410 }
1411#endif
1412 return (X*)(rpp);
1413#endif // for ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1414}

◆ operator=() [1/2]

template<class X >
PassivePtr< X > & Heed::PassivePtr< X >::operator= ( const PassivePtr< X > &  f)
inline

Definition at line 1316 of file AbsPtr.h.

1316 {
1317 if (this != &f) put(f.get());
1318 return *this;
1319}

◆ operator=() [2/2]

template<class X >
PassivePtr< X > & Heed::PassivePtr< X >::operator= ( X *  f)
inline

Definition at line 1322 of file AbsPtr.h.

1322 {
1323 put(f);
1324 return *this;
1325}

◆ print()

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

Definition at line 1242 of file AbsPtr.h.

1242 {
1243 Ifile << "PassivePtr<X>:";
1244 if (get() == NULL)
1245 file << " pointer is NULL, no object, number of ref's is "
1246 << get_total_number_of_references() << "\n";
1247 else {
1248 file << noindent;
1249 get()->print(file, l);
1250 file << yesindent;
1251 indn.n += 2;
1252 Ifile << "number of ref's is " << get_total_number_of_references() << '\n';
1253 indn.n -= 2;
1254 }
1255}
X * get(void) const
Definition: AbsPtr.h:1142
long get_total_number_of_references(void) const
Definition: AbsPtr.h:1217
std::ostream & noindent(std::ostream &f)
Definition: prstream.cpp:17
indentation indn
Definition: prstream.cpp:15
std::ostream & yesindent(std::ostream &f)
Definition: prstream.cpp:21
#define Ifile
Definition: prstream.h:196

◆ put()

template<class X >
void Heed::PassivePtr< X >::put ( X *  fptr)
inline

Definition at line 1275 of file AbsPtr.h.

1275 {
1276 // unregister old registered object and pass fptr to this.
1277 if (cpp != NULL) {
1278#ifdef USE_DELETE_AT_ZERO_COUNT
1279 const RegPassivePtr* arptr;
1280 if ((arptr = cpp->get_rpp()) != NULL &&
1282 arptr->get_s_allow_del_at_zero_count() == 1 &&
1283#else
1284 arptr->s_allow_del_at_zero_count == 1 &&
1285#endif
1286 cpp->get_number_of_booked() == 1)
1287 delete arptr;
1288// fptr should not be part of old object!
1289#endif
1290 cpp->unbook();
1291 if (cpp->get_rpp() == NULL && cpp->get_number_of_booked() == 0)
1292 // there is no referred object and no other references
1293 delete cpp;
1294 }
1295 if (fptr != NULL)
1296 cpp = fptr->book();
1297 else
1298 cpp = NULL;
1299#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1300 ptr = fptr;
1301#endif
1302}

Referenced by Heed::PassivePtr< X >::move_pointer(), Heed::PassivePtr< X >::PassivePtr(), and Heed::absvol::range().

Friends And Related Function Documentation

◆ RegPassivePtr

template<class X >
friend class RegPassivePtr
friend

Definition at line 1140 of file AbsPtr.h.


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