CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
envUtil.cc
Go to the documentation of this file.
2 #include <cstdlib>
3 #include <iostream>
4 
5 envUtil::envUtil(const char * envName, const char * defaultValue) :
6  envName_(envName),
7  env_(::getenv(envName) ? ::getenv(envName) : "") {
8  if (env_.length()==0) env_ = defaultValue;
9 }
10 
11 
12 envUtil::envUtil(const char * envName, const std::string & defaultValue) :
13  envName_(envName),
14  env_(::getenv(envName) ? ::getenv(envName) : "") {
15  if (env_.length()==0) env_ = defaultValue;
16 }
17 
18 
19 // avoid mess, go for a leak....
21  if (envName_.empty()) return;
22  std::string * mess = new std::string(envName_);
23  *mess += "=";
24  *mess += env_;
25  ::putenv((char*)((*mess).c_str()));
26 }
27 
28 
29 void envUtil::setEnv(const std::string & nval) {
30  env_=nval;
31  setEnv();
32 }
33 
34 const std::string & envUtil::getEnv(const char * envName, const char * defaultValue) {
35  envName_ = envName;
36  env_ = ::getenv(envName) ? ::getenv(envName) : "";
37  if (env_.length()==0) env_ = defaultValue;
38  return env_;
39  }
40 
41 envSwitch::envSwitch(const char * envName) : envName_(envName),
42  it(::getenv(envName)!=0) {}
43 
44 
45 std::ostream & operator<<(std::ostream & co, const envUtil & eu) {
46  return co << eu.getEnv();
47 }
48 
49 std::istream & operator>>(std::istream & ci, envUtil & eu) {
50  std::string m;
51  ci >> m;
52  eu.setEnv(m);
53  return ci;
54 }
void setEnv()
Definition: envUtil.cc:20
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
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
std::istream & operator>>(std::istream &input, CLHEP::HepGenMatrix &matrix)
Definition: matrixSaver.cc:111
envSwitch(const char *envName)
constructor from env var name
Definition: envUtil.cc:41