Warning, /include/ThePEG/Interface/Switch.tcc is written in an unsupported language. File is not indexed.
0001 // -*- C++ -*-
0002 //
0003 // Switch.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 Switch class.
0012 //
0013
0014 namespace ThePEG {
0015
0016 template <typename EnumT>
0017 SwitchOption::SwitchOption(SwitchBase & theSwitch, string newName,
0018 string newDescription, EnumT newValue)
0019 : Named(newName), theDescription(newDescription),
0020 theValue(static_cast<long>(newValue)) {
0021 theSwitch.registerOption(*this);
0022 }
0023
0024
0025 template <typename T, typename Int>
0026 void Switch<T,Int>::set(InterfacedBase & i, long newValue) const
0027 {
0028 T * t = dynamic_cast<T *>(&i);
0029 if ( readOnly() ) throw InterExReadOnly(*this, i);
0030 if ( !t ) throw InterExClass(*this, i);
0031 if ( !check(newValue) ) throw SwExSetOpt(*this, i, newValue);
0032 long oldValue = get(i);
0033 if ( theSetFn ) {
0034 try { (t->*theSetFn)(Int(newValue)); }
0035 catch (InterfaceException & e) { throw e; }
0036 catch ( ... ) { throw SwExSetUnknown(*this, i, newValue); }
0037 } else {
0038 if ( theMember ) t->*theMember = Int(newValue);
0039 else throw InterExSetup(*this, i);
0040 }
0041 if ( !InterfaceBase::dependencySafe() && oldValue != get(i) ) i.touch();
0042 }
0043
0044
0045 template <typename T, typename Int>
0046 long Switch<T,Int>::get(const InterfacedBase & i) const
0047 {
0048 const T * t = dynamic_cast<const T *>(&i);
0049 if ( !t ) throw InterExClass(*this, i);
0050 if ( theGetFn ) {
0051 try { return static_cast<long>((t->*theGetFn)()); }
0052 catch (InterfaceException & e) { throw e; }
0053 catch ( ... ) { throw SwExGetUnknown(*this, i, "current"); }
0054 }
0055 if ( theMember ) return static_cast<long>(t->*theMember);
0056 throw InterExSetup(*this, i);
0057 }
0058
0059 template <typename T, typename Int>
0060 long Switch<T,Int>::def(const InterfacedBase & i) const
0061 {
0062 if ( theDefFn ) {
0063 const T * t = dynamic_cast<const T *>(&i);
0064 if ( !t ) throw InterExClass(*this, i);
0065 try { return static_cast<long>((t->*theDefFn)()); }
0066 catch (InterfaceException & e) { throw e; }
0067 catch ( ... ) { throw SwExGetUnknown(*this, i, "default"); }
0068 }
0069 return static_cast<long>(theDef);
0070 }
0071
0072 template <typename T, typename Int>
0073 void Switch<T,Int>::doxygenDescription(ostream & os) const {
0074 SwitchBase::doxygenDescription(os);
0075 os << "<b>Registered options:</b>\n<dl>\n";
0076 for ( OptionMap::const_iterator it = options().begin();
0077 it != options().end(); ++it )
0078 os << "<dt>" << it->first << "(<code>" << it->second.name() << "</code>)</dt>"
0079 << "<dd>" << it->second.description() << "\n";
0080 os << "</dl>\n<b>Default value:</b> " << static_cast<long>(theDef);
0081 if ( theDefFn ) os << " (May be changed by member function.)";
0082 os << "\n\n";
0083 }
0084
0085 }