2018-03-03 01:03:39 +00:00
|
|
|
/*!
|
|
|
|
* \file INIReader.h
|
|
|
|
* \brief This class reads an INI file into easy-to-access name/value pairs.
|
|
|
|
* \author Brush Technologies, 2009.
|
|
|
|
*
|
|
|
|
* inih (INI Not Invented Here) is a simple .INI file parser written in C++.
|
|
|
|
* It's only a couple of pages of code, and it was designed to be small
|
|
|
|
* and simple, so it's good for embedded systems. To use it, just give
|
|
|
|
* ini_parse() an INI file, and it will call a callback for every
|
|
|
|
* name=value pair parsed, giving you strings for the section, name,
|
|
|
|
* and value. It's done this way because it works well on low-memory
|
|
|
|
* embedded systems, but also because it makes for a KISS implementation.
|
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2018-03-03 01:03:39 +00:00
|
|
|
* inih and INIReader are released under the New BSD license:
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009, Brush Technology
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
2020-02-08 00:20:02 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2018-03-03 01:03:39 +00:00
|
|
|
*
|
|
|
|
* Go to the project home page for more info:
|
|
|
|
*
|
2020-02-05 20:24:46 +00:00
|
|
|
* https://github.com/benhoyt/inih
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2018-03-03 01:03:39 +00:00
|
|
|
*/
|
|
|
|
|
2020-02-08 09:10:46 +00:00
|
|
|
#ifndef GNSS_SDR_INIREADER_H
|
|
|
|
#define GNSS_SDR_INIREADER_H
|
2018-03-03 01:03:39 +00:00
|
|
|
|
2018-12-02 04:29:11 +00:00
|
|
|
#include <cstdint>
|
2018-03-03 01:03:39 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2020-11-01 12:37:19 +00:00
|
|
|
/** \addtogroup Core
|
|
|
|
* \{ */
|
|
|
|
/** \addtogroup Core_Receiver_Library
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
/*!
|
|
|
|
* \brief Read an INI file into easy-to-access name/value pairs. (Note that I've gone
|
|
|
|
* for simplicity here rather than speed, but it should be pretty decent.)
|
|
|
|
*/
|
|
|
|
class INIReader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//! Construct INIReader and parse given filename. See ini.h for more info about the parsing.
|
2019-08-23 19:25:44 +00:00
|
|
|
explicit INIReader(const std::string& filename);
|
2018-03-03 01:03:39 +00:00
|
|
|
|
|
|
|
//! 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.
|
2020-12-30 20:49:29 +00:00
|
|
|
int ParseError() const;
|
2018-03-03 01:03:39 +00:00
|
|
|
|
|
|
|
//! Get a string value from INI file, returning default_value if not found.
|
2018-12-08 17:49:31 +00:00
|
|
|
std::string Get(const std::string& section, const std::string& name,
|
2019-06-29 20:04:03 +00:00
|
|
|
const std::string& default_value);
|
2018-03-03 01:03:39 +00:00
|
|
|
|
|
|
|
//! Get an integer (long) value from INI file, returning default_value if not found.
|
2018-12-08 17:49:31 +00:00
|
|
|
int64_t GetInteger(const std::string& section, const std::string& name, int64_t default_value);
|
2018-03-03 01:03:39 +00:00
|
|
|
|
2021-01-24 23:49:36 +00:00
|
|
|
//! Return true if the given section exists (section must contain at least one name=value pair).
|
|
|
|
bool HasSection(const std::string& section) const;
|
|
|
|
|
|
|
|
//! Return true if a value exists with the given section and field names.
|
|
|
|
bool HasValue(const std::string& section, const std::string& name) const;
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
private:
|
2018-12-03 18:01:47 +00:00
|
|
|
static std::string MakeKey(const std::string& section, const std::string& name);
|
2018-03-03 01:03:39 +00:00
|
|
|
static int ValueHandler(void* user, const char* section, const char* name,
|
|
|
|
const char* value);
|
2020-06-27 07:25:04 +00:00
|
|
|
|
|
|
|
std::map<std::string, std::string> _values;
|
|
|
|
int _error;
|
2018-03-03 01:03:39 +00:00
|
|
|
};
|
|
|
|
|
2020-11-01 12:37:19 +00:00
|
|
|
|
|
|
|
/** \} */
|
|
|
|
/** \} */
|
2020-02-08 09:10:46 +00:00
|
|
|
#endif // GNSS_SDR_INIREADER_H
|