Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
folium-app
GitHub Repository: folium-app/Folium
Path: blob/a-new-beginning/SharedDependencies/Sources/inih/include/INIReader.h
2 views
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-2025, 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 <map>
16
#include <string>
17
#include <cstdint>
18
#include <vector>
19
#include <set>
20
21
// Visibility symbols, required for Windows DLLs
22
#ifndef INI_API
23
#if defined _WIN32 || defined __CYGWIN__
24
# ifdef INI_SHARED_LIB
25
# ifdef INI_SHARED_LIB_BUILDING
26
# define INI_API __declspec(dllexport)
27
# else
28
# define INI_API __declspec(dllimport)
29
# endif
30
# else
31
# define INI_API
32
# endif
33
#else
34
# if defined(__GNUC__) && __GNUC__ >= 4
35
# define INI_API __attribute__ ((visibility ("default")))
36
# else
37
# define INI_API
38
# endif
39
#endif
40
#endif
41
42
// 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
class INIReader
45
{
46
public:
47
// Construct INIReader and parse given filename. See ini.h for more info
48
// about the parsing.
49
INI_API explicit INIReader(const std::string& filename);
50
51
// Construct INIReader and parse given buffer. See ini.h for more info
52
// about the parsing.
53
INI_API explicit INIReader(const char *buffer, size_t buffer_size);
54
55
// Return the result of ini_parse(), i.e., 0 on success, line number of
56
// first error on parse error, -1 on file open error, or -2 if there was a
57
// memory allocation error.
58
INI_API int ParseError() const;
59
60
// Return a message that describes the type of error that occurred.
61
// It will return "" (empty string) if there was no error.
62
INI_API std::string ParseErrorMessage() const;
63
64
// Get a string value from INI file, returning default_value if not found.
65
INI_API std::string Get(const std::string& section, const std::string& name,
66
const std::string& default_value) const;
67
68
// Get a string value from INI file, returning default_value if not found,
69
// empty, or contains only whitespace.
70
INI_API std::string GetString(const std::string& section, const std::string& name,
71
const std::string& default_value) const;
72
73
// Get an integer (long) value from INI file, returning default_value if
74
// not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").
75
INI_API long GetInteger(const std::string& section, const std::string& name, long default_value) const;
76
77
// Get a 64-bit integer (int64_t) value from INI file, returning default_value if
78
// not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").
79
INI_API int64_t GetInteger64(const std::string& section, const std::string& name, int64_t default_value) const;
80
81
// Get an unsigned integer (unsigned long) value from INI file, returning default_value if
82
// not found or not a valid unsigned integer (decimal "1234", or hex "0x4d2").
83
INI_API unsigned long GetUnsigned(const std::string& section, const std::string& name, unsigned long default_value) const;
84
85
// Get an unsigned 64-bit integer (uint64_t) value from INI file, returning default_value if
86
// not found or not a valid unsigned integer (decimal "1234", or hex "0x4d2").
87
INI_API uint64_t GetUnsigned64(const std::string& section, const std::string& name, uint64_t default_value) const;
88
89
// Get a real (floating point double) value from INI file, returning
90
// default_value if not found or not a valid floating point value
91
// according to strtod().
92
INI_API double GetReal(const std::string& section, const std::string& name, double default_value) const;
93
94
// Get a boolean value from INI file, returning default_value if not found or if
95
// not a valid true/false value. Valid true values are "true", "yes", "on", "1",
96
// and valid false values are "false", "no", "off", "0" (not case sensitive).
97
INI_API bool GetBoolean(const std::string& section, const std::string& name, bool default_value) const;
98
99
// Return a newly-allocated vector of all section names, in alphabetical order.
100
INI_API std::vector<std::string> Sections() const;
101
102
// Return a newly-allocated vector of keys in the given section, in alphabetical order.
103
INI_API std::vector<std::string> Keys(const std::string& section) const;
104
105
// Return true if the given section exists (section must contain at least
106
// one name=value pair).
107
INI_API bool HasSection(const std::string& section) const;
108
109
// Return true if a value exists with the given section and field names.
110
INI_API bool HasValue(const std::string& section, const std::string& name) const;
111
112
protected:
113
int _error;
114
std::map<std::string, std::string> _values;
115
static std::string MakeKey(const std::string& section, const std::string& name);
116
static int ValueHandler(void* user, const char* section, const char* name,
117
const char* value);
118
};
119
120
#endif // INIREADER_H
121
122