多数据源中间件标准版1.0

YamlConfig.cpp 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "stdafx.h"
  2. #include "YamlConfig.h"
  3. YamlConfig::YamlConfig()
  4. {
  5. ReadConfig();
  6. }
  7. YamlConfig::~YamlConfig()
  8. {
  9. }
  10. YamlConfig YamlConfig::sp;
  11. bool YamlConfig::ReadConfig()
  12. {
  13. try
  14. {
  15. CTime tm;
  16. tm = CTime::GetCurrentTime();
  17. CString curDay = tm.Format("%Y-%m-%d ");
  18. string day = curDay.GetString();
  19. YAML::Node config = YAML::LoadFile(YAMLCONFIGFILEPATH);
  20. for (YAML::const_iterator it = config["TIMES"].begin(); it != config["TIMES"].end(); ++it)
  21. {
  22. cout << it->first.as<string>() << "--:--" << it->second.as<string>() << endl;
  23. m_Times[it->first.as<string>()] = it->second.as<string>();
  24. }
  25. this->isUsed = config["ISUSED"].as<bool>();
  26. this->isResetFreeTime = config["ISRESETFREETIME"].as<bool>();
  27. }
  28. catch (const std::exception& e)
  29. {
  30. cout << e.what() << endl;
  31. YAML::Node config;
  32. config["ISUSED"] = false;
  33. config["TIMES"]["08:00"] = "17:00";
  34. config["ISRESETFREETIME"] = false;
  35. ofstream outfile(YAMLCONFIGFILEPATH);
  36. outfile << config;
  37. outfile.close();
  38. for (YAML::const_iterator it = config["TIMES"].begin(); it != config["TIMES"].end(); ++it)
  39. {
  40. cout << it->first.as<string>() << "--:--" << it->second.as<string>() << endl;
  41. m_Times[it->first.as<string>()] = it->second.as<string>();
  42. }
  43. this->isUsed = config["ISUSED"].as<bool>();
  44. this->isResetFreeTime = config["ISRESETFREETIME"].as<bool>();
  45. return false;
  46. }
  47. cout << "---mapsize:" << m_Times.size() << endl;
  48. return true;
  49. }
  50. //CTime startTime, endTime;
  51. //startTime = timestr((day + it->first.as<string>()).c_str());
  52. //endTime = timestr((day + it->first.as<string>()).c_str());
  53. //if (startTime > endTime)
  54. //{
  55. // endTime = timestr((day + it->first.as<string>()).c_str(), 1);
  56. //}
  57. //m_Times[&startTime] = &endTime;