| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #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<string>() << "--:--" << it->second.as<string>() << endl;
- m_Times[it->first.as<string>()] = it->second.as<string>();
- }
- this->isUsed = config["ISUSED"].as<bool>();
- this->isResetFreeTime = config["ISRESETFREETIME"].as<bool>();
- }
- 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<string>() << "--:--" << it->second.as<string>() << endl;
- m_Times[it->first.as<string>()] = it->second.as<string>();
- }
- this->isUsed = config["ISUSED"].as<bool>();
- this->isResetFreeTime = config["ISRESETFREETIME"].as<bool>();
- return false;
- }
- cout << "---mapsize:" << m_Times.size() << endl;
- return true;
- }
- //CTime startTime, endTime;
- //startTime = timestr((day + it->first.as<string>()).c_str());
- //endTime = timestr((day + it->first.as<string>()).c_str());
- //if (startTime > endTime)
- //{
- // endTime = timestr((day + it->first.as<string>()).c_str(), 1);
- //}
- //m_Times[&startTime] = &endTime;
|