OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
inifile.h
Go to the documentation of this file.
1#pragma once
2
3#include <Tempest/File>
4#include <vector>
5#include <string>
6
7class IniFile final {
8 public:
9 IniFile() = default;
10 IniFile(std::u16string_view file);
11 IniFile(Tempest::RFile& fin);
12
13 void flush();
14
15 bool has (std::string_view sec);
16 bool has (std::string_view sec, std::string_view name);
17 int getI(std::string_view sec, std::string_view name, int idef = 0);
18 void set (std::string_view sec, std::string_view name, int ival);
19 float getF(std::string_view sec, std::string_view name, float fdef = 0);
20 void set (std::string_view sec, std::string_view name, float fval);
21
22 auto getS(std::string_view sec, std::string_view name) -> std::string_view;
23 void set (std::string_view sec, std::string_view name, std::string_view sval);
24
25 private:
26 struct Value final {
27 std::string name;
28 std::string val;
29 };
30
31 struct Section {
32 std::string name;
33 std::vector<Value> val;
34 };
35
36 void implRead(Tempest::RFile& fin);
37 void implLine(std::istream &fin);
38 char implSpace(std::istream &fin);
39 auto implName (std::istream &fin) -> std::string;
40 auto implValue (std::istream &fin) -> std::string;
41
42 void addSection(std::string&& name);
43 void addValue (std::string&& name, std::string&& val);
44 void addValue (Section& sec, std::string&& name, std::string&& val);
45 auto find (std::string_view sec, std::string_view name) -> Value&;
46 auto find (std::string_view sec, std::string_view name, bool autoCreate) -> Value*;
47 int getI (const Value& v) const;
48 float getF (const Value& v) const;
49
50 std::vector<Section> sec;
51 std::u16string fileName;
52 bool changeFlag = false;
53 };
void set(std::string_view sec, std::string_view name, int ival)
Definition inifile.cpp:93
IniFile()=default
auto getS(std::string_view sec, std::string_view name) -> std::string_view
Definition inifile.cpp:115
float getF(std::string_view sec, std::string_view name, float fdef=0)
Definition inifile.cpp:101
int getI(std::string_view sec, std::string_view name, int idef=0)
Definition inifile.cpp:87
bool has(std::string_view sec)
Definition inifile.cpp:76
void flush()
Definition inifile.cpp:52