Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members

s11n::environment Class Reference

environment is an OO front-end to getenv()-like functionality. More...

#include <environment.h>

Inheritance diagram for s11n::environment:

s11n::property_store List of all members.

Public Member Functions

virtual void set_string (const std::string &key, std::string val)
 Re-implemented to pass the key/val to setenv() (so subshells can access them).
virtual bool unset (const std::string &key)
 Overridden to call unsetenv() if propagate_sets() has been set.
std::string expand_vars (const std::string &text) const
 Parsed env vars out of text, replacing them with their values.
size_t expand_vars_inline (std::string &text) const
 Exactly like expand_vars() but directly modifies the input string.
void propagate_sets (bool)
 If set to true then calls to set_string() will also make a call to setenv(), effectively propagating changes back into the main environment.
bool expand_tilde_home (std::string &) const
 Does conventions-compliant tilde/HOME expansion on the given input.

Static Public Member Functions

static environmentenv (char **=0)
 Returns a reference to a shared object containing the keys/values from the given char ** (defaults to 'environ', from <unistd.h>, which represents the shell's environment).

Detailed Description

environment is an OO front-end to getenv()-like functionality.

It provides some type-casting-like functionality, so you can easily read in environment vars which have, e.g., numeric values.

Definition at line 17 of file environment.h.


Member Function Documentation

static environment& s11n::environment::env char **  = 0  )  [static]
 

Returns a reference to a shared object containing the keys/values from the given char ** (defaults to 'environ', from <unistd.h>, which represents the shell's environment).

The input array is not changed, but is not const because environ is not const. See 'man 5 environ' for info about the default environment array.

Calling it with a non-0 parameter will clear the current environment settings and parse them from the passed-in array, which is expected to be in the form:

"KEY1=VAL1",
"KEY2=VALUE TWO",
...
0

The returned object has propagate_sets() == true.

Tip: s11n::s11n_node::serialize_properties() can de/serialize this object.

bool s11n::environment::expand_tilde_home std::string &   )  const
 

Does conventions-compliant tilde/HOME expansion on the given input.

Returns true if it modifies the string, else false.

Bug: it only works on single tokens. That is, the input must be only one token long, where whitespace delimits tokens.

std::string s11n::environment::expand_vars const std::string &  text  )  const
 

Parsed env vars out of text, replacing them with their values.

Accepts variable tokens in these forms:

${VAR} $VAR

e.g., $foo correspond's to the value returned by this->get_string("foo").

Referencing a variable which is not set does not expand the variable to an empty value: it is left as-is. Thus expanding $FOO when "FOO" is not set will result in "$FOO".

To get a dollar sign into the resulting string, escape it with a single backslash: this keeps it from being parsed as a $variable.

size_t s11n::environment::expand_vars_inline std::string &  text  )  const
 

Exactly like expand_vars() but directly modifies the input string.

Returns the number of variables expanded.

void s11n::environment::propagate_sets bool   ) 
 

If set to true then calls to set_string() will also make a call to setenv(), effectively propagating changes back into the main environment.

The default is false.

virtual void s11n::environment::set_string const std::string &  key,
std::string  val
[virtual]
 

Re-implemented to pass the key/val to setenv() (so subshells can access them).

Changes are not written back to the global shell environment (using setenv()) unless propagate_sets() has been set to true.

virtual bool s11n::environment::unset const std::string &  key  )  [virtual]
 

Overridden to call unsetenv() if propagate_sets() has been set.

Note that the parent class' clear_properties() does not call unset(), so calling clear_properties() on this object will not hose the global environment even if propagate_sets() is true.

Reimplemented from s11n::property_store.


The documentation for this class was generated from the following file:
Generated on Thu Jun 16 16:18:13 2005 for s11n by  doxygen 1.4.3-20050530