thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
BaseRepository.h
1 // -*- C++ -*-
2 //
3 // BaseRepository.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2019 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 3 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 const vector<string> & listReadDirs();
224 
228  static void prependReadDir(string);
229 
233  static void prependReadDir(const std::vector<std::string>& dirs);
234 
238  static void appendReadDir(string);
239 
243  static void appendReadDir(const std::vector<std::string>& dirs);
244 
246 
254  template <typename T>
255  static typename Ptr<T>::pointer GetPtr(const T &);
256 
262  template <typename PtrType>
263  static PtrType GetPtr(string);
264 
273  template <typename PtrType>
274  static PtrType GetObject(string);
275 
280  static IBPtr GetPointer(string);
281 
286  static IVector SearchDirectory(string name, string className = "");
287 
297  static IBPtr TraceObject(string name);
298 
303  static string GetInterfacedBaseClasses(const ClassDescriptionBase * cdb);
304 
311  static IBPtr getObjectFromNoun(string noun);
313 
321 
327 
334  static void addReferences(tIBPtr obj, ObjectSet & refs);
336 
347  static InterfaceMap getInterfaces(const type_info & ti, bool all = true);
348 
352  static const InterfaceBase * FindInterface(IBPtr object, string name);
353 
360  static string getInterfaceFromNoun(string noun);
361 
368  static string getPosArgFromNoun(string noun);
369 
374  template <typename Cont>
375  static vector< pair<IBPtr, const InterfaceBase *> >
376  getNonDefaultInterfaces(const Cont &);
377 
379 
385  static void update();
386 
391  template<typename Cont>
392  static void clearAll(const Cont & c)
393  {
394  for_each(c, mem_fn(&InterfacedBase::clear));
395  }
396 
401  template<typename Cont>
402  static void resetAll(const Cont & c)
403  {
404  for_each(c, mem_fn(&InterfacedBase::reset));
405  }
406 
411  static void readSetup(tIBPtr ip, istream & is);
412 
417  static void lock(tIBPtr ip) { ip->lock(); }
418 
423  static void unlock(tIBPtr ip) { ip->unlock(); }
425 
432 
437  static string getModelDescription(tcIBPtr ip);
438 
443  static string getModelReferences(tcIBPtr ip);
445 
451  static void cout(ostream & os) { coutp() = &os; }
452 
456  static ostream & cout() { return *coutp(); }
457 
461  static void cerr(ostream & os) { cerrp() = &os; }
462 
466  static ostream & cerr() { return *cerrp(); }
467 
471  static void clog(ostream & os) { clogp() = &os; }
472 
476  static ostream & clog() { return *clogp(); }
478 
479 protected:
480 
488  template <typename T>
489  static typename Ptr<T>::pointer clone(const T & t);
490 
496  template <typename T>
497  static typename Ptr<T>::pointer fullclone(const T & t);
498 
507  static void rebind(InterfacedBase & obj, const TranslationMap & trans,
508  const IVector & defaults);
510 
511 
516  static void addInterfaces(const ClassDescriptionBase &,
517  InterfaceMap &, bool all = true);
518 
525  static ObjectMap & objects();
526 
530  static ObjectSet & allObjects();
531 
536  static TypeInterfaceMap & interfaces();
537 
543 
547  static DirectorySet & directories();
548 
552  static StringVector & directoryStack();
553 
557  static bool & updating();
558 
562  static ostream *& coutp();
563 
567  static ostream *& cerrp();
571  static ostream *& clogp();
573 
574 };
575 
576 
577 }
578 
579 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
580 #include "BaseRepository.tcc"
581 #endif
582 
583 #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:696
TransientRCPtr is a simple wrapper around a bare pointer which can be assigned to and from an RCPtr a...
Definition: RCPtr.h:519
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...
This is the main config header file for ThePEG.
static void appendReadDir(string)
Add a directory to readDirs().
static IVector GetObjectsReferringTo(IBPtr)
Get referring objects.
static const vector< string > & listReadDirs()
Access to list of directories to search for files for the "read" command.
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.