Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:08:22

0001 #ifndef x_TagName_h
0002 #define x_TagName_h
0003 
0004 #include <utility>
0005 #include <string>
0006 #include <iostream>
0007 #include <map>
0008 
0009 class TagName {
0010 public:
0011   TagName() : id_(count()) {}
0012 
0013   explicit TagName(const std::string& name) : name_(regName(name)), id_(count()){};
0014 
0015   const std::string& str() const { return name_->first; }
0016 
0017   std::string operator()() const { return name_->first; }
0018 
0019   bool sameName(const TagName& tn) const { return (name_ == tn.name_); }
0020 
0021   bool operator<(const TagName& n) const { return (id_ < n.id_); }
0022 
0023 private:
0024   typedef std::map<std::string, unsigned int> Registry;
0025   typedef unsigned int count_type;
0026 
0027   Registry::iterator name_;
0028   count_type id_;  // identification for equality checks
0029 
0030   static Registry::iterator regName(const std::string& s) {
0031     static Registry reg;
0032     Registry::size_type sz = reg.size();
0033     Registry::value_type val(s, sz);
0034     /*
0035     std::pair<Registry::iterator, bool> insert = reg.insert(val);
0036     if (!insert.second) {  
0037       sz = insert.first->second;
0038     }  
0039     return insert.first;
0040     */
0041     return reg.insert(val).first;
0042   }
0043 
0044   static count_type count() {
0045     static count_type i = 0;
0046     ++i;
0047     return i;
0048   }
0049 };
0050 
0051 #endif