iash  v0.5
Library to provide a bash-like shell in an application
Environment Class Reference

Environment variable manager for iash. More...

#include <Environment.h>

Public Member Functions

 Environment (const std::string appName="iash")
 Creates an Environment instance with the given application name. More...
 
void set (const std::string &key, const std::string &value)
 Sets the environment variable key to value. More...
 
void set (const std::string &key, const bool value)
 Sets the environment variable key to the boolean value value. More...
 
void set (const std::string &key, const int value)
 Sets the environment variable key to the integer value value. More...
 
void set (const std::string &key, const double value)
 Sets the environment variable key to the floating-point value value. More...
 
const std::string & getString (const std::string &key) const
 Gets the environment variable key as a string. More...
 
bool getBool (const std::string &key) const
 Gets the environment variable key as a boolean value. More...
 
int getInt (const std::string &key) const
 Gets the environment variable key as an integer. More...
 
double getDouble (const std::string &key) const
 Gets the environment variable key as a floating-point value. More...
 
void rm (const std::string &key)
 Removes the environment variable key. More...
 

Friends

class iash
 

Detailed Description

Environment variable manager for iash.

Using environment variables is one method that iash provides to allow different Command instances to communicate with each other. Internally, environment variables are stored as string instances, but Environment provides functions to convert numeric and boolean data types to and from the string format.

As of version 0.5, iash has the following protected environment variables, which can be read but not modified:

  • IASH_APP_NAME: (since v0.1) The name of the application
  • CWD: (since v0.5) The absolute path to the iash current working directory
Since
0.5

Constructor & Destructor Documentation

◆ Environment()

Environment::Environment ( const std::string  appName = "iash")

Creates an Environment instance with the given application name.

iash instantiates its own Environment instance, so there is no need to construct one manually.

Parameters
appNamethe name of the application

Member Function Documentation

◆ getBool()

bool Environment::getBool ( const std::string &  key) const

Gets the environment variable key as a boolean value.

key will automatically be converted to upper case, if it is not already.

Parameters
keythe name of the environment variable
Returns
the value of the environment variable, as a string

◆ getDouble()

double Environment::getDouble ( const std::string &  key) const

Gets the environment variable key as a floating-point value.

key will automatically be converted to upper case, if it is not already.

Parameters
keythe name of the environment variable
Returns
the value of the environment variable, as a string

◆ getInt()

int Environment::getInt ( const std::string &  key) const

Gets the environment variable key as an integer.

key will automatically be converted to upper case, if it is not already.

Parameters
keythe name of the environment variable
Returns
the value of the environment variable, as a string

◆ getString()

const string & Environment::getString ( const std::string &  key) const

Gets the environment variable key as a string.

key will automatically be converted to upper case, if it is not already.

Parameters
keythe name of the environment variable
Returns
the value of the environment variable, as a string

◆ rm()

void Environment::rm ( const std::string &  key)

Removes the environment variable key.

key will automatically be converted to upper case, if it is not already.

Parameters
keythe name of the environment variable to delete

◆ set() [1/4]

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

Sets the environment variable key to value.

key will automatically be converted to upper case, if it is not already.

Parameters
keythe name of the environment variable
valuethe new value of the environment variable

◆ set() [2/4]

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

Sets the environment variable key to the boolean value value.

key will automatically be converted to upper case, if it is not already.

Parameters
keythe name of the environment variable
valuethe new value of the environment variable

◆ set() [3/4]

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

Sets the environment variable key to the integer value value.

key will automatically be converted to upper case, if it is not already.

Parameters
keythe name of the environment variable
valuethe new value of the environment variable

◆ set() [4/4]

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

Sets the environment variable key to the floating-point value value.

key will automatically be converted to upper case, if it is not already.

Parameters
keythe name of the environment variable
valuethe new value of the environment variable

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