Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef PhysicsTools_Parameter_h
0002 #define PhysicsTools_Parameter_h
0003 #include <string>
0004 #include <memory>
0005 #include <ostream>
0006 
0007 namespace funct {
0008   class Parameter {
0009   public:
0010     explicit Parameter(const std::string& name = "undefined", double value = 0)
0011         : name_(name), value_(new double(value)) {}
0012     const std::string& name() const { return name_; }
0013     double value() const { return *value_; }
0014     double operator()() const { return *value_; }
0015     operator double() const { return value(); }
0016     double operator()(double) const { return *value_; }
0017     double operator()(double, double) const { return *value_; }
0018     std::shared_ptr<double> ptr() const { return value_; }
0019     operator std::shared_ptr<double>() const { return value_; }
0020     Parameter& operator=(double value) {
0021       *value_ = value;
0022       return *this;
0023     }
0024 
0025   private:
0026     std::string name_;
0027     std::shared_ptr<double> value_;
0028   };
0029 
0030   inline std::ostream& operator<<(std::ostream& cout, const funct::Parameter& p) {
0031     return cout << p.name() << " = " << p.value();
0032   }
0033 
0034 }  // namespace funct
0035 
0036 #endif