CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
envUtil.h
Go to the documentation of this file.
1 #ifndef UTILITIES_GENERAL_ENVUTIL_H
2 #define UTILITIES_GENERAL_ENVUTIL_H
3 //
4 // small utility to handle
5 // enviromental variables
6 //
7 // Version 0.0 V.I. 5/5/98
8 //
9 // Version 1.0 V.I. 11/11/01
10 // also set env
11 // much less inlined
12 //
13 
14 #include <string>
15 #include <iosfwd>
16 
19 class envUtil {
20 
21 public:
22 
24  envUtil(){}
25 
29  envUtil(const char * envName, const char * defaultValue="");
30 
34  envUtil(const char * envName, const std::string & defaultValue);
35 
37  envUtil(const std::string & defaultValue) : env_(defaultValue) {}
38 
39 
41  envUtil & operator = (const std::string& s) { env_ = s; return *this;}
42 
43  // operator const string & () const { return _env;}
44 
46  operator const char * () const { return env_.c_str();}
47 
49  const std::string & getEnv() const { return env_;}
50 
51  // set env to current value;
52  void setEnv();
53 
54  // set env to arg
55  void setEnv(const std::string & nval);
56 
58  const std::string & getEnv(const char * envName, const char * defaultValue="");
59 
60  const std::string & name() const { return envName_;}
61 
62 protected:
63 
64  std::string envName_;
65  std::string env_;
66 
67 };
68 
71 class envSwitch {
72 public:
73 
75  envSwitch(const char * envName);
76 
78  envSwitch & operator = (bool b) { it=b; return *this;}
79 
80 
82  operator const bool& () const { return it;}
83 
85  const bool & getEnv() const { return it;}
86 
87  const std::string & name() const { return envName_;}
88 
89 private:
90 
91  std::string envName_;
92  bool it;
93 
94 };
95 
96 std::ostream & operator<<(std::ostream & co, const envUtil & eu);
97 std::istream & operator>>(std::istream & ci, envUtil & eu);
98 
99 #endif // UTILITIES_GENERAL_ENVUTIL_H
void setEnv()
Definition: envUtil.cc:20
envUtil & operator=(const std::string &s)
assignement operator (change the value...)
Definition: envUtil.h:41
const std::string & name() const
Definition: envUtil.h:87
const std::string & name() const
Definition: envUtil.h:60
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
const bool & getEnv() const
return the value
Definition: envUtil.h:85
std::string envName_
Definition: envUtil.h:91
bool it
Definition: envUtil.h:92
std::string env_
Definition: envUtil.h:65
envUtil()
default constructor
Definition: envUtil.h:24
std::string envName_
Definition: envUtil.h:64
const std::string & getEnv() const
return the value
Definition: envUtil.h:49
envSwitch & operator=(bool b)
assignement operator (change the value...)
Definition: envUtil.h:78
double b
Definition: hdecay.h:120
std::istream & operator>>(std::istream &input, CLHEP::HepGenMatrix &matrix)
Definition: matrixSaver.cc:111
envUtil(const std::string &defaultValue)
constructor from the default value only
Definition: envUtil.h:37
envSwitch(const char *envName)
constructor from env var name
Definition: envUtil.cc:41