Go to the documentation of this file.00001 #ifndef Framework_es_Label_h
00002 #define Framework_es_Label_h
00003
00004
00005
00006
00007
00016
00017
00018
00019
00020
00021
00022 #include "boost/shared_ptr.hpp"
00023 #include <string>
00024 #include <vector>
00025
00026
00027 #include "FWCore/Utilities/interface/EDMException.h"
00028 #include "FWCore/Utilities/interface/Algorithms.h"
00029
00030
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 L(const L<T,ILabel>& iOther) : product_(iOther.product_) {}
00042
00043 T& operator*() { return *product_;}
00044 T* operator->() { return product_.get(); }
00045 mutable boost::shared_ptr<T> product_;
00046 };
00047 template<int ILabel,typename T>
00048 L<T,ILabel> l(boost::shared_ptr<T>& iP) {
00049 L<T,ILabel> temp(iP);
00050 return temp;
00051 }
00052 struct Label {
00053 Label() : labels_(), default_() {}
00054 Label(const char* iLabel) : labels_(), default_(iLabel) {}
00055 Label(const std::string& iString) : labels_(), default_(iString) {}
00056 Label(const std::string& iString, unsigned int iIndex) :
00057 labels_(iIndex+1,def()), default_() {labels_[iIndex] = iString;}
00058
00059 Label& operator()(const std::string& iString, unsigned int iIndex) {
00060 if(iIndex==labels_.size()){
00061 labels_.push_back(iString);
00062 } else if(iIndex > labels_.size()) {
00063 std::vector<std::string> temp(iIndex+1,def());
00064 copy_all(labels_, temp.begin());
00065 labels_.swap(temp);
00066 } else {
00067 if( labels_[iIndex] != def() ) {
00068 Exception e(errors::Configuration,"Duplicate Label");
00069 e <<"The index "<<iIndex<<" was previously assigned the label \""
00070 <<labels_[iIndex]<<"\" and then was later assigned \""
00071 <<iString<<"\"";
00072 e.raise();
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