CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/Utilities/General/interface/envUtil.h

Go to the documentation of this file.
00001 #ifndef UTILITIES_GENERAL_ENVUTIL_H
00002 #define UTILITIES_GENERAL_ENVUTIL_H
00003 //
00004 //   small utility to handle
00005 //   enviromental variables
00006 //
00007 //   Version 0.0      V.I.  5/5/98
00008 //
00009 //   Version 1.0      V.I.  11/11/01
00010 //     also set env
00011 //     much less inlined
00012 //
00013 
00014 #include <string>
00015 #include <iosfwd>
00016 
00019 class envUtil {
00020 
00021 public:
00022 
00024   envUtil(){}
00025 
00029   envUtil(const char * envName, const char * defaultValue="");
00030 
00034   envUtil(const char * envName, const std::string & defaultValue);
00035  
00037   envUtil(const std::string & defaultValue) :  env_(defaultValue) {}
00038 
00039 
00041   envUtil & operator = (const std::string& s) { env_ = s; return *this;}
00042 
00043   // operator const string & () const { return _env;}
00044 
00046   operator const char * () const { return env_.c_str();}
00047 
00049   const std::string &  getEnv() const { return env_;}
00050 
00051   // set env to current value;
00052   void setEnv();
00053 
00054   // set env to arg
00055   void setEnv(const std::string & nval);
00056 
00058   const std::string &  getEnv(const char * envName, const char * defaultValue="");
00059   
00060   const std::string & name() const { return envName_;}
00061 
00062 protected:
00063 
00064   std::string envName_;
00065   std::string env_;
00066 
00067 };
00068 
00071 class envSwitch {
00072 public:
00073 
00075   envSwitch(const char * envName);
00076 
00078   envSwitch & operator = (bool b) { it=b; return *this;}
00079   
00080 
00082   operator const bool& () const { return it;}
00083 
00085   const bool &  getEnv() const { return it;}
00086 
00087   const std::string & name() const { return envName_;}
00088 
00089 private:
00090 
00091   std::string envName_;
00092   bool it;
00093 
00094 };
00095 
00096 std::ostream & operator<<(std::ostream & co, const envUtil & eu);
00097 std::istream & operator>>(std::istream & ci, envUtil & eu);
00098 
00099 #endif // UTILITIES_GENERAL_ENVUTIL_H