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
55{
56 friend class FileIni;
57public:
59private:
60 FileIniSection(FileIni* parent) :
61 _ini{ parent }
62 {}
63public:
71 void Set(std::string_view key, std::string_view value);
79 void Add(std::string_view key, std::string_view value);
80
81 bool Change(std::string_view key, std::string_view value);
86 bool Del(std::string_view key);
91 std::string Get(std::string_view key);
92private:
93 std::vector<size_t> _allSectionNode;
94 FileIni* _ini;
95};
96
98{
99 friend class FileIniSection;
100public:
102
103 bool Open(std::string_view path_name);
104
105 bool Save(std::string_view path_name);
106
107 bool DelSection(std::string_view key);
108
109 FileIniSection& AddSection(std::string_view name);
110
111 FileIniSection& GetSection(std::string_view key);
112
113 std::vector<std::string> GetAllSectionName();
114
115private:
116 std::vector<FileIniSectionNode> _allSection;
117 std::unordered_map<std::string, FileIniSection> _mapSection;
118 FileIniSection _secNull;
119};
120
121
122}
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)
字符串相关