- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2
scl::config_file Documentation
This page provides documentation for the scl::config_file class of SCL. This is the primary class for the library and serves as an interface to a configuration file. To avoid memory leaks, this class is currently non-copyable. That means that you can't compose a new config_file from another one. It also means that you can only pass a config_file to a function as a reference.
Functions necessary to begin writing or reading to/from a file and to clean up afterward.
Initializes and opens a new config_file.
Arguments:
- 
filename- the name of the file to read or write to/from
- 
mode- the mode to open the file in (eitherconfig_file::READorconfig_file::WRITE)
Check if the file is open. Note that this function may return false if the file does not already exist, so checking is not necessary in config_file::WRITE mode. Returns true if the file is open, and false if it is not.
Close the handle to the file, and clear out the data buffer. This method is called in the destructor for this class, so calling it isn't strictly necessary unless you need/want to free memory before the object goes out of scope.
Functions that can only be used in config_file::READmode.
Attempts to load the data from the file into the internal buffer for access. Must be run before using any of the get_* functions. Returns true if the data was loaded successfully and false if it was not.
Generic function to retrieve a value from the data buffer. You must specify the type to retrieve in the template (like this file.get<int>("blah blah")). Please note that the default value is initialized using braced initialization. If you are trying to get a custom class with a constructor that accepts an std::initializer_list, this may be problematic. Therefore, it is highly recommended that you pass a value for def when using a custom class with SCL. Returns the value under name from the buffer if it can be found, and def if it could not.
Arguments:
- 
name- the name of the value to retrieve
- 
def- the value to return ifnameis not in the buffer, defaults to the default initialization (T var ={};). For most primitive types, this is some form of0. For most classes, this is the default constructor(ex:std::string s;).
Generic function to retrieve a series of values from the data buffer. You must specify the type to retrieve in the template arguments (like this file.gets<char>("blah blah")). Returns a vector of the series of values if they could be found, and def if they could not.
Arguments:
- 
name- the name of the series of values to retrieve
- 
def- the vector to return ifnameis not in the buffer, defaults to an empty vector
Note: The remaining read functions are DEPRECATED and subject to removal in a future version of SCL.
Retrieve a boolean value from the data buffer. Returns the value in the buffer if it could be retrieved, and def if it could not.
Arguments:
- 
name- the name of the boolean to retrieve
- 
def- the value to return ifnameis not in the buffer, defaults tofalse
Retrieve a series of boolean values from the data buffer. Returns a vector of values if they could be retrieved, and def if it could not.
Arguments:
- 
name- the name of the vector of booleans to retrieve
- 
def- the value to return ifnameis not in the buffer. Defaults to an empty vector
Retrieve an integer value from the data buffer. Returns the value in the buffer if it could be retrieved, and def if it could not.
Arguments:
- 
name- the name of the integer to retrieve
- 
def- the value to return ifnameis not in the buffer, defaults to0
Retrieve a series of integer values from the data buffer. Returns a vector of values if they could be retrieved, and def if it could not.
Arguments:
- 
name- the name of the vector of integers to retrieve
- 
def- the value to return ifnameis not in the buffer. Defaults to an empty vector
Retrieve a floating point value from the data buffer. Returns the value in the buffer if it could be retrieved, and def if it could not.
Arguments:
- 
name- the name of the float to retrieve
- 
def- the value to return ifnameis not in the buffer, defaults to0.0f
Retrieve a series of float values from the data buffer. Returns a vector of values if they could be retrieved, and def if it could not.
Arguments:
- 
name- the name of the vector offloats to retrieve
- 
def- the value to return ifnameis not in the buffer. Defaults to an empty vector
Retrieve a double value from the data buffer. Returns the value in the buffer if it could be retrieved, and def if it could not.
Arguments:
- 
name- the name of the double to retrieve
- 
def- the value to return ifnameis not in the buffer, defaults to0.0
Retrieve a series of double values from the data buffer. Returns a vector of values if they could be retrieved, and def if it could not.
Arguments:
- 
name- the name of the vector ofdoubles to retrieve
- 
def- the value to return ifnameis not in the buffer. Defaults to an empty vector
Retrieve a single character value from the data buffer. Returns the value in the buffer if it could be retrieved, and def if it could not.
Arguments:
- 
name- the name of the character to retrieve
- 
def- the value to return ifnameis not in the buffer, defaults to
Retrieve a series of characters from the data buffer. Returns a vector of values if they could be retrieved, and def if it could not.
Arguments:
- 
name- the name of the vector of characters to retrieve
- 
def- the value to return ifnameis not in the buffer. Defaults to an empty vector
Retrieve a string value from the data buffer. Returns the value in the buffer if it could be retrieved, and def if it could not.
Arguments:
- 
name- the name of the string to retrieve
- 
def- the value to return ifnameis not in the buffer, defaults to""(an empty string)
Retrieve a series of string values from the data buffer. It is important to note that strings containing spaces will be split up into component words. This is because spaces are used by the library as seperators between values when reading/writing vectors. Returns a vector of values if they could be retrieved, and def if it could not.
Arguments:
- 
name- the name of the vector of strings to retrieve
- 
def- the value to return ifnameis not in the buffer. Defaults to an empty vector
Functions that can only be used in config_file::WRITE mode
Attempts to write data put into the buffer to filename. Returns true if writing was successful, and false, if it was not.
Template function that puts a value into the data buffer (which will be written to the file when write_changes is called). If a value under name already exists in the buffer, it will be overwritten. Accepts any value which can be converted by an std::stringstream into an std::string. Returns true if insertion was successful, and false if it was not.
Arguements:
- 
name- the name of the value to put
- 
val- the value to insert into the data buffer undername
Template function to add a value to the data buffer (which is written to the file when write_changes is called) using an std::pair. The first value of the pair will be the name of the value, and the second will be the value to insert. If the name already exists in the buffer Returns true if insertion was successful, and false if it was not.
Arguments:
- 
val- thepairto insert into the data buffer
Template function that puts a vector of values into the data buffer (which is written to the file when write_changes is called). Accepts any series of values which can be converted by an std::stringstream int an std::string. Returns true if insertion was successful, and false if it was not.
Arguements:
- 
name- the name of the value to put
- 
val- the series of values to put
Template function to add a series of values to the data buffer (which is written to the file when write_changes is called) using an std::pair. The first value of the pair will be the name of the value, and the second will be the vector of values to insert. Returns true if insertion was successful, and false if it was not.
Arguments:
- 
val- thepairto insert into the data buffer
Puts a comment (#blah blah blah) into the data buffer (which is written to the file when write_changes is called). The value of the text field of the comment will be inserted. Returns true if insertion was successful, and false if it was not.
Arguments:
- 
c- the comment object to insert
Insert a number of empty lines into the data buffer (which is written to the file when write_changes is called). Used for readability purposes. The number of lines inserted is equal to the value of the num_lines field in the empty_lines object. Returns true if insertion was successful and false if it was not.
Arguments:
- 
lines- the empty_lines object to insert