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

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

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