CMS 3D CMS Logo

DDName.h
Go to the documentation of this file.
1 #ifndef DDName_h
2 #define DDName_h
3 
4 #include <iosfwd>
5 #include <map>
6 #include <string>
7 #include <utility>
8 #include <vector>
9 
10 class DDCurrentNamespace;
11 class DDStreamer;
12 
14 
16 class DDName
17 {
18  friend class DStreamer; // intrusive!
19 
20 public:
21 
23  typedef int id_type;
24  typedef std::map<std::pair<std::string,std::string>,id_type> Registry;
25  typedef std::vector<Registry::const_iterator> IdToName;
26 
28  DDName( const std::string & name,
29  const std::string & ns);
30 
32  DDName( const std::string & name );
33  DDName( const char* name );
34  DDName( const char* name, const char* ns );
35  // DDName(pair<int,int>);
36  DDName(id_type);
38  static void defineId( const std::pair<std::string,std::string> &, id_type id);
39 
40  explicit DDName();
41 
43  static bool exists(const std::string & name, const std::string & ns);
45  const std::string & name() const;
46 
48  const std::string & ns() const;
49 
53  const std::string fullname() const { return ns() + ":" + name(); }
54 
55  // DEPRECATED!!!
56  operator std::string() const { return ns() + ":" + name(); }
57 
58  id_type id() const { return id_;}
59 
60  bool operator<(const DDName & rhs) const { return id_ < rhs.id_; }
61  bool operator==(const DDName & rhs) const { return id_ == rhs.id_; }
62 
63 private:
64  id_type id_;
65 
66  static Registry::iterator registerName(const std::pair<std::string,std::string> & s);
67 };
68 
70 
75 {
76  virtual ~DDNameInterface() {}
77 
79  virtual const std::string & name() const=0; // name without namespace
80 
82  virtual const std::string & ns() const=0; // only the namespace
83 
85  DDName ddname() const { return DDName(name(),ns()); }
86 
87  virtual operator bool() const=0;
88 
90  virtual int id() const=0; // dont't know if usefull ...
91 };
92 
93 std::ostream & operator<<(std::ostream & os, const DDName & n);
94 
95 #endif
id_type id() const
Definition: DDName.h:58
DDCurrentNamespace CNS
Definition: DDName.h:22
Streaming the DDD transient store from/into a std::istream/std::ostream */.
Definition: DDStreamer.h:42
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:104
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:16
DDName()
Definition: DDName.cc:58
std::ostream & operator<<(std::ostream &os, const DDName &n)
Definition: DDName.cc:12
DDNameInterface provides a common interface to DDD entities.
Definition: DDName.h:74
std::map< std::pair< std::string, std::string >, id_type > Registry
Definition: DDName.h:24
friend class DStreamer
Definition: DDName.h:18
const std::string fullname() const
Definition: DDName.h:53
bool operator<(const DDName &rhs) const
Definition: DDName.h:60
static void defineId(const std::pair< std::string, std::string > &, id_type id)
register pre-defined ids
Definition: DDName.cc:66
std::vector< Registry::const_iterator > IdToName
Definition: DDName.h:25
int id_type
Definition: DDName.h:23
static bool exists(const std::string &name, const std::string &ns)
true, if a DDName with given name and namespace (ns) already is registerd, otherwise false ...
Definition: DDName.cc:119
id_type id_
Definition: DDName.h:64
bool operator==(const DDName &rhs) const
Definition: DDName.h:61
virtual ~DDNameInterface()
Definition: DDName.h:76
static Registry::iterator registerName(const std::pair< std::string, std::string > &s)
Definition: DDName.cc:127
const std::string & name() const
Returns the name.
Definition: DDName.cc:90
DDName ddname() const
Return the DDName.
Definition: DDName.h:85