Files
2024-12-04 17:15:04 +01:00

51 lines
2.1 KiB
C++
Executable File

#ifndef PARAMETER_H
#define PARAMETER_H
#include <array>
#include <string>
#include <vector>
#include "jansson.h"
#include "simulation/jansson_additionals.h"
// class to handle the json-parameter file and read it's data
class Parameter {
public:
Parameter(std::string filename);
~Parameter();
// read the value at the json path and return it as a double; defaults to 0.0
double doubleValue(const json_path& path) const;
// read the value at the json path and return it as a double; defaults to the default value
double doubleValue(const json_path& path, double default_value) const;
// read the value at the json path and return it as a int; defaults to 0
int intValue(const json_path& path) const;
// read the value at the json path and return it as a int; defaults to default value
int intValue(const json_path& path, int default_value) const;
// read the value at the json path and return it as a string; defaults to the empty string
std::string stringValue(const json_path& path) const;
// read the value at the json path and return it as a string; defaults to the default value
std::string stringValue(const json_path& path,
const std::string& default_value) const;
// read the value at the json path and return it as a string;
// the string "true" in the json file results in true, everything else in false
bool boolValue(const json_path& path) const;
// read the value at the json path and return it as a string;
// the string "true" in the json file results in true, everything else in the default value
bool boolValue(const json_path& path, bool default_value) const;
// check if "path" exists in the json-parameter file
bool pathExists(const json_path& path) const;
// return a pointer to the json_t object of the json-parameter_file
json_t* jsonFile() const;
// return a pointer to the json_t object of the group specified by "path"
json_t* jsonObjectFromBase(const json_path& path) const;
private:
json_error_t* j_error_;
json_t* j_file_;
json_t* openParameterFile(const std::string& filename) const;
};
#endif /* PARAMETER_H */