Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:51

0001 #ifndef FWCore_ParameterSet_ParameterDescriptionCases_h
0002 #define FWCore_ParameterSet_ParameterDescriptionCases_h
0003 
0004 // This class is used to store temporary objects created when
0005 // building ParameterSwitch's in a ParameterSetDescription.
0006 // It gets created while evaluating an expression something
0007 // like
0008 //
0009 // parameterSetDescription.ifValue( ParameterDescription<int>("switch", 0),
0010 //                                  0 >> ParameterDescription<int>("label1", 11) or
0011 //                                  1 >> ParameterDescription<float>("label2", 11.0f) or
0012 //                                  2 >> ParameterDescription<std::string>("label3", "aValue");
0013 // It hold the temporary results of the operator>> and operator||
0014 // functions in the expression.  The ONLY way to create one
0015 // is via the operator>> function. The intent is that user
0016 // should not need to save this temporary result nor directly
0017 // reference this class, but ...
0018 
0019 // If one decided to save the value then one should be aware
0020 // the class has been optimized to minimize the number of copies made
0021 // while evaluating such an expression.  It contains a unique_ptr and
0022 // the class has move semantics like a unique_ptr.
0023 
0024 #include "FWCore/Utilities/interface/value_ptr.h"
0025 #include "FWCore/ParameterSet/interface/ParameterDescriptionNode.h"
0026 
0027 #include <map>
0028 #include <memory>
0029 #include <string>
0030 #include <utility>
0031 
0032 namespace edm {
0033 
0034   template <typename T>
0035   class ParameterDescriptionCases {
0036   public:
0037     typedef std::map<T, edm::value_ptr<ParameterDescriptionNode> > CaseMap;
0038 
0039     void insert(T caseValue, std::unique_ptr<ParameterDescriptionNode> node) {
0040       std::pair<T, edm::value_ptr<ParameterDescriptionNode> > casePair(caseValue,
0041                                                                        edm::value_ptr<ParameterDescriptionNode>());
0042       std::pair<typename CaseMap::iterator, bool> status;
0043       status = caseMap_->insert(casePair);
0044       (*caseMap_)[caseValue] = std::move(node);
0045       if (status.second == false)
0046         duplicateCaseValues_ = true;
0047     }
0048 
0049     std::unique_ptr<CaseMap> caseMap() { return std::move(caseMap_); }
0050     bool duplicateCaseValues() const { return duplicateCaseValues_; }
0051 
0052   private:
0053     friend std::unique_ptr<ParameterDescriptionCases<bool> > operator>>(bool caseValue,
0054                                                                         std::unique_ptr<ParameterDescriptionNode> node);
0055 
0056     friend std::unique_ptr<ParameterDescriptionCases<int> > operator>>(int caseValue,
0057                                                                        std::unique_ptr<ParameterDescriptionNode> node);
0058 
0059     friend std::unique_ptr<ParameterDescriptionCases<std::string> > operator>>(
0060         std::string const& caseValue, std::unique_ptr<ParameterDescriptionNode> node);
0061 
0062     friend std::unique_ptr<ParameterDescriptionCases<std::string> > operator>>(
0063         char const* caseValue, std::unique_ptr<ParameterDescriptionNode> node);
0064 
0065     // The constructor is intentionally private so that only the operator>> functions
0066     // can create these.
0067     ParameterDescriptionCases(T const& caseValue, std::unique_ptr<ParameterDescriptionNode> node)
0068         : caseMap_(new CaseMap), duplicateCaseValues_(false) {
0069       std::pair<T, edm::value_ptr<ParameterDescriptionNode> > casePair(caseValue,
0070                                                                        edm::value_ptr<ParameterDescriptionNode>());
0071       caseMap_->insert(casePair);
0072       (*caseMap_)[caseValue] = std::move(node);
0073     }
0074 
0075     std::unique_ptr<CaseMap> caseMap_;
0076     bool duplicateCaseValues_;
0077   };
0078 
0079   std::unique_ptr<ParameterDescriptionCases<bool> > operator||(std::unique_ptr<ParameterDescriptionCases<bool> >,
0080                                                                std::unique_ptr<ParameterDescriptionCases<bool> >);
0081 
0082   std::unique_ptr<ParameterDescriptionCases<int> > operator||(std::unique_ptr<ParameterDescriptionCases<int> >,
0083                                                               std::unique_ptr<ParameterDescriptionCases<int> >);
0084 
0085   std::unique_ptr<ParameterDescriptionCases<std::string> > operator||(
0086       std::unique_ptr<ParameterDescriptionCases<std::string> >,
0087       std::unique_ptr<ParameterDescriptionCases<std::string> >);
0088 }  // namespace edm
0089 #endif