#include "InfrastConfiger.h" #include #include #include #include "Logger.hpp" using namespace asst; bool InfrastConfiger::load(const std::string& filename) { DebugTraceFunction; DebugTrace("Configer::load | ", filename); InfrastConfiger temp; if (temp._load(filename)) { *this = std::move(temp); return true; } else { return false; } } bool InfrastConfiger::_load(const std::string& filename) { std::ifstream ifs(filename, std::ios::in); if (!ifs.is_open()) { return false; } std::stringstream iss; iss << ifs.rdbuf(); ifs.close(); std::string content(iss.str()); auto&& ret = json::parser::parse(content); if (!ret) { DebugTrace("parse error", content); return false; } json::value root = ret.value(); try { // ÖÆÔìÕ¾ for (json::value& comb_info : root["Manufacturing"]["combs"].as_array()) { std::vector comb_vec; for (json::value& oper_name : comb_info["comb"].as_array()) { std::string oper_name_str = oper_name.as_string(); comb_vec.emplace_back(std::move(oper_name_str)); } m_mfg_combs.emplace_back(std::move(comb_vec)); } m_mfg_end = root["Manufacturing"]["end"].as_string(); for (json::value& oper : root["Manufacturing"]["all"].as_array()) { m_mfg_opers.emplace(oper["name"].as_string()); } // óÒ×Õ¾ TODO¡­¡­ } catch (json::exception& e) { DebugTraceError("Load config json error!", e.what()); return false; } DebugTrace("Load config succeed"); return true; }