Skip to content

Commit 97db419

Browse files
committed
doc: add documentation
1 parent ca896a0 commit 97db419

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

ini/ini.h

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,21 @@ class INIReader {
280280
#ifndef __INIREADER__
281281
#define __INIREADER__
282282

283+
/**
284+
* @brief Construct an INIReader object from a file name
285+
* @param filename The name of the INI file to parse
286+
* @throws std::runtime_error if there is an error parsing the INI file
287+
*/
283288
inline INIReader::INIReader(std::string filename) {
284289
_error = ini_parse(filename.c_str(), ValueHandler, this);
285290
ParseError();
286291
}
287292

293+
/**
294+
* @brief Construct an INIReader object from a file pointer
295+
* @param file A pointer to the INI file to parse
296+
* @throws std::runtime_error if there is an error parsing the INI file
297+
*/
288298
inline INIReader::INIReader(FILE* file) {
289299
_error = ini_parse_file(file, ValueHandler, this);
290300
ParseError();
@@ -308,8 +318,6 @@ inline int INIReader::ParseError() const {
308318
/**
309319
* @brief Return the list of sections found in ini file
310320
* @return The list of sections found in ini file
311-
*
312-
*
313321
*/
314322
inline const std::set<std::string> INIReader::Sections() const {
315323
std::set<std::string> retval;
@@ -333,6 +341,12 @@ inline const std::set<std::string> INIReader::Keys(std::string section) const {
333341
return retval;
334342
}
335343

344+
/**
345+
* @brief Get the map representing the values in a section of the INI file
346+
* @param section The name of the section to retrieve
347+
* @return The map representing the values in the given section
348+
* @throws std::runtime_error if the section is not found
349+
*/
336350
inline const std::unordered_map<std::string, std::string> INIReader::Get(
337351
std::string section) const {
338352
auto const _section = _values.find(section);
@@ -447,6 +461,13 @@ inline std::vector<T> INIReader::GetVector(
447461
};
448462
}
449463

464+
/**
465+
* @brief Insert a key-value pair into the INI file
466+
* @param section The section name
467+
* @param name The key name
468+
* @param v The value to insert
469+
* @throws std::runtime_error if the key already exists in the section
470+
*/
450471
template <typename T>
451472
inline void INIReader::InsertEntry(const std::string& section,
452473
const std::string& name, const T& v) {
@@ -457,6 +478,13 @@ inline void INIReader::InsertEntry(const std::string& section,
457478
_values[section][name] = V2String(v);
458479
}
459480

481+
/**
482+
* @brief Insert a vector of values into the INI file
483+
* @param section The section name
484+
* @param name The key name
485+
* @param vs The vector of values to insert
486+
* @throws std::runtime_error if the key already exists in the section
487+
*/
460488
template <typename T>
461489
inline void INIReader::InsertEntry(const std::string& section,
462490
const std::string& name,
@@ -468,6 +496,13 @@ inline void INIReader::InsertEntry(const std::string& section,
468496
_values[section][name] = Vec2String(vs);
469497
}
470498

499+
/**
500+
* @brief Update a key-value pair in the INI file
501+
* @param section The section name
502+
* @param name The key name
503+
* @param v The new value to set
504+
* @throws std::runtime_error if the key does not exist in the section
505+
*/
471506
template <typename T>
472507
inline void INIReader::UpdateEntry(const std::string& section,
473508
const std::string& name, const T& v) {
@@ -478,6 +513,13 @@ inline void INIReader::UpdateEntry(const std::string& section,
478513
_values[section][name] = V2String(v);
479514
}
480515

516+
/**
517+
* @brief Update a vector of values in the INI file
518+
* @param section The section name
519+
* @param name The key name
520+
* @param vs The new vector of values to set
521+
* @throws std::runtime_error if the key does not exist in the section
522+
*/
481523
template <typename T>
482524
inline void INIReader::UpdateEntry(const std::string& section,
483525
const std::string& name,
@@ -552,6 +594,13 @@ inline int INIReader::ValueHandler(void* user, const char* section,
552594
class INIWriter {
553595
public:
554596
INIWriter(){};
597+
/**
598+
* @brief Write the contents of an INI file to a new file
599+
* @param filepath The path of the output file
600+
* @param reader The INIReader object to write to the file
601+
* @throws std::runtime_error if the output file already exists or cannot be
602+
* opened
603+
*/
555604
inline static void write(const std::string& filepath,
556605
const INIReader& reader) {
557606
if (struct stat buf; stat(filepath.c_str(), &buf) == 0) {

0 commit comments

Comments
 (0)