ThePEG  1.8.0
BaseRepository.h
1 // -*- C++ -*-
2 //
3 // BaseRepository.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2011 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 2 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef ThePEG_BaseRepository_H
10 #define ThePEG_BaseRepository_H
11 // This is the declaration of the BaseRepository class.
12 
13 #include "ThePEG/Config/ThePEG.h"
14 #include "BaseRepository.xh"
15 #include "ThePEG/Interface/InterfaceBase.fh"
16 #include "ThePEG/Interface/ClassDocumentation.fh"
17 #include "ThePEG/Interface/InterfacedBase.h"
18 #include "ThePEG/Utilities/ClassDescription.fh"
19 
20 namespace ThePEG {
21 
46 
47 public:
48 
50  typedef StringSet DirectorySet;
51 
53  typedef vector<string> StringVector;
54 
56  typedef set<const InterfaceBase *> InterfaceSet;
57 
60  typedef map<const ClassDescriptionBase *, InterfaceSet> TypeInterfaceMap;
61 
64  typedef map<const ClassDescriptionBase *, const ClassDocumentationBase *>
66 
67 public:
68 
75  static string exec(string cmd, ostream &);
76 
83  static void Register(const InterfaceBase &, const type_info &);
84 
90  static void Register(const ClassDocumentationBase &, const type_info &);
91 
98  static void Register(IBPtr);
99 
106  static void Register(IBPtr, string name);
107 
112  static void remove(tIBPtr);
113 
120  static string remove(const ObjectSet & rmset);
121 
126  static void rename(tIBPtr object, string newName);
128 
137  static void CreateDirectory(string);
138 
151  static void CheckObjectDirectory(string);
152 
163  static void CheckDirectory(string);
164 
171  static void DirectoryAppend(string &);
172 
180  static void ChangeDirectory(string name);
181 
189  static void PushDirectory(string name);
190 
195  static void PopDirectory();
196 
200  static vector<string> & globalLibraries();
201 
203 
206 protected:
207 
211  static stack<string> & currentReadDirStack();
212 
216  static vector<string> & readDirs();
217 
218 public:
219 
223  static void prependReadDir(string);
224 
228  static void appendReadDir(string);
229 
231 
239  template <typename T>
240  static typename Ptr<T>::pointer GetPtr(const T &);
241 
247  template <typename PtrType>
248  static PtrType GetPtr(string);
249 
258  template <typename PtrType>
259  static PtrType GetObject(string);
260 
265  static IBPtr GetPointer(string);
266 
271  static IVector SearchDirectory(string name, string className = "");
272 
282  static IBPtr TraceObject(string name);
283 
288  static string GetInterfacedBaseClasses(const ClassDescriptionBase * cdb);
289 
296  static IBPtr getObjectFromNoun(string noun);
298 
306 
312 
319  static void addReferences(tIBPtr obj, ObjectSet & refs);
321 
332  static InterfaceMap getInterfaces(const type_info & ti, bool all = true);
333 
337  static const InterfaceBase * FindInterface(IBPtr object, string name);
338 
345  static string getInterfaceFromNoun(string noun);
346 
353  static string getPosArgFromNoun(string noun);
354 
359  template <typename Cont>
360  static vector< pair<IBPtr, const InterfaceBase *> >
361  getNonDefaultInterfaces(const Cont &);
362 
364 
370  static void update();
371 
376  template<typename Cont>
377  static void clearAll(const Cont & c)
378  {
379  for_each(c, mem_fun(&InterfacedBase::clear));
380  }
381 
386  template<typename Cont>
387  static void resetAll(const Cont & c)
388  {
389  for_each(c, mem_fun(&InterfacedBase::reset));
390  }
391 
396  static void readSetup(tIBPtr ip, istream & is);
397 
402  static void lock(tIBPtr ip) { ip->lock(); }
403 
408  static void unlock(tIBPtr ip) { ip->unlock(); }
410 
417 
422  static string getModelDescription(tcIBPtr ip);
423 
428  static string getModelReferences(tcIBPtr ip);
430 
436  static void cout(ostream & os) { coutp() = &os; }
437 
441  static ostream & cout() { return *coutp(); }
442 
446  static void cerr(ostream & os) { cerrp() = &os; }
447 
451  static ostream & cerr() { return *cerrp(); }
452 
456  static void clog(ostream & os) { clogp() = &os; }
457 
461  static ostream & clog() { return *clogp(); }
463 
464 protected:
465 
473  template <typename T>
474  static typename Ptr<T>::pointer clone(const T & t);
475 
481  template <typename T>
482  static typename Ptr<T>::pointer fullclone(const T & t);
483 
492  static void rebind(InterfacedBase & obj, const TranslationMap & trans,
493  const IVector & defaults);
495 
496 
501  static void addInterfaces(const ClassDescriptionBase &,
502  InterfaceMap &, bool all = true);
503 
510  static ObjectMap & objects();
511 
515  static ObjectSet & allObjects();
516 
521  static TypeInterfaceMap & interfaces();
522 
528 
532  static DirectorySet & directories();
533 
537  static StringVector & directoryStack();
538 
542  static bool & updating();
543 
547  static ostream *& coutp();
548 
552  static ostream *& cerrp();
556  static ostream *& clogp();
558 
559 };
560 
561 
562 }
563 
564 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
565 #include "BaseRepository.tcc"
566 #endif
567 
568 #endif /* ThePEG_BaseRepository_H */
static void rename(tIBPtr object, string newName)
Rename a given object.
static string getModelReferences(tcIBPtr ip)
Get the references for the model implemented in the class of the given object.
static void Register(const InterfaceBase &, const type_info &)
Register an interface.
static DirectorySet & directories()
All defined directories.
static string getPosArgFromNoun(string noun)
Get interface index.
ClassDescriptionBase is the base class for all class description classes.
static ostream *& cerrp()
The current current standard error stream.
static InterfaceMap getInterfaces(const type_info &ti, bool all=true)
Get interfaces.
void clear()
Calls reset() and unTouch().
static void CreateDirectory(string)
Create a new directory with the given name.
StringSet DirectorySet
A set of strings.
static void cout(ostream &os)
Set the standard output stream.
ThePEG::Ptr< InterfacedBase >::transient_pointer tIBPtr
Alias for a transient pointer to InterfacedBase .
Definition: Pointers.h:62
The InterfaceBase class defines a generic interface to any class derived from the InterfacedBase clas...
Definition: InterfaceBase.h:59
FNC for_each(IteratorRange< Iterator > r, FNC f)
The std::for_each function taking an IteratorRange as argument.
Definition: algorithm.h:79
static bool & updating()
Flag to say if we are in the middle of an update procedure.
static stack< string > & currentReadDirStack()
The stack of directories used by the "read" command.
static ostream & cout()
Get the standard output stream.
TransientConstRCPtr is a simple wrapper around a bare const pointer which can be assigned to and from...
Definition: RCPtr.h:681
TransientRCPtr is a simple wrapper around a bare pointer which can be assigned to and from an RCPtr a...
Definition: RCPtr.h:509
static IVector SearchDirectory(string name, string className="")
Return all objects in the directory name.
static void rebind(InterfacedBase &obj, const TranslationMap &trans, const IVector &defaults)
Rebind references.
static StringVector & directoryStack()
The current directory stack.
Rebinder is a class associating pairs of pointers to objects.
Definition: Rebinder.h:27
static string getInterfaceFromNoun(string noun)
Get an interface name.
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
static ostream & cerr()
Get the standard error stream.
static vector< pair< IBPtr, const InterfaceBase * > > getNonDefaultInterfaces(const Cont &)
Return a list of the interfaces which do not have their default values for the given objects...
static void appendReadDir(string)
Add a directory to readDirs().
static IVector GetObjectsReferringTo(IBPtr)
Get referring objects.
static vector< string > & readDirs()
List of directories to search for files for the "read" command.
static ObjectSet & allObjects()
All InterfacedBase objects.
static IBPtr GetPointer(string)
Return a pointer to an object with the given name or null if no such object exists.
static ostream & clog()
Get the standard log stream.
static void update()
Call the InterfacedBase::update() function of all objects.
static Ptr< T >::pointer clone(const T &t)
Return a clone of the given object.
static ostream *& coutp()
The current current standard output stream.
static void addReferences(tIBPtr obj, ObjectSet &refs)
Get all references.
void reset()
Set the state of this object to uninitialized.
static void CheckDirectory(string)
Check if directory exixts.
static IBPtr TraceObject(string name)
Find an object.
static const ClassDocumentationBase * getDocumentation(tcIBPtr ip)
Return the class documentation of a given object.
static void CheckObjectDirectory(string)
Check if directory exixts.
static void clog(ostream &os)
Set the standard log stream.
BaseRepository is a purely static class which keeps a set of InterfacedBase objects indexed by their ...
InterfacedBase is the base class of all Interfaced objects to be handled by the BaseRepository class...
static ostream *& clogp()
The current current standard log stream.
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
static const InterfaceBase * FindInterface(IBPtr object, string name)
Return an interface with the given name to the given object.
static Ptr< T >::pointer fullclone(const T &t)
Return a clone of the given object.
static TypeDocumentationMap & documentations()
Sets of ClassDocumentationBase objects mapped to the class description of the class for which they ar...
static void PopDirectory()
Pop the directory stack.
static void DirectoryAppend(string &)
Return the absolute path.
static void prependReadDir(string)
Add a directory to readDirs().
vector< string > StringVector
A vector of character strings.
map< const ClassDescriptionBase *, InterfaceSet > TypeInterfaceMap
A map of sets of IterfaceBase objects indexed by pointers to ClassDescriptionBase objects...
map< const ClassDescriptionBase *, const ClassDocumentationBase * > TypeDocumentationMap
A map of ClassDocumentationBase objects indexed by pointers to ClassDescriptionBase objects...
static void clearAll(const Cont &c)
Clear the InterfacedBase::touched() flag in all objects in the given container.
static void addInterfaces(const ClassDescriptionBase &, InterfaceMap &, bool all=true)
Add interfaces to the given map for the class with the given class description.
The ClassDocumentationBase class is used to communicate documetation about an Interfaced class to the...
static void unlock(tIBPtr ip)
Unlock the given object.
static string getModelDescription(tcIBPtr ip)
Get the description for the model implemented in the class of the given object.
set< const InterfaceBase * > InterfaceSet
A set of pointers to InterfaceBase objects.
static void resetAll(const Cont &c)
Set the status of all objects in the given container to InterfacedBase::uninitialized.
static void cerr(ostream &os)
Set the standard error stream.
static IBPtr getObjectFromNoun(string noun)
Get an object.
static IVector DirectReferences(IBPtr)
Get direct references.
static void lock(tIBPtr ip)
Lock the given object.
static void readSetup(tIBPtr ip, istream &is)
Setup an object.
static void ChangeDirectory(string name)
Set the current directory to name.
vector< IBPtr > IVector
A vector of pointers to InterfacedBase objects.
Definition: Containers.h:67
static Ptr< T >::pointer GetPtr(const T &)
Return a reference counted pointer to the given object.
static void PushDirectory(string name)
Set the current directory to name.
static vector< string > & globalLibraries()
A list of all globally loaded libraries.
static ObjectMap & objects()
All InterfacedBase objects mapped to their name.
static string exec(string cmd, ostream &)
Interpret the command in cmd and return possible messages.
static TypeInterfaceMap & interfaces()
Sets of InterfaceBase objects mapped to the class description of the class for which they are defined...
static string GetInterfacedBaseClasses(const ClassDescriptionBase *cdb)
Return a string containing the name of the given class description and its base classes, one on each line.
static PtrType GetObject(string)
Return a pointer of the specified type to an object with the given name.