00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ThePEG_InterfacedBase_H
00010 #define ThePEG_InterfacedBase_H
00011
00012
00013 #include "ThePEG/Config/ThePEG.h"
00014 #include "ThePEG/Utilities/Named.h"
00015 #include "ThePEG/Utilities/ClassDescription.h"
00016 #include "ThePEG/Utilities/HoldFlag.h"
00017 #include "InterfacedBase.xh"
00018
00019 namespace ThePEG {
00020
00045 class InterfacedBase: public PersistentBase, public Named {
00046
00048 friend class BaseRepository;
00049
00051 friend class EventGenerator;
00052
00053 public:
00054
00058 enum InitState {
00059 initializing = -1,
00063 uninitialized = 0,
00064 initialized = 1,
00065 runready = 2
00067 };
00068
00069 public:
00070
00074 virtual ~InterfacedBase();
00075
00080 string fullName() const { return Named::name(); }
00081
00085 string name() const {
00086 return Named::name().substr(Named::name().rfind('/')+1);
00087 }
00088
00093 string path() const {
00094 string::size_type slash = Named::name().rfind('/');
00095 string ret;
00096 if ( slash != string::npos ) ret = Named::name().substr(0,slash);
00097 return ret;
00098 }
00099
00103 string comment() const { return theComment; }
00104
00112 void setup(istream & is) {
00113 readSetup(is);
00114 getline(is, theComment);
00115 }
00116
00117 protected:
00118
00129 virtual void readSetup(istream & is);
00130
00153 virtual void doupdate() {}
00154
00176 virtual void doinit() {}
00177
00193 virtual void doinitrun() {}
00194
00205 virtual void dofinish() {}
00206
00212 virtual IVector getReferences() { return IVector(); }
00213
00221 virtual void rebind(const TranslationMap &) {}
00223
00224 public:
00225
00231 void update() {
00232 if ( initState ) return;
00233 HoldFlag<InitState> hold(initState, initializing, initialized);
00234 doupdate();
00235 }
00236
00240 void init() {
00241 if ( initState ) return;
00242 HoldFlag<InitState> hold(initState, initializing, initialized);
00243 doinit();
00244 }
00245
00252 virtual bool preInitialize() const;
00253
00257 void initrun() {
00258 if ( initState == runready || initState == initializing ) return;
00259 HoldFlag<InitState> hold(initState, initializing, runready);
00260 doinitrun();
00261 }
00262
00266 void finish() {
00267 if ( initState == uninitialized || initState == initializing ) return;
00268 HoldFlag<InitState> hold(initState, initializing, uninitialized);
00269 dofinish();
00270 }
00271
00277 void touch() { isTouched = true; }
00278
00282 void reset() { initState = uninitialized; }
00283
00287 void clear() {
00288 reset();
00289 untouch();
00290 }
00291
00295 InitState state() const { return initState; }
00296
00301 bool locked() const { return isLocked; }
00302
00307 bool touched() const { return isTouched; }
00309
00314 virtual IBPtr fullclone() const { return clone(); }
00315
00322 void persistentOutput(PersistentOStream & os) const;
00323
00329 void persistentInput(PersistentIStream & is, int version);
00331
00335 static void Init();
00336
00337 protected:
00338
00343 virtual IBPtr clone() const = 0;
00344
00348 InterfacedBase()
00349 : Named(""), isLocked(false), isTouched(true),
00350 initState(uninitialized) {}
00351
00355 InterfacedBase(string newName)
00356 : Named(newName), isLocked(false), isTouched(true),
00357 initState(uninitialized) {}
00358
00362 InterfacedBase(const InterfacedBase & i)
00363 : Base(i), Named(i), isLocked(false), isTouched(true),
00364 initState(uninitialized), theComment(i.theComment) {}
00365
00366 private:
00367
00371 void name(string newName) { Named::name(newName); }
00372
00376 void lock() { isLocked = true; }
00377
00381 void unlock() { isLocked = false; }
00382
00386 void untouch() { isTouched = false; }
00387
00388 private:
00389
00393 string addComment(string);
00394
00395 private:
00396
00400 bool isLocked;
00401
00406 bool isTouched;
00407
00412 InitState initState;
00413
00417 string theComment;
00418
00419 public:
00420
00425 virtual void debugme() const;
00426
00427 private:
00428
00432 static AbstractClassDescription<InterfacedBase> initInterfacedBase;
00433
00437 InterfacedBase & operator=(const InterfacedBase &);
00438
00439 protected:
00440
00444 struct UpdateChecker {
00446 UpdateChecker(bool & touched) : isTouched(touched) {}
00448 UpdateChecker(const UpdateChecker & uc) : isTouched(uc.isTouched) {}
00450 static void check(tIBPtr, bool &);
00452 template <typename ptr> void operator()(const ptr & i) {
00453 check(i, isTouched);
00454 }
00456 bool & isTouched;
00457 };
00458
00462 struct UpdateMapChecker {
00464 UpdateMapChecker(bool & touched) : isTouched(touched) {}
00466 UpdateMapChecker(const UpdateMapChecker & uc) : isTouched(uc.isTouched) {}
00468 template <typename ref> void operator()(const ref & i) {
00469 UpdateChecker::check(i.second, isTouched);
00470 }
00472 bool & isTouched;
00473 };
00474
00475 };
00476
00483 template <>
00484 struct BaseClassTrait<InterfacedBase,1>: public ClassTraitsType {
00486 typedef PersistentBase NthBase;
00487 };
00488
00493 template <>
00494 struct ClassTraits<InterfacedBase>: public ClassTraitsBase<InterfacedBase> {
00496 static string className() { return "ThePEG::InterfacedBase"; }
00497 };
00498
00501 }
00502
00503 #endif