提交 06fa8cf7 编写于 作者: L longdafeng 提交者: Longda

Format all code by the OceanBase Clang-Format pattern file.

上级 ad4a1c38
...@@ -27,22 +27,23 @@ namespace common { ...@@ -27,22 +27,23 @@ namespace common {
const std::string Ini::DEFAULT_SECTION = std::string(""); const std::string Ini::DEFAULT_SECTION = std::string("");
const std::map<std::string, std::string> Ini::empty_map_; const std::map<std::string, std::string> Ini::empty_map_;
Ini::Ini() {} Ini::Ini()
{}
Ini::~Ini() {} Ini::~Ini()
{}
void Ini::insert_session(const std::string &session_name) { void Ini::insert_session(const std::string &session_name)
{
std::map<std::string, std::string> session_map; std::map<std::string, std::string> session_map;
std::pair < std::string, std::map < std::string, std::string >> entry = std::pair<std::string, std::map<std::string, std::string>> entry =
std::pair < std::string, std::map < std::string, std::string std::pair<std::string, std::map<std::string, std::string>>(session_name, session_map);
>> (session_name,
session_map);
sections_.insert(entry); sections_.insert(entry);
} }
std::map<std::string, std::string> *Ini::switch_session( std::map<std::string, std::string> *Ini::switch_session(const std::string &session_name)
const std::string &session_name) { {
SessionsMap::iterator it = sections_.find(session_name); SessionsMap::iterator it = sections_.find(session_name);
if (it != sections_.end()) { if (it != sections_.end()) {
return &it->second; return &it->second;
...@@ -59,8 +60,8 @@ std::map<std::string, std::string> *Ini::switch_session( ...@@ -59,8 +60,8 @@ std::map<std::string, std::string> *Ini::switch_session(
return nullptr; return nullptr;
} }
const std::map<std::string, std::string> &Ini::get( const std::map<std::string, std::string> &Ini::get(const std::string &section)
const std::string &section) { {
SessionsMap::iterator it = sections_.find(section); SessionsMap::iterator it = sections_.find(section);
if (it == sections_.end()) { if (it == sections_.end()) {
return empty_map_; return empty_map_;
...@@ -69,8 +70,8 @@ const std::map<std::string, std::string> &Ini::get( ...@@ -69,8 +70,8 @@ const std::map<std::string, std::string> &Ini::get(
return it->second; return it->second;
} }
std::string Ini::get(const std::string &key, const std::string &defaultValue, std::string Ini::get(const std::string &key, const std::string &defaultValue, const std::string &section)
const std::string &section) { {
std::map<std::string, std::string> section_map = get(section); std::map<std::string, std::string> section_map = get(section);
std::map<std::string, std::string>::iterator it = section_map.find(key); std::map<std::string, std::string>::iterator it = section_map.find(key);
...@@ -81,8 +82,8 @@ std::string Ini::get(const std::string &key, const std::string &defaultValue, ...@@ -81,8 +82,8 @@ std::string Ini::get(const std::string &key, const std::string &defaultValue,
return it->second; return it->second;
} }
int Ini::put(const std::string &key, const std::string &value, int Ini::put(const std::string &key, const std::string &value, const std::string &section)
const std::string &section) { {
std::map<std::string, std::string> *section_map = switch_session(section); std::map<std::string, std::string> *section_map = switch_session(section);
section_map->insert(std::pair<std::string, std::string>(key, value)); section_map->insert(std::pair<std::string, std::string>(key, value));
...@@ -90,17 +91,15 @@ int Ini::put(const std::string &key, const std::string &value, ...@@ -90,17 +91,15 @@ int Ini::put(const std::string &key, const std::string &value,
return 0; return 0;
} }
int Ini::insert_entry(std::map<std::string, std::string> *session_map, int Ini::insert_entry(std::map<std::string, std::string> *session_map, const std::string &line)
const std::string &line) { {
if (session_map == nullptr) { if (session_map == nullptr) {
std::cerr << __FILE__ << __FUNCTION__ << " session map is null" std::cerr << __FILE__ << __FUNCTION__ << " session map is null" << std::endl;
<< std::endl;
return -1; return -1;
} }
size_t equal_pos = line.find_first_of('='); size_t equal_pos = line.find_first_of('=');
if (equal_pos == std::string::npos) { if (equal_pos == std::string::npos) {
std::cerr << __FILE__ << __FUNCTION__ << "Invalid configuration line " std::cerr << __FILE__ << __FUNCTION__ << "Invalid configuration line " << line << std::endl;
<< line << std::endl;
return -1; return -1;
} }
...@@ -115,15 +114,15 @@ int Ini::insert_entry(std::map<std::string, std::string> *session_map, ...@@ -115,15 +114,15 @@ int Ini::insert_entry(std::map<std::string, std::string> *session_map,
return 0; return 0;
} }
int Ini::load(const std::string &file_name) { int Ini::load(const std::string &file_name)
{
std::ifstream ifs; std::ifstream ifs;
try { try {
bool continue_last_line = false; bool continue_last_line = false;
std::map<std::string, std::string> *current_session = std::map<std::string, std::string> *current_session = switch_session(DEFAULT_SECTION);
switch_session(DEFAULT_SECTION);
char line[MAX_CFG_LINE_LEN]; char line[MAX_CFG_LINE_LEN];
...@@ -148,8 +147,7 @@ int Ini::load(const std::string &file_name) { ...@@ -148,8 +147,7 @@ int Ini::load(const std::string &file_name) {
continue; continue;
} }
if (read_buf[0] == CFG_SESSION_START_TAG && if (read_buf[0] == CFG_SESSION_START_TAG && read_buf[strlen(read_buf) - 1] == CFG_SESSION_END_TAG) {
read_buf[strlen(read_buf) - 1] == CFG_SESSION_END_TAG) {
read_buf[strlen(read_buf) - 1] = '\0'; read_buf[strlen(read_buf) - 1] = '\0';
std::string session_name = std::string(read_buf + 1); std::string session_name = std::string(read_buf + 1);
...@@ -171,7 +169,7 @@ int Ini::load(const std::string &file_name) { ...@@ -171,7 +169,7 @@ int Ini::load(const std::string &file_name) {
continue_last_line = true; continue_last_line = true;
// remove the last character // remove the last character
line_entry = line_entry.substr(0, line_entry.size() -1); line_entry = line_entry.substr(0, line_entry.size() - 1);
continue; continue;
} else { } else {
continue_last_line = false; continue_last_line = false;
...@@ -186,21 +184,20 @@ int Ini::load(const std::string &file_name) { ...@@ -186,21 +184,20 @@ int Ini::load(const std::string &file_name) {
if (ifs.is_open()) { if (ifs.is_open()) {
ifs.close(); ifs.close();
} }
std::cerr << "Failed to load " << file_name << SYS_OUTPUT_ERROR std::cerr << "Failed to load " << file_name << SYS_OUTPUT_ERROR << std::endl;
<< std::endl;
return -1; return -1;
} }
return 0; return 0;
} }
void Ini::to_string(std::string &output_str) { void Ini::to_string(std::string &output_str)
{
output_str.clear(); output_str.clear();
output_str += "Begin dump configuration\n"; output_str += "Begin dump configuration\n";
for (SessionsMap::iterator it = sections_.begin(); it != sections_.end(); for (SessionsMap::iterator it = sections_.begin(); it != sections_.end(); it++) {
it++) {
output_str += CFG_SESSION_START_TAG; output_str += CFG_SESSION_START_TAG;
output_str += it->first; output_str += it->first;
output_str += CFG_SESSION_END_TAG; output_str += CFG_SESSION_END_TAG;
...@@ -208,9 +205,8 @@ void Ini::to_string(std::string &output_str) { ...@@ -208,9 +205,8 @@ void Ini::to_string(std::string &output_str) {
std::map<std::string, std::string> &section_map = it->second; std::map<std::string, std::string> &section_map = it->second;
for (std::map<std::string, std::string>::iterator sub_it = for (std::map<std::string, std::string>::iterator sub_it = section_map.begin(); sub_it != section_map.end();
section_map.begin(); sub_it++) {
sub_it != section_map.end(); sub_it++) {
output_str += sub_it->first; output_str += sub_it->first;
output_str += "="; output_str += "=";
output_str += sub_it->second; output_str += sub_it->second;
...@@ -225,9 +221,10 @@ void Ini::to_string(std::string &output_str) { ...@@ -225,9 +221,10 @@ void Ini::to_string(std::string &output_str) {
} }
//! Accessor function which wraps global properties object //! Accessor function which wraps global properties object
Ini *&get_properties() { Ini *&get_properties()
{
static Ini *properties = new Ini(); static Ini *properties = new Ini();
return properties; return properties;
} }
} //namespace common } // namespace common
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册