| 119 | |
| 120 | |
| 121 | bool DimBuilder::execute() |
| 122 | { |
| 123 | std::ifstream in(m_input); |
| 124 | |
| 125 | if (!in) |
| 126 | throw dimbuilder_error("Can't open input file."); |
| 127 | |
| 128 | NL::json root; |
| 129 | try |
| 130 | { |
| 131 | in >> root; |
| 132 | } |
| 133 | catch (NL::json::parse_error& err) |
| 134 | { |
| 135 | throw dimbuilder_error(err.what()); |
| 136 | } |
| 137 | |
| 138 | NL::json dims; |
| 139 | auto it = root.find("dimensions"); |
| 140 | if (it != root.end()) |
| 141 | dims = *it; |
| 142 | if (root.size() != 1 || !dims.is_array()) |
| 143 | { |
| 144 | std::ostringstream oss; |
| 145 | |
| 146 | oss << "Root node must contain a single 'dimensions' array."; |
| 147 | throw dimbuilder_error(oss.str()); |
| 148 | } |
| 149 | for (auto& dim : dims) |
| 150 | { |
| 151 | if (!dim.is_object()) |
| 152 | { |
| 153 | std::ostringstream oss; |
| 154 | |
| 155 | oss << "Found a dimension that is not an object: " << |
| 156 | dim.get<std::string>(); |
| 157 | throw dimbuilder_error(oss.str()); |
| 158 | } |
| 159 | extractDim(dim); |
| 160 | } |
| 161 | |
| 162 | std::ofstream out(m_output); |
| 163 | if (!out) |
| 164 | { |
| 165 | std::ostringstream oss; |
| 166 | |
| 167 | oss << "Unable to open output file '" << m_output << "'."; |
| 168 | throw dimbuilder_error(oss.str()); |
| 169 | } |
| 170 | writeOutput(out); |
| 171 | return true; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | void DimBuilder::extractDim(NL::json& dim) |
no test coverage detected