00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ThePEG_Switch_H
00010 #define ThePEG_Switch_H
00011
00012
00013 #include "ThePEG/Config/ThePEG.h"
00014 #include "Switch.fh"
00015 #include "Switch.xh"
00016 #include "InterfaceBase.h"
00017
00018 namespace ThePEG {
00019
00036 class SwitchOption: public Named {
00037
00038 public:
00039
00054 SwitchOption(SwitchBase & theSwitch, string newName,
00055 string newDescription, long newValue);
00056
00060 SwitchOption() : theValue(-999) {}
00061
00065 const string & description() const { return theDescription; }
00066
00070 long value() const { return theValue; }
00071
00075 operator long () const;
00076
00077 protected:
00078
00079 private:
00080
00084 string theDescription;
00085
00089 long theValue;
00090
00091 };
00092
00117 class SwitchBase: public InterfaceBase {
00118
00119 public:
00120
00122 typedef map<long, SwitchOption> OptionMap;
00124 typedef map<string, SwitchOption> StringMap;
00125
00127 friend class SwitchOption;
00128
00129 public:
00130
00151 SwitchBase(string newName, string newDescription,
00152 string newClassName, const type_info & newTypeInfo,
00153 bool depSafe, bool readonly)
00154 : InterfaceBase(newName, newDescription, newClassName,
00155 newTypeInfo, depSafe, readonly) {}
00156
00164 virtual string exec(InterfacedBase & ib, string action,
00165 string arguments) const;
00166
00170 virtual string fullDescription(const InterfacedBase & ib) const;
00171
00175 virtual string type() const;
00176
00180 virtual void set(InterfacedBase & ib, long val)
00181 const = 0;
00182
00186 virtual long get(const InterfacedBase & ib)
00187 const = 0;
00188
00192 virtual long def(const InterfacedBase & ib)
00193 const = 0;
00194
00198 void setDef(InterfacedBase & i) const {
00199 set(i, def(i));
00200 }
00201
00205 bool check(long newValue) const { return member(theOptions, newValue); }
00206
00210 const OptionMap & options() const { return theOptions; }
00211
00216 virtual string doxygenType() const;
00217
00218 protected:
00219
00223 void registerOption(const SwitchOption & o) {
00224 theOptions[o.value()] = o;
00225 theOptionNames[o.name()] = o;
00226 }
00227
00228 private:
00229
00233 OptionMap theOptions;
00234
00238 StringMap theOptionNames;
00239
00240 };
00241
00266 template <typename T, typename Int>
00267 class Switch: public SwitchBase {
00268
00269 public:
00270
00275 typedef void (T::*SetFn)(Int);
00280 typedef Int (T::*GetFn)() const;
00281
00285 typedef Int T::* Member;
00286
00287 public:
00288
00318 Switch(string newName, string newDescription,
00319 Member newMember, Int newDef, bool depSafe = false,
00320 bool readonly = false, SetFn newSetFn = 0, GetFn newGetFn = 0,
00321 GetFn newDefFn = 0)
00322 : SwitchBase(newName, newDescription, ClassTraits<T>::className(),
00323 typeid(T), depSafe, readonly),
00324 theMember(newMember), theDef(newDef), theSetFn(newSetFn),
00325 theGetFn(newGetFn), theDefFn(newDefFn) {}
00326
00330 virtual void set(InterfacedBase & ib, long val) const
00331 ;
00332
00336 virtual long get(const InterfacedBase & ib) const;
00337
00341 virtual long def(const InterfacedBase & ib) const;
00342
00346 void setSetFunction(SetFn sf) { theSetFn = sf; }
00347
00351 void setGetFunction(GetFn gf) { theGetFn = gf; }
00352
00356 void setDefaultFunction(GetFn df) { theDefFn = df; }
00357
00362 virtual void doxygenDescription(ostream & stream) const;
00363
00364 private:
00365
00369 Member theMember;
00370
00375 Int theDef;
00376
00380 SetFn theSetFn;
00381
00385 GetFn theGetFn;
00386
00390 GetFn theDefFn;
00391
00392 };
00393
00394 }
00395
00396 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
00397 #include "Switch.tcc"
00398 #endif
00399
00400 #endif