dl
dl_file_ini.h
浏览该文件的文档.
1
12#pragma once
13
14#include <map>
15#include <unordered_map>
16
17#include "base/dl_string.h"
18
19namespace dl
20{
22{
23 enum class Type
24 {
29 };
31 std::string value;
32 std::string key;
33};
34
36{
37 friend class FileIni;
38public:
40 bool Set(std::string_view key, std::string_view value);
42 bool Add(std::string_view key, std::string_view value);
43 //
44 bool Change(std::string_view key, std::string_view value);
45
46 bool Del(std::string_view key);
47
48 bool Get(std::string_view key, FileIniLine& ret);
49private:
50 std::vector<FileIniLine> _vecData;
51 std::unordered_map<std::string, size_t> _mapKeyIndex;
52};
53
54class FileIni;
56{
57 friend class FileIni;
58public:
60private:
61 FileIniSection(FileIni* parent) :
62 _ini{ parent }
63 {}
64public:
72 void Set(std::string_view key, std::string_view value);
80 void Add(std::string_view key, std::string_view value);
81
82 bool Change(std::string_view key, std::string_view value);
87 bool Del(std::string_view key);
92 std::string Get(std::string_view key);
93private:
94 std::vector<size_t> _allSectionNode;
95 FileIni* _ini;
96};
97
99{
100 friend class FileIniSection;
101public:
103
104 bool Open(std::string_view path_name);
105
106 bool Save(std::string_view path_name);
107
108 bool DelSection(std::string_view key);
109
110 FileIniSection& AddSection(std::string_view name);
111
112 FileIniSection& GetSection(std::string_view key);
113
114 std::vector<std::string> GetAllSectionName();
115
116private:
117 std::vector<FileIniSectionNode> _allSection;
118 std::unordered_map<std::string, FileIniSection> _mapSection;
119 FileIniSection _secNull;
120};
121
122
123}
ini文件解析
std::vector< std::string > GetAllSectionName()
bool Save(std::string_view path_name)
FileIniSection & AddSection(std::string_view name)
bool DelSection(std::string_view key)
FileIniSection & GetSection(std::string_view key)
friend class FileIniSection
bool Open(std::string_view path_name)
bool Del(std::string_view key)
删除键值对
void Set(std::string_view key, std::string_view value)
设置键值对
std::string Get(std::string_view key)
获取键值对
void Add(std::string_view key, std::string_view value)
添加键值对
bool Change(std::string_view key, std::string_view value)
bool Add(std::string_view key, std::string_view value)
存在则失败
bool Set(std::string_view key, std::string_view value)
覆盖
bool Del(std::string_view key)
bool Get(std::string_view key, FileIniLine &ret)
bool Change(std::string_view key, std::string_view value)
字符串相关