GNSS-SDR 0.0.21
An Open Source GNSS Software Defined Receiver
Loading...
Searching...
No Matches
INIReader.h
Go to the documentation of this file.
1/*!
2 * \file INIReader.h
3 * \brief This class reads an INI file into easy-to-access name/value pairs.
4 * \author Brush Technologies, 2009.
5 *
6 * inih (INI Not Invented Here) is a simple .INI file parser written in C++.
7 * It's only a couple of pages of code, and it was designed to be small
8 * and simple, so it's good for embedded systems. To use it, just give
9 * ini_parse() an INI file, and it will call a callback for every
10 * name=value pair parsed, giving you strings for the section, name,
11 * and value. It's done this way because it works well on low-memory
12 * embedded systems, but also because it makes for a KISS implementation.
13 *
14 * -----------------------------------------------------------------------------
15 * inih and INIReader are released under the New BSD license:
16 *
17 * Copyright (c) 2009, Brush Technology
18 * All rights reserved.
19 *
20 * SPDX-License-Identifier: BSD-3-Clause
21 *
22 * Go to the project home page for more info:
23 *
24 * https://github.com/benhoyt/inih
25 * -----------------------------------------------------------------------------
26 */
27
28#ifndef GNSS_SDR_INIREADER_H
29#define GNSS_SDR_INIREADER_H
30
31#include <cstdint>
32#include <map>
33#include <string>
34
35/** \addtogroup Core
36 * \{ */
37/** \addtogroup Core_Receiver_Library
38 * \{ */
39
40
41/*!
42 * \brief Read an INI file into easy-to-access name/value pairs. (Note that I've gone
43 * for simplicity here rather than speed, but it should be pretty decent.)
44 */
46{
47public:
48 //! Construct INIReader and parse given filename. See ini.h for more info about the parsing.
49 explicit INIReader(const std::string& filename);
50
51 //! Return the result of ini_parse(), i.e., 0 on success, line number of first error on parse error, or -1 on file open error.
52 int ParseError() const;
53
54 //! Get a string value from INI file, returning default_value if not found.
55 std::string Get(const std::string& section, const std::string& name,
56 const std::string& default_value);
57
58 //! Get an integer (long) value from INI file, returning default_value if not found.
59 int64_t GetInteger(const std::string& section, const std::string& name, int64_t default_value);
60
61 //! Return true if the given section exists (section must contain at least one name=value pair).
62 bool HasSection(const std::string& section) const;
63
64 //! Return true if a value exists with the given section and field names.
65 bool HasValue(const std::string& section, const std::string& name) const;
66
67private:
68 static std::string MakeKey(const std::string& section, const std::string& name);
69 static int ValueHandler(void* user, const char* section, const char* name,
70 const char* value);
71
72 std::map<std::string, std::string> _values;
73 int _error;
74};
75
76
77/** \} */
78/** \} */
79#endif // GNSS_SDR_INIREADER_H
INIReader(const std::string &filename)
Construct INIReader and parse given filename. See ini.h for more info about the parsing.
std::string Get(const std::string &section, const std::string &name, const std::string &default_value)
Get a string value from INI file, returning default_value if not found.
int ParseError() const
Return the result of ini_parse(), i.e., 0 on success, line number of first error on parse error,...
int64_t GetInteger(const std::string &section, const std::string &name, int64_t default_value)
Get an integer (long) value from INI file, returning default_value if not found.
bool HasSection(const std::string &section) const
Return true if the given section exists (section must contain at least one name=value pair).
bool HasValue(const std::string &section, const std::string &name) const
Return true if a value exists with the given section and field names.