Path: blob/a-new-beginning/SharedDependencies/Sources/inih/include/INIReader.h
2 views
// Read an INI file into easy-to-access name/value pairs.12// SPDX-License-Identifier: BSD-3-Clause34// Copyright (C) 2009-2025, Ben Hoyt56// inih and INIReader are released under the New BSD license (see LICENSE.txt).7// Go to the project home page for more info:8//9// https://github.com/benhoyt/inih1011#ifndef INIREADER_H12#define INIREADER_H1314#include <map>15#include <string>16#include <cstdint>17#include <vector>18#include <set>1920// Visibility symbols, required for Windows DLLs21#ifndef INI_API22#if defined _WIN32 || defined __CYGWIN__23# ifdef INI_SHARED_LIB24# ifdef INI_SHARED_LIB_BUILDING25# define INI_API __declspec(dllexport)26# else27# define INI_API __declspec(dllimport)28# endif29# else30# define INI_API31# endif32#else33# if defined(__GNUC__) && __GNUC__ >= 434# define INI_API __attribute__ ((visibility ("default")))35# else36# define INI_API37# endif38#endif39#endif4041// Read an INI file into easy-to-access name/value pairs. (Note that I've gone42// for simplicity here rather than speed, but it should be pretty decent.)43class INIReader44{45public:46// Construct INIReader and parse given filename. See ini.h for more info47// about the parsing.48INI_API explicit INIReader(const std::string& filename);4950// Construct INIReader and parse given buffer. See ini.h for more info51// about the parsing.52INI_API explicit INIReader(const char *buffer, size_t buffer_size);5354// Return the result of ini_parse(), i.e., 0 on success, line number of55// first error on parse error, -1 on file open error, or -2 if there was a56// memory allocation error.57INI_API int ParseError() const;5859// Return a message that describes the type of error that occurred.60// It will return "" (empty string) if there was no error.61INI_API std::string ParseErrorMessage() const;6263// Get a string value from INI file, returning default_value if not found.64INI_API std::string Get(const std::string& section, const std::string& name,65const std::string& default_value) const;6667// Get a string value from INI file, returning default_value if not found,68// empty, or contains only whitespace.69INI_API std::string GetString(const std::string& section, const std::string& name,70const std::string& default_value) const;7172// Get an integer (long) value from INI file, returning default_value if73// not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").74INI_API long GetInteger(const std::string& section, const std::string& name, long default_value) const;7576// Get a 64-bit integer (int64_t) value from INI file, returning default_value if77// not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").78INI_API int64_t GetInteger64(const std::string& section, const std::string& name, int64_t default_value) const;7980// Get an unsigned integer (unsigned long) value from INI file, returning default_value if81// not found or not a valid unsigned integer (decimal "1234", or hex "0x4d2").82INI_API unsigned long GetUnsigned(const std::string& section, const std::string& name, unsigned long default_value) const;8384// Get an unsigned 64-bit integer (uint64_t) value from INI file, returning default_value if85// not found or not a valid unsigned integer (decimal "1234", or hex "0x4d2").86INI_API uint64_t GetUnsigned64(const std::string& section, const std::string& name, uint64_t default_value) const;8788// Get a real (floating point double) value from INI file, returning89// default_value if not found or not a valid floating point value90// according to strtod().91INI_API double GetReal(const std::string& section, const std::string& name, double default_value) const;9293// Get a boolean value from INI file, returning default_value if not found or if94// not a valid true/false value. Valid true values are "true", "yes", "on", "1",95// and valid false values are "false", "no", "off", "0" (not case sensitive).96INI_API bool GetBoolean(const std::string& section, const std::string& name, bool default_value) const;9798// Return a newly-allocated vector of all section names, in alphabetical order.99INI_API std::vector<std::string> Sections() const;100101// Return a newly-allocated vector of keys in the given section, in alphabetical order.102INI_API std::vector<std::string> Keys(const std::string& section) const;103104// Return true if the given section exists (section must contain at least105// one name=value pair).106INI_API bool HasSection(const std::string& section) const;107108// Return true if a value exists with the given section and field names.109INI_API bool HasValue(const std::string& section, const std::string& name) const;110111protected:112int _error;113std::map<std::string, std::string> _values;114static std::string MakeKey(const std::string& section, const std::string& name);115static int ValueHandler(void* user, const char* section, const char* name,116const char* value);117};118119#endif // INIREADER_H120121122