Exiv2
ini.hpp
1 // ***************************************************************** -*- C++ -*-
2 /*
3  * Copyright (C) 2004-2021 Exiv2 authors
4  * This program is part of the Exiv2 distribution.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 // Read an INI file into easy-to-access name/value pairs.
22 
23 // inih and INIReader are released under the New BSD license (see LICENSE.txt).
24 // Go to the project home page for more info:
25 //
26 // https://github.com/benhoyt/inih
27 
28 #ifndef __INIREADER_H__
29 #define __INIREADER_H__
30 
31 #include "exiv2lib_export.h"
32 
33 #include <map>
34 #include <string>
35 #include <stdio.h>
36 
37 namespace Exiv2 {
38 
39 /* inih -- simple .INI file parser
40 
41 inih is released under the New BSD license (see LICENSE.txt). Go to the project
42 home page for more info:
43 
44 https://github.com/benhoyt/inih
45 
46 */
47 
48 #ifndef __INI_H__
49 #define __INI_H__
50 
51 /* Make this header file easier to include in C++ code */
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
57 typedef int (*ini_handler)(void* user, const char* section,
58  const char* name, const char* value);
59 
61 typedef char* (*ini_reader)(char* str, int num, void* stream);
62 
83 int ini_parse(const char* filename, ini_handler handler, void* user);
84 
92 int ini_parse_file(FILE* file, ini_handler handler, void* user);
93 
103 int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
104  void* user);
105 
110 #ifndef INI_ALLOW_MULTILINE
111 #define INI_ALLOW_MULTILINE 1
112 #endif
113 
117 #ifndef INI_ALLOW_BOM
118 #define INI_ALLOW_BOM 1
119 #endif
120 
125 #ifndef INI_ALLOW_INLINE_COMMENTS
126 #define INI_ALLOW_INLINE_COMMENTS 1
127 #endif
128 #ifndef INI_INLINE_COMMENT_PREFIXES
129 #define INI_INLINE_COMMENT_PREFIXES ";"
130 #endif
131 
133 #ifndef INI_USE_STACK
134 #define INI_USE_STACK 1
135 #endif
136 
138 #ifndef INI_STOP_ON_FIRST_ERROR
139 #define INI_STOP_ON_FIRST_ERROR 0
140 #endif
141 
143 #ifndef INI_MAX_LINE
144 #define INI_MAX_LINE 200
145 #endif
146 
147 #ifdef __cplusplus
148 }
149 #endif
150 
151 #endif /* __INI_H__ */
152 
153 
157 class EXIV2API INIReader
158 {
159 public:
163  explicit INIReader(const std::string& filename);
164 
168  int ParseError();
169 
178  std::string Get(std::string section, std::string name,
179  std::string default_value);
180 
190  long GetInteger(std::string section, std::string name, long default_value);
191 
202  double GetReal(std::string section, std::string name, double default_value);
203 
214  bool GetBoolean(std::string section, std::string name, bool default_value);
215 
216 private:
217  int _error;
218  std::map<std::string, std::string> _values;
219  static std::string MakeKey(std::string section, std::string name);
220  static int ValueHandler(void* user, const char* section, const char* name,
221  const char* value);
222 };
223 } // namespace Exiv2
224 
225 #endif // __INIREADER_H__
Read an INI file into easy-to-access name/value pairs. (Note that I've gone for simplicity here rathe...
Definition: ini.hpp:158
Provides classes and functions to encode and decode Exif and Iptc data. The libexiv2 API consists of ...
Definition: asfvideo.hpp:36
char *(* ini_reader)(char *str, int num, void *stream)
Typedef for prototype of fgets-style reader function.
Definition: ini.hpp:61
int(* ini_handler)(void *user, const char *section, const char *name, const char *value)
typedef for prototype of handler function.
Definition: ini.hpp:57
int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler, void *user)
Same as ini_parse(), but takes an ini_reader function pointer instead of filename....
Definition: ini.cpp:108
int ini_parse_file(FILE *file, ini_handler handler, void *user)
Same as ini_parse(), but takes a FILE* instead of filename. This doesn't close the file when it's fin...
Definition: ini.cpp:212
int ini_parse(const char *filename, ini_handler handler, void *user)
Parse given INI-style file. May have [section]s, name=value pairs (whitespace stripped),...
Definition: ini.cpp:218