CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/FWCore/ParameterSet/interface/ParameterDescriptionCases.h

Go to the documentation of this file.
00001 #ifndef FWCore_ParameterSet_ParameterDescriptionCases_h
00002 #define FWCore_ParameterSet_ParameterDescriptionCases_h
00003 
00004 // This class is used to store temporary objects created when
00005 // building ParameterSwitch's in a ParameterSetDescription.
00006 // It gets created while evaluating an expression something
00007 // like
00008 //
00009 // parameterSetDescription.ifValue( ParameterDescription<int>("switch", 0),
00010 //                                  0 >> ParameterDescription<int>("label1", 11) or
00011 //                                  1 >> ParameterDescription<float>("label2", 11.0f) or
00012 //                                  2 >> ParameterDescription<std::string>("label3", "aValue");
00013 // It hold the temporary results of the operator>> and operator||
00014 // functions in the expression.  The ONLY way to create one
00015 // is via the operator>> function. The intent is that user
00016 // should not need to save this temporary result nor directly
00017 // reference this class, but ...
00018 
00019 // If one decided to save the value then one should be aware
00020 // the class has been optimized to minimize the number of copies made
00021 // while evaluating such an expression.  It contains an auto_ptr and
00022 // the class has copy semantics like an auto_ptr.  If you tried to use
00023 // this class directly you must be aware that if a copy is
00024 // made the original contains a null pointer. Then it would
00025 // be easy to write code that dereferences that null pointer.
00026 
00027 #include "FWCore/Utilities/interface/value_ptr.h"
00028 #include "FWCore/ParameterSet/interface/ParameterDescriptionNode.h"
00029 
00030 #include <map>
00031 #include <memory>
00032 #include <string>
00033 #include <utility>
00034 
00035 namespace edm {
00036 
00037   template<typename T>
00038   class ParameterDescriptionCases {
00039   public:
00040     typedef std::map<T, edm::value_ptr<ParameterDescriptionNode> > CaseMap;
00041 
00042     void insert(T caseValue, std::auto_ptr<ParameterDescriptionNode> node) {
00043       std::pair<T, edm::value_ptr<ParameterDescriptionNode> > casePair(caseValue,edm::value_ptr<ParameterDescriptionNode>());
00044       std::pair<typename CaseMap::iterator,bool> status;
00045       status = caseMap_->insert(casePair);
00046       (*caseMap_)[caseValue] = node;
00047       if (status.second == false) duplicateCaseValues_ = true;
00048     }
00049 
00050     std::auto_ptr<CaseMap> caseMap() { return caseMap_; }
00051     bool duplicateCaseValues() const { return duplicateCaseValues_; }
00052 
00053   private:
00054 
00055     friend
00056     std::auto_ptr<ParameterDescriptionCases<bool> >
00057     operator>>(bool caseValue,
00058                std::auto_ptr<ParameterDescriptionNode> node);
00059 
00060     friend
00061     std::auto_ptr<ParameterDescriptionCases<int> >
00062     operator>>(int caseValue,
00063                std::auto_ptr<ParameterDescriptionNode> node);
00064 
00065     friend
00066     std::auto_ptr<ParameterDescriptionCases<std::string> >
00067     operator>>(std::string const& caseValue,
00068                std::auto_ptr<ParameterDescriptionNode> node);
00069 
00070     friend
00071     std::auto_ptr<ParameterDescriptionCases<std::string> >
00072     operator>>(char const* caseValue,
00073                std::auto_ptr<ParameterDescriptionNode> node);
00074 
00075     // The constructor is intentionally private so that only the operator>> functions
00076     // can create these. 
00077     ParameterDescriptionCases(T const& caseValue, std::auto_ptr<ParameterDescriptionNode> node) :
00078       caseMap_(new CaseMap),
00079       duplicateCaseValues_(false)
00080     {
00081       std::pair<T, edm::value_ptr<ParameterDescriptionNode> > casePair(caseValue,edm::value_ptr<ParameterDescriptionNode>());
00082       caseMap_->insert(casePair);
00083       (*caseMap_)[caseValue] = node;
00084     }
00085 
00086     std::auto_ptr<CaseMap> caseMap_;
00087     bool duplicateCaseValues_;
00088   };
00089 
00090   std::auto_ptr<ParameterDescriptionCases<bool> >
00091   operator||(std::auto_ptr<ParameterDescriptionCases<bool> >,
00092              std::auto_ptr<ParameterDescriptionCases<bool> >);
00093 
00094   std::auto_ptr<ParameterDescriptionCases<int> >
00095   operator||(std::auto_ptr<ParameterDescriptionCases<int> >,
00096              std::auto_ptr<ParameterDescriptionCases<int> >);
00097 
00098   std::auto_ptr<ParameterDescriptionCases<std::string> >
00099   operator||(std::auto_ptr<ParameterDescriptionCases<std::string> >,
00100              std::auto_ptr<ParameterDescriptionCases<std::string> >);
00101 }
00102 #endif