Warning, /include/ThePEG/Interface/RefVector.tcc is written in an unsupported language. File is not indexed.
0001 // -*- C++ -*-
0002 //
0003 // RefVector.tcc is a part of ThePEG - Toolkit for HEP Event Generation
0004 // Copyright (C) 1999-2019 Leif Lonnblad
0005 //
0006 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
0008 //
0009 //
0010 // This is the implementation of the non-inlined templated member
0011 // functions of the RefVector class.
0012 //
0013
0014 namespace ThePEG {
0015
0016 template <class T, class R>
0017 RefVector<T,R>::
0018 RefVector(string newName, string newDescription,
0019 Member newMember, int newSize, bool depSafe,
0020 bool readonly, bool rebind, bool nullable, SetFn newSetFn,
0021 InsFn newInsFn, DelFn newDelFn, GetFn newGetFn, CheckFn newCheckFn)
0022 : RefVectorBase(newName, newDescription, ClassTraits<T>::className(),
0023 typeid(T), ClassTraits<R>::className(), typeid(R), newSize,
0024 depSafe, readonly, !rebind, nullable, false),
0025 theMember(newMember), theSetFn(newSetFn), theInsFn(newInsFn),
0026 theDelFn(newDelFn), theGetFn(newGetFn), theCheckFn(newCheckFn) {}
0027
0028 template <class T, class R>
0029 RefVector<T,R>::
0030 RefVector(string newName, string newDescription,
0031 Member newMember, int newSize, bool depSafe,
0032 bool readonly, bool rebind, bool nullable, bool defnull,
0033 SetFn newSetFn, InsFn newInsFn, DelFn newDelFn, GetFn newGetFn,
0034 CheckFn newCheckFn)
0035 : RefVectorBase(newName, newDescription, ClassTraits<T>::className(),
0036 typeid(T), ClassTraits<R>::className(), typeid(R), newSize,
0037 depSafe, readonly, !rebind, nullable, defnull),
0038 theMember(newMember), theSetFn(newSetFn), theInsFn(newInsFn),
0039 theDelFn(newDelFn), theGetFn(newGetFn), theCheckFn(newCheckFn) {}
0040
0041 template <class T, class R>
0042 void RefVector<T,R>::
0043 set(InterfacedBase & i, IBPtr newRef, int place, bool chk) const
0044 {
0045 if ( readOnly() ) throw InterExReadOnly(*this, i);
0046 T * t = dynamic_cast<T *>(&i);
0047 if ( !t ) throw InterExClass(*this, i);
0048 if ( noNull() && !newRef ) throw InterExNoNull(*this, i);
0049 RefPtr r = dynamic_ptr_cast<RefPtr>(newRef);
0050 if ( !r && newRef ) throw RefVExRefClass(*this, i, newRef, "set");
0051 IVector oldVector = get(i);
0052 if ( theSetFn && ( chk || !theMember ) ) {
0053 try { (t->*theSetFn)(r, place); }
0054 catch (InterfaceException & e) { throw e; }
0055 catch ( ... ) { throw RefVExSetUnknown(*this, i, r, place, "set"); }
0056 } else {
0057 if ( !theMember ) throw RefVExNoSet(*this, i);
0058 if ( place < 0 || static_cast<unsigned long>(place) >= (t->*theMember).size() )
0059 throw RefVExIndex(*this, i, place);
0060 (t->*theMember)[place] = r;
0061 }
0062 if ( !InterfaceBase::dependencySafe() && oldVector != get(i) ) i.touch();
0063 }
0064
0065 template <class T, class R>
0066 void RefVector<T,R>::
0067 insert(InterfacedBase & i, IBPtr newRef, int place, bool chk) const
0068 {
0069 if ( readOnly() ) throw InterExReadOnly(*this, i);
0070 if ( size() > 0 ) throw RefVExFixed(*this, i);
0071 T * t = dynamic_cast<T *>(&i);
0072 if ( !t ) throw InterExClass(*this, i);
0073 if ( noNull() && !newRef ) throw InterExNoNull(*this, i);
0074 RefPtr r = dynamic_ptr_cast<RefPtr>(newRef);
0075 if ( !r && newRef ) throw RefVExRefClass(*this, i, newRef, "insert");
0076 IVector oldVector = get(i);
0077 if ( theInsFn && ( chk || !theMember ) ) {
0078 try { (t->*theInsFn)(r, place); }
0079 catch (InterfaceException & e) { throw e; }
0080 catch ( ... ) { throw RefVExSetUnknown(*this, i, r, place, "insert"); }
0081 } else {
0082 if ( !theMember ) throw RefVExNoIns(*this, i);
0083 if ( place < 0 || static_cast<unsigned long>(place) > (t->*theMember).size() )
0084 throw RefVExIndex(*this, i, place);
0085 (t->*theMember).insert((t->*theMember).begin()+place, r);
0086 }
0087 if ( !InterfaceBase::dependencySafe() && oldVector != get(i) ) i.touch();
0088 }
0089
0090 template <class T, class R>
0091 void RefVector<T,R>::erase(InterfacedBase & i, int place) const
0092 {
0093 if ( readOnly() ) throw InterExReadOnly(*this, i);
0094 if ( size() > 0 ) throw RefVExFixed(*this, i);
0095 T * t = dynamic_cast<T *>(&i);
0096 if ( !t ) throw InterExClass(*this, i);
0097 IVector oldVector = get(i);
0098 if ( theDelFn ) {
0099 try { (t->*theDelFn)(place); }
0100 catch (InterfaceException & e) { throw e; }
0101 catch ( ... ) { throw RefVExDelUnknown(*this, i, place); }
0102 } else {
0103 if ( !theMember ) throw RefVExNoDel(*this, i);
0104 if ( place < 0 || static_cast<unsigned long>(place) >= (t->*theMember).size() )
0105 throw RefVExIndex(*this, i, place);
0106 (t->*theMember).erase((t->*theMember).begin()+place);
0107 }
0108 if ( !InterfaceBase::dependencySafe() && oldVector != get(i) ) i.touch();
0109 }
0110
0111 template <class T, class R>
0112 void RefVector<T,R>::clear(InterfacedBase & i) const
0113 {
0114 if ( readOnly() ) throw InterExReadOnly(*this, i);
0115 if ( size() > 0 ) throw RefVExFixed(*this, i);
0116 T * t = dynamic_cast<T *>(&i);
0117 if ( !t ) throw InterExClass(*this, i);
0118 if ( !theMember ) throw RefVExNoDel(*this, i);
0119 (t->*theMember).clear();
0120 if ( !InterfaceBase::dependencySafe() ) i.touch();
0121 }
0122
0123 template <class T, class R>
0124 IVector RefVector<T,R>::get(const InterfacedBase & i) const
0125 {
0126 const T * t = dynamic_cast<const T *>(&i);
0127 if ( !t ) throw InterExClass(*this, i);
0128 if ( theGetFn ) {
0129 try {
0130 vector<RefPtr> ret = (t->*theGetFn)();
0131 return IVector(ret.begin(), ret.end());
0132 }
0133 catch (InterfaceException & e) { throw e; }
0134 catch ( ... ) { throw RefVExGetUnknown(*this, i); }
0135 }
0136 if ( theMember ) return IVector((t->*theMember).begin(),
0137 (t->*theMember).end());
0138 throw InterExSetup(*this, i);
0139 }
0140
0141 template <class T, class R>
0142 bool RefVector<T,R>::check(const InterfacedBase & i, cIBPtr ir, int place) const
0143 {
0144 const T * t = dynamic_cast<const T *>(&i);
0145 if ( !t ) throw InterExClass(*this, i);
0146 if ( noNull() && !ir ) return false;
0147 cRefPtr r = dynamic_ptr_cast<cRefPtr>(ir);
0148 if ( !r && ir ) return false;
0149 if ( theCheckFn ) return (t->*theCheckFn)(r, place);
0150 if ( !theMember ) return true;
0151 return place >= 0 && static_cast<unsigned long>(place) <= (t->*theMember).size();
0152 }
0153
0154 }
0155