MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
ini.h
1/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
2miniob is licensed under Mulan PSL v2.
3You can use this software according to the terms and conditions of the Mulan PSL v2.
4You may obtain a copy of Mulan PSL v2 at:
5 http://license.coscl.org.cn/MulanPSL2
6THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9See the Mulan PSL v2 for more details. */
10
11//
12// Created by Longda on 2010
13//
14
15#if !defined(__COMMON_CONF_INI_H__)
16#define __COMMON_CONF_INI_H__
17
18#include <stdio.h>
19
20#include <iostream>
21
22#include "common/lang/map.h"
23#include "common/lang/set.h"
24#include "common/lang/string.h"
25
26namespace common {
27
28//********************************************************************
29// #means comments
30// Ini configuration format
31//[section]
32// VARNAME=VALUE
33
34class Ini
35{
36public:
41 Ini();
42 ~Ini();
43
49 int load(const string &ini_file);
50
55 const map<string, string> &get(const string &section = DEFAULT_SECTION);
56
62 string get(const string &key, const string &default_value, const string &section = DEFAULT_SECTION);
63
69 int put(const string &key, const string &value, const string &section = DEFAULT_SECTION);
70
74 void to_string(string &output_str);
75
76 static const string DEFAULT_SECTION;
77
78 // one line max length
79 static const int MAX_CFG_LINE_LEN = 1024;
80
81 // value split tag
82 static const char CFG_DELIMIT_TAG = ',';
83
84 // comments's tag
85 static const char CFG_COMMENT_TAG = '#';
86
87 // continue line tag
88 static const char CFG_CONTINUE_TAG = '\\';
89
90 // session name tag
91 static const char CFG_SESSION_START_TAG = '[';
92 static const char CFG_SESSION_END_TAG = ']';
93
94protected:
98 void insert_session(const string &session_name);
99
104 map<string, string> *switch_session(const string &session_name);
105
111 int insert_entry(map<string, string> *session_map, const string &line);
112
113 typedef map<string, map<string, string>> SessionsMap;
114
115private:
116 static const map<string, string> empty_map_;
117
118 set<string> file_names_;
119 SessionsMap sections_;
120};
121
125Ini *&get_properties();
126//********************************************************************
127
128} // namespace common
129#endif //__COMMON_CONF_INI_H__
Definition: ini.h:35
const map< string, string > & get(const string &section=DEFAULT_SECTION)
Definition: ini.cpp:63
int load(const string &ini_file)
Definition: ini.cpp:117
map< string, string > * switch_session(const string &session_name)
Definition: ini.cpp:45
int put(const string &key, const string &value, const string &section=DEFAULT_SECTION)
Definition: ini.cpp:85
Ini()
Definition: ini.cpp:33
void to_string(string &output_str)
Definition: ini.cpp:194
void insert_session(const string &session_name)
Definition: ini.cpp:37
int insert_entry(map< string, string > *session_map, const string &line)
Definition: ini.cpp:94