| 173 | |
| 174 | |
| 175 | void DimBuilder::extractDim(NL::json& dim) |
| 176 | { |
| 177 | DimSpec d; |
| 178 | |
| 179 | // Get dimension name. |
| 180 | auto it = dim.find("name"); |
| 181 | if (it == dim.end()) |
| 182 | throw dimbuilder_error("Dimension missing name."); |
| 183 | NL::json name = *it; |
| 184 | if (!name.is_string()) |
| 185 | throw dimbuilder_error("Dimension name must be a string."); |
| 186 | d.m_name = name.get<std::string>(); |
| 187 | validateDimension(d.m_name); |
| 188 | dim.erase(it); |
| 189 | |
| 190 | if (dim.count("deprecated")) |
| 191 | { |
| 192 | if (!dim.at("deprecated").is_boolean()) |
| 193 | { |
| 194 | std::ostringstream oss; |
| 195 | oss << "Dimension '" << d.m_name << |
| 196 | "' deprecated field must be boolean if it exists."; |
| 197 | throw dimbuilder_error(oss.str()); |
| 198 | } |
| 199 | |
| 200 | d.m_deprecated = dim.at("deprecated").get<bool>(); |
| 201 | dim.erase("deprecated"); |
| 202 | } |
| 203 | |
| 204 | // Get dimension description. |
| 205 | it = dim.find("description"); |
| 206 | if (it == dim.end()) |
| 207 | { |
| 208 | std::ostringstream oss; |
| 209 | |
| 210 | oss << "Dimension '" << d.m_name << "' must have a description."; |
| 211 | throw dimbuilder_error(oss.str()); |
| 212 | } |
| 213 | NL::json description = *it; |
| 214 | if (!description.is_string()) |
| 215 | { |
| 216 | std::ostringstream oss; |
| 217 | |
| 218 | oss << "Description of dimension '" << d.m_name << "' must be a " |
| 219 | "string."; |
| 220 | throw dimbuilder_error(oss.str()); |
| 221 | } |
| 222 | d.m_description = description.get<std::string>(); |
| 223 | dim.erase(it); |
| 224 | |
| 225 | // Get dimension type |
| 226 | it = dim.find("type"); |
| 227 | if (it == dim.end()) |
| 228 | { |
| 229 | std::ostringstream oss; |
| 230 | |
| 231 | oss << "Dimension '" << d.m_name << "' must have a type."; |
| 232 | throw dimbuilder_error(oss.str()); |