ocssw
V2022
|
#include <KvStore.hpp>
Friends | |
std::ostream & | operator<< (std::ostream &os, const KvStore &kv) |
Detailed Description
Key-value file reader (commonly called par files)
Format
A simple file with various quoting and no commands (test1.par):
A key-value file with groups and another key-value file loaded first (test2.par):
Examples
Creating a simple map out of key-value files:
Walking though a key-value file as it is being read:
Definition at line 35 of file KvStore.hpp.
Constructor & Destructor Documentation
◆ KvStore() [1/3]
|
default |
Default constructor, use load(std::string file)
to read files.
◆ KvStore() [2/3]
|
explicit |
Construct a key-value map, loading the given file upon creation.
- Parameters
-
file Path to key-value store to read
- Exceptions
-
not::sure if any lines read are invalid
◆ KvStore() [3/3]
KvStore | ( | const std::string & | file, |
read_callback | callback | ||
) |
Construct a key-value map, with default file and processing callback.
- Parameters
-
file Path to key-value store to read callback Function to call for each value read
- Exceptions
-
not::sure if any lines read are invalid
Member Function Documentation
◆ at() [1/2]
std::string& at | ( | const std::string & | k | ) |
Returns a reference to the mapped value of the element identified with key k.
◆ at() [2/2]
std::string& at | ( | std::string && | k | ) |
Returns a reference to the mapped value of the element identified with key k.
◆ begin() [1/2]
iterator begin | ( | ) |
std::unordered_map iterator to recurse key-values
- Returns
- Start iterator
◆ begin() [2/2]
group_filtered_iterator begin | ( | const std::string & | group | ) | const |
focs::FilterIterator iterator to recurse key-values of the input group
- Returns
- Start iterator
◆ callback() [1/2]
|
inline |
Get the key-value callback.
- Returns
- the current key-value callback
Definition at line 263 of file KvStore.hpp.
◆ callback() [2/2]
|
inline |
Set a function to be called for each key-value read.
- Parameters
-
callback New callback
Definition at line 257 of file KvStore.hpp.
◆ cbegin()
const_iterator cbegin | ( | ) | const |
std::unordered_map iterator to recurse key-values
- Returns
- Start iterator
◆ cend()
const_iterator cend | ( | ) | const |
std::unordered_map end iterator to recurse key-values
- Returns
- End iterator
◆ command()
bool command | ( | std::string && | cmd, |
std::string && | args | ||
) |
Process a key-value store command by name.
- Parameters
-
cmd Command name to run args Arguments to pass to command function
- Returns
- true on error, false on success
◆ command_group()
bool command_group | ( | std::string && | group | ) |
Change the current key group.
- Parameters
-
group New group name
- Returns
- true on error, false on success
◆ command_include()
bool command_include | ( | std::string && | file | ) |
Include another key-value store, relative to current file, into the global group.
- Parameters
-
file file relative to current key-value file path
- Returns
- true on error, false on success
◆ command_include_local()
bool command_include_local | ( | std::string && | file | ) |
Include another key-value store, relative to current file, into the current group.
- Parameters
-
file file relative to current key-value file path
- Returns
- true on error, false on success
◆ count() [1/2]
size_t count | ( | const std::string & | k | ) | const |
Count elements with a specific key.
Searches the container for an element with k as key and returns an iterator to it if found, otherwise it returns an iterator to unordered_map::end (the element past the end of the container).
- Parameters
-
k Key to look up
- Returns
- 1 if an element with a key equivalent to k is found, or zero otherwise.
◆ count() [2/2]
size_t count | ( | std::string && | k | ) | const |
◆ end() [1/2]
iterator end | ( | ) |
std::unordered_map end iterator to recurse key-values
- Returns
- End iterator
◆ end() [2/2]
group_filtered_iterator end | ( | const std::string & | group | ) | const |
focs::FilterIterator end iterator to recurse key-values of the input group
- Returns
- End iterator
◆ find() [1/4]
KvStore::iterator find | ( | const std::string & | k | ) |
Get iterator to element.
Searches the container for an element with k as key and returns an iterator to it if found, otherwise it returns an iterator to unordered_map::end (the element past the end of the container).
- Parameters
-
k Key to look up
- Returns
- An iterator to the element, if the specified key value is found, or unordered_map::end if the specified key is not found in the container.
◆ find() [2/4]
KvStore::iterator find | ( | std::string && | k | ) |
Get iterator to element.
Searches the container for an element with k as key and returns an iterator to it if found, otherwise it returns an iterator to unordered_map::end (the element past the end of the container).
- Parameters
-
k Key to look up
- Returns
- An iterator to the element, if the specified key value is found, or unordered_map::end if the specified key is not found in the container.
◆ find() [3/4]
KvStore::const_iterator find | ( | std::string && | k | ) | const |
Get iterator to element.
Searches the container for an element with k as key and returns an iterator to it if found, otherwise it returns an iterator to unordered_map::end (the element past the end of the container).
- Parameters
-
k Key to look up
- Returns
- An iterator to the element, if the specified key value is found, or unordered_map::end if the specified key is not found in the container.
◆ find() [4/4]
KvStore::const_iterator find | ( | std::string & | k | ) | const |
Get iterator to element.
Searches the container for an element with k as key and returns an iterator to it if found, otherwise it returns an iterator to unordered_map::end (the element past the end of the container).
- Parameters
-
k Key to look up
- Returns
- An iterator to the element, if the specified key value is found, or unordered_map::end if the specified key is not found in the container.
◆ group_begin()
group_iterator group_begin | ( | ) | const |
std::vector iterator to recurse group names
- Returns
- Start iterator
◆ group_end()
group_iterator group_end | ( | ) | const |
std::vector end iterator to recurse group names
- Returns
- End iterator
◆ group_separator() [1/2]
|
inline |
Get the current group separator.
- Returns
- the current group separator
Definition at line 250 of file KvStore.hpp.
◆ group_separator() [2/2]
|
inline |
Set the character(s) to use between group and key when inserting into map.
- Parameters
-
s New separator
Definition at line 244 of file KvStore.hpp.
◆ load() [1/2]
bool load | ( | const std::string & | file | ) |
Read key-value file, appending values to current map.
- Parameters
-
file Path to key-value store to read
- Exceptions
-
not::sure if any lines read are invalid
- Returns
- true on failure, false on success
◆ load() [2/2]
bool load | ( | std::istream & | in | ) |
Read key-values from input stream, appending values to current map.
- Parameters
-
in Input stream containing lines of key-value definitions
- Exceptions
-
not::sure if any lines read are invalid
- Returns
- true on failure, false on success
◆ load_line()
bool load_line | ( | const std::string & | line | ) |
Process key-value line, appending value to current map.
- Parameters
-
line Single key-value line to process
- Exceptions
-
not::sure if any lines read are invalid
- Returns
- true on failure, false on success
◆ operator[]() [1/2]
std::string& operator[] | ( | const std::string & | k | ) |
If k matches the key of an element in the KvStore, the function returns a reference to its mapped value.
If k does not match the key of any element in the container, the function inserts a new element with that key and returns a reference to its mapped value. Notice that this always increases the container size by one, even if no mapped value is assigned to the element (the element is constructed using its default constructor).
- Parameters
-
k Key to look up
- Returns
- A reference to the mapped value
◆ operator[]() [2/2]
std::string& operator[] | ( | std::string && | k | ) |
If k matches the key of an element in the KvStore, the function returns a reference to its mapped value.
If k does not match the key of any element in the container, the function inserts a new element with that key and returns a reference to its mapped value. Notice that this always increases the container size by one, even if no mapped value is assigned to the element (the element is constructed using its default constructor).
- Parameters
-
k Key to look up
- Returns
- A reference to the mapped value
◆ switch_group()
void switch_group | ( | const std::string & | group | ) |
Switch default group for retrieving values.
- Parameters
-
group Group to use by default
Friends And Related Function Documentation
◆ operator<<
The documentation for this class was generated from the following file:
- /gfs-oceanweb/web/ocssw/ocssw_src/include/focs/KvStore.hpp