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,
42  std::pair<typename CaseMap::iterator, bool> status;
43  status = caseMap_->insert(casePair);
44  (*caseMap_)[caseValue] = std::move(node);
45  if (status.second == false)
46  duplicateCaseValues_ = true;
47  }
48 
49  std::unique_ptr<CaseMap> caseMap() { return std::move(caseMap_); }
50  bool duplicateCaseValues() const { return duplicateCaseValues_; }
51 
52  private:
53  friend std::unique_ptr<ParameterDescriptionCases<bool> > operator>>(bool caseValue,
54  std::unique_ptr<ParameterDescriptionNode> node);
55 
56  friend std::unique_ptr<ParameterDescriptionCases<int> > operator>>(int caseValue,
57  std::unique_ptr<ParameterDescriptionNode> node);
58 
59  friend std::unique_ptr<ParameterDescriptionCases<std::string> > operator>>(
60  std::string const& caseValue, std::unique_ptr<ParameterDescriptionNode> node);
61 
62  friend std::unique_ptr<ParameterDescriptionCases<std::string> > operator>>(
63  char const* caseValue, std::unique_ptr<ParameterDescriptionNode> node);
64 
65  // The constructor is intentionally private so that only the operator>> functions
66  // can create these.
67  ParameterDescriptionCases(T const& caseValue, std::unique_ptr<ParameterDescriptionNode> node)
68  : caseMap_(new CaseMap), duplicateCaseValues_(false) {
69  std::pair<T, edm::value_ptr<ParameterDescriptionNode> > casePair(caseValue,
71  caseMap_->insert(casePair);
72  (*caseMap_)[caseValue] = std::move(node);
73  }
74 
75  std::unique_ptr<CaseMap> caseMap_;
77  };
78 
79  std::unique_ptr<ParameterDescriptionCases<bool> > operator||(std::unique_ptr<ParameterDescriptionCases<bool> >,
80  std::unique_ptr<ParameterDescriptionCases<bool> >);
81 
82  std::unique_ptr<ParameterDescriptionCases<int> > operator||(std::unique_ptr<ParameterDescriptionCases<int> >,
83  std::unique_ptr<ParameterDescriptionCases<int> >);
84 
85  std::unique_ptr<ParameterDescriptionCases<std::string> > operator||(
87  std::unique_ptr<ParameterDescriptionCases<std::string> >);
88 } // namespace edm
89 #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:511
std::map< T, edm::value_ptr< ParameterDescriptionNode > > CaseMap