CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
es_Label.h
Go to the documentation of this file.
1 #ifndef Framework_es_Label_h
2 #define Framework_es_Label_h
3 // -*- C++ -*-
4 //
5 // Package: Framework
6 // Class : es_Label
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Fri Sep 30 09:35:20 EDT 2005
19 //
20 
21 // system include files
22 #include "boost/shared_ptr.hpp"
23 #include <string>
24 #include <vector>
25 
26 // user include files
29 
30 // forward declarations
31 
32 namespace edm {
33  namespace es{
34  template<typename T, int ILabel>
35  struct L {
36  typedef T element_type;
37 
38  L() : product_() {}
39  explicit L(boost::shared_ptr<T> iP) : product_(iP) {}
40  explicit L(T* iP) : product_(iP) {}
41  L(const L<T,ILabel>& iOther) : product_(iOther.product_) {}
42 
43  T& operator*() { return *product_;}
44  T* operator->() { return product_.get(); }
45  mutable boost::shared_ptr<T> product_;
46  };
47  template<int ILabel,typename T>
48  L<T,ILabel> l(boost::shared_ptr<T>& iP) {
49  L<T,ILabel> temp(iP);
50  return temp;
51  }
52  struct Label {
53  Label() : labels_(), default_() {}
54  Label(const char* iLabel) : labels_(), default_(iLabel) {}
55  Label(const std::string& iString) : labels_(), default_(iString) {}
56  Label(const std::string& iString, unsigned int iIndex) :
57  labels_(iIndex+1,def()), default_() {labels_[iIndex] = iString;}
58 
59  Label& operator()(const std::string& iString, unsigned int iIndex) {
60  if(iIndex==labels_.size()){
61  labels_.push_back(iString);
62  } else if(iIndex > labels_.size()) {
63  std::vector<std::string> temp(iIndex+1,def());
64  copy_all(labels_, temp.begin());
65  labels_.swap(temp);
66  } else {
67  if( labels_[iIndex] != def() ) {
68  Exception e(errors::Configuration,"Duplicate Label");
69  e <<"The index "<<iIndex<<" was previously assigned the label \""
70  <<labels_[iIndex]<<"\" and then was later assigned \""
71  <<iString<<"\"";
72  e.raise();
73  }
74  labels_[iIndex] = iString;
75  }
76  return *this;
77  }
78  Label& operator()(int iIndex, const std::string& iString) {
79  return (*this)(iString, iIndex);
80  }
81 
82  static const std::string& def() {
83  static const std::string s_def("\n\t");
84  return s_def;
85  }
86  std::vector<std::string> labels_;
87  std::string default_;
88  };
89 
90  inline Label label(const std::string& iString, int iIndex) {
91  return Label(iString, iIndex);
92  }
93  inline Label label(int iIndex, const std::string& iString) {
94  return Label(iString, iIndex);
95  }
96  }
97 }
98 
99 #endif
Label & operator()(const std::string &iString, unsigned int iIndex)
Definition: es_Label.h:59
static const std::string & def()
Definition: es_Label.h:82
Label label(const std::string &iString, int iIndex)
Definition: es_Label.h:90
Label(const char *iLabel)
Definition: es_Label.h:54
L(T *iP)
Definition: es_Label.h:40
void raise()
Definition: Exception.h:128
Label(const std::string &iString)
Definition: es_Label.h:55
T & operator*()
Definition: es_Label.h:43
boost::shared_ptr< T > product_
Definition: es_Label.h:45
Label & operator()(int iIndex, const std::string &iString)
Definition: es_Label.h:78
L(boost::shared_ptr< T > iP)
Definition: es_Label.h:39
std::string default_
Definition: es_Label.h:87
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:24
L(const L< T, ILabel > &iOther)
Definition: es_Label.h:41
T * operator->()
Definition: es_Label.h:44
std::vector< std::string > labels_
Definition: es_Label.h:86
L< T, ILabel > l(boost::shared_ptr< T > &iP)
Definition: es_Label.h:48
Label(const std::string &iString, unsigned int iIndex)
Definition: es_Label.h:56
T element_type
Definition: es_Label.h:36