Skip to content

Commit

Permalink
WIP: Exporting symbols needed by Cython
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Jan 24, 2023
1 parent 1bc0edb commit 8201853
Show file tree
Hide file tree
Showing 29 changed files with 365 additions and 343 deletions.
5 changes: 3 additions & 2 deletions ext/SConscript
Expand Up @@ -40,8 +40,9 @@ if not env['system_fmt']:
license_files["fmtlib"] = File("#ext/fmt/LICENSE.rst")
localenv = prep_default(env)
localenv.Prepend(CPPPATH=Dir('#ext/fmt/include'))
libraryTargets.extend(
localenv.SharedObject(multi_glob(localenv, 'fmt/src', 'cc')))
localenv.Append(CPPDEFINES={"FMT_EXPORT": None})
env['fmt_targets'] = localenv.SharedObject(multi_glob(localenv, 'fmt/src', 'cc'))
libraryTargets.extend(env['fmt_targets'])
for name in ('format.h', 'ostream.h', 'printf.h', 'core.h', 'format-inl.h'):
ext_copies.extend(
copyenv.Command("#include/cantera/ext/fmt/" + name,
Expand Down
113 changes: 59 additions & 54 deletions include/cantera/base/AnyMap.h
Expand Up @@ -33,7 +33,7 @@ namespace Cantera
//! objects.
class AnyBase {
public:
AnyBase();
CT_API AnyBase();
virtual ~AnyBase() {};

//! For values which are derived from an input file, set the line and column
Expand Down Expand Up @@ -84,19 +84,19 @@ class AnyMap;
class AnyValue : public AnyBase
{
public:
AnyValue();
~AnyValue();
AnyValue(AnyValue const& other);
AnyValue(AnyValue&& other);
AnyValue& operator=(AnyValue const& other);
AnyValue& operator=(AnyValue&& other);
CT_API AnyValue();
CT_API ~AnyValue();
CT_API AnyValue(AnyValue const& other);
CT_API AnyValue(AnyValue&& other);
CT_API AnyValue& operator=(AnyValue const& other);
CT_API AnyValue& operator=(AnyValue&& other);

bool operator==(const AnyValue& other) const;
bool operator!=(const AnyValue& other) const;
CT_API bool operator==(const AnyValue& other) const;
CT_API bool operator!=(const AnyValue& other) const;

//! If this AnyValue is an AnyMap, return the value stored in `key`.
AnyValue& operator[](const std::string& key);
const AnyValue& operator[](const std::string& key) const;
CT_API AnyValue& operator[](const std::string& key);
CT_API const AnyValue& operator[](const std::string& key) const;

//! Returns `true` if this AnyValue is an AnyMap and that map contains
//! a key with the given name.
Expand All @@ -120,27 +120,27 @@ class AnyValue : public AnyBase
const std::type_info& type() const;

//! Returns a string specifying the type of the held value.
std::string type_str() const;
CT_API std::string type_str() const;

//! Return boolean indicating whether AnyValue is empty.
bool empty() const;
CT_API bool empty() const;

//! Returns `true` if the held value is of the specified type.
template<class T>
bool is() const;

//! Returns `true` if the held value is a scalar type (such as `double`, `long
//! int`, `string`, or `bool`).
bool isScalar() const;
CT_API bool isScalar() const;

explicit AnyValue(const std::string& value);
explicit AnyValue(const char* value);
AnyValue& operator=(const std::string& value);
AnyValue& operator=(const char* value);
CT_API AnyValue& operator=(const std::string& value);
CT_API AnyValue& operator=(const char* value);
//! Return the held value, if it is a string
const std::string& asString() const;
bool operator==(const std::string& other) const;
bool operator!=(const std::string& other) const;
CT_API bool operator==(const std::string& other) const;
CT_API bool operator!=(const std::string& other) const;
friend bool operator==(const std::string& lhs, const AnyValue& rhs);
friend bool operator!=(const std::string& lhs, const AnyValue& rhs);

Expand Down Expand Up @@ -172,33 +172,33 @@ class AnyValue : public AnyBase
//! @} end group quantity conversions

explicit AnyValue(double value);
AnyValue& operator=(double value);
CT_API AnyValue& operator=(double value);
//! Return the held value as a `double`, if it is a `double` or a `long
//! int`.
double& asDouble();
const double& asDouble() const;
bool operator==(const double& other) const;
bool operator!=(const double& other) const;
CT_API bool operator==(const double& other) const;
CT_API bool operator!=(const double& other) const;
friend bool operator==(const double& lhs, const AnyValue& rhs);
friend bool operator!=(const double& lhs, const AnyValue& rhs);

explicit AnyValue(bool value);
AnyValue& operator=(bool value);
CT_API AnyValue& operator=(bool value);
//! Return the held value, if it is a `bool`.
bool& asBool();
const bool& asBool() const;

explicit AnyValue(long int value);
explicit AnyValue(int value);
AnyValue& operator=(long int value);
AnyValue& operator=(int value);
CT_API AnyValue& operator=(long int value);
CT_API AnyValue& operator=(int value);
//! Return the held value, if it is a `long int`.
long int& asInt();
const long int& asInt() const;
bool operator==(const long int& other) const;
bool operator!=(const long int& other) const;
bool operator==(const int& other) const;
bool operator!=(const int& other) const;
CT_API bool operator==(const long int& other) const;
CT_API bool operator!=(const long int& other) const;
CT_API bool operator==(const int& other) const;
CT_API bool operator!=(const int& other) const;
friend bool operator==(const long int& lhs, const AnyValue& rhs);
friend bool operator!=(const long int& lhs, const AnyValue& rhs);
friend bool operator==(const int& lhs, const AnyValue& rhs);
Expand All @@ -216,8 +216,8 @@ class AnyValue : public AnyBase
std::vector<T>& asVector(size_t nMin=npos, size_t nMax=npos);

explicit AnyValue(const AnyMap& value);
AnyValue& operator=(const AnyMap& value);
AnyValue& operator=(AnyMap&& value);
CT_API AnyValue& operator=(const AnyMap& value);
CT_API AnyValue& operator=(AnyMap&& value);

template<class T>
AnyValue& operator=(const std::unordered_map<std::string, T> items);
Expand Down Expand Up @@ -329,6 +329,11 @@ const std::vector<AnyMap>& AnyValue::asVector<AnyMap>(size_t nMin, size_t nMax)
template<>
std::vector<AnyMap>& AnyValue::asVector<AnyMap>(size_t nMin, size_t nMax);

CT_API bool operator==(const std::string& lhs, const AnyValue& rhs);
CT_API bool operator==(const double& lhs, const AnyValue& rhs);
CT_API bool operator==(const long int& lhs, const AnyValue& rhs);
CT_API bool operator==(const int& lhs, const AnyValue& rhs);

//! A map of string keys to values whose type can vary at runtime
/*!
* Values in an AnyMap are held by instances of AnyValue. Instances of AnyMap
Expand Down Expand Up @@ -399,25 +404,25 @@ std::vector<AnyMap>& AnyValue::asVector<AnyMap>(size_t nMin, size_t nMax);
class AnyMap : public AnyBase
{
public:
AnyMap();
CT_API AnyMap();

//! Create an AnyMap from a YAML file.
/*!
* Searches the directory containing the optionally-specified parent file
* first, followed by the current working directory and the Cantera include
* path.
*/
static AnyMap fromYamlFile(const std::string& name,
CT_API static AnyMap fromYamlFile(const std::string& name,
const std::string& parent_name="");

//! Create an AnyMap from a string containing a YAML document
static AnyMap fromYamlString(const std::string& yaml);
CT_API static AnyMap fromYamlString(const std::string& yaml);

std::string toYamlString() const;

//! Get the value of the item stored in `key`.
AnyValue& operator[](const std::string& key);
const AnyValue& operator[](const std::string& key) const;
CT_API AnyValue& operator[](const std::string& key);
CT_API const AnyValue& operator[](const std::string& key) const;

//! Used to create a new item which will be populated from a YAML input
//! string, where the item with `key` occurs at the specified line and
Expand All @@ -429,20 +434,20 @@ class AnyMap : public AnyBase
const AnyValue& at(const std::string& key) const;

//! Return boolean indicating whether AnyMap is empty.
bool empty() const;
CT_API bool empty() const;

//! Returns `true` if the map contains an item named `key`.
bool hasKey(const std::string& key) const;
CT_API bool hasKey(const std::string& key) const;

//! Erase the value held by `key`.
void erase(const std::string& key);

//! Erase all items in the mapping
void clear();
CT_API void clear();

//! Add items from `other` to this AnyMap. If keys in `other` also exist in
//! this AnyMap, the `keepExisting` option determines which item is used.
void update(const AnyMap& other, bool keepExisting=true);
CT_API void update(const AnyMap& other, bool keepExisting=true);

//! Return a string listing the keys in this AnyMap, for use in error
//! messages, for example
Expand All @@ -463,17 +468,17 @@ class AnyMap : public AnyBase
void propagateMetadata(shared_ptr<AnyMap>& file);

//! If `key` exists, return it as a `bool`, otherwise return `default_`.
bool getBool(const std::string& key, bool default_) const;
CT_API bool getBool(const std::string& key, bool default_) const;

//! If `key` exists, return it as a `long int`, otherwise return `default_`.
long int getInt(const std::string& key, long int default_) const;
CT_API long int getInt(const std::string& key, long int default_) const;

//! If `key` exists, return it as a `double`, otherwise return `default_`.
double getDouble(const std::string& key, double default_) const;
CT_API double getDouble(const std::string& key, double default_) const;

//! If `key` exists, return it as a `string`, otherwise return `default_`.
const std::string& getString(const std::string& key,
const std::string& default_) const;
CT_API const std::string& getString(const std::string& key,
const std::string& default_) const;

//! Convert the item stored by the given `key` to the units specified in
//! `units`. If the stored value is a double, convert it using the default
Expand Down Expand Up @@ -549,9 +554,9 @@ class AnyMap : public AnyBase
class OrderedProxy {
public:
OrderedProxy() {}
OrderedProxy(const AnyMap& data);
OrderedIterator begin() const;
OrderedIterator end() const;
CT_API OrderedProxy(const AnyMap& data);
CT_API OrderedIterator begin() const;
CT_API OrderedIterator end() const;

typedef std::vector<std::pair<
std::pair<int, int>,
Expand Down Expand Up @@ -596,8 +601,8 @@ class AnyMap : public AnyBase
return m_data.size();
};

bool operator==(const AnyMap& other) const;
bool operator!=(const AnyMap& other) const;
CT_API bool operator==(const AnyMap& other) const;
CT_API bool operator!=(const AnyMap& other) const;

//! Return the default units that should be used to convert stored values
const UnitSystem& units() const { return *m_units; }
Expand All @@ -618,10 +623,10 @@ class AnyMap : public AnyBase
* @warning This function is an experimental part of the %Cantera API and
* may be changed or removed without notice.
*/
void applyUnits();
CT_API void applyUnits();

//! See applyUnits()
void applyUnits(shared_ptr<UnitSystem>& units);
CT_API void applyUnits(shared_ptr<UnitSystem>& units);

//! Set the unit system for this AnyMap. The applyUnits() method should be
//! called on the root AnyMap object after all desired calls to setUnits()
Expand Down Expand Up @@ -740,9 +745,9 @@ class InputFileError : public CanteraError
return "InputFileError";
}
protected:
static std::string formatError(const std::string& message,
int line, int column,
const shared_ptr<AnyMap>& metadata);
CT_API static std::string formatError(const std::string& message,
int line, int column,
const shared_ptr<AnyMap>& metadata);
static std::string formatError2(const std::string& message,
int line1, int column1, const shared_ptr<AnyMap>& metadata1,
int line2, int column2, const shared_ptr<AnyMap>& metadata2);
Expand Down
4 changes: 2 additions & 2 deletions include/cantera/base/AnyMap.inl.h
Expand Up @@ -11,7 +11,7 @@
namespace Cantera
{
// re-declared to avoid needing to include global.h here
std::string demangle(const std::type_info& type);
CT_API std::string demangle(const std::type_info& type);

// Definitions for AnyValue templated functions

Expand Down Expand Up @@ -59,7 +59,7 @@ bool AnyValue::is() const {
return m_value->type() == typeid(T);
}

template<> bool AnyValue::is<std::vector<double>>() const;
template<> CT_API bool AnyValue::is<std::vector<double>>() const;

template<class T>
AnyValue &AnyValue::operator=(const std::vector<T> &value) {
Expand Down
6 changes: 3 additions & 3 deletions include/cantera/base/Solution.h
Expand Up @@ -141,7 +141,7 @@ class Solution : public std::enable_shared_from_this<Solution>
* on the phase definition.
* @returns an initialized Solution object.
*/
shared_ptr<Solution> newSolution(const std::string& infile, const std::string& name,
shared_ptr<Solution> CT_API newSolution(const std::string& infile, const std::string& name,
const std::string& transport, const std::vector<std::string>& adjacent);

//! Create and initialize a new Solution manager from an input file
Expand All @@ -157,7 +157,7 @@ shared_ptr<Solution> newSolution(const std::string& infile, const std::string& n
* phases will be instantiated based on the phase definition.
* @returns an initialized Solution object.
*/
shared_ptr<Solution> newSolution(const std::string& infile,
shared_ptr<Solution> CT_API newSolution(const std::string& infile,
const std::string& name="",
const std::string& transport="",
const std::vector<shared_ptr<Solution>>& adjacent={});
Expand All @@ -180,7 +180,7 @@ shared_ptr<Solution> newSolution(const std::string& infile,
* instantiated only once.
* @returns an initialized Solution object.
*/
shared_ptr<Solution> newSolution(
shared_ptr<Solution> CT_API newSolution(
const AnyMap& phaseNode, const AnyMap& rootNode=AnyMap(),
const std::string& transport="",
const std::vector<shared_ptr<Solution>>& adjacent={},
Expand Down
16 changes: 8 additions & 8 deletions include/cantera/base/Units.h
Expand Up @@ -30,15 +30,15 @@ class Units
{
public:
//! Create a Units object with the specified dimensions.
explicit Units(double factor=1.0, double mass=0, double length=0,
CT_API explicit Units(double factor=1.0, double mass=0, double length=0,
double time=0, double temperature=0, double current=0,
double quantity=0);

//! Create an object with the specified dimensions
//! @param units A string representation of the units. See UnitSystem
//! for a description of the formatting options.
//! @param force_unity ensure that conversion factor is equal to one
explicit Units(const std::string& units, bool force_unity=false);
CT_API explicit Units(const std::string& units, bool force_unity=false);

//! Returns `true` if the specified Units are dimensionally consistent
bool convertible(const Units& other) const;
Expand All @@ -53,7 +53,7 @@ class Units

//! Provide a string representation of these Units
//! @param skip_unity do not print '1' if conversion factor is equal to one
std::string str(bool skip_unity=true) const;
CT_API std::string str(bool skip_unity=true) const;

//! Raise these Units to a power, changing both the conversion factor and
//! the dimensions of these Units.
Expand All @@ -63,7 +63,7 @@ class Units

//! Return dimension of primary unit component
//! ("mass", "length", "time", "temperature", "current", or "quantity")
double dimension(const std::string& primary) const;
CT_API double dimension(const std::string& primary) const;

private:
//! Scale the unit by the factor `k`
Expand Down Expand Up @@ -127,7 +127,7 @@ struct UnitStack
void update(const Units& units, double exponent);

//! Calculate product of units-exponent stack
Units product() const;
CT_API Units product() const;

std::vector<std::pair<Units, double>> stack; //!< Stack uses vector of pairs
};
Expand Down Expand Up @@ -161,14 +161,14 @@ class UnitSystem
{
public:
//! Create a unit system with the specified default units
UnitSystem(std::initializer_list<std::string> units);
CT_API UnitSystem(std::initializer_list<std::string> units);

//! Default constructor for unit system (needed as VS2019 does not
//! recognize an optional argument with a default value)
UnitSystem() : UnitSystem({}) {}

//! Return default units used by the unit system
std::map<std::string, std::string> defaults() const;
CT_API std::map<std::string, std::string> defaults() const;

//! Set the default units to convert from when explicit units are not
//! provided. Defaults can be set for mass, length, time, quantity, energy,
Expand All @@ -177,7 +177,7 @@ class UnitSystem
//!
//! * To use SI+kmol: `setDefaults({"kg", "m", "s", "Pa", "J", "kmol"});`
//! * To use CGS+mol: `setDefaults({"cm", "g", "dyn/cm^2", "erg", "mol"});`
void setDefaults(std::initializer_list<std::string> units);
CT_API void setDefaults(std::initializer_list<std::string> units);

//! Set the default units using a map of dimension to unit pairs.
//!
Expand Down

0 comments on commit 8201853

Please sign in to comment.