46 return (stat(name.c_str(), &buffer) == 0);
49 std::map<std::string, std::string>
parseJSONFile(std::string JSONFileName)
52 std::ifstream infile(JSONFileName.c_str());
53 assert(infile.good());
56 std::string entireStr;
57 while (std::getline(infile,
line))
59 if (
line.find(
"//") == std::string::npos)
62 entireStr +=
line.substr(0,
line.find(
"//"));
65 std::map<std::string, std::string> res;
68 entireStr = std::string(entireStr.begin() + 1, entireStr.end() - 1);
69 std::vector<std::string> jsonBlocks;
70 strSplit(entireStr, jsonBlocks,
",");
72 for (
auto jsonBlock : jsonBlocks)
74 if (jsonBlock.find(
":") == std::string::npos)
76 if (jsonBlock.find(
"\"") == std::string::npos)
79 int quote1Loc = jsonBlock.find(
"\"");
80 int quote2Loc = jsonBlock.find(
"\"", quote1Loc + 1);
81 int quote3Loc = jsonBlock.find(
"\"", quote2Loc + 1);
82 int quote4Loc = jsonBlock.find(
"\"", quote3Loc + 1);
84 assert(quote1Loc >= 0 && quote2Loc >= 0 && quote3Loc >= 0 && quote4Loc >= 0 &&
85 "the json file has some syntax error");
87 res[jsonBlock.substr(quote1Loc + 1, quote2Loc - quote1Loc - 1)] =
88 jsonBlock.substr(quote3Loc + 1, quote4Loc - quote3Loc - 1);
91 if (res.find(
"dumpDirectory") == res.end())
93 res[
"dumpDirectory"] =
"./";
97 res[
"dumpDirectory"] +=
"/";
100 std::map<std::string, std::string>::iterator it;
101 for (it = res.begin(); it != res.end(); it++)
103 if (it->first ==
"dumpDirectory")
105 if (it->first.find(
"dump") != std::string::npos || it->first.find(
"Dump") != std::string::npos)
107 res[it->first] = res[
"dumpDirectory"] +
"/" + it->second;
111 print_warning(
"Placer configuration is loaded and the information is shown below, please check:");
113 for (
auto pair : res)
115 std::cout <<
" \"" << pair.first <<
"\" ==== \"" << pair.second <<
"\"\n";