Added documentation

This commit is contained in:
matthias@arch 2022-09-28 15:31:27 +02:00
parent 2e8498aa90
commit 3b7d1dc159
2 changed files with 23 additions and 2 deletions

View File

@ -38,7 +38,7 @@ namespace gz {
getline(file, line); getline(file, line);
// ignore commented lines // ignore commented lines
if (line.find("#") != std::string::npos) { continue; } if (line.starts_with('#')) { continue; }
// if "=" in line: split into key - value pair and store in map // if "=" in line: split into key - value pair and store in map
if (line.find("=") != std::string::npos) { if (line.find("=") != std::string::npos) {

View File

@ -11,6 +11,7 @@ namespace gz {
* @details * @details
* This template function is instantiated for the default unordered_map<string, string> and the util::string_map from util/string.hpp * This template function is instantiated for the default unordered_map<string, string> and the util::string_map from util/string.hpp
* @throws FileIOError * @throws FileIOError
* @see @ref fio_t_key_value "Key-Value filetype"
*/ */
template<typename Hash, typename Pred> template<typename Hash, typename Pred>
bool writeKeyValueFile(const std::string& filepath, const std::unordered_map<std::string, std::string, Hash, Pred>& content); bool writeKeyValueFile(const std::string& filepath, const std::unordered_map<std::string, std::string, Hash, Pred>& content);
@ -18,7 +19,27 @@ namespace gz {
/** /**
* @brief Read a file that contains key = value pairs * @brief Read a file that contains key = value pairs
* @throws FileIOError * @throws FileIOError
* @see @ref fio_t_key_value "Key-Value filetype"
*/ */
std::unordered_map<std::string, std::string> readKeyValueFile(const std::string& filepath, bool removeSpaces=false); std::unordered_map<std::string, std::string> readKeyValueFile(const std::string& filepath, bool removeSpaces=false);
} }
/**
* @file
* @brief Contains file reading/writing utility
*/
/**
* @page FileIO
* @section fio_filetypes Filetypes
* @subsection fio_t_key_value Simple Key-Value file
* A file that contains key - value pairs in each line, separated with "=".
* Any number of whitespaces around the separator is allowed.
* If the first character of a line is "#", the whole line is a comment.
* Example:
* @code
* key1 = value1
* # this is a comment
* key2= #this_is_value_not_a_comment
* arr = val1, val2, val3
* @endcode
*/