CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DetectorDescription/Core/interface/DDName.h

Go to the documentation of this file.
00001 #ifndef DDName_h
00002 #define DDName_h
00003 
00004 #include <utility>
00005 #include <string>
00006 #include <iosfwd>
00007 #include <map>
00008 #include <vector>
00009 #include <stdexcept>
00010 //#include "DetectorDescription/Base/interface/Singleton.h"
00011 
00012 class DDCurrentNamespace;
00013 class DDStreamer;
00014 
00016 
00018 class DDName // : public std::pair<std::string,std::string>
00019 {
00020   friend class DStreamer; // intrusive!
00021   
00022 public:
00023   
00024   typedef DDCurrentNamespace CNS;
00025   typedef int id_type;
00026   typedef std::map<std::pair<std::string,std::string>,id_type> Registry;
00027   typedef std::vector<Registry::const_iterator> IdToName;
00028 
00029   
00031   DDName( const std::string & name,
00032           const std::string & ns);
00033 
00035   DDName( const std::string & name );
00036   DDName( const char* name ); 
00037   DDName( const char* name, const char* ns );
00038   // DDName(pair<int,int>);
00039   DDName(id_type);
00041   static void defineId( const std::pair<std::string,std::string> &, id_type id);
00042 
00043   explicit DDName();
00044   
00046   static bool exists(const std::string & name, const std::string & ns);
00048   const std::string & name() const;
00049   
00051   const std::string & ns() const;
00052   
00056   const std::string fullname() const { return ns() + ":" + name(); }
00057 
00058   // DEPRECATED!!!
00059   operator std::string() const { return ns() + ":" + name(); }
00060 
00061   id_type id() const { return id_;}
00062     
00063   bool operator<(const DDName & rhs) const { return id_ < rhs.id_; }
00064   bool operator==(const DDName & rhs) const { return id_ == rhs.id_; }
00065 
00066 private:
00067   id_type id_;
00068     
00069   static Registry::iterator registerName(const std::pair<std::string,std::string> & s);  
00070 };
00071 
00073 
00077 struct DDNameInterface
00078 {
00079   virtual ~DDNameInterface() {}
00080   //virtual const DDName & ddName() const=0; // qualified Name
00081   
00083   virtual const std::string & name() const=0;   // name without namespace
00084   
00086   virtual const std::string & ns() const=0; // only the namespace 
00087   
00089   DDName ddname() const { return DDName(name(),ns()); } 
00090   
00091   virtual operator bool() const=0;
00092   
00094   virtual int id() const=0; // dont't know if usefull ...
00095 };
00096 
00097 std::ostream & operator<<(std::ostream & os, const DDName & n); 
00098 
00099 #endif