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 
13 
15 class DDName
16 {
17  friend class DStreamer; // intrusive!
18 
19 public:
20 
22  typedef int id_type;
23  typedef std::map<std::pair<std::string,std::string>,id_type> Registry;
24  typedef std::vector<Registry::const_iterator> IdToName;
25 
27  DDName( const std::string & name,
28  const std::string & ns);
29 
31  DDName( const std::string & name );
32  DDName( const char* name );
33  DDName( const char* name, const char* ns );
34  // DDName(pair<int,int>);
35  DDName(id_type);
37  static void defineId( const std::pair<std::string,std::string> &, id_type id);
38 
39  explicit DDName();
40 
42  static bool exists(const std::string & name, const std::string & ns);
44  const std::string & name() const;
45 
47  const std::string & ns() const;
48 
52  const std::string fullname() const { return ns() + ":" + name(); }
53 
54  // DEPRECATED!!!
55  operator std::string() const { return ns() + ":" + name(); }
56 
57  id_type id() const { return id_;}
58 
59  bool operator<(const DDName & rhs) const { return id_ < rhs.id_; }
60  bool operator==(const DDName & rhs) const { return id_ == rhs.id_; }
61 
62 private:
63  id_type id_;
64 
65  static Registry::iterator registerName(const std::pair<std::string,std::string> & s);
66 };
67 
69 
74 {
75  virtual ~DDNameInterface() {}
76 
78  virtual const std::string & name() const=0; // name without namespace
79 
81  virtual const std::string & ns() const=0; // only the namespace
82 
84  DDName ddname() const { return DDName(name(),ns()); }
85 
86  virtual operator bool() const=0;
87 
89  virtual int id() const=0; // dont't know if usefull ...
90 };
91 
92 std::ostream & operator<<(std::ostream & os, const DDName & n);
93 
94 #endif
id_type id() const
Definition: DDName.h:57
DDCurrentNamespace CNS
Definition: DDName.h:21
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:102
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
DDName()
Definition: DDName.cc:56
std::ostream & operator<<(std::ostream &os, const DDName &n)
Definition: DDName.cc:12
DDNameInterface provides a common interface to DDD entities.
Definition: DDName.h:73
std::map< std::pair< std::string, std::string >, id_type > Registry
Definition: DDName.h:23
friend class DStreamer
Definition: DDName.h:17
const std::string fullname() const
Definition: DDName.h:52
bool operator<(const DDName &rhs) const
Definition: DDName.h:59
static void defineId(const std::pair< std::string, std::string > &, id_type id)
register pre-defined ids
Definition: DDName.cc:64
std::vector< Registry::const_iterator > IdToName
Definition: DDName.h:24
int id_type
Definition: DDName.h:22
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:117
id_type id_
Definition: DDName.h:63
bool operator==(const DDName &rhs) const
Definition: DDName.h:60
virtual ~DDNameInterface()
Definition: DDName.h:75
static Registry::iterator registerName(const std::pair< std::string, std::string > &s)
Definition: DDName.cc:125
const std::string & name() const
Returns the name.
Definition: DDName.cc:88
DDName ddname() const
Return the DDName.
Definition: DDName.h:84