Skip to content

Commit

Permalink
Add get<T> to Property.
Browse files Browse the repository at this point in the history
  • Loading branch information
endJunction committed Dec 21, 2018
1 parent b7731c4 commit 3064216
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions MaterialLib/MPL/mpProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,36 @@ class Property
/// This virtual method will compute the derivative of a property
/// with respect to the given variables pv.
virtual PropertyDataType dvalue(VariableArray const& variable_array,
Variables const variables);
Variables const variables) const;
/// This virtual method will compute the second derivative of a
/// property with respect to the given variables pv1 and pv2.
virtual PropertyDataType ddvalue(VariableArray const& variable_array,
Variables const variables1,
Variables const variables2);
Variables const variables2) const;

template <typename T>
T getValue() const
{
return boost::get<T>(value());
}
template <typename T>
T getValue(VariableArray const& variables) const
{
return boost::get<T>(value(variables));
}
template <typename T>
T getDValue(VariableArray const& variable_array,
Variables const variables) const
{
return boost::get<T>(dvalue(variable_array, variables));
}
template <typename T>
T getDDValue(VariableArray const& variable_array,
Variables const& variables1,
Variables const& variables2) const
{
return boost::get<T>(ddvalue(variable_array, variables1, variables2));
}
};

/// This data type is based on a std::array. It can hold pointers to objects of
Expand Down Expand Up @@ -113,49 +137,49 @@ inline double getScalar(Property& p)
assert((getType(p) == PropertyDataTypeName::nScalar) &&
"The requested value type is not of type 'double'");

return boost::get<double>(p.value());
return p.getValue<double>();
}

/// This method forces the computation of a value of type double and returns it.
inline double getScalar(Property& p, VariableArray const& v)
{
return boost::get<double>(p.value(v));
return p.getValue<double>(v);
}

/// This method forces the computation of a value of type Pair and returns it
inline Pair getPair(Property& p, VariableArray const& v)
{
return boost::get<Pair>(p.value(v));
return p.getValue<Pair>(v);
}

/// This method forces the computation of a value of type Vector and returns it.
inline Vector getVector(Property& p)
{
assert((getType(p) == PropertyDataTypeName::nVector) &&
"The requested value type is not of type 'Vector'");
return boost::get<Vector>(p.value());
return p.getValue<Vector>();
}

/// This method forces the computation of a value of type Vector and returns it.
inline Vector getVector(Property& p, VariableArray const& v)
{
return boost::get<Vector>(p.value(v));
return p.getValue<Vector>(v);
}

/// This method forces the computation the derivative of a value, returns a pair
/// of double values. The derivative is computed with respect to variable pv.
inline Pair getPairDerivative(Property& p, VariableArray const& v,
Variables const pv)
{
return boost::get<Pair>(p.dvalue(v, pv));
return p.getDValue<Pair>(v, pv);
}

/// This method forces the computation the derivative of a value, returns a
/// double value. The derivative is computed with respect to variable pv.
inline double getScalarDerivative(Property& p, VariableArray const& v,
Variables const pv)
{
return boost::get<double>(p.dvalue(v, pv));
return p.getDValue<double>(v, pv);
}

/// This method forces the computation the second derivative of a value, returns
Expand All @@ -164,14 +188,14 @@ inline double getScalarDerivative(Property& p, VariableArray const& v,
inline double getScalarDerivative(Property& p, VariableArray const& v,
Variables const pv1, Variables const pv2)
{
return boost::get<double>(p.ddvalue(v, pv1, pv2));
return p.getDDValue<double>(v, pv1, pv2);
}

/// This method returns a value of type string from the property value
/// attribute.
inline std::string getString(Property const& p)
{
return boost::get<std::string>(p.value());
return p.getValue<std::string>();
}

/// This method returns a value of any valid type from the property value
Expand Down

0 comments on commit 3064216

Please sign in to comment.