MCPcopy Create free account
hub / github.com/PDAL/PDAL / fromJsonFile

Method fromJsonFile

pdal/Options.cpp:198–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

196
197
198Options Options::fromJsonFile(const std::string& filename, const std::string& s)
199{
200 Options options;
201
202 NL::json node;
203 try
204 {
205 std::ifstream in(filename);
206 in >> node;
207 }
208 catch (NL::json::parse_error& err)
209 {
210 throw pdal_error("Unable to parse options file '" + filename +
211 "' as JSON: \n" + err.what());
212 }
213
214 for (auto& element : node.items())
215 {
216 const std::string& name = element.key();
217 const NL::json& n = element.value();
218
219 if (n.is_string())
220 options.add(name, n.get<std::string>());
221 else if (n.is_number_unsigned())
222 options.add(name, n.get<uint64_t>());
223 else if (n.is_number_integer())
224 options.add(name, n.get<int64_t>());
225 else if (n.is_number_float())
226 options.add(name, n.get<double>());
227 else if (n.is_boolean())
228 options.add(name, n.get<bool>());
229 else if (n.is_null())
230 options.add(name, "");
231 else if (n.is_array() || n.is_object())
232 options.add(name, n.get<std::string>());
233 else
234 throw pdal_error("Value of stage option '" +
235 name + "' in options file '" + filename +
236 "' cannot be converted.");
237 }
238 return options;
239}
240
241
242Options Options::fromCmdlineFile(const std::string& filename,

Callers

nothing calls this directly

Calls 5

itemsMethod · 0.80
whatMethod · 0.45
keyMethod · 0.45
valueMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected