20 JsonParam JsonConfig::s_nullParam;
37 : _label (copy._label),
42 _allowedValues (copy._allowedValues)
56 memcpy(
_value, value,
sizeof(
bool));
60 memcpy(
_value, value,
sizeof(
int));
64 memcpy(
_value, value,
sizeof(
unsigned int));
68 memcpy(
_value, value,
sizeof(
double));
71 _value =
new string(*(
string*)(value));
74 _value =
new vector<double>(*(vector<double>*)(value));
102 ((vector<double>*)
_value)->clear();
103 delete (vector<double>*)
_value;
115 _name = paramNode[
"name"].asString();
116 _label = paramNode[
"label"].asString();
117 _descr = paramNode[
"descr"].asString();
118 Json::Value value = paramNode[
"value"];
119 Json::Value allowedValues = paramNode[
"allowedValues"];
127 if (ptype ==
"VECTOR")
133 int n = value.size();
134 for (
unsigned int j=0; j<
n; ++j)
135 v.push_back(value[j].asDouble());
149 bool v = value.asBool();
152 else if (ptype ==
"UINT")
155 unsigned int v = value.asUInt();
158 else if (ptype ==
"INT")
161 int v = value.asInt();
164 else if (ptype ==
"FLOAT")
167 double v = value.asDouble();
170 else if (ptype ==
"STRING")
173 string v = value.asString();
175 if (!allowedValues.empty() && allowedValues.isArray())
177 for (
const auto &allowedValue : allowedValues)
186 "but should check the JsonConfig JSON for parameter <"<<
_name<<
">."<<endl;
194 vector<double>& v = *(vector<double>*)
_value;
208 paramNode[
"type"] =
"bool";
210 paramNode[
"value"] = b;
214 paramNode[
"type"] =
"int";
216 paramNode[
"value"] = i;
220 paramNode[
"type"] =
"uint";
222 paramNode[
"value"] =
n;
226 paramNode[
"type"] =
"float";
228 paramNode[
"value"] = f;
232 paramNode[
"type"] =
"string";
234 paramNode[
"value"] = s;
237 Json::Value allowedValues(Json::arrayValue);
239 allowedValues.append(allowedValue.c_str());
240 paramNode[
"allowedValues"] = allowedValues;
245 paramNode[
"type"] =
"vector";
247 for (
unsigned int j=0; j<
n; ++j)
248 paramNode[
"value"][j] = v[j];
267 return *(
unsigned int*)
_value;
296 v = *(vector<double>*)
_value;
301 Json::Value jsonNode;
303 out << jsonNode << endl;
321 preferencesKWL().findKey( std::string(
"ossim_share_directory" )));
322 if (!shareName.
isDir())
323 throw ossimException(
"Nonexistent share drive provided for config files.");
327 if (!shareDir.
open(shareName))
328 throw ossimException(
"Share drive provided for config files is not readable.");
329 std::vector<ossimFilename> jsonFiles;
333 for (
unsigned int i=0; i<jsonFiles.size(); i++)
335 configFilename = jsonFiles[i];
336 if (!
open(configFilename))
344 "config file at <"<< configFilename <<
">. Error: "<<e.
what()<<endl;
350 if (!
open(configFile))
362 if (configFile.fail())
364 Json::Value jsonRoot;
365 configFile >> jsonRoot;
366 if (jsonRoot.empty())
368 if (jsonRoot.isMember(
"parameters"))
370 Json::Value& paramsNode = jsonRoot[
"parameters"];
379 map<string, JsonParam>::iterator i =
m_paramsMap.find(
string(paramName));
389 std::map<std::string, JsonParam>::iterator iter =
m_paramsMap.find(key);
406 if (json_node.isArray())
409 for (
const auto &i : json_node)
419 Json::Value::Members members = json_node.getMemberNames();
420 for (
auto &member : members)
426 "nonexistent parameter <"<< member <<
">. Ignoring request."<<endl;
432 <<
" "<<p.
descr()<<endl;
438 Json::Value paramNode;
440 paramNode[
"value"] = json_node[p.
name().
string()];
450 map<string, JsonParam>::const_iterator param =
m_paramsMap.begin();
454 Json::Value paramNode;
455 param->second.saveJSON(paramNode);
456 json_node[entry++] = paramNode;
463 map<string, JsonParam>::const_iterator i =
m_paramsMap.find(
string(
"diagnosticLevel"));
466 unsigned int levelSetting = i->second.asUint();
467 return (level <= levelSetting);
474 Json::Value configJsonNode;
476 out<<configJsonNode<<endl;
JsonParam & getParameter(const char *paramName)
Returns a parameter (might be a null parameter if paramName not found in the configuration.
const ossimString & descr() const
static ossimString upcase(const ossimString &aString)
void setValue(void *value)
JsonConfig()
Default Ctor loads all default .json files in the share/ossim system dir.
std::basic_ifstream< char > ifstream
Class for char input file streams.
double nan()
Method to return ieee floating point double precision NAN.
This code was derived from https://gist.github.com/mshockwave.
Base class for maintaining parameters affecting the runtime configuration of OSSIM executables...
bool contains(char aChar) const
unsigned int asUint() const
void asVector(std::vector< double > &v) const
std::vector< ossimString > _allowedValues
void findAllFilesThatMatch(std::vector< ossimFilename > &result, const ossimString ®ularExpressionPattern, int flags=OSSIM_DIR_DEFAULT)
bool paramExists(const char *paramName) const
virtual void saveJSON(Json::Value ¶ms_json_node) const
Reads the params controlling the process from the JSON node named "parameters".
std::map< std::string, JsonParam > m_paramsMap
std::string asString() const
Represents a single configuration parameter.
void saveJSON(Json::Value &json_node) const
virtual const char * what() const
Returns the error message.
os2<< "> n<< " > nendobj n
const ossimString & name() const
bool open(const ossimFilename &configFile)
Opens and parses JSON file. The "parameters" keyword is expected in the root node.
static ossimPreferences * instance()
bool diagnosticLevel(unsigned int level) const
Convenience method returns TRUE if the currently set diagnostic level is <= level.
bool open(const ossimFilename &dir)
bool loadJSON(const Json::Value &json_node)
Initializes from a JSON node.
ostream & operator<<(std::ostream &out, const JsonParam &obj)
void setParameter(const JsonParam &p)
Adds parameter to the configuration.
virtual void loadJSON(const Json::Value ¶ms_json_node)
Reads the params controlling the process from the JSON node named "parameters".
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
virtual ~JsonConfig()
Destructor.
const std::string & string() const
static JsonParam s_nullParam