Class to access environment variable.
More...
#include <EnvVar.h>
|
| EnvVar (const std::string &key) |
| Construct a new EnvVar object.
|
|
std::string | asString (const std::string &def) const |
| Get environment variable of string type.
|
|
bool | asBool (bool def) const |
| Get environment variable of boolean type.
|
|
int | asInt (int def) const |
| Get environment variable of int type.
|
|
float | asFloat (float def) const |
| Get environment variable of float type.
|
|
Class to access environment variable.
Definition at line 38 of file EnvVar.h.
◆ EnvVar()
nnfw::misc::EnvVar::EnvVar |
( |
const std::string & |
key | ) |
|
|
inline |
Construct a new EnvVar object.
- Parameters
-
[in] | key | environment variable |
Definition at line 45 of file EnvVar.h.
46 {
47 const char *value = std::getenv(key.c_str());
48 if (value == nullptr)
49 {
50
51 _value = "";
52 }
53 else
54 {
55 _value = value;
56 }
57 }
◆ asBool()
bool nnfw::misc::EnvVar::asBool |
( |
bool |
def | ) |
const |
|
inline |
Get environment variable of boolean type.
- Parameters
-
[in] | def | Default value of environment variable |
- Returns
- Defaut value passed as a parameter when there is no environment variable, otherwise the value of environment variable passed into constructor
Definition at line 78 of file EnvVar.h.
79 {
80 if (_value.empty())
81 return def;
82 static const std::array<std::string, 5> false_list{"0", "OFF", "FALSE", "N", "NO"};
83 auto false_found = std::find(false_list.begin(), false_list.end(), _value);
84 return (false_found == false_list.end());
85 }
◆ asFloat()
float nnfw::misc::EnvVar::asFloat |
( |
float |
def | ) |
const |
|
inline |
Get environment variable of float type.
- Parameters
-
[in] | def | Default value of environment variable |
- Returns
- Defaut value passed as a parameter when there is no environment variable, otherwise the value of environment variable passed into constructor
Definition at line 106 of file EnvVar.h.
107 {
108 if (_value.empty())
109 return def;
110 return std::stof(_value);
111 }
◆ asInt()
int nnfw::misc::EnvVar::asInt |
( |
int |
def | ) |
const |
|
inline |
Get environment variable of int type.
- Parameters
-
[in] | def | Default value of environment variable |
- Returns
- Defaut value passed as a parameter when there is no environment variable, otherwise the value of environment variable passed into constructor
Definition at line 93 of file EnvVar.h.
94 {
95 if (_value.empty())
96 return def;
97 return std::stoi(_value);
98 }
◆ asString()
std::string nnfw::misc::EnvVar::asString |
( |
const std::string & |
def | ) |
const |
|
inline |
Get environment variable of string type.
- Parameters
-
[in] | def | Default value of environment variable |
- Returns
- Defaut value passed as a parameter when there is no environment variable, otherwise the value of environment variable passed into constructor
Definition at line 65 of file EnvVar.h.
66 {
67 if (_value.empty())
68 return def;
69 return _value;
70 }
The documentation for this class was generated from the following file: