sbuild::environment Class Reference

Container of environment variables. More...

#include <sbuild-environment.h>

Inheritance diagram for sbuild::environment:
Inheritance graph
[legend]
Collaboration diagram for sbuild::environment:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 environment ()
 The constructor.
 environment (char **environment)
 The constructor.
 ~environment ()
 The destructor.
void set_filter (regex const &filter)
 Set environment filter.
regex const & get_filter () const
 Get environment filter.
void add (char **environment)
 Add environment variables.
void add (environment const &environment)
 Add environment variables.
void add (value_type const &value)
 Add environment variable.
void add (std::string const &name, std::string const &value)
 Add environment variable.
template<typename T >
void add (std::string const &name, T const &value)
 Add environment variable.
void add (std::string const &value)
 Add environment variable.
void remove (char **environment)
 Remove environment variables.
void remove (environment const &environment)
 Remove environment variables.
void remove (std::string const &value)
 Remove environment variable.
void remove (value_type const &value)
 Remove environment variable.
template<typename T >
bool get (std::string const &name, T &value) const
 Get the value of an environment variable.
char ** get_strv () const
 Get the evironment variables as a string vector.
template<typename T >
environmentoperator+= (T const &rhs)
 Add variables to the environment.
template<typename T >
environmentoperator-= (T const &rhs)
 Remove variables from the environment.

Private Attributes

regex filter
 Filter regex.

Friends

template<typename T >
environment operator+ (environment const &lhs, T const &rhs)
 Add variables to the environment.
template<typename T >
environment operator- (environment const &lhs, T const &rhs)
 Remove variables from the environment.
template<class charT , class traits >
std::basic_ostream< charT,
traits > & 
operator<< (std::basic_ostream< charT, traits > &stream, environment const &rhs)
 Output the environment to an ostream.

Detailed Description

Container of environment variables.


Constructor & Destructor Documentation

environment::environment (  ) 

The constructor.

environment::environment ( char **  environment  ) 

The constructor.

Parameters:
environment the environment to set.

References add().

environment::~environment (  ) 

The destructor.


Member Function Documentation

void environment::add ( std::string const &  value  ) 

Add environment variable.

Any existing variable sharing the name will be replaced.

Parameters:
value the environment variable to add. This is a string in the form key=value.

References add().

template<typename T >
void sbuild::environment::add ( std::string const &  name,
T const &  value 
) [inline]

Add environment variable.

Any existing variable sharing the name will be replaced.

Parameters:
name the environment variable name
value the environment variable value to add.

References add().

void sbuild::environment::add ( std::string const &  name,
std::string const &  value 
) [inline]

Add environment variable.

Any existing variable sharing the name will be replaced.

Parameters:
name the environment variable name
value the environment variable value to add.

References add().

void environment::add ( value_type const &  value  ) 

Add environment variable.

Any existing variable sharing the name will be replaced.

Parameters:
value the environment variable to add.

References sbuild::DEBUG_INFO, sbuild::DEBUG_NOTICE, filter, and sbuild::log_debug().

void environment::add ( environment const &  environment  ) 

Add environment variables.

Any existing variables sharing the name of a new value will be replaced.

Parameters:
environment the environment variables to add.

References add().

void environment::add ( char **  environment  ) 
template<typename T >
bool sbuild::environment::get ( std::string const &  name,
T &  value 
) const [inline]

Get the value of an environment variable.

Parameters:
name the name of the environment variable.
value the variable to store the value in on success.
Returns:
true on success, false if the variable does not exist, or there is a parse error.

References sbuild::DEBUG_INFO, sbuild::DEBUG_NOTICE, sbuild::log_debug(), sbuild::log_warning(), and sbuild::parse_value().

Referenced by sbuild::session::get_login_directories(), sbuild::session::get_user_command(), and sbuild::session::run_child().

regex const & environment::get_filter (  )  const

Get environment filter.

Returns:
the filter regex.

References filter.

char ** environment::get_strv (  )  const

Get the evironment variables as a string vector.

This form is suitable for use as an envp argument with execve, for example.

Returns:
a newly-allocated string vector. This is allocated with new, and should be freed with strv_delete().

Referenced by sbuild::exec().

template<typename T >
environment& sbuild::environment::operator+= ( T const &  rhs  )  [inline]

Add variables to the environment.

Parameters:
rhs the values to add.
Returns:
the modified environment.

References add().

template<typename T >
environment& sbuild::environment::operator-= ( T const &  rhs  )  [inline]

Remove variables from the environment.

Parameters:
rhs the values to remove.
Returns:
the modified environment.
void environment::remove ( value_type const &  value  ) 

Remove environment variable.

Any variable sharing the name of the specified value will be removed.

Parameters:
value the environment variable to remove.
void environment::remove ( std::string const &  value  ) 

Remove environment variable.

Any variable sharing the name of the specified value will be removed.

Parameters:
value the environment variable to remove.
void environment::remove ( environment const &  environment  ) 

Remove environment variables.

Any variables sharing the names of a specified value will be removed.

Parameters:
environment the environment variables to remove.
void environment::remove ( char **  environment  ) 

Remove environment variables.

Any variables sharing the names of a specified value will be removed.

Parameters:
environment the environment variables to remove. This is a null-terminated array of pointers to char.
void environment::set_filter ( regex const &  filter  ) 

Set environment filter.

If the environment variable name matches the regex when add() is called, addition will be .

The default filter is to allow all strings.

If the regex contains errors, an exception will be thrown.

Parameters:
filter the filter regex.

Referenced by sbuild::session::run_child().


Friends And Related Function Documentation

template<typename T >
environment operator+ ( environment const &  lhs,
T const &  rhs 
) [friend]

Add variables to the environment.

Parameters:
lhs the environment to add to.
rhs the values to add.
Returns:
the new environment.
template<typename T >
environment operator- ( environment const &  lhs,
T const &  rhs 
) [friend]

Remove variables from the environment.

Parameters:
lhs the environment to remove from.
rhs the values to remove.
Returns:
the new environment.
template<class charT , class traits >
std::basic_ostream<charT,traits>& operator<< ( std::basic_ostream< charT, traits > &  stream,
environment const &  rhs 
) [friend]

Output the environment to an ostream.

Parameters:
stream the stream to output to.
rhs the environment to output.
Returns:
the stream.

Member Data Documentation

Filter regex.

Referenced by add(), and get_filter().


The documentation for this class was generated from the following files:
Generated on Sat Apr 3 02:44:47 2010 for sbuild by  doxygen 1.6.3