CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DetectorDescription/RegressionTest/src/TagName.h

Go to the documentation of this file.
00001 #ifndef x_TagName_h
00002 #define x_TagName_h
00003 
00004 #include <utility>
00005 #include <string>
00006 #include <iostream>
00007 #include <map>
00008 
00009 class TagName 
00010 {
00011 public:
00012   
00013   TagName() {}
00014   
00015   explicit TagName(const std::string & name) 
00016     : name_(regName(name)), id_(count()) 
00017     { };
00018   
00019   const std::string & str() const { return name_->first; }
00020   
00021   std::string operator()() const { return name_->first; }
00022   
00023   bool sameName(const TagName & tn) const {
00024     return (name_ == tn.name_);
00025   }
00026   
00027   bool operator<(const TagName & n) const {
00028     return (id_ < n.id_);
00029   }
00030     
00031 private:
00032   typedef std::map<std::string,unsigned int> Registry;
00033   typedef unsigned int count_type;
00034   
00035   Registry::iterator name_;
00036   count_type id_; // identification for equality checks
00037   
00038   static Registry::iterator regName(const std::string & s) {
00039     static Registry reg;
00040     Registry::size_type sz = reg.size();
00041     Registry::value_type val(s, sz);
00042     /*
00043     std::pair<Registry::iterator, bool> insert = reg.insert(val);
00044     if (!insert.second) {  
00045       sz = insert.first->second;
00046     }  
00047     return insert.first;
00048     */
00049     return reg.insert(val).first;
00050   }
00051   
00052   static count_type count()  {
00053     static count_type i=0;
00054     ++i;
00055     return i;
00056    } 
00057 };
00058 
00059 #endif