CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDName.h
Go to the documentation of this file.
1 #ifndef DDName_h
2 #define DDName_h
3 
4 #include <utility>
5 #include <string>
6 #include <iosfwd>
7 #include <map>
8 #include <vector>
9 #include <stdexcept>
10 //#include "DetectorDescription/Base/interface/Singleton.h"
11 
12 class DDCurrentNamespace;
13 class DDStreamer;
14 
16 
18 class DDName // : public std::pair<std::string,std::string>
19 {
20  friend class DStreamer; // intrusive!
21 
22 public:
23 
25  typedef int id_type;
26  typedef std::map<std::pair<std::string,std::string>,id_type> Registry;
27  typedef std::vector<Registry::const_iterator> IdToName;
28 
29 
31  DDName( const std::string & name,
32  const std::string & ns);
33 
35  DDName( const std::string & name );
36  DDName( const char* name );
37  DDName( const char* name, const char* ns );
38  // DDName(pair<int,int>);
39  DDName(id_type);
41  static void defineId( const std::pair<std::string,std::string> &, id_type id);
42 
43  explicit DDName();
44 
46  static bool exists(const std::string & name, const std::string & ns);
48  const std::string & name() const;
49 
51  const std::string & ns() const;
52 
56  const std::string fullname() const { return ns() + ":" + name(); }
57 
58  // DEPRECATED!!!
59  operator std::string() const { return ns() + ":" + name(); }
60 
61  id_type id() const { return id_;}
62 
63  bool operator<(const DDName & rhs) const { return id_ < rhs.id_; }
64  bool operator==(const DDName & rhs) const { return id_ == rhs.id_; }
65 
66 private:
68 
69  static Registry::iterator registerName(const std::pair<std::string,std::string> & s);
70 };
71 
73 
78 {
79  virtual ~DDNameInterface() {}
80  //virtual const DDName & ddName() const=0; // qualified Name
81 
83  virtual const std::string & name() const=0; // name without namespace
84 
86  virtual const std::string & ns() const=0; // only the namespace
87 
89  DDName ddname() const { return DDName(name(),ns()); }
90 
91  virtual operator bool() const=0;
92 
94  virtual int id() const=0; // dont't know if usefull ...
95 };
96 
97 std::ostream & operator<<(std::ostream & os, const DDName & n);
98 
99 #endif
id_type id() const
Definition: DDName.h:61
DDCurrentNamespace CNS
Definition: DDName.h:24
Streaming the DDD transient store from/into a std::istream/std::ostream */.
Definition: DDStreamer.h:41
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:101
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:18
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
DDName()
Definition: DDName.cc:55
DDNameInterface provides a common interface to DDD entities.
Definition: DDName.h:77
std::map< std::pair< std::string, std::string >, id_type > Registry
Definition: DDName.h:26
virtual const std::string & ns() const =0
Return the namespace.
friend class DStreamer
Definition: DDName.h:20
const std::string fullname() const
Definition: DDName.h:56
bool operator<(const DDName &rhs) const
Definition: DDName.h:63
virtual const std::string & name() const =0
Returns the name without the namespace.
static void defineId(const std::pair< std::string, std::string > &, id_type id)
register pre-defined ids
Definition: DDName.cc:63
std::vector< Registry::const_iterator > IdToName
Definition: DDName.h:27
int id_type
Definition: DDName.h:25
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:116
id_type id_
Definition: DDName.h:67
bool operator==(const DDName &rhs) const
Definition: DDName.h:64
virtual ~DDNameInterface()
Definition: DDName.h:79
static Registry::iterator registerName(const std::pair< std::string, std::string > &s)
Definition: DDName.cc:124
const std::string & name() const
Returns the name.
Definition: DDName.cc:87
virtual int id() const =0
don&#39;t use !
DDName ddname() const
Return the DDName.
Definition: DDName.h:89