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#ifdef _WIN32
13 #include <windows.h>
14#endif
15
16namespace utf8 {
17
20{
21public:
23 explicit IniFile (const std::string& name);
24
26 IniFile ();
27
29 IniFile (const IniFile& p);
30
32 ~IniFile ();
33
35 IniFile& operator= (const IniFile&);
36
38 const std::string& File () const
39 { return filename; };
40
42 void File (const std::string& filename);
43
45 size_t GetString (char *value, size_t len, const std::string& key, const std::string& section, const std::string& defval = std::string()) const;
46
48 std::string GetString (const std::string& key, const std::string& section, const std::string& defval = std::string ()) const;
49
51 int GetInt (const std::string& key, const std::string& section, int defval=0) const;
52
54 double GetDouble (const std::string& key, const std::string& section, double defval=0.) const;
55
57 bool GetBool (const std::string& key, const std::string& section, bool defval=false) const;
58
60 bool HasKey (const std::string& key, const std::string& section) const;
61
63 bool PutString (const std::string& key, const std::string& value, const std::string& section);
64
66 bool PutInt (const std::string& key, long value, const std::string& section);
67
69 bool PutBool (const std::string& key, bool value, const std::string& section);
70
72 bool PutDouble (const std::string& key, double value, const std::string& section, int dec = 2);
73
75 bool DeleteKey (const std::string& key, const std::string& section);
76
78 bool DeleteSection (const std::string& section);
79
81 bool CopySection (const IniFile& from_file, const std::string& from_sect, const std::string& to_sect=std::string());
82
84 bool HasSection (const std::string& section);
85
87 int GetKeys (char *buffer, size_t sz, const std::string& section);
88
90 size_t GetKeys (std::deque<std::string>& keys, const std::string& section);
91
93 size_t GetSections (char *sects, size_t sz);
94
96 size_t GetSections (std::deque<std::string>& sections);
97
98#ifdef _WIN32 // Windows specific vvvvvvvv
100 COLORREF GetColor (const std::string& key, const std::string& section, COLORREF defval = RGB (0, 0, 0)) const;
101
103 HFONT GetFont (const std::string& key, const std::string& section, HFONT defval = NULL) const;
104
106 bool PutColor (const std::string& key, COLORREF value, const std::string& section);
107
109 bool PutFont (const std::string& key, HFONT font, const std::string& section);
110#endif // end Windows specific ^^^^^^^^
111
112private:
113
114 std::string filename;
115 bool temp_file;
116};
117
118
119}
Operations on INI files.
Definition ini.h:20
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:38
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:162