1+ // Read an INI file into easy-to-access name/value pairs.
2+
3+ // SPDX-License-Identifier: BSD-3-Clause
4+
5+ // Copyright (C) 2009-2020, Ben Hoyt
6+
7+ // inih and INIReader are released under the New BSD license (see LICENSE.txt).
8+ // Go to the project home page for more info:
9+ //
10+ // https://github.com/benhoyt/inih
11+
12+ #ifndef INIREADER_H
13+ #define INIREADER_H
14+
15+ #include < cstdint>
16+ #include < map>
17+ #include < string>
18+
19+ // Visibility symbols, required for Windows DLLs
20+ #ifndef INI_API
21+ #if defined _WIN32 || defined __CYGWIN__
22+ #ifdef INI_SHARED_LIB
23+ #ifdef INI_SHARED_LIB_BUILDING
24+ #define INI_API __declspec (dllexport)
25+ #else
26+ #define INI_API __declspec (dllimport)
27+ #endif
28+ #else
29+ #define INI_API
30+ #endif
31+ #else
32+ #if defined(__GNUC__) && __GNUC__ >= 4
133#define INI_API __attribute__ ((visibility(" default" )))
2- class INIReader
3- {
4- public:
5- __attribute__ ((visibility (" default" ))) explicit INIReader (const char *filename);
6- INI_API explicit INIReader (const char *buffer, long buffer_size);
7- ~INIReader ();
34+ #else
35+ #define INI_API
36+ #endif
37+ #endif
38+ #endif
39+
40+ // Read an INI file into easy-to-access name/value pairs. (Note that I've gone
41+ // for simplicity here rather than speed, but it should be pretty decent.)
42+ class INIReader {
43+ public:
44+ // Construct INIReader and parse given filename. See ini.h for more info
45+ // about the parsing.
46+ __attribute__ ((visibility(" default" ))) explicit INIReader (const std::string &filename);
47+
48+ // Construct INIReader and parse given buffer. See ini.h for more info
49+ // about the parsing.
50+ INI_API explicit INIReader (const char *buffer, size_t buffer_size);
51+
52+ // Return the result of ini_parse(), i.e., 0 on success, line number of
53+ // first error on parse error, or -1 on file open error.
854 INI_API int ParseError () const ;
9- INI_API const char *Get (const char *section, const char *name,
10- const char *default_value) const ;
1155
12- private:
13- static const char *MakeKey (const char *section, const char *name);
14- };
56+ // Get a string value from INI file, returning default_value if not found.
57+ INI_API std::string Get (const std::string §ion, const std::string &name,
58+ const std::string &default_value) const ;
59+
60+ // Get a string value from INI file, returning default_value if not found,
61+ // empty, or contains only whitespace.
62+ INI_API std::string GetString (const std::string §ion, const std::string &name,
63+ const std::string &default_value) const ;
64+
65+ // Get an integer (long) value from INI file, returning default_value if
66+ // not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").
67+ INI_API long GetInteger (const std::string §ion, const std::string &name, long default_value) const ;
68+
69+ // Get a 64-bit integer (int64_t) value from INI file, returning default_value if
70+ // not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").
71+ INI_API int64_t GetInteger64 (const std::string §ion, const std::string &name, int64_t default_value) const ;
72+
73+ // Get an unsigned integer (unsigned long) value from INI file, returning default_value if
74+ // not found or not a valid unsigned integer (decimal "1234", or hex "0x4d2").
75+ INI_API unsigned long GetUnsigned (const std::string §ion, const std::string &name,
76+ unsigned long default_value) const ;
77+
78+ // Get an unsigned 64-bit integer (uint64_t) value from INI file, returning default_value if
79+ // not found or not a valid unsigned integer (decimal "1234", or hex "0x4d2").
80+ INI_API uint64_t GetUnsigned64 (const std::string §ion, const std::string &name, uint64_t default_value) const ;
81+
82+ // Get a real (floating point double) value from INI file, returning
83+ // default_value if not found or not a valid floating point value
84+ // according to strtod().
85+ INI_API double GetReal (const std::string §ion, const std::string &name, double default_value) const ;
86+
87+ // Get a boolean value from INI file, returning default_value if not found or if
88+ // not a valid true/false value. Valid true values are "true", "yes", "on", "1",
89+ // and valid false values are "false", "no", "off", "0" (not case sensitive).
90+ INI_API bool GetBoolean (const std::string §ion, const std::string &name, bool default_value) const ;
91+
92+ // Return true if the given section exists (section must contain at least
93+ // one name=value pair).
94+ INI_API bool HasSection (const std::string §ion) const ;
95+
96+ // Return true if a value exists with the given section and field names.
97+ INI_API bool HasValue (const std::string §ion, const std::string &name) const ;
98+
99+ private:
100+ int _error;
101+ std::map<std::string, std::string> _values;
102+ static std::string MakeKey (const std::string §ion, const std::string &name);
103+ static int ValueHandler (void *user, const char *section, const char *name, const char *value);
104+ };
105+
106+ #endif // INIREADER_H
0 commit comments