test
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 <memory>
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(std::shared_ptr<T> iP) : product_(iP) {}
40  explicit L(T* iP) : product_(iP) {}
41 
42  T& operator*() { return *product_;}
43  T* operator->() { return product_.get(); }
44  mutable std::shared_ptr<T> product_;
45  };
46  template<int ILabel,typename T>
47  L<T,ILabel> l(std::shared_ptr<T>& iP) {
48  L<T,ILabel> temp(iP);
49  return temp;
50  }
51  struct Label {
52  Label() : labels_(), default_() {}
53  Label(const char* iLabel) : labels_(), default_(iLabel) {}
54  Label(const std::string& iString) : labels_(), default_(iString) {}
55  Label(const std::string& iString, unsigned int iIndex) :
56  labels_(iIndex+1,def()), default_() {labels_[iIndex] = iString;}
57 
58  Label& operator()(const std::string& iString, unsigned int iIndex) {
59  if(iIndex==labels_.size()){
60  labels_.push_back(iString);
61  } else if(iIndex > labels_.size()) {
62  std::vector<std::string> temp(iIndex+1,def());
63  copy_all(labels_, temp.begin());
64  labels_.swap(temp);
65  } else {
66  if( labels_[iIndex] != def() ) {
67  Exception e(errors::Configuration,"Duplicate Label");
68  e <<"The index "<<iIndex<<" was previously assigned the label \""
69  <<labels_[iIndex]<<"\" and then was later assigned \""
70  <<iString<<"\"";
71  e.raise();
72  }
73  labels_[iIndex] = iString;
74  }
75  return *this;
76  }
77  Label& operator()(int iIndex, const std::string& iString) {
78  return (*this)(iString, iIndex);
79  }
80 
81  static const std::string& def() {
82  static const std::string s_def("\n\t");
83  return s_def;
84  }
85  std::vector<std::string> labels_;
87  };
88 
89  inline Label label(const std::string& iString, int iIndex) {
90  return Label(iString, iIndex);
91  }
92  inline Label label(int iIndex, const std::string& iString) {
93  return Label(iString, iIndex);
94  }
95  }
96 }
97 
98 #endif
Label & operator()(const std::string &iString, unsigned int iIndex)
Definition: es_Label.h:58
static const std::string & def()
Definition: es_Label.h:81
Label label(const std::string &iString, int iIndex)
Definition: es_Label.h:89
Label(const char *iLabel)
Definition: es_Label.h:53
L(T *iP)
Definition: es_Label.h:40
void raise()
Definition: Exception.h:105
Label(const std::string &iString)
Definition: es_Label.h:54
T & operator*()
Definition: es_Label.h:42
L< T, ILabel > l(std::shared_ptr< T > &iP)
Definition: es_Label.h:47
std::shared_ptr< T > product_
Definition: es_Label.h:44
L(std::shared_ptr< T > iP)
Definition: es_Label.h:39
Label & operator()(int iIndex, const std::string &iString)
Definition: es_Label.h:77
std::string default_
Definition: es_Label.h:86
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:24
T * operator->()
Definition: es_Label.h:43
std::vector< std::string > labels_
Definition: es_Label.h:85
long double T
Label(const std::string &iString, unsigned int iIndex)
Definition: es_Label.h:55
T element_type
Definition: es_Label.h:36