CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Attributes
envUtil Class Reference

#include <envUtil.h>

Public Member Functions

 envUtil ()
 default constructor More...
 
 envUtil (const char *envName, const char *defaultValue="")
 
 envUtil (const char *envName, const std::string &defaultValue)
 
 envUtil (const std::string &defaultValue)
 constructor from the default value only More...
 
const std::string & getEnv () const
 return the value More...
 
const std::string & getEnv (const char *envName, const char *defaultValue="")
 acts as the constructor with the same signature More...
 
const std::string & name () const
 
 operator const char * () const
 cast in char * (for old interface and c-like interface) More...
 
envUtiloperator= (const std::string &s)
 assignement operator (change the value...) More...
 
void setEnv ()
 
void setEnv (const std::string &nval)
 

Protected Attributes

std::string env_
 
std::string envName_
 

Detailed Description

a class to handle enviromental variables

Definition at line 19 of file envUtil.h.

Constructor & Destructor Documentation

envUtil::envUtil ( )
inline

default constructor

Definition at line 24 of file envUtil.h.

24 {}
envUtil::envUtil ( const char *  envName,
const char *  defaultValue = "" 
)

constructor by the evironmental variable name and its default value (used if the environmental variable is not set)

Definition at line 5 of file envUtil.cc.

References env_.

5  :
6  envName_(envName),
7  env_(::getenv(envName) ? ::getenv(envName) : "") {
8  if (env_.length()==0) env_ = defaultValue;
9 }
std::string env_
Definition: envUtil.h:65
std::string envName_
Definition: envUtil.h:64
envUtil::envUtil ( const char *  envName,
const std::string &  defaultValue 
)

constructor by the evironmental variable name and its default value (used if the environmental variable is not set)

Definition at line 12 of file envUtil.cc.

References env_.

12  :
13  envName_(envName),
14  env_(::getenv(envName) ? ::getenv(envName) : "") {
15  if (env_.length()==0) env_ = defaultValue;
16 }
std::string env_
Definition: envUtil.h:65
std::string envName_
Definition: envUtil.h:64
envUtil::envUtil ( const std::string &  defaultValue)
inline

constructor from the default value only

Definition at line 37 of file envUtil.h.

37 : env_(defaultValue) {}
std::string env_
Definition: envUtil.h:65

Member Function Documentation

const std::string& envUtil::getEnv ( ) const
inline

return the value

Definition at line 49 of file envUtil.h.

References env_.

Referenced by operator<<().

49 { return env_;}
std::string env_
Definition: envUtil.h:65
const std::string & envUtil::getEnv ( const char *  envName,
const char *  defaultValue = "" 
)

acts as the constructor with the same signature

Definition at line 34 of file envUtil.cc.

References env_, and envName_.

34  {
35  envName_ = envName;
36  env_ = ::getenv(envName) ? ::getenv(envName) : "";
37  if (env_.length()==0) env_ = defaultValue;
38  return env_;
39  }
std::string env_
Definition: envUtil.h:65
std::string envName_
Definition: envUtil.h:64
const std::string& envUtil::name ( void  ) const
inline

Definition at line 60 of file envUtil.h.

References envName_.

60 { return envName_;}
std::string envName_
Definition: envUtil.h:64
envUtil::operator const char * ( ) const
inline

cast in char * (for old interface and c-like interface)

Definition at line 46 of file envUtil.h.

References env_.

46 { return env_.c_str();}
std::string env_
Definition: envUtil.h:65
envUtil& envUtil::operator= ( const std::string &  s)
inline

assignement operator (change the value...)

Definition at line 41 of file envUtil.h.

References env_, and alignCSCRings::s.

41 { env_ = s; return *this;}
std::string env_
Definition: envUtil.h:65
void envUtil::setEnv ( )

Definition at line 20 of file envUtil.cc.

References env_, and envName_.

Referenced by operator>>(), and setEnv().

20  {
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 }
std::string env_
Definition: envUtil.h:65
std::string envName_
Definition: envUtil.h:64
void envUtil::setEnv ( const std::string &  nval)

Definition at line 29 of file envUtil.cc.

References env_, and setEnv().

29  {
30  env_=nval;
31  setEnv();
32 }
void setEnv()
Definition: envUtil.cc:20
std::string env_
Definition: envUtil.h:65

Member Data Documentation

std::string envUtil::env_
protected

Definition at line 65 of file envUtil.h.

Referenced by envUtil(), getEnv(), operator const char *(), operator=(), and setEnv().

std::string envUtil::envName_
protected

Definition at line 64 of file envUtil.h.

Referenced by getEnv(), name(), and setEnv().