DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
OksSystem::Environment Struct Reference

Wrapper for environnement variable manipulation. More...

#include <Environment.hpp>

Static Public Member Functions

static std::string get (const std::string &key)
 get a environnement variable
 
static void set (const std::string &key, const std::string &value)
 sets an environnement variable
 
static void set (const std::map< std::string, std::string > &values)
 sets a collection of variables
 

Detailed Description

Wrapper for environnement variable manipulation.

This class contains utility methods to handle environnement variables

Author
Matthias Wiesmann
Version
1.0

Definition at line 24 of file Environment.hpp.

Member Function Documentation

◆ get()

std::string OksSystem::Environment::get ( const std::string & key)
static

get a environnement variable

Gets an environnement variable

Parameters
keythe name of the variable
Returns
the value of the variable, of the string NO_VALUE if the variable is unknown.

Definition at line 49 of file Environment.cpp.

49 {
50 const char* c_value = ::getenv(key.c_str());
51 if (c_value==0) return std::string();
52 return std::string(c_value);
53} // get

◆ set() [1/2]

void OksSystem::Environment::set ( const std::map< std::string, std::string > & values)
static

sets a collection of variables

Sets a collection of environnement variables.

Parameters
valuesThe map of string string pairs containing the name / values pairs
Exceptions
PosixIssueunable to set environnement variable

Definition at line 38 of file Environment.cpp.

38 {
39 for(std::map<std::string,std::string>::const_iterator pos = values.begin();pos!=values.end();++pos) {
40 set(pos->first,pos->second);
41 } // for
42} // set
static void set(const std::string &key, const std::string &value)
sets an environnement variable

◆ set() [2/2]

void OksSystem::Environment::set ( const std::string & key,
const std::string & value )
static

sets an environnement variable

Sets an environnement variable

Parameters
keythe name of the variable
valuethe value of the variable
Exceptions
PosixIssueunable to set environnement variable

Definition at line 23 of file Environment.cpp.

23 {
24 const char* c_key = key.c_str();
25 const char* c_value = value.c_str();
26 const int status = ::setenv(c_key,c_value,1);
27 if (status<0) {
28 std::string message = "while setting " + key + " to " + value;
29 throw OksSystemCallIssue( ERS_HERE, errno, "setenv", message.c_str());
30 }
31} // set
#define ERS_HERE

The documentation for this struct was generated from the following files: