| 318 | } |
| 319 | |
| 320 | std::string Create(const std::string& source_config_path, |
| 321 | const char* target_type, |
| 322 | const std::string& suffix) { |
| 323 | const std::string content = ReadFile(source_config_path); |
| 324 | JSONDocument document; |
| 325 | document.Parse(content.c_str()); |
| 326 | if (document.HasParseError() || !document.IsObject()) { |
| 327 | throw InvalidFormat("Error parsing benchmark config JSON"); |
| 328 | } |
| 329 | |
| 330 | RewriteConfigToText(document, document.GetAllocator(), target_type); |
| 331 | RewriteSegmentationResourcesToAbsolute(document, document.GetAllocator(), |
| 332 | GetParentDirectory(source_config_path)); |
| 333 | |
| 334 | rapidjson::StringBuffer buffer; |
| 335 | rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); |
| 336 | document.Accept(writer); |
| 337 | |
| 338 | const std::string temp_path = BuildTempPath(source_config_path, suffix); |
| 339 | std::ofstream stream(temp_path.c_str(), std::ios::binary); |
| 340 | stream << buffer.GetString(); |
| 341 | stream.close(); |
| 342 | if (!stream) { |
| 343 | throw FileNotWritable(temp_path); |
| 344 | } |
| 345 | |
| 346 | paths_.push_back(temp_path); |
| 347 | return temp_path; |
| 348 | } |
| 349 | |
| 350 | private: |
| 351 | std::string BuildTempPath(const std::string& source_config_path, |
nothing calls this directly
no test coverage detected