CMS 3D CMS Logo

Public Member Functions | Protected Attributes

envUtil Class Reference

#include <envUtil.h>

List of all members.

Public Member Functions

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

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.

{}
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_.

                                                                :  
  envName_(envName),
  env_(::getenv(envName) ? ::getenv(envName) : "") {
  if (env_.length()==0) env_ = defaultValue;
}
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_.

                                                                     : 
  envName_(envName),
  env_(::getenv(envName) ? ::getenv(envName) : "") {
  if (env_.length()==0) env_ = defaultValue;
}
envUtil::envUtil ( const std::string &  defaultValue) [inline]

constructor from the default value only

Definition at line 37 of file envUtil.h.

:  env_(defaultValue) {}

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<<().

{ return env_;}
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_.

                                                                                  {
    envName_ = envName;
    env_ = ::getenv(envName) ? ::getenv(envName) : "";
    if (env_.length()==0) env_ = defaultValue;
    return env_;
  }
const std::string& envUtil::name ( void  ) const [inline]

Definition at line 60 of file envUtil.h.

References envName_.

{ return envName_;}
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_.

{ return env_.c_str();}
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.

{ env_ = s; return *this;}
void envUtil::setEnv ( const std::string &  nval)

Definition at line 29 of file envUtil.cc.

References env_, and setEnv().

                                           {
  env_=nval;
  setEnv();
}
void envUtil::setEnv ( )

Definition at line 20 of file envUtil.cc.

References env_, and envName_.

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

                     {
  if (envName_.empty()) return;
  std::string * mess = new std::string(envName_);
  *mess += "=";
  *mess += env_;
  ::putenv((char*)((*mess).c_str()));
}

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().