| 39 | |
| 40 | template <typename T> |
| 41 | void paramIO(const std::string& filename, YAML::Emitter& out, std::string key, T& value) { |
| 42 | int ucToInt = 0; |
| 43 | |
| 44 | if constexpr (!std::is_same_v<T, unsigned char>) { |
| 45 | if (saveFlag) { |
| 46 | out << YAML::BeginMap; |
| 47 | out << YAML::Key << key; |
| 48 | out << YAML::Value << value; |
| 49 | std::cout << "Parameter: " << key.c_str() << " | Value: " << value << std::endl; |
| 50 | out << YAML::EndMap; |
| 51 | } |
| 52 | } |
| 53 | else { |
| 54 | ucToInt = static_cast<int>(value); |
| 55 | if (saveFlag) { |
| 56 | out << YAML::BeginMap; |
| 57 | out << YAML::Key << key; |
| 58 | out << YAML::Value << ucToInt; |
| 59 | std::cout << "Parameter: " << key.c_str() << " | Value: " << ucToInt << std::endl; |
| 60 | out << YAML::EndMap; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | if (loadFlag && !saveFlag) { |
| 65 | std::ifstream inFile(filename, std::ios::in | std::ios::binary); |
| 66 | if (!inFile.is_open()) { |
| 67 | std::cerr << "Failed to open file for reading: " << filename << std::endl; |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | const std::string sepToken = "---PARTICLE BINARY DATA---"; |
| 72 | std::string line; |
| 73 | std::string yamlText; |
| 74 | bool sawSeparator = false; |
| 75 | |
| 76 | while (std::getline(inFile, line)) { |
| 77 | if (line.find(sepToken) != std::string::npos) { |
| 78 | sawSeparator = true; |
| 79 | break; |
| 80 | } |
| 81 | yamlText += line + "\n"; |
| 82 | } |
| 83 | |
| 84 | inFile.close(); |
| 85 | |
| 86 | try { |
| 87 | std::vector<YAML::Node> documents = YAML::LoadAll(yamlText); |
| 88 | bool found = false; |
| 89 | |
| 90 | for (const auto& doc : documents) { |
| 91 | if (!doc || !doc[key]) continue; |
| 92 | |
| 93 | if constexpr (!std::is_same_v<T, unsigned char>) { |
| 94 | value = doc[key].as<T>(); |
| 95 | std::cout << "Loaded " << key << ": " << value << std::endl; |
| 96 | } |
| 97 | else { |
| 98 | int tempInt = doc[key].as<int>(); |
nothing calls this directly
no outgoing calls
no test coverage detected