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  T const& operator*() const { return *product_; }
47  T const* operator->() const { return product_.get(); }
48  mutable std::shared_ptr<T> product_{nullptr};
49  };
50 
51  template <int ILabel, typename T>
52  L<T, ILabel> l(std::shared_ptr<T>& iP) {
53  return L<T, ILabel>{iP};
54  }
55 
56  struct Label {
57  Label() = default;
58  Label(const char* iLabel) : default_{iLabel} {}
59  Label(const std::string& iString) : default_{iString} {}
60  Label(const std::string& iString, unsigned int const iIndex) : labels_(iIndex + 1, def()) {
61  labels_[iIndex] = iString;
62  }
63 
64  Label& operator()(const std::string& iString, unsigned int const iIndex) {
65  if (iIndex == labels_.size()) {
66  labels_.push_back(iString);
67  } else if (iIndex > labels_.size()) {
68  std::vector<std::string> temp(iIndex + 1, def());
69  copy_all(labels_, temp.begin());
70  labels_.swap(temp);
71  } else {
72  if (labels_[iIndex] != def()) {
73  Exception e(errors::Configuration, "Duplicate Label");
74  e << "The index " << iIndex << " was previously assigned the label \"" << labels_[iIndex]
75  << "\" and then was later assigned \"" << iString << "\"";
76  e.raise();
77  }
78  labels_[iIndex] = iString;
79  }
80  return *this;
81  }
82  Label& operator()(int iIndex, const std::string& iString) { return (*this)(iString, iIndex); }
83 
84  static const std::string& def() {
85  static const std::string s_def("\n\t");
86  return s_def;
87  }
88 
89  std::vector<std::string> labels_{};
91  };
92 
93  inline Label label(const std::string& iString, int iIndex) { return Label(iString, iIndex); }
94  inline Label label(int iIndex, const std::string& iString) { return Label(iString, iIndex); }
95 } // namespace edm::es
96 
97 #endif
edm::es::Label::default_
std::string default_
Definition: es_Label.h:90
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:52
edm::es::Label::Label
Label(const char *iLabel)
Definition: es_Label.h:58
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:82
edm::es::Label
Definition: es_Label.h:56
edm::es::Label::def
static const std::string & def()
Definition: es_Label.h:84
edm::es::label
Label label(const std::string &iString, int iIndex)
Definition: es_Label.h:93
edm::es::L::operator*
T const & operator*() const
Definition: es_Label.h:46
edm::es::L::element_type
T element_type
Definition: es_Label.h:37
edm::es::L
Definition: es_Label.h:36
edm::es::L::product_
std::shared_ptr< T > product_
Definition: es_Label.h:48
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:89
edm::es::L::L
L(std::shared_ptr< T > iP)
Definition: es_Label.h:40
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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:60
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:64
DataMixerDataOnData_cff.Label
Label
Definition: DataMixerDataOnData_cff.py:21
edm::errors::Configuration
Definition: EDMException.h:36
edm::es::L::operator->
T const * operator->() const
Definition: es_Label.h:47
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::es::Label::Label
Label(const std::string &iString)
Definition: es_Label.h:59