mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-04-01 03:00:13 -04:00
getting/setting configuration values from python works
Signed-off-by: Ian Bell <ian.h.bell@gmail.com>
This commit is contained in:
@@ -161,7 +161,7 @@ class Configuration
|
||||
/// Return the value of a boolean key from the configuration
|
||||
bool get_config_bool(configuration_keys key);
|
||||
double get_config_double(configuration_keys key);
|
||||
rapidjson::Document get_config_as_json();
|
||||
void get_config_as_json(rapidjson::Document &doc);
|
||||
/// Get values in the configuration based as json data in string format
|
||||
std::string get_config_as_json_string();
|
||||
|
||||
@@ -173,7 +173,7 @@ void set_config_bool(configuration_keys key, bool val);
|
||||
void set_config_double(configuration_keys key, double val);
|
||||
void set_config_string(configuration_keys key, std::string val);
|
||||
/// Set values in the configuration based on a json file
|
||||
void set_config_json(rapidjson::Document & doc);
|
||||
void set_config_json(rapidjson::Document &doc);
|
||||
void set_config_as_json_string(std::string &s);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ std::string config_key_to_string(configuration_keys keys)
|
||||
}
|
||||
// Back to a warning again
|
||||
#pragma GCC diagnostic warning "-Wswitch"
|
||||
throw ValueError();
|
||||
throw ValueError();// will never get here, just to make compiler happy
|
||||
};
|
||||
|
||||
/// Go from string to enum key
|
||||
@@ -44,21 +44,17 @@ double get_config_double(configuration_keys key){
|
||||
std::string get_config_string(configuration_keys key){
|
||||
return static_cast<std::string>(config.get_item(key));
|
||||
}
|
||||
rapidjson::Document get_config_as_json(){
|
||||
// Init the rapidjson doc
|
||||
rapidjson::Document doc;
|
||||
doc.SetObject();
|
||||
|
||||
void get_config_as_json(rapidjson::Document &doc){
|
||||
// Get the items
|
||||
std::map<configuration_keys, ConfigurationItem> items = config.get_items();
|
||||
for (std::map<configuration_keys, ConfigurationItem>::iterator it = items.begin(); it != items.end(); ++it){
|
||||
it->second.add_to_json(doc, doc);
|
||||
}
|
||||
// Convert to string
|
||||
return doc;
|
||||
}
|
||||
std::string get_config_as_json_string(){
|
||||
rapidjson::Document doc = get_config_as_json();
|
||||
rapidjson::Document doc;
|
||||
doc.SetObject();
|
||||
get_config_as_json(doc);
|
||||
return cpjson::to_string(doc);
|
||||
}
|
||||
void set_config_as_json(rapidjson::Value &val){
|
||||
|
||||
@@ -18,6 +18,10 @@ cdef extern from "CoolPropTools.h" namespace "CoolProp":
|
||||
cdef extern from "Backends/Helmholtz/MixtureParameters.h" namespace "CoolProp":
|
||||
string _get_mixture_binary_pair_data "CoolProp::get_mixture_binary_pair_data"(const string CAS1, const string CAS2, const string key) except +
|
||||
|
||||
cdef extern from "Configuration.h" namespace "CoolProp":
|
||||
string _get_config_as_json_string "CoolProp::get_config_as_json_string"() except +
|
||||
void _set_config_as_json_string "CoolProp::set_config_as_json_string"(string) except +
|
||||
|
||||
cdef extern from "DataStructures.h" namespace "CoolProp":
|
||||
string _get_parameter_information "CoolProp::get_parameter_information"(int, string) except +
|
||||
int _get_parameter_index "CoolProp::get_parameter_index"(string) except +
|
||||
|
||||
@@ -117,6 +117,12 @@ def set_reference_state(string FluidName, *args):
|
||||
# else:
|
||||
# return val
|
||||
|
||||
cpdef string get_config_as_json_string():
|
||||
return _get_config_as_json_string()
|
||||
|
||||
cpdef set_config_as_json_string(string s):
|
||||
_set_config_as_json_string(s)
|
||||
|
||||
cpdef int get_parameter_index(string key):
|
||||
return _get_parameter_index(key)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user