neic-glass3 configuration class using JSON formatting
More...
#include <config.h>
|
| | Config () |
| | Config constructor. More...
|
| |
| | Config (std::string filePath, std::string fileName) |
| | An advanced constructor that loads configuration from a JSON formatted file accessed via filePath/fileName. More...
|
| |
| | Config (std::string newConfig) |
| | An advanced constructor that parses configuration from a JSON formatted string provided in newConfig. More...
|
| |
| | ~Config () |
| | Config destructor. More...
|
| |
| std::shared_ptr< const json::Object > | parseJSONFromFile (std::string filePath, std::string fileName) |
| | A function that loads configuration from a JSON formatted file accessed via filePath/fileName. More...
|
| |
| std::shared_ptr< const json::Object > | parseJSONFromString (std::string newConfig) |
| | A function that parses a configuration from a JSON formatted string. More...
|
| |
| std::shared_ptr< const json::Object > | getJSON () |
| | Get configuration as json object. More...
|
| |
| void | clear () |
| | Config clear function. More...
|
| |
neic-glass3 configuration class using JSON formatting
The glass3::util::Config class is a class used to read JSON formatted configuration files from disk. The Config class filters out comment lines (signified by '#'), newlines, and white space, and provides the configuration as a JSON object.
- Warning
- This class is NOT thread safe
| glass3::util::Config::Config |
( |
| ) |
|
Config constructor.
The constructor for the Config class. Initializes members to default values.
| glass3::util::Config::Config |
( |
std::string |
filePath, |
|
|
std::string |
fileName |
|
) |
| |
An advanced constructor that loads configuration from a JSON formatted file accessed via filePath/fileName.
Loads the provided configuration file identified by filePath/fileName which contains the configuration.
- Parameters
-
| filePath | - A std::string containing the path to the configuration file |
| fileName | - A std::string containing the configuration file name. |
- Exceptions
-
| glass3::util::Config::Config |
( |
std::string |
newConfig | ) |
|
|
explicit |
An advanced constructor that parses configuration from a JSON formatted string provided in newConfig.
Parses the provided newConfig std::string which contains the configuration.
- Parameters
-
| newConfig | - A std::string containing the JSON formatted configuration data to load. |
- Exceptions
-
| glass3::util::Config::~Config |
( |
| ) |
|
| void glass3::util::Config::clear |
( |
| ) |
|
Config clear function.
Returns class members to default values.
| void glass3::util::Config::closeFile |
( |
std::ifstream & |
inFile | ) |
|
|
protected |
Closes the open file.
This function closes the provided file referenced by inFile
- Parameters
-
| inFile | - A reference to the std::ifstream to close |
| std::shared_ptr< const json::Object > glass3::util::Config::getJSON |
( |
| ) |
|
Get configuration as json object.
Get the last loaded/parsed configuration as a json::Object
- Returns
- Return a json::Object containing the configuration
| bool glass3::util::Config::isFileOpen |
( |
std::ifstream & |
inFile | ) |
|
|
protected |
Checks if provided file is open.
Checks that the provided file referenced by inFile is still open and is not at the end of the file
- Parameters
-
| inFile | - A reference to the std::ifstream to check |
- Returns
- Returns true if the file is open and valid, false otherwise
| std::ifstream glass3::util::Config::openFile |
( |
std::string |
filePath, |
|
|
std::string |
fileName |
|
) |
| |
|
protected |
Opens the configuration file.
- Parameters
-
| filePath | - A std::string containing the path to the configuration file |
| fileName | - A std::string containing the configuration file name. |
- Returns
- Returns a std::ifstream for accessing the open file
- Exceptions
-
| Throws | std::invalid_argument if the fileName is empty |
| Throws | std::ios_base::failure if the file failed to open |
| std::shared_ptr< const json::Object > glass3::util::Config::parseJSONFromFile |
( |
std::string |
filePath, |
|
|
std::string |
fileName |
|
) |
| |
A function that loads configuration from a JSON formatted file accessed via filePath/fileName.
Loads the provided configuration file identified by filePath/fileName which contains the configuration.
- Parameters
-
| filePath | - A std::string containing the path to the configuration file |
| fileName | - A std::string containing the configuration file name. |
- Returns
- Returns a json::Object containing the loaded configuration
- Exceptions
-
| std::shared_ptr< const json::Object > glass3::util::Config::parseJSONFromString |
( |
std::string |
newConfig | ) |
|
A function that parses a configuration from a JSON formatted string.
Parses the provided JSON formatted configuration string contained in newConfig
- Parameters
-
| newConfig | - A std::string containing the JSON formatted configuration data to parse. |
- Returns
- Returns a json::Object containing the loaded configuration
- Exceptions
-
| Throws | std::invalid_argument if the newConfig string is empty |
| Throws | std::invalid_argument if the newConfig string failed to parse |
| std::string glass3::util::Config::parseLineFromFile |
( |
std::ifstream & |
inFile | ) |
|
|
protected |
Parses next line from file.
Parses the next line from the provided file referenced by inFile, removing tabs, and comment lines
- Parameters
-
| inFile | - A reference to the std::ifstream to get the next line from. |
- Returns
- Returns a std::string containing the next line
The documentation for this class was generated from the following files: