CMS 3D CMS Logo

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 // $Id: es_Label.h,v 1.4 2008/01/17 01:05:20 wmtan Exp $
00020 //
00021 
00022 // system include files
00023 #include "boost/shared_ptr.hpp"
00024 #include <string>
00025 #include <vector>
00026 
00027 // user include files
00028 #include "FWCore/Utilities/interface/EDMException.h"
00029 #include "FWCore/Utilities/interface/Algorithms.h"
00030 
00031 // forward declarations
00032 
00033 namespace edm {
00034    namespace es{
00035       template<typename T, int ILabel>
00036       struct L {
00037          typedef T element_type;
00038          
00039          L() : product_() {}
00040          explicit L(boost::shared_ptr<T> iP) : product_(iP) {}
00041          explicit L(T* iP) : product_(iP) {}
00042          L(const L<T,ILabel>& iOther) : product_(iOther.product_) {}
00043          
00044          T& operator*() { return *product_;}
00045          T* operator->() { return product_.get(); }
00046          mutable boost::shared_ptr<T> product_;
00047       };
00048       template<int ILabel,typename T>
00049          L<T,ILabel> l(boost::shared_ptr<T>& iP) { 
00050             L<T,ILabel> temp(iP);
00051             return temp;
00052          }
00053       struct Label {
00054          Label() : labels_(), default_() {}
00055          Label(const char* iLabel) : labels_(), default_(iLabel) {}
00056          Label(const std::string& iString) : labels_(), default_(iString) {}
00057          Label(const std::string& iString, unsigned int iIndex) : 
00058            labels_(iIndex+1,def()), default_() {labels_[iIndex] = iString;}
00059          
00060          Label& operator()(const std::string& iString, unsigned int iIndex) {
00061             if(iIndex==labels_.size()){
00062                labels_.push_back(iString);
00063             } else if(iIndex > labels_.size()) {
00064                std::vector<std::string> temp(iIndex+1,def());
00065                copy_all(labels_, temp.begin());
00066                labels_.swap(temp);
00067             } else {
00068                if( labels_[iIndex] != def() ) {
00069                   throw edm::Exception(errors::Configuration,"Duplicate Label")
00070                   <<"The index "<<iIndex<<" was previously assigned the label \""
00071                   <<labels_[iIndex]<<"\" and then was later assigned \""
00072                   <<iString<<"\"";
00073                }
00074                labels_[iIndex] = iString;
00075             }
00076             return *this;
00077          }
00078          Label& operator()(int iIndex, const std::string& iString) {
00079             return (*this)(iString, iIndex);
00080          }
00081          
00082          static const std::string& def() {
00083             static const std::string s_def("\n\t");
00084             return s_def;
00085          }
00086          std::vector<std::string> labels_;
00087          std::string default_;
00088       };
00089       
00090       inline Label label(const std::string& iString, int iIndex) {
00091          return Label(iString, iIndex);
00092       }
00093       inline Label label(int iIndex, const std::string& iString) {
00094          return Label(iString, iIndex);
00095       }
00096    }
00097 }   
00098 
00099 #endif

Generated on Tue Jun 9 17:35:29 2009 for CMSSW by  doxygen 1.5.4