CMS 3D CMS Logo

ParameterDescriptionCases.h
Go to the documentation of this file.
1 #ifndef FWCore_ParameterSet_ParameterDescriptionCases_h
2 #define FWCore_ParameterSet_ParameterDescriptionCases_h
3 
4 // This class is used to store temporary objects created when
5 // building ParameterSwitch's in a ParameterSetDescription.
6 // It gets created while evaluating an expression something
7 // like
8 //
9 // parameterSetDescription.ifValue( ParameterDescription<int>("switch", 0),
10 // 0 >> ParameterDescription<int>("label1", 11) or
11 // 1 >> ParameterDescription<float>("label2", 11.0f) or
12 // 2 >> ParameterDescription<std::string>("label3", "aValue");
13 // It hold the temporary results of the operator>> and operator||
14 // functions in the expression. The ONLY way to create one
15 // is via the operator>> function. The intent is that user
16 // should not need to save this temporary result nor directly
17 // reference this class, but ...
18 
19 // If one decided to save the value then one should be aware
20 // the class has been optimized to minimize the number of copies made
21 // while evaluating such an expression. It contains a unique_ptr and
22 // the class has move semantics like a unique_ptr.
23 
26 
27 #include <map>
28 #include <memory>
29 #include <string>
30 #include <utility>
31 
32 namespace edm {
33 
34  template<typename T>
36  public:
37  typedef std::map<T, edm::value_ptr<ParameterDescriptionNode> > CaseMap;
38 
39  void insert(T caseValue, std::unique_ptr<ParameterDescriptionNode> node) {
40  std::pair<T, edm::value_ptr<ParameterDescriptionNode> > casePair(caseValue,edm::value_ptr<ParameterDescriptionNode>());
41  std::pair<typename CaseMap::iterator,bool> status;
42  status = caseMap_->insert(casePair);
43  (*caseMap_)[caseValue] = std::move(node);
44  if (status.second == false) duplicateCaseValues_ = true;
45  }
46 
47  std::unique_ptr<CaseMap> caseMap() { return std::move(caseMap_); }
48  bool duplicateCaseValues() const { return duplicateCaseValues_; }
49 
50  private:
51 
52  friend
53  std::unique_ptr<ParameterDescriptionCases<bool> >
54  operator>>(bool caseValue,
55  std::unique_ptr<ParameterDescriptionNode> node);
56 
57  friend
58  std::unique_ptr<ParameterDescriptionCases<int> >
59  operator>>(int caseValue,
60  std::unique_ptr<ParameterDescriptionNode> node);
61 
62  friend
63  std::unique_ptr<ParameterDescriptionCases<std::string> >
64  operator>>(std::string const& caseValue,
65  std::unique_ptr<ParameterDescriptionNode> node);
66 
67  friend
68  std::unique_ptr<ParameterDescriptionCases<std::string> >
69  operator>>(char const* caseValue,
70  std::unique_ptr<ParameterDescriptionNode> node);
71 
72  // The constructor is intentionally private so that only the operator>> functions
73  // can create these.
74  ParameterDescriptionCases(T const& caseValue, std::unique_ptr<ParameterDescriptionNode> node) :
75  caseMap_(new CaseMap),
77  {
78  std::pair<T, edm::value_ptr<ParameterDescriptionNode> > casePair(caseValue,edm::value_ptr<ParameterDescriptionNode>());
79  caseMap_->insert(casePair);
80  (*caseMap_)[caseValue] = std::move(node);
81  }
82 
83  std::unique_ptr<CaseMap> caseMap_;
85  };
86 
87  std::unique_ptr<ParameterDescriptionCases<bool> >
89  std::unique_ptr<ParameterDescriptionCases<bool> >);
90 
91  std::unique_ptr<ParameterDescriptionCases<int> >
93  std::unique_ptr<ParameterDescriptionCases<int> >);
94 
95  std::unique_ptr<ParameterDescriptionCases<std::string> >
97  std::unique_ptr<ParameterDescriptionCases<std::string> >);
98 }
99 #endif
void insert(T caseValue, std::unique_ptr< ParameterDescriptionNode > node)
std::unique_ptr< CaseMap > caseMap()
friend std::unique_ptr< ParameterDescriptionCases< bool > > operator>>(bool caseValue, std::unique_ptr< ParameterDescriptionNode > node)
std::unique_ptr< ParameterDescriptionCases< bool > > operator||(std::unique_ptr< ParameterDescriptionCases< bool > >, std::unique_ptr< ParameterDescriptionCases< bool > >)
ParameterDescriptionCases(T const &caseValue, std::unique_ptr< ParameterDescriptionNode > node)
HLT enums.
std::unique_ptr< CaseMap > caseMap_
long double T
def move(src, dest)
Definition: eostools.py:510
std::map< T, edm::value_ptr< ParameterDescriptionNode > > CaseMap