CMS 3D CMS Logo

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 <string_view>
25 #include <vector>
26 
27 // user include files
30 
31 // forward declarations
32 
33 namespace edm::es {
34 
35  template <typename T, int ILabel>
36  struct L {
37  using element_type = T;
38 
39  L() = default;
40  explicit L(std::shared_ptr<T> iP) : product_{std::move(iP)} {}
41  explicit L(std::unique_ptr<T> iP) : product_{std::move(iP)} {}
42  explicit L(T* iP) : product_(iP) {}
43 
44  T& operator*() { return *product_; }
45  T* operator->() { return product_.get(); }
46  mutable std::shared_ptr<T> product_{nullptr};
47  };
48 
49  template <int ILabel, typename T>
50  L<T, ILabel> l(std::shared_ptr<T>& iP) {
51  return L<T, ILabel>{iP};
52  }
53 
54  struct Label {
55  Label() = default;
56  Label(const char* iLabel) : default_{iLabel} {}
57  Label(const std::string& iString) : default_{iString} {}
58  Label(const std::string& iString, unsigned int const iIndex) : labels_(iIndex + 1, def()) {
59  labels_[iIndex] = iString;
60  }
61 
62  Label& operator()(const std::string& iString, unsigned int const iIndex) {
63  if (iIndex == labels_.size()) {
64  labels_.push_back(iString);
65  } else if (iIndex > labels_.size()) {
66  std::vector<std::string> temp(iIndex + 1, def());
67  copy_all(labels_, temp.begin());
68  labels_.swap(temp);
69  } else {
70  if (labels_[iIndex] != def()) {
71  Exception e(errors::Configuration, "Duplicate Label");
72  e << "The index " << iIndex << " was previously assigned the label \"" << labels_[iIndex]
73  << "\" and then was later assigned \"" << iString << "\"";
74  e.raise();
75  }
76  labels_[iIndex] = iString;
77  }
78  return *this;
79  }
80  Label& operator()(int iIndex, const std::string& iString) { return (*this)(iString, iIndex); }
81 
82  static const std::string& def() {
83  static const std::string s_def("\n\t");
84  return s_def;
85  }
86 
87  std::vector<std::string> labels_{};
89  };
90 
91  inline Label label(const std::string& iString, int iIndex) { return Label(iString, iIndex); }
92  inline Label label(int iIndex, const std::string& iString) { return Label(iString, iIndex); }
93 } // namespace edm::es
94 
95 #endif
edm::es::Label::default_
std::string default_
Definition: es_Label.h:88
edm::copy_all
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:20
edm::es::l
L< T, ILabel > l(std::shared_ptr< T > &iP)
Definition: es_Label.h:50
edm::es::Label::Label
Label(const char *iLabel)
Definition: es_Label.h:56
Algorithms.h
edm::es::L::L
L(std::unique_ptr< T > iP)
Definition: es_Label.h:41
edm::es::L::L
L()=default
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::es::Label::Label
Label()=default
edm::Exception
Definition: EDMException.h:77
EDMException.h
edm::es::Label::operator()
Label & operator()(int iIndex, const std::string &iString)
Definition: es_Label.h:80
edm::es::Label
Definition: es_Label.h:54
edm::es::Label::def
static const std::string & def()
Definition: es_Label.h:82
edm::es::label
Label label(const std::string &iString, int iIndex)
Definition: es_Label.h:91
edm::es::L::element_type
T element_type
Definition: es_Label.h:37
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::es::L
Definition: es_Label.h:36
edm::es::L::product_
std::shared_ptr< T > product_
Definition: es_Label.h:46
edm::es::L::operator*
T & operator*()
Definition: es_Label.h:44
edm::es::L::operator->
T * operator->()
Definition: es_Label.h:45
edm::es::L::L
L(T *iP)
Definition: es_Label.h:42
edm::es::Label::labels_
std::vector< std::string > labels_
Definition: es_Label.h:87
edm::es::L::L
L(std::shared_ptr< T > iP)
Definition: es_Label.h:40
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::es::Label::Label
Label(const std::string &iString, unsigned int const iIndex)
Definition: es_Label.h:58
T
long double T
Definition: Basic3DVectorLD.h:48
edm::es
Definition: es_Label.h:33
edm::es::Label::operator()
Label & operator()(const std::string &iString, unsigned int const iIndex)
Definition: es_Label.h:62
DataMixerDataOnData_cff.Label
Label
Definition: DataMixerDataOnData_cff.py:21
edm::errors::Configuration
Definition: EDMException.h:36
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::es::Label::Label
Label(const std::string &iString)
Definition: es_Label.h:57