Warning, /include/ThePEG/Interface/Reference.tcc is written in an unsupported language. File is not indexed.
0001 // -*- C++ -*-
0002 //
0003 // Reference.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 Reference class.
0012 //
0013
0014 namespace ThePEG {
0015
0016 template <class T, class R>
0017 void Reference<T,R>::set(InterfacedBase & i, IBPtr newRef, bool chk) const
0018 {
0019 if ( readOnly() ) throw InterExReadOnly(*this, i);
0020 T * t = dynamic_cast<T *>(&i);
0021 if ( !t ) throw InterExClass(*this, i);
0022 if ( noNull() && !newRef ) throw InterExNoNull(*this, i);
0023 RefPtr r = dynamic_ptr_cast<RefPtr>(newRef);
0024 if ( !r && newRef) throw RefExSetRefClass(*this, i, newRef);
0025 RefPtr oldRef = dynamic_ptr_cast<RefPtr>(get(i));
0026 if ( theSetFn && ( chk || !theMember ) ) {
0027 try { (t->*theSetFn)(r); }
0028 catch (InterfaceException & e) { throw e; }
0029 catch ( ... ) { throw RefExSetUnknown(*this, i, r); }
0030 } else {
0031 if ( theMember ) t->*theMember = r;
0032 else throw InterExSetup(*this, i);
0033 }
0034 if ( !InterfaceBase::dependencySafe() && oldRef != get(i) ) i.touch();
0035 }
0036
0037 template <class T, class R>
0038 IBPtr Reference<T,R>::get(const InterfacedBase & i) const
0039 {
0040 const T * t = dynamic_cast<const T *>(&i);
0041 if ( !t ) throw InterExClass(*this, i);
0042 if ( theGetFn ) {
0043 try { return (t->*theGetFn)(); }
0044 catch (InterfaceException & e) { throw e; }
0045 catch ( ... ) { throw RefExGetUnknown(*this, i); }
0046 }
0047 if ( theMember ) return t->*theMember;
0048 throw InterExSetup(*this, i);
0049 }
0050
0051 template <class T, class R>
0052 bool Reference<T,R>::check(const InterfacedBase & i, cIBPtr ir) const
0053 {
0054 const T * t = dynamic_cast<const T *>(&i);
0055 if ( !t ) throw InterExClass(*this, i);
0056 if ( noNull() && !ir ) return false;
0057 cRefPtr r = dynamic_ptr_cast<cRefPtr>(ir);
0058 if ( !r && ir ) return false;
0059 if ( !theCheckFn ) return true;
0060 return (t->*theCheckFn)(r);
0061 }
0062
0063 }
0064