OW_NAMESPACE::EnvVars Class Reference

The EnvVars class is an abstraction for a set of environment variables. More...

#include <OW_EnvVars.hpp>

Collaboration diagram for OW_NAMESPACE::EnvVars:

Collaboration graph
[legend]
List of all members.

Public Types

enum  EEnvVarFlag { E_CURRENT_ENVIRONMENT, E_EMPTY_ENVIRONMENT }

Public Member Functions

 EnvVars (EEnvVarFlag flag=E_EMPTY_ENVIRONMENT)
 Create an EnvVars object that is either empty or contains all of the environment variable from the current environment.
 EnvVars (const char *const envp[])
 Create an EnvVars object that contains the evironment variables specifed in a string array.
 EnvVars (const EnvVars &arg)
 Copy constructor.
 ~EnvVars ()
 Destructor.
EnvVarsoperator= (const EnvVars &arg)
 Assignment operator.
const char *const * getenvp () const
size_t size () const
String getValue (const String &key, const String &notFoundRetVal=String()) const
 Get the value associated with a given key.
bool removeVar (const String &key)
 Remove an environment variable from this EnvVars object.
void setVar (const String &keyValue)
 Set the value for a given environemt variable.
void setVar (const String &key, const String &value)
 Set the value for a given environemt variable.
bool addVar (const String &name, const String &value)
 Adds the variable name if its not already part of the set.
bool updateVar (const String &name, const String &value)
 Updates an existing variable.

Private Types

typedef Map< String, StringEnvMap

Private Member Functions

void deleteEnvp () const

Static Private Member Functions

static void fillEnvMap (const char *const envp[], EnvMap &envMap)

Private Attributes

EnvMap m_envMap
char ** m_envp

Detailed Description

The EnvVars class is an abstraction for a set of environment variables.

Definition at line 48 of file OW_EnvVars.hpp.


Member Typedef Documentation

typedef Map<String, String> OW_NAMESPACE::EnvVars::EnvMap [private]
 

Definition at line 147 of file OW_EnvVars.hpp.


Member Enumeration Documentation

enum OW_NAMESPACE::EnvVars::EEnvVarFlag
 

Enumerator:
E_CURRENT_ENVIRONMENT 
E_EMPTY_ENVIRONMENT 

Definition at line 51 of file OW_EnvVars.hpp.


Constructor & Destructor Documentation

OW_NAMESPACE::EnvVars::EnvVars EEnvVarFlag  flag = E_EMPTY_ENVIRONMENT  ) 
 

Create an EnvVars object that is either empty or contains all of the environment variable from the current environment.

Definition at line 88 of file OW_EnvVars.cpp.

References E_CURRENT_ENVIRONMENT, environ, fillEnvMap(), and m_envMap.

OW_NAMESPACE::EnvVars::EnvVars const char *const   envp[]  ) 
 

Create an EnvVars object that contains the evironment variables specifed in a string array.

Parameters:
envp A NULL terminated char* array that contains the environment variables for the EnvVars object. Each element of the array must be in the form of "ENV_VAR_NAME=VALUE".

Definition at line 99 of file OW_EnvVars.cpp.

References fillEnvMap(), and m_envMap.

OW_NAMESPACE::EnvVars::EnvVars const EnvVars arg  ) 
 

Copy constructor.

Parameters:
arg The EnvVars object this object will be a copy of.

OW_NAMESPACE::EnvVars::~EnvVars  ) 
 

Destructor.

Definition at line 107 of file OW_EnvVars.cpp.

References deleteEnvp().


Member Function Documentation

bool OW_NAMESPACE::EnvVars::addVar const String name,
const String value
 

Adds the variable name if its not already part of the set.

Returns:
true if it was added, false if it already exists.

Definition at line 209 of file OW_EnvVars.cpp.

References deleteEnvp(), OW_NAMESPACE::Map< Key, T, Compare >::end(), OW_NAMESPACE::Map< Key, T, Compare >::find(), m_envMap, and name.

void OW_NAMESPACE::EnvVars::deleteEnvp  )  const [private]
 

Definition at line 131 of file OW_EnvVars.cpp.

References i, and m_envp.

Referenced by addVar(), removeVar(), setVar(), updateVar(), and ~EnvVars().

void OW_NAMESPACE::EnvVars::fillEnvMap const char *const   envp[],
EnvMap envMap
[static, private]
 

Definition at line 115 of file OW_EnvVars.cpp.

References OW_NAMESPACE::Map< Key, T, Compare >::clear(), OW_NAMESPACE::getKeyValue(), i, and OW_NAMESPACE::String::length().

Referenced by EnvVars().

const char *const * OW_NAMESPACE::EnvVars::getenvp  )  const
 

Returns:
A null terminated char* array that contains all the environment variables contained by this EnvVars object. Each element of the returned array will be of the form "ENV_VAR_NAME=VALUE".

Definition at line 162 of file OW_EnvVars.cpp.

References OW_NAMESPACE::Map< Key, T, Compare >::begin(), OW_NAMESPACE::Map< Key, T, Compare >::end(), i, m_envMap, m_envp, and OW_NAMESPACE::Map< Key, T, Compare >::size().

Referenced by OW_NAMESPACE::Exec::safePopen(), and OW_NAMESPACE::Exec::safeSystem().

String OW_NAMESPACE::EnvVars::getValue const String key,
const String notFoundRetVal = String()
const
 

Get the value associated with a given key.

Parameters:
key The name for the value to retrieve.
notFoundRetVal If the environment variable by the name of 'key' is not found, then return the value specified by this parameter.
Returns:
The value associated with a given key. If the key does not exist in this EnvVars object, the return value will be an empty string.

Definition at line 153 of file OW_EnvVars.cpp.

References OW_NAMESPACE::Map< Key, T, Compare >::end(), OW_NAMESPACE::Map< Key, T, Compare >::find(), and m_envMap.

EnvVars& OW_NAMESPACE::EnvVars::operator= const EnvVars arg  ) 
 

Assignment operator.

Parameters:
arg The EnvVars object to assign to this one.
Returns:
A reference to this EnvVars object after the assignment is done.

bool OW_NAMESPACE::EnvVars::removeVar const String key  ) 
 

Remove an environment variable from this EnvVars object.

Parameters:
key The name of the environment variable to be removed.
Returns:
true if key was found and removed. Otherwise return false.

Definition at line 193 of file OW_EnvVars.cpp.

References deleteEnvp(), OW_NAMESPACE::Map< Key, T, Compare >::end(), OW_NAMESPACE::Map< Key, T, Compare >::erase(), OW_NAMESPACE::Map< Key, T, Compare >::find(), and m_envMap.

void OW_NAMESPACE::EnvVars::setVar const String key,
const String value
 

Set the value for a given environemt variable.

If the environment variable does not exist in the EnvVars object, it will be added.

Parameters:
key The name of the environment variable
value The value to set the environment variable to.

Definition at line 223 of file OW_EnvVars.cpp.

References deleteEnvp(), and m_envMap.

void OW_NAMESPACE::EnvVars::setVar const String keyValue  ) 
 

Set the value for a given environemt variable.

If the environment variable does not exist in the EnvVars object, it will be added.

Parameters:
keyValue A key=value string that represent the key/value of the environemt variable to be set/added.

Definition at line 231 of file OW_EnvVars.cpp.

References OW_NAMESPACE::String::c_str(), OW_NAMESPACE::getKeyValue(), and OW_NAMESPACE::String::length().

size_t OW_NAMESPACE::EnvVars::size  )  const [inline]
 

Returns:
The number of environment variables contained by this object as a size_t.

Definition at line 96 of file OW_EnvVars.hpp.

Referenced by OW_NAMESPACE::Exec::safePopen(), and OW_NAMESPACE::Exec::safeSystem().

bool OW_NAMESPACE::EnvVars::updateVar const String name,
const String value
 

Updates an existing variable.

Returns:
true if variable name was updated, false it it doesn't exist.

Definition at line 243 of file OW_EnvVars.cpp.

References deleteEnvp(), OW_NAMESPACE::Map< Key, T, Compare >::end(), OW_NAMESPACE::Map< Key, T, Compare >::find(), m_envMap, and name.


Member Data Documentation

EnvMap OW_NAMESPACE::EnvVars::m_envMap [private]
 

Definition at line 152 of file OW_EnvVars.hpp.

Referenced by addVar(), EnvVars(), getenvp(), getValue(), removeVar(), setVar(), and updateVar().

char** OW_NAMESPACE::EnvVars::m_envp [mutable, private]
 

Definition at line 153 of file OW_EnvVars.hpp.

Referenced by deleteEnvp(), and getenvp().


The documentation for this class was generated from the following files:
Generated on Thu Feb 9 09:13:43 2006 for openwbem by  doxygen 1.4.6