mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-04-23 03:00:17 -04:00
* Bump revision on msgpack-c * Remove warnings when using Julia 0.4 realease Some change in Julia 0.4 have occurred since the last update of this wrapper. This update should now ensure better behaviour with Julia 0.4 which is now in release state. https://raw.githubusercontent.com/JuliaLang/julia/0ff703b40afddf9b705bd6a06d3a59cb4c089ea5/NEWS.md * Added PT flash for cubic EOS * Added PQ and QT inputs for pure fluids with cubic backend * Added derivation for relationship between saturation pressure and acentric factor * Fixed T_critical and p_critical for pure fluids with cubic backends * Bump revision for msgpack-c; everything should work now * Correct get_parameter_information_string, fixes #974 Put the catch in a more useful way and solves the call to CoolProp::get_parameter_information. * Relax convergence criterion for TS inputs; closes #956 * Update the updating of the TPD state class * Fix initial delta value in critical point search routine * Make CMake+Python integration work on OSX (finally) * Fix some bugs with cubics and critical point evaluation * Added conda builds again to please #905 and #956 * Added conda to the release cycle with directory cleaning. Should solve the problems discussed in #956, #905 and #707, but we have to wait for the next nightly build to see if it really works. Remember that the upload token on the server expires in June and uploads will fail silently. * Added cppformat as external library, see #952 and #907. Does https://github.com/CoolProp/CoolProp/blob/master/dev/codelite/coolprop.project need updating? * Add ability to get/set kij for cubics by overloading set/set_binary_interaction_double * Pull in the correct include path for linking with other applications (PDSim, etc.) * Don't package _JSON.h binary files when distributing CoolProp * Fixed the docker docs * Moved the binstar upload into a loop, if a single upload fails, we continue with the next one as mentioned in #905 * Update critical point evaluation routines and remove some double-calculations of critical matrices * Move search radii into the cpp file * Bump revision for Eigen to fix annoying warnings in MSVC9 2008 * Added info about Props1SI and other options to docs; closes #970 * Bump number of fluids * Update CoolProp.jl Other update due to `Julia 0.4` changes + added `CoolProp` functions * Just a minor fix of the docker docs * Also add the msgpack headers to CoolProp installation - more annoying than you would imagine... * Break up tools headers into pieces that make more sense, allowing for potentially smaller binaries and faster compilation * Fix some header issues * Update DBL_EPSILON * Fix _HUGE and accumulate errors * Add missing fstream include * One more try with header refactor * Add header to get thread_local for ftw * Added the cahced saturation densities to the keyed outputs for REFPROP and Helmholtz, see #977 * Add 'G' as alias for mass-based Gibbs energy * Eliminated some more warnings regarding missing return values * Fixed the white-space issues in the header files * Add IWYU integration to main module; see #983 * Fix order of getting/setting parameters * Fix order of parameter getting/setting for real this time * For REFPROP, get/set BIP for mixture with indices * Fix some edge cases in critical point calculation * Switch back to the PDF generator for the fitting reports * Massive improvements to stability of flash routines. Nitrogen now has 0 failures. * Added Syltherm800 for @adesideri * Fixes #990 Javascript works again. * Clarified the docs for #990 * Fix R123ze(E) reference; closes #992 * Some help with #986 * Added the generated cubic header to the ignore files * Add example showing how to get REFPROP version * Added two headers that might help with #995 * More sensible error message when using inappropriate version of REFPROP for phase envelope construction * Add comment about MinGW generator for Android build * Add example for calling DLL from C; closes #993 * Maybe this fixes multiple papers in the same category from #987 * Introducing limits for build logs to save disk space * Clean up Android docs * Kill min and max macros to close #995 * Bump REFPROP header file revision * Small updates to docs closes #996 closes #997 * Significant improvements to phase envelope construction Thanks to the critical point evaluation routines * Also add the configuration key * Refactor phase envelope packaging with msgpack to remove external msgpack-c include Also, don't package msgpack or rapidjson with CoolProp. Doesn't seem necessary now * Refine the phase envelopes in the liquid side based on difference in pressure Closes #998 * Allow ability to adjust the fineness of the refinement of the phase envelope from the high-level * Improvement in stability of refinement of phase envelopes * Cubics library should use all uppercase names for matching * Got QT inputs working for cubic mixtures Also implemented the explicit solution for p from Wilson * Progress with PQ inputs for cubics; some bugs remain still * Still not obvious why SRK PQ fails.... Updated tests for derivatives of fugacity_coefficient * Mostly a false alarm. Seems PQ works ok, not at very low pressure though * Implement 95% of the BIP setting/getting See #1000 * Fix journal abbreviations; closes #999 * Update mixtures setting/getting BIP docs * Where possible, remove include paths Can't do so for Eigen. closes #994 * Fix include for msgpack-c; see #994 * Fix path for IF97 in HumidAirProp.cpp * Move error string into solver class; see #985 * Add docs for explicit solution for p from T for Wilson K-factor relationship * Fix include paths for OSX; see #994 * First attempt at adding python 3.5 wheels; see #1002 * Upgrade cython as part of python build * Fix typo in coolprop cp 3.5 build in buildbot * Install cython into the appropriate environment this time * Fix order of initialization for solver wrapper class * Wrap all configuration variables into enumerations and a python module * Added docs for new config strings * Upgrade cython for sphinx builder * Fix configuration sample in docs * Fix constant in Chung method for estimation of e/k and sigma * Added the Python 3.5 docs for #1002 * Added Python 3.5 to the Linux slaves, this won't work until CoolProp/Dockerfiles#1 is resolved * Removed unused variables * Better deal with inputs for tabular backends that are two-phase * Fix stupid bug with tabular backends trying to evaluate pure_saturation tables when two-phase in first_partial_deriv * Rename cubics schema file * Cubics now are validated and new cubic fluids can be added Lots of changes: * Cubics are validated against schema * Schema can be returned as string * Added preliminary docs for cubics * Cubic fluids can be added programmatically * Add cair_sat to DLL/SO; closes #1005 * Add link to cubics page to main dos page * Actually commit the docs for the cubic EOS this time. * Fix Android docs formatting * Add Ar alias for Argon; closes #1007 * Once more addressing #979 thanks to @shrx . * I am constantly running out of disk space on the Windows machine. * Add chemical potential as abstract state method For example: ``` auto fluids = strsplit("Methane&Ethane", '&'); auto x = { 0.6,0.4 }; shared_ptr<CoolProp::AbstractState> RP(CoolProp::AbstractState::factory("HEOS", fluids)); RP->set_mole_fractions(x); RP->update(PT_INPUTS, 101325, 300); auto mu1 = RP->chemical_potential(0); RP.reset(CoolProp::AbstractState::factory("REFPROP", fluids)); RP->set_mole_fractions(x); RP->update(PT_INPUTS, 101325, 300); auto mu2 = RP->chemical_potential(0); ``` * Abbreviate JCT properly * Removed the cython upgrades to get more errors from the builders * Update references; closes #1011 * Give access to dalphar_ddelta_consttau and dalphar_ddtau_constdelta in high-level api; closes #1010 * Implement stability analysis based on TPD analysis; partly working * The Windows builder has been upgraded to 4 cores * Typo in master.cfg * It is more difficult than I though to have parallel builds * Add ability to use GERG in REFPROP; closes #923 * Give access to alphar in high-level API; closes #1012 * Add a few more spaces * And remove the condition on the additional spaces * Allow beta to be outside (0,1) in stability analysis in first SS part * Add REFPROP version output to the examples * Fix typo in use of GERG in docs * Secant behaves properly now when y1 approx. y2; closes #1015 * target_link_libraries * clear molar mass in clear function; closes #1021 * Fix docs for tangent_plane_distance; closes #1019 * Typo in TPD fix; see #1019 * Make the gas constant an adjustable parameter and update to CODATA 2014 value * Skip volume translation for cubics; closes #1018 * Fix typo in R_u update * Fix copying of kij in cubic backend get_copy function * Disable some optional checks in specialized low-level update functions * Finish stability calculations for critical point calculations! * Remove check of eigenvalues of L* matrix to determine stability (or not) * Add access to h_Ice, s_Ice, etc. through HAProps_Aux; closes #1017 * Add script to do mingw static library building for python; closes #1016 * Use cmake to build sphinx docs on OSX * Pad fluid string all the way to 10k characters * Run R example with Rscript rather than R * Fix call to Rscript * Add Rscript to CMake test as well * Update the Rscript calling stuff * Fix Rscript calling in example_generator.py * Fix typo in debugging printing for stability calcs * Add some info to the Help section * Describe how to make coolprop static library a clean cmake dependency; closes #1014 * Fix typo in CMake integration * Fix call to Rscript in CMakeLists.txt? * Another try with Rscript * Yet another try with R * Add new OSX slave for OSX 10.10+ * Try to fix the install path for OSX * python static library builds should be release builds * Another try with MATLAB on OSX 10.10 * Another attempt with MATLAB path * Allow MATLAB tests to be disabled * Add link to binaries for MATLAB for OSX 10.10; see #1013 * Add coefficients from JCED paper; closes #854 * Fix interaction parameters for new mixtures * Fix docs for new BIP from JCED paper * Fix REFPROP version for older version of REFPROP. * Add updated docs for cubics (WIP) * Small modifications to finish (?) critical point calculations * Small bug fixes * Guard against multiple definitions of "_CRT_SECURE_NO_WARNINGS" macro on Windows * More macro definitions * Refactor HMX.BNC path handling for REFPROP Closes #1028 See #1023 * Add pass-throughs for testing derivatives; closes #1030 * Fix(?) issues with loading multiple predefined mixtures in REFPROP; see #1023 * Fix failures for PQ at triple-point pressure; closes #1009 * Switch python 3.5 windows builds to use vc14 cmake compiler; see #1002 * Remove static library linkage when building pythonn 3.5 wheels; see #1002 * Updates to docs for cubics and VLE tolerances closes #1024 closes #1025 * Fixes STRING conflict between Mathcad library and cppformat The Mathcad library header, mcadincl.h, defines a STRING constant. This should be MC_STRING, as STRING is too dangerous and conflicts with STRING enumeration value in format.h from external/cppformat. * Move a lot of mixture derivatives to the new formulation; see #1032 * First attempt at fixing logo size in cloud theme. See #1029 * Another try at resizing logo for firefox; see #1029 * a quick fix that might work with #1029 * forgot the match the aspect ratio, see #1029 * Disabled the conda builds again, closes #1033 * Removed scipy references or changed them to be imported locally, fixes #1036 * Circumvent Cython issues from #1039, not sure this is a fix * Changed the string handling to tackle #979 * manylinux builds for 64-bit linux wheels are up-and-running Run the ./build_images.sh script, builds docker image, and uses docker image to build the linux wheels * Small logo instead of big one; see #1029 * Fixed #1040 thanks to the comments by @LORENZOTOCCI * Pushing the new viscosities to the JSON files, getting ready for an intermediate nightly release * Removed the conda builds from the docs, they are abandoned for now * Make the logo smaller * Disable the python linux builds in preparation of changeover to manylinux1 builds * More changes for manylinux * manylinux wheels fully working now * Copy cppformat to the appropriate location * Fix typo in OSX build flags * Fixed Minor MSVC Compiler Warnings (#1041) * Fixed Minor Warnings from MSVC Minor type mis-matches, etc. * Replace int(...) with static_cast<int>(...) * First attempt at #1044 * Fix PT inputs along critical isobar and critical isotherm; closes #1034 * Add REFPROP version to REFPROP comparison script; closes #1026 * Added a number of new predefined mixtures; see #719 * Tidy up sphinx docs; closes #1029 * Moved more mixture derivatives tests to use new format; see #1032 * Fixed typo in fugacity wrapper function; see #1032 * Add acentric factor for Air; closes #1001 * Fixed units in RP1485 validation tables * Disable image resizing Could be done by setting DPI in savefig * Copy PlatformDetermination.h into the top of CoolPropLib.h; see #946 * Try to resize the font a little bit in the sphinx output * Mathcad Wrapper Updates for CoolProp 5.x and 6 (#1047) Minor type mis-matches, etc. * Update CMakeLists.txt for both Mathcad Prime and Mathad 15 Copied original MATHCAD module and modified for a PRIME module and a MATHCAD15 module. * Updated Mathcad Wrapper for version 5 & 6 Changes to CoolPropMathad.cpp: * Uses PropsSI(), Props1SI(), and HAPropsSI() * One source for both Prime and Mathcad 15 * Replaced Mathcad error #defines with enumerated values * Replaced STRING const with MC_STRING enum * Uses LP* and LPC* types from MCADINCL.h instead of * const * Implemented get_global_param_string & get_fluid_param_string * Cleaned up comments GENERAL: * Removed batch files (they don't work anymore) * Updated README.rst in both directories with compile instruct. * Removed cpp file from Prime directory (no longer needed) * Removed MCADINCL headers (better to use from install directory) * Fixed Typo on Props1SI function name * Add function documentation XML file for Mathcad 15 Puts the functions in the Insert Function panel off the main menu of Mathcad * Modify Mathcad 15 README.rst * Update Prime README.rst * Update Prime README.rst (again) * Fixed CmakeLists path and updated README files. More robust CMake file and updated README info for clarity. * Fixed RST syntax in README * Update install commands for cmake, update doc index * Commit the RST files for MathCAD15 and Prime * Add MathCAD builders to buildbot * Finished conversion of derivatives to new formulation; closes #1032 * Fix MathCAD build? * Fix REFPROP comparison string * Another try at MathCAD buildbot * Add apply_simple_mixing_rule to AbstractState; fix bug with SatL and SatV and setting interaction parameters closes #1048 closes #1049 * One more go for MathCAD+buildbot * Touch the time-stamped file for expensive builds only after success * Yet another try with MathCAD * Align Tmax with REFPROP values (#1053) * Remove non-operative gitignore rule. This rule matches the /dev/fluids folder and all its contents, but those were already in the repo, so the rule is not in effect. * Align Tmax with REFPROP values. Fixes #257. I used the list given in #257. DME, C12, Neon, SF6 values went down. R11, R123, R152A had two occurences in EOS, I changed both. * Added "set_reference_state" wrapper for Mathcad and Updated Example Worksheets (#1056) - Added Mathcad wrapper for set_reference_stateS(), designated set_reference_state in Mathcad. - Added to the funcdoc interface (CoolProp_EN.xml) - Tidy up some formatting in the README files * Updated Mathcad 15 and Prime Example Sheets + PDFs of Each @ibell I know we don't like binaries in the rep, but I feel these are critical. They are updates to the Mathcad worksheets that were already there and PDF versions for anyone who doesn't have Mathcad (i.e. @ibell). The files are only about 250 KB each or 1MB total. I don't expect we'll need to add to them or add more. We might consider how to put these out with the DLL binaries as well. They are the only documentation on how to use the wrappers correctly. * Fixed CMakeList.txt confict and modified M15 worksheet from .xmcd to .xmcdz (compressed file type) * Install the smaller compressed worksheet for MathCAD 15; see #1056 * Add rho*sr scaling methodology for viscosity from Bell paper in Purdue conference closes #816 closes #665 * Add reference to Purdue paper * Prep for version 6 release * Added contributors
265 lines
12 KiB
C++
265 lines
12 KiB
C++
#ifndef COOLPROP_CONFIGURATION
|
|
#define COOLPROP_CONFIGURATION
|
|
|
|
#include "Exceptions.h"
|
|
#include "CoolPropTools.h"
|
|
|
|
#if !defined(SWIG) // Hide this for swig - Swig gets confused
|
|
#include "rapidjson_include.h"
|
|
#endif
|
|
|
|
/* See http://stackoverflow.com/a/148610
|
|
* See http://stackoverflow.com/questions/147267/easy-way-to-use-variables-of-enum-types-as-string-in-c#202511
|
|
* This will be used to generate an enum like:
|
|
* enum configuration_keys {NORMALIZE_GAS_CONSTANTS, CRITICAL_SPLINES_ENABLED};
|
|
*
|
|
* The values in this list are given by:
|
|
* enum, string representation of enum, default value, description
|
|
*
|
|
* The type of the default value specifies the only type that will be accepted for this parameter
|
|
*/
|
|
#define CONFIGURATION_KEYS_ENUM \
|
|
X(NORMALIZE_GAS_CONSTANTS, "NORMALIZE_GAS_CONSTANTS", true, "If true, for mixtures, the molar gas constant (R) will be set to the CODATA value") \
|
|
X(CRITICAL_WITHIN_1UK, "CRITICAL_WITHIN_1UK", true, "If true, any temperature within 1 uK of the critical temperature will be considered to be AT the critical point") \
|
|
X(CRITICAL_SPLINES_ENABLED, "CRITICAL_SPLINES_ENABLED", true, "If true, the critical splines will be used in the near-vicinity of the critical point") \
|
|
X(SAVE_RAW_TABLES, "SAVE_RAW_TABLES", false, "If true, the raw, uncompressed tables will also be written to file") \
|
|
X(ALTERNATIVE_TABLES_DIRECTORY, "ALTERNATIVE_TABLES_DIRECTORY", "", "If provided, this path will be the root directory for the tabular data. Otherwise, ${HOME}/.CoolProp/Tables is used") \
|
|
X(ALTERNATIVE_REFPROP_PATH, "ALTERNATIVE_REFPROP_PATH", "", "An alternative path to be provided to the directory that contains REFPROP's fluids and mixtures directories. If provided, the SETPATH function will be called with this directory prior to calling any REFPROP functions.") \
|
|
X(ALTERNATIVE_REFPROP_HMX_BNC_PATH, "ALTERNATIVE_REFPROP_HMX_BNC_PATH", "", "An alternative path to the HMX.BNC file. If provided, it will be passed into REFPROP's SETUP or SETMIX routines") \
|
|
X(REFPROP_DONT_ESTIMATE_INTERACTION_PARAMETERS, "REFPROP_DONT_ESTIMATE_INTERACTION_PARAMETERS", false, "If true, if the binary interaction parameters in REFPROP are estimated, throw an error rather than silently continuing") \
|
|
X(REFPROP_USE_GERG, "REFPROP_USE_GERG", false, "If true, rather than using the highly-accurate pure fluid equations of state, use the pure-fluid EOS from GERG-2008") \
|
|
X(MAXIMUM_TABLE_DIRECTORY_SIZE_IN_GB, "MAXIMUM_TABLE_DIRECTORY_SIZE_IN_GB", 1.0, "The maximum allowed size of the directory that is used to store tabular data") \
|
|
X(DONT_CHECK_PROPERTY_LIMITS, "DONT_CHECK_PROPERTY_LIMITS", false, "If true, when possible, CoolProp will skip checking whether values are inside the property limits") \
|
|
X(HENRYS_LAW_TO_GENERATE_VLE_GUESSES, "HENRYS_LAW_TO_GENERATE_VLE_GUESSES", false, "If true, when doing water-based mixture dewpoint calculations, use Henry's Law to generate guesses for liquid-phase composition") \
|
|
X(PHASE_ENVELOPE_STARTING_PRESSURE_PA, "PHASE_ENVELOPE_STARTING_PRESSURE_PA", 100.0, "Starting pressure [Pa] for phase envelope construction") \
|
|
X(R_U_CODATA, "R_U_CODATA", 8.3144598, "The value for the ideal gas constant in J/mol/K according to CODATA 2014. This value is used to harmonize all the ideal gas constants. This is especially important in the critical region.") \
|
|
|
|
// Use preprocessor to create the Enum
|
|
enum configuration_keys{
|
|
#define X(Enum, String, Default, Desc) Enum,
|
|
CONFIGURATION_KEYS_ENUM
|
|
#undef X
|
|
};
|
|
|
|
// Evidently SWIG+MATLAB cannot properly wrap enums within classes
|
|
enum ConfigurationDataTypes {
|
|
CONFIGURATION_NOT_DEFINED_TYPE = 0,
|
|
CONFIGURATION_BOOL_TYPE,
|
|
CONFIGURATION_DOUBLE_TYPE,
|
|
CONFIGURATION_INTEGER_TYPE,
|
|
CONFIGURATION_STRING_TYPE,
|
|
CONFIGURATION_ENDOFLIST_TYPE
|
|
};
|
|
|
|
namespace CoolProp
|
|
{
|
|
|
|
/// Convert the configuration key to a string in a 1-1 representation.
|
|
std::string config_key_to_string(configuration_keys keys);
|
|
|
|
/// Return a string description of the configuration key
|
|
std::string config_key_description(configuration_keys keys);
|
|
|
|
/// Return a string description of the configuration key (with the key passed as a string)
|
|
std::string config_key_description(std::string key);
|
|
|
|
/// A class that contains one entry in configuration
|
|
/// Can be cast to yield the output value
|
|
class ConfigurationItem
|
|
{
|
|
public:
|
|
|
|
/// Cast to boolean
|
|
operator bool() const { check_data_type(CONFIGURATION_BOOL_TYPE); return v_bool; };
|
|
/// Cast to double
|
|
operator double() const { check_data_type(CONFIGURATION_DOUBLE_TYPE); return v_double; };
|
|
/// Cast to string
|
|
operator std::string() const { check_data_type(CONFIGURATION_STRING_TYPE); return v_string; };
|
|
// Initializer for bool
|
|
ConfigurationItem(configuration_keys key, bool val){
|
|
this->key = key; type = CONFIGURATION_BOOL_TYPE; v_bool = val;
|
|
};
|
|
// Initializer for integer
|
|
ConfigurationItem(configuration_keys key, int val){
|
|
this->key = key; type = CONFIGURATION_INTEGER_TYPE; v_integer = val;
|
|
};
|
|
// Initializer for double
|
|
ConfigurationItem(configuration_keys key, double val){
|
|
this->key = key; type = CONFIGURATION_DOUBLE_TYPE; v_double = val;
|
|
};
|
|
// Initializer for const char *
|
|
ConfigurationItem(configuration_keys key, const char *val){
|
|
this->key = key; type = CONFIGURATION_STRING_TYPE; v_string = val;
|
|
};
|
|
// Initializer for string
|
|
ConfigurationItem(configuration_keys key, const std::string &val){
|
|
this->key = key; type = CONFIGURATION_STRING_TYPE; v_string = val;
|
|
};
|
|
void set_bool(bool val){
|
|
check_data_type(CONFIGURATION_BOOL_TYPE);
|
|
v_bool = val;
|
|
}
|
|
void set_integer(int val){
|
|
check_data_type(CONFIGURATION_INTEGER_TYPE);
|
|
v_integer = val;
|
|
}
|
|
void set_double(double val){
|
|
check_data_type(CONFIGURATION_DOUBLE_TYPE);
|
|
v_double = val;
|
|
}
|
|
void set_string(const std::string &val){
|
|
check_data_type(CONFIGURATION_STRING_TYPE);
|
|
v_string = val;
|
|
}
|
|
|
|
configuration_keys get_key(void) const {
|
|
return this->key;
|
|
}
|
|
#if !defined(SWIG)
|
|
/// Cast to rapidjson::Value
|
|
void add_to_json(rapidjson::Value &val, rapidjson::Document &d) const {
|
|
std::string name_string = config_key_to_string(key);
|
|
rapidjson::Value name(name_string.c_str(), d.GetAllocator());
|
|
switch (type){
|
|
case CONFIGURATION_BOOL_TYPE:
|
|
{
|
|
rapidjson::Value v(v_bool);
|
|
val.AddMember(name, v, d.GetAllocator()); break;
|
|
}
|
|
case CONFIGURATION_INTEGER_TYPE:
|
|
{
|
|
rapidjson::Value v(v_integer);
|
|
val.AddMember(name, v, d.GetAllocator()); break;
|
|
}
|
|
case CONFIGURATION_DOUBLE_TYPE:
|
|
{
|
|
rapidjson::Value v(v_double); // Try to upcast
|
|
val.AddMember(name, v, d.GetAllocator()); break;
|
|
}
|
|
case CONFIGURATION_STRING_TYPE:
|
|
{
|
|
rapidjson::Value v(v_string.c_str(), d.GetAllocator());
|
|
val.AddMember(name, v, d.GetAllocator()); break;
|
|
}
|
|
case CONFIGURATION_ENDOFLIST_TYPE:
|
|
case CONFIGURATION_NOT_DEFINED_TYPE:
|
|
throw ValueError();
|
|
}
|
|
}
|
|
void set_from_json(rapidjson::Value &val){
|
|
switch (type){
|
|
case CONFIGURATION_BOOL_TYPE: if (!val.IsBool()){throw ValueError(format("Input is not boolean"));}; v_bool = val.GetBool(); break;
|
|
case CONFIGURATION_INTEGER_TYPE: if (!val.IsInt()){throw ValueError(format("Input is not integer"));}; v_integer = val.GetInt(); break;
|
|
case CONFIGURATION_DOUBLE_TYPE: {
|
|
if (!val.IsDouble() && !val.IsInt()){throw ValueError(format("Input [%s] is not double (or something that can be cast to double)",cpjson::to_string(val).c_str()));};
|
|
if (val.IsDouble()){ v_double = val.GetDouble(); }
|
|
else{ v_double = static_cast<double>(val.GetInt()); }
|
|
break;
|
|
}
|
|
case CONFIGURATION_STRING_TYPE: if (!val.IsString()){throw ValueError(format("Input is not string"));}; v_string = val.GetString(); break;
|
|
case CONFIGURATION_ENDOFLIST_TYPE:
|
|
case CONFIGURATION_NOT_DEFINED_TYPE:
|
|
throw ValueError();
|
|
}
|
|
}
|
|
#endif // !defined(SWIG)
|
|
|
|
private:
|
|
void check_data_type(ConfigurationDataTypes type) const {
|
|
if (type != this->type){
|
|
throw ValueError(format("type does not match"));
|
|
}
|
|
};
|
|
ConfigurationDataTypes type;
|
|
union {
|
|
double v_double;
|
|
bool v_bool;
|
|
int v_integer;
|
|
|
|
};
|
|
std::string v_string;
|
|
configuration_keys key;
|
|
};
|
|
|
|
class Configuration
|
|
{
|
|
protected:
|
|
std::map<configuration_keys,ConfigurationItem> items;
|
|
|
|
public:
|
|
Configuration(){set_defaults();};
|
|
~Configuration(){};
|
|
|
|
/// Get an item from the configuration
|
|
ConfigurationItem &get_item(configuration_keys key){
|
|
// Try to find it
|
|
std::map<configuration_keys,ConfigurationItem>::iterator it = items.find(key);
|
|
// If equal to end, not found
|
|
if (it != items.end()){
|
|
// Found, return it
|
|
return it->second;
|
|
}
|
|
else{
|
|
throw ValueError(format("invalid item"));
|
|
}
|
|
}
|
|
/// Add an item to the configuration
|
|
void add_item(ConfigurationItem item)
|
|
{
|
|
std::pair<configuration_keys, ConfigurationItem> pair(item.get_key(), item);
|
|
items.insert(pair);
|
|
};
|
|
|
|
/// Return a reference to all of the items
|
|
std::map<configuration_keys, ConfigurationItem> & get_items(void){return items;};
|
|
|
|
/// Set the default values in the configuration
|
|
void set_defaults(void)
|
|
{
|
|
/* ***MAGIC WARNING**!!
|
|
* See http://stackoverflow.com/a/148610
|
|
* See http://stackoverflow.com/questions/147267/easy-way-to-use-variables-of-enum-types-as-string-in-c#202511
|
|
*/
|
|
#define X(Enum, String, Default, Desc) \
|
|
add_item(ConfigurationItem(Enum, Default));
|
|
CONFIGURATION_KEYS_ENUM
|
|
#undef X
|
|
};
|
|
};
|
|
|
|
/// *********************************************************
|
|
/// GETTERS
|
|
/// *********************************************************
|
|
|
|
/// Return the value of a boolean key from the configuration
|
|
bool get_config_bool(configuration_keys key);
|
|
/// Return the value of a double configuration key
|
|
double get_config_double(configuration_keys key);
|
|
/// Return the value of a string configuration key
|
|
std::string get_config_string(configuration_keys key);
|
|
#if !defined(SWIG) // Hide this for swig - Swig gets confused
|
|
void get_config_as_json(rapidjson::Document &doc);
|
|
#endif
|
|
/// Get all the values in the configuration as a json-formatted string
|
|
std::string get_config_as_json_string();
|
|
|
|
/// *********************************************************
|
|
/// SETTERS
|
|
/// *********************************************************
|
|
|
|
/// Set the value of a boolean configuration value
|
|
void set_config_bool(configuration_keys key, bool val);
|
|
/// Set the value of a double configuration value
|
|
void set_config_double(configuration_keys key, double val);
|
|
/// Set the value of a string configuration value
|
|
void set_config_string(configuration_keys key, const std::string &val);
|
|
/// Set values in the configuration based on a json file
|
|
#if !defined(SWIG) // Hide this for swig - Swig gets confused
|
|
void set_config_json(rapidjson::Document &doc);
|
|
#endif
|
|
/// Set the entire configuration based on a json-formatted string
|
|
void set_config_as_json_string(const std::string &s);
|
|
}
|
|
|
|
#endif // COOLPROP_CONFIGURATION
|