Garfield++ 4.0
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 833 of file AbsPtr.h.

Constructor & Destructor Documentation

◆ PassivePtr() [1/5]

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

Definition at line 869 of file AbsPtr.h.

870 : cpp(NULL)
871#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
872 ,
873 ptr(NULL)
874#endif
875 {
876 }

◆ PassivePtr() [2/5]

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

Definition at line 877 of file AbsPtr.h.

877 {
878 if (fptr != NULL)
879 cpp = fptr->book();
880 else
881 cpp = NULL;
882#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
883 ptr = fptr;
884#endif
885 }

◆ PassivePtr() [3/5]

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

Definition at line 886 of file AbsPtr.h.

886 {
887 cpp = fptr.book();
888#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
889 ptr = &fptr;
890#endif
891 }

◆ PassivePtr() [4/5]

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

Definition at line 1000 of file AbsPtr.h.

1000 {
1001 if (f.cpp != NULL) {
1002 f.cpp->book();
1003 cpp = f.cpp;
1004 } else
1005 cpp = NULL;
1006#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1007 ptr = f.ptr;
1008#endif
1009}

◆ PassivePtr() [5/5]

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

Definition at line 931 of file AbsPtr.h.

932 : cpp(NULL) {
933 put((f.get()));
934}
void put(X *fptr)
Definition: AbsPtr.h:970

◆ ~PassivePtr()

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

Definition at line 1309 of file AbsPtr.h.

1309 {
1310 if (cpp) {
1311#ifdef USE_DELETE_AT_ZERO_COUNT
1312 const RegPassivePtr* arptr;
1313 if ((arptr = cpp->get_rpp()) != NULL &&
1315 arptr->get_s_allow_del_at_zero_count() == 1 &&
1316#else
1317 arptr->s_allow_del_at_zero_count == 1 &&
1318#endif
1319 cpp->get_number_of_booked() == 1)
1320 delete arptr;
1321#endif
1322 cpp->unbook();
1323 // mcout<<"PassivePtr<X>::~PassivePtr(): &ptr="<<&ptr<<" *ptr="<<*ptr<<'\n';
1324 if (cpp->get_rpp() == NULL && cpp->get_number_of_booked() == 0) {
1325 delete cpp;
1326 cpp = NULL;
1327 }
1328 }
1329}
#define USE_PRIVATE_PARAM_IN_PASSIVEPTR
Definition: AbsPtr.h:73
const RegPassivePtr * get_rpp(void)
Definition: AbsPtr.h:210
friend class RegPassivePtr
Definition: AbsPtr.h:835

Member Function Documentation

◆ copy()

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

Definition at line 919 of file AbsPtr.h.

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

◆ get()

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

Definition at line 837 of file AbsPtr.h.

837 {
838 if (cpp == NULL) return NULL;
839#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
840
841 if (cpp->get_rpp() == NULL) return NULL;
842#ifdef USE_CHECK_DOUBLE_PTR_IN_PASSIVEPTR
843 X* temp_ptr = dynamic_cast<X*>(const_cast<RegPassivePtr*>(cpp->get_rpp()));
844 if (ptr != temp_ptr) {
845 mcerr << "Error in inline X* PassivePtr::get(void):\n";
846 mcerr << "ptr != temp_ptr\n";
847 spexit(mcerr);
848 }
849#endif
850 return ptr;
851#else // for ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
852 else
853 return (X*)(cpp->get_rpp());
854#endif // for ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
855 }
#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 912 of file AbsPtr.h.

912 {
913 if (cpp == NULL)
914 return 0;
915 else
916 return cpp->get_number_of_booked();
917 }

Referenced by Heed::operator<<().

◆ getver()

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

Definition at line 1181 of file AbsPtr.h.

1181 {
1182#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1183#ifdef SKIP_CHECKS_NULL
1184 return ptr;
1185#else
1186 if (cpp == NULL) {
1187 mcerr << "Error in X* PassivePtr<X>::getver(void) const: cpp == NULL\n";
1188 mcerr << "This means that the pointer is emtpy, "
1189 << "there is no addressed object.\n";
1190 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1191 << '\n';
1192 spexit(mcerr);
1193 }
1194 if (cpp->get_rpp() == NULL) {
1195 mcerr << "Error in X* PassivePtr<X>::getver(void) const: cpp->get_rpp() == "
1196 "NULL\n";
1197 mcerr << "This means that the pointer is emtpy, "
1198 << "there is no addressed object.\n";
1199 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1200 << '\n';
1201 spexit(mcerr);
1202 }
1203#ifdef USE_CHECK_DOUBLE_PTR_IN_PASSIVEPTR
1204 X* temp_ptr = dynamic_cast<X*>(const_cast<RegPassivePtr*>(cpp->get_rpp()));
1205 if (ptr != temp_ptr) {
1206 mcerr << "Error in inline X* PassivePtr::getver(void):\n";
1207 mcerr << "ptr != temp_ptr\n";
1208 spexit(mcerr);
1209 }
1210#endif
1211 return ptr;
1212#endif // for ifdef SKIP_CHECKS_NULL
1213#else // for ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1214#ifdef SKIP_CHECKS_NULL
1215 const RegPassivePtr* rpp = cpp->get_rpp();
1216#else
1217 if (cpp == NULL) {
1218 mcerr << "Error in X* PassivePtr<X>::getver(void) const: cpp == NULL\n";
1219 mcerr << "This means that the pointer is emtpy, "
1220 << "there is no addressed object.\n";
1221 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1222 << '\n';
1223 spexit(mcerr);
1224 }
1225 const RegPassivePtr* rpp;
1226 if ((rpp = cpp->get_rpp()) == NULL) {
1227 mcerr << "Error in X* PassivePtr<X>::getver(void) const: cpp->get_rpp() == "
1228 "NULL\n";
1229 mcerr << "This means that the pointer is emtpy, "
1230 << "there is no addressed object.\n";
1231 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1232 << '\n';
1233 spexit(mcerr);
1234 }
1235#endif
1236 return (X*)(rpp);
1237#endif // for ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1238}

◆ move_pointer()

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

Definition at line 1023 of file AbsPtr.h.

1023 {
1024 if (cpp != NULL) {
1025#ifdef USE_DELETE_AT_ZERO_COUNT
1026 const RegPassivePtr* arptr;
1027 if ((arptr = cpp->get_rpp()) != NULL &&
1029 arptr->get_s_allow_del_at_zero_count() == 1 &&
1030#else
1031 arptr->s_allow_del_at_zero_count == 1 &&
1032#endif
1033 cpp->get_number_of_booked() == 1)
1034 delete arptr;
1035// fptr should not be part of old object!
1036#endif
1037 cpp->unbook();
1038 if (cpp->get_rpp() == NULL && cpp->get_number_of_booked() == 0) {
1039 delete cpp;
1040 cpp = NULL;
1041 }
1042 }
1043 cpp = f.cpp;
1044 if (cpp != NULL) cpp->book();
1045#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1046 ptr = f.ptr;
1047#endif
1048 f.put(NULL);
1049}

◆ operator*()

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

Definition at line 1112 of file AbsPtr.h.

1112 {
1113#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1114#ifdef SKIP_CHECKS_NULL
1115 return *ptr;
1116#else
1117 if (cpp == NULL) {
1118 mcerr << "Error in X& PassivePtr<X>::operator*(void) const: cpp == NULL\n";
1119 mcerr << "This means that the pointer is emtpy, "
1120 << "there is no addressed object.\n";
1121 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1122 << '\n';
1123 spexit(mcerr);
1124 }
1125 if (cpp->get_rpp() == NULL) {
1126 mcerr << "Error in X& PassivePtr<X>::operator*(void) const: cpp->get_rpp() "
1127 "== NULL\n";
1128 mcerr << "This means that the pointer is emtpy, "
1129 << "there is no addressed object.\n";
1130 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1131 << '\n';
1132 spexit(mcerr);
1133 }
1134#ifdef USE_CHECK_DOUBLE_PTR_IN_PASSIVEPTR
1135 X* temp_ptr = dynamic_cast<X*>(const_cast<RegPassivePtr*>(cpp->get_rpp()));
1136 if (ptr != temp_ptr) {
1137 mcerr << "Error in inline X& PassivePtr::operator*(void):\n";
1138 mcerr << "ptr != temp_ptr\n";
1139 spexit(mcerr);
1140 }
1141#endif
1142 return *ptr;
1143#endif // for ifdef SKIP_CHECKS_NULL
1144#else // for ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1145#ifdef SKIP_CHECKS_NULL
1146 static const RegPassivePtr* rpp = cpp->get_rpp();
1147#else
1148 if (cpp == NULL) {
1149 mcerr << "Error in X& PassivePtr<X>::operator*(void) const: cpp == NULL\n";
1150 mcerr << "This means that the pointer is emtpy, "
1151 << "there is no addressed object.\n";
1152 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1153 << '\n';
1154 spexit(mcerr);
1155 }
1156 static const RegPassivePtr* rpp;
1157 // I have put static here only to avoid
1158 // perhaps erroneous warning which appear
1159 // in compiler : gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
1160 // This is old compiler. At newer ones there is no problems.
1161 // The message is
1162 // AbsPtr.h:997: warning: reference to local variable `rpp' returned
1163 // This is in fact wrong statement, but so as not to make users thinking
1164 // about it, I made this variable static.
1165
1166 if ((rpp = cpp->get_rpp()) == NULL) {
1167 mcerr << "Error in X& PassivePtr<X>::operator*(void) const: cpp->get_rpp() "
1168 "== NULL\n";
1169 mcerr << "This means that the pointer is emtpy, "
1170 << "there is no addressed object.\n";
1171 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1172 << '\n';
1173 spexit(mcerr);
1174 }
1175#endif
1176 return *((X*)(rpp));
1177#endif // for ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1178}

◆ operator->()

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

Definition at line 1052 of file AbsPtr.h.

1052 {
1053#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1054#ifdef SKIP_CHECKS_NULL
1055 return ptr;
1056#else
1057 if (cpp == NULL) {
1058 mcerr << "Error in X* PassivePtr<X>::operator->(void) const: cpp == NULL\n";
1059 mcerr << "This means that the pointer is emtpy, "
1060 << "there is no addressed object.\n";
1061 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1062 << '\n';
1063 spexit(mcerr);
1064 }
1065 if (cpp->get_rpp() == NULL) {
1066 mcerr << "Error in X* PassivePtr<X>::operator->(void) const: "
1067 "cpp->get_rpp() == NULL\n";
1068 mcerr << "This means that the pointer is emtpy, "
1069 << "there is no addressed object.\n";
1070 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1071 << '\n';
1072 spexit(mcerr);
1073 }
1074#ifdef USE_CHECK_DOUBLE_PTR_IN_PASSIVEPTR
1075 X* temp_ptr = dynamic_cast<X*>(const_cast<RegPassivePtr*>(cpp->get_rpp()));
1076 if (ptr != temp_ptr) {
1077 mcerr << "Error in inline X* PassivePtr::operator->(void):\n";
1078 mcerr << "ptr != temp_ptr\n";
1079 spexit(mcerr);
1080 }
1081#endif
1082 return ptr;
1083#endif // for ifdef SKIP_CHECKS_NULL
1084#else // for ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1085#ifdef SKIP_CHECKS_NULL
1086 const RegPassivePtr* rpp = cpp->get_rpp();
1087#else
1088 if (cpp == NULL) {
1089 mcerr << "Error in X* PassivePtr<X>::operator->(void) const: cpp == NULL\n";
1090 mcerr << "This means that the pointer is emtpy, "
1091 << "there is no addressed object.\n";
1092 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1093 << '\n';
1094 spexit(mcerr);
1095 }
1096 const RegPassivePtr* rpp;
1097 if ((rpp = cpp->get_rpp()) == NULL) {
1098 mcerr << "Error in X* PassivePtr<X>::operator->(void) const: "
1099 "cpp->get_rpp() == NULL\n";
1100 mcerr << "This means that the pointer is emtpy, "
1101 << "there is no addressed object.\n";
1102 mcerr << "Type of X is (in internal notations) " << typeid(X).name()
1103 << '\n';
1104 spexit(mcerr);
1105 }
1106#endif
1107 return (X*)(rpp);
1108#endif // for ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
1109}

◆ operator=() [1/2]

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

Definition at line 1011 of file AbsPtr.h.

1011 {
1012 if (this != &f) put(f.get());
1013 return *this;
1014}

◆ operator=() [2/2]

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

Definition at line 1017 of file AbsPtr.h.

1017 {
1018 put(f);
1019 return *this;
1020}

◆ print()

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

Definition at line 937 of file AbsPtr.h.

937 {
938 Ifile << "PassivePtr<X>:";
939 if (get() == NULL)
940 file << " pointer is NULL, no object, number of ref's is "
942 else {
943 file << noindent;
944 get()->print(file, l);
945 file << yesindent;
946 indn.n += 2;
947 Ifile << "number of ref's is " << get_total_number_of_references() << '\n';
948 indn.n -= 2;
949 }
950}
X * get(void) const
Definition: AbsPtr.h:837
long get_total_number_of_references(void) const
Definition: AbsPtr.h:912
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:195

◆ put()

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

Definition at line 970 of file AbsPtr.h.

970 {
971 // unregister old registered object and pass fptr to this.
972 if (cpp != NULL) {
973#ifdef USE_DELETE_AT_ZERO_COUNT
974 const RegPassivePtr* arptr;
975 if ((arptr = cpp->get_rpp()) != NULL &&
977 arptr->get_s_allow_del_at_zero_count() == 1 &&
978#else
979 arptr->s_allow_del_at_zero_count == 1 &&
980#endif
981 cpp->get_number_of_booked() == 1)
982 delete arptr;
983// fptr should not be part of old object!
984#endif
985 cpp->unbook();
986 if (cpp->get_rpp() == NULL && cpp->get_number_of_booked() == 0)
987 // there is no referred object and no other references
988 delete cpp;
989 }
990 if (fptr != NULL)
991 cpp = fptr->book();
992 else
993 cpp = NULL;
994#ifdef USE_DOUBLE_PTR_IN_PASSIVEPTR
995 ptr = fptr;
996#endif
997}

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

Friends And Related Function Documentation

◆ RegPassivePtr

template<class X >
friend class RegPassivePtr
friend

Definition at line 835 of file AbsPtr.h.


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