UTF8 - Simple Library for Internationalization
Loading...
Searching...
No Matches
ini.h
Go to the documentation of this file.
1/*
2 Copyright (c) Mircea Neacsu (2014-2024) Licensed under MIT License.
3 This is part of UTF8 project. See LICENSE file for full license terms.
4*/
5
8#pragma once
9
10#include <string>
11#include <deque>
12
13namespace utf8 {
14
17{
18public:
20 explicit IniFile (const std::string& name);
21
23 IniFile ();
24
26 IniFile (const IniFile& p);
27
29 ~IniFile ();
30
32 IniFile& operator= (const IniFile&);
33
35 const std::string& File () const
36 { return filename; };
37
39 void File (const std::string& filename);
40
42 size_t GetString (char *value, size_t len, const std::string& key, const std::string& section, const std::string& defval = std::string()) const;
43
45 std::string GetString (const std::string& key, const std::string& section, const std::string& defval = std::string ()) const;
46
48 int GetInt (const std::string& key, const std::string& section, int defval=0) const;
49
51 double GetDouble (const std::string& key, const std::string& section, double defval=0.) const;
52
54 bool GetBool (const std::string& key, const std::string& section, bool defval=false) const;
55
57 bool HasKey (const std::string& key, const std::string& section) const;
58
60 bool PutString (const std::string& key, const std::string& value, const std::string& section);
61
63 bool PutInt (const std::string& key, long value, const std::string& section);
64
66 bool PutBool (const std::string& key, bool value, const std::string& section);
67
69 bool PutDouble (const std::string& key, double value, const std::string& section, int dec = 2);
70
72 bool DeleteKey (const std::string& key, const std::string& section);
73
75 bool DeleteSection (const std::string& section);
76
78 bool CopySection (const IniFile& from_file, const std::string& from_sect, const std::string& to_sect=std::string());
79
81 bool HasSection (const std::string& section);
82
84 int GetKeys (char *buffer, size_t sz, const std::string& section);
85
87 size_t GetKeys (std::deque<std::string>& keys, const std::string& section);
88
90 size_t GetSections (char *sects, size_t sz);
91
93 size_t GetSections (std::deque<std::string>& sections);
94
95#ifdef _WIN32 // Windows specific vvvvvvvv
97 COLORREF GetColor (const std::string& key, const std::string& section, COLORREF defval = RGB (0, 0, 0)) const;
98
100 HFONT GetFont (const std::string& key, const std::string& section, HFONT defval = NULL) const;
101
103 bool PutColor (const std::string& key, COLORREF value, const std::string& section);
104
106 bool PutFont (const std::string& key, HFONT font, const std::string& section);
107#endif // end Windows specific ^^^^^^^^
108
109private:
110
111 std::string filename;
112 bool temp_file;
113};
114
115
116}
Operations on INI files.
Definition ini.h:17
double GetDouble(const std::string &key, const std::string &section, double defval=0.) const
Return a floating point value.
Definition ini.cpp:271
const std::string & File() const
Return file name associated with this object.
Definition ini.h:35
bool PutBool(const std::string &key, bool value, const std::string &section)
Write a boolean key.
Definition ini.cpp:519
bool PutDouble(const std::string &key, double value, const std::string &section, int dec=2)
Write a floating point value key.
Definition ini.cpp:296
IniFile & operator=(const IniFile &)
Assignment operator.
Definition ini.cpp:235
bool DeleteSection(const std::string &section)
Delete an entire section.
Definition ini.cpp:649
size_t GetSections(char *sects, size_t sz)
Return the names of all sections in the INI file.
Definition ini.cpp:786
bool HasKey(const std::string &key, const std::string &section) const
Check for key existence.
Definition ini.cpp:249
bool HasSection(const std::string &section)
Return true if profile contains a non empty section with the given name.
Definition ini.cpp:628
int GetKeys(char *buffer, size_t sz, const std::string &section)
Retrieve names of all keys in a section.
Definition ini.cpp:662
bool PutInt(const std::string &key, long value, const std::string &section)
Write an integer key.
Definition ini.cpp:283
int GetInt(const std::string &key, const std::string &section, int defval=0) const
Return an integer key.
Definition ini.cpp:260
~IniFile()
Destructor.
Definition ini.cpp:199
bool PutString(const std::string &key, const std::string &value, const std::string &section)
Write a string key.
Definition ini.cpp:768
bool GetBool(const std::string &key, const std::string &section, bool defval=false) const
Return a boolean key.
Definition ini.cpp:499
bool DeleteKey(const std::string &key, const std::string &section)
Delete a key.
Definition ini.cpp:641
bool CopySection(const IniFile &from_file, const std::string &from_sect, const std::string &to_sect=std::string())
Copy all keys from one section to another.
Definition ini.cpp:537
size_t GetString(char *value, size_t len, const std::string &key, const std::string &section, const std::string &defval=std::string()) const
Get a string key.
Definition ini.cpp:720
IniFile()
Default constructor uses a temporary file.
Definition ini.cpp:181
A simple buffer for caching values returned by Windows API.
Definition winutf8.h:160