CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/FWCore/Framework/interface/es_Label.h

Go to the documentation of this file.
00001 #ifndef Framework_es_Label_h
00002 #define Framework_es_Label_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     Framework
00006 // Class  :     es_Label
00007 // 
00016 //
00017 // Original Author:  Chris Jones
00018 //         Created:  Fri Sep 30 09:35:20 EDT 2005
00019 //
00020 
00021 // system include files
00022 #include "boost/shared_ptr.hpp"
00023 #include <string>
00024 #include <vector>
00025 
00026 // user include files
00027 #include "FWCore/Utilities/interface/EDMException.h"
00028 #include "FWCore/Utilities/interface/Algorithms.h"
00029 
00030 // forward declarations
00031 
00032 namespace edm {
00033    namespace es{
00034       template<typename T, int ILabel>
00035       struct L {
00036          typedef T element_type;
00037          
00038          L() : product_() {}
00039          explicit L(boost::shared_ptr<T> iP) : product_(iP) {}
00040          explicit L(T* iP) : product_(iP) {}
00041          
00042          T& operator*() { return *product_;}
00043          T* operator->() { return product_.get(); }
00044          mutable boost::shared_ptr<T> product_;
00045       };
00046       template<int ILabel,typename T>
00047          L<T,ILabel> l(boost::shared_ptr<T>& iP) { 
00048             L<T,ILabel> temp(iP);
00049             return temp;
00050          }
00051       struct Label {
00052          Label() : labels_(), default_() {}
00053          Label(const char* iLabel) : labels_(), default_(iLabel) {}
00054          Label(const std::string& iString) : labels_(), default_(iString) {}
00055          Label(const std::string& iString, unsigned int iIndex) : 
00056            labels_(iIndex+1,def()), default_() {labels_[iIndex] = iString;}
00057          
00058          Label& operator()(const std::string& iString, unsigned int iIndex) {
00059             if(iIndex==labels_.size()){
00060                labels_.push_back(iString);
00061             } else if(iIndex > labels_.size()) {
00062                std::vector<std::string> temp(iIndex+1,def());
00063                copy_all(labels_, temp.begin());
00064                labels_.swap(temp);
00065             } else {
00066                if( labels_[iIndex] != def() ) {
00067                   Exception e(errors::Configuration,"Duplicate Label");
00068                   e <<"The index "<<iIndex<<" was previously assigned the label \""
00069                     <<labels_[iIndex]<<"\" and then was later assigned \""
00070                     <<iString<<"\"";
00071                   e.raise();
00072                }
00073                labels_[iIndex] = iString;
00074             }
00075             return *this;
00076          }
00077          Label& operator()(int iIndex, const std::string& iString) {
00078             return (*this)(iString, iIndex);
00079          }
00080          
00081          static const std::string& def() {
00082             static const std::string s_def("\n\t");
00083             return s_def;
00084          }
00085          std::vector<std::string> labels_;
00086          std::string default_;
00087       };
00088       
00089       inline Label label(const std::string& iString, int iIndex) {
00090          return Label(iString, iIndex);
00091       }
00092       inline Label label(int iIndex, const std::string& iString) {
00093          return Label(iString, iIndex);
00094       }
00095    }
00096 }   
00097 
00098 #endif