|
Modular Megafauna Model 1.1.5
A physiological, dynamic herbivore simulator in C++.
|
#include <forage_values.h>
Public Member Functions | |
| ForageValues (const double init_value=0.0) | |
| Constructor with initializing value. More... | |
| ForageValues< tag > | divide_safely (const ForageValues< tag > &divisor, const double na_value) const |
| Divide safely also by zero values. More... | |
| double | get (const ForageType ft) const |
| Get a value (read-only). More... | |
| ForageValues< tag > & | merge (const ForageValues< tag > &other, const double this_weight=1.0, const double other_weight=1.0) |
| Merge this object with another one by building (weighted) means. More... | |
| ForageValues< tag > & | max (const ForageValues< tag > &other) |
| For each forage type, take the maximum value. More... | |
| ForageValues< tag > & | min (const ForageValues< tag > &other) |
| For each forage type, take the minimum value. More... | |
| double | operator[] (const ForageType ft) const |
| Read-only value access. More... | |
| double & | operator[] (const ForageType ft) |
| Write access to values. More... | |
| void | set (const ForageType forage_type, double value) |
| Set a value, only finite values are allowed. More... | |
| void | set (double value) |
| Set all forage types to one value. More... | |
| double | sum () const |
| Sum of all values. More... | |
Operator overload. | |
| ForageValues< tag > & | operator+= (const double rhs) |
| ForageValues< tag > & | operator-= (const double rhs) |
| ForageValues< tag > & | operator*= (const double rhs) |
| ForageValues< tag > & | operator/= (const double rhs) |
| ForageValues< tag > | operator+ (const double rhs) const |
| ForageValues< tag > | operator- (const double rhs) const |
| ForageValues< tag > | operator* (const double rhs) const |
| ForageValues< tag > | operator/ (const double rhs) const |
| ForageValues< tag > | operator+ (const ForageValues< tag > &rhs) const |
| ForageValues< tag > | operator- (const ForageValues< tag > &rhs) const |
| ForageValues< tag > | operator* (const ForageValues< tag > &rhs) const |
| ForageValues< tag > | operator/ (const ForageValues< tag > &rhs) const |
| ForageValues< tag > & | operator+= (const ForageValues< tag > &rhs) |
| ForageValues< tag > & | operator-= (const ForageValues< tag > &rhs) |
| ForageValues< tag > & | operator*= (const ForageValues< tag > &rhs) |
| ForageValues< tag > & | operator/= (const ForageValues< tag > &rhs) |
| bool | operator== (const ForageValues< tag > &rhs) const |
| bool | operator!= (const ForageValues< tag > &rhs) const |
| bool | operator< (const ForageValues< tag > &rhs) const |
| bool | operator<= (const ForageValues< tag > &rhs) const |
| bool | operator> (const ForageValues< tag > &rhs) const |
| bool | operator>= (const ForageValues< tag > &rhs) const |
Static Public Attributes | |
| static constexpr const double | IMPRECISION_TOLERANCE = 1e-3 |
| Tolerance range for imprecise floating point results. More... | |
Private Member Functions | |
| void | check_value (double &value) const |
Helper function to throw exceptions in the set() functions. More... | |
Private Attributes | |
| std::array< double, 1 > | array |
Forage values for all but ForageType::Inedible. More... | |
Multi-purpose template class for double values mapped by edible(!) forage type. The forage type ForageType::Inedible is excluded from all operations.
| tag | Defines the allowed data range. |
F1 and F2 ForageValues objects. F1>F2 then means that each value in F1 (one for each forage type) is greater than the corresponding value in F2. In the same way, F1==F2 means that all corresponding values are identical. F1!=F2 means then that each pair of values is not equal. If one value pair, is identical, the result is false! In the same logic, F1==d is true if all values in F1 are equal to the double value d. Now, F1!=d is true only if all values in F1 are not equal to d. If only one value of F1 matches d, the result will be false! To check if not all values in F1 are equal to d, you would use !(F1==d).
|
inline |
Constructor with initializing value.
| std::invalid_argument | If init_value is not allowed by given tag. |
| std::logic_error | If tag is not implemented. |
|
inlineprivate |
Helper function to throw exceptions in the set() functions.
| value | The value to check. It is passed as reference so that it can be corrected with IMPRECISION_TOLERANCE. |
|
inline |
Divide safely also by zero values.
| divisor | Numbers to divide by; can contain zeros. |
| na_value | Value that shall be set as a result for division by zero. |
|
inline |
Get a value (read-only).
| std::invalid_argument | If ForageType::Inedible is passed. |
|
inline |
For each forage type, take the maximum value.
| other | The object to compare this object with. |
|
inline |
Merge this object with another one by building (weighted) means.
| other | Other object to merge into this one. |
| this_weight | Weight of this object’s values. |
| other_weight | Weight of the other object’s values. |
| std::invalid_argument | The same as average(). |
|
inline |
For each forage type, take the minimum value.
| other | The object to compare this object with. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | On division by zero. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | On division by zero. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
| std::domain_error | If rhs==0.0. |
|
inline |
Write access to values.
|
inline |
Read-only value access.
|
inline |
Set a value, only finite values are allowed.
| std::invalid_argument | If value is not allowed by given tag, is NAN or is INFINITY. |
| std::invalid_argument | If forage_type==ForageType::Inedible. |
| std::logic_error | If tag is not implemented. |
|
inline |
Set all forage types to one value.
| std::invalid_argument | If value is not allowed by given tag, is NAN or is INFINITY. |
| std::invalid_argument | If forage_type==ForageType::Inedible. |
| std::logic_error | If tag is not implemented. |
|
inline |
Sum of all values.
|
private |
Forage values for all but ForageType::Inedible.
|
staticconstexpr |
Tolerance range for imprecise floating point results.
For example, if no negative values are allowed, a value only slightly below zero could result from an imprecise floating point calculation. This must be corrected. So a value barely below zero will be corrected to actual zero.
Setting the tolerance is an arbitrary decision. In general, ecologically significant numbers throughout the program should be above 1.0. Therefore it is important to choose your units carefully. If you encounter errors that are certainly coming from rounding imprecision, you may try to increase this tolerance value.