#include "stdafx.h" #include "YamlConfig.h" YamlConfig::YamlConfig() { ReadConfig(); } YamlConfig::~YamlConfig() { } YamlConfig YamlConfig::sp; bool YamlConfig::ReadConfig() { try { CTime tm; tm = CTime::GetCurrentTime(); CString curDay = tm.Format("%Y-%m-%d "); string day = curDay.GetString(); YAML::Node config = YAML::LoadFile(YAMLCONFIGFILEPATH); for (YAML::const_iterator it = config["TIMES"].begin(); it != config["TIMES"].end(); ++it) { cout << it->first.as() << "--:--" << it->second.as() << endl; m_Times[it->first.as()] = it->second.as(); } this->isUsed = config["ISUSED"].as(); this->isResetFreeTime = config["ISRESETFREETIME"].as(); } catch (const std::exception& e) { cout << e.what() << endl; YAML::Node config; config["ISUSED"] = false; config["TIMES"]["08:00"] = "17:00"; config["ISRESETFREETIME"] = false; ofstream outfile(YAMLCONFIGFILEPATH); outfile << config; outfile.close(); for (YAML::const_iterator it = config["TIMES"].begin(); it != config["TIMES"].end(); ++it) { cout << it->first.as() << "--:--" << it->second.as() << endl; m_Times[it->first.as()] = it->second.as(); } this->isUsed = config["ISUSED"].as(); this->isResetFreeTime = config["ISRESETFREETIME"].as(); return false; } cout << "---mapsize:" << m_Times.size() << endl; return true; } //CTime startTime, endTime; //startTime = timestr((day + it->first.as()).c_str()); //endTime = timestr((day + it->first.as()).c_str()); //if (startTime > endTime) //{ // endTime = timestr((day + it->first.as()).c_str(), 1); //} //m_Times[&startTime] = &endTime;