Class that stores all the data of a Unit.
The Unit class encapsulates all the variables and containers that are related to the definition of a unit. Those are:
- Unit factor
- Unit dimensions
- Unit name
- Nominator units
- Denominator units
The unit factor is calculated based on the unit factor if it is stated and the factors of the units that describe the units and are on the nominator or the denominator of the unit. The calculation of the factor is done by the UnitTable class, as it is needed to check the factors and dimensions of the units that this unit is based upon and are stored into the UnitTable table that keeps all the units parsed from a units file (nrnunits.lib by default) or the mod files. The dimensions of the unit represent which basic units are used to define this unit. They are represented by an array of ints of size MAX_DIMS. An array was used, as the base units do not change based on the SI units. If a base unit is used in this unit's definition then there is a 1 in the responding or else 0. If a unit is on the nominator of the unit definition, then its factor is multiplied by the unit's factor, while if it is on the denominator, its factor is divided by the unit's factor. The dimensions of the nominator units are added to the dimensions of the units and the dimensions of the denominator are subtracted from the unit's dimensions. The Unit representation is designed based on the units representation of the MOD2C parser.
Definition at line 73 of file units.hpp.
|
void | add_unit (const std::string &name) |
| Add unit name to the Unit. More...
|
|
void | add_base_unit (const std::string &name) |
| If the Unit is a base unit the dimensions of the Unit should be calculated based on the name of the base unit (ex. More...
|
|
void | add_nominator_double (const std::string &double_string) |
| Takes as argument a double as string, parses it as double and stores it to the Unit factor. More...
|
|
void | add_nominator_dims (const std::array< int, MAX_DIMS > &dimensions) |
| Add the dimensions of a nominator of the unit to the dimensions of the Unit. More...
|
|
void | add_denominator_dims (const std::array< int, MAX_DIMS > &dimensions) |
| Subtract the dimensions of a nominator of the unit to the dimensions of the Unit. More...
|
|
void | add_nominator_unit (const std::string &nom) |
| Add a unit to the vector of nominator strings of the Unit, so it can be processed later. More...
|
|
void | add_nominator_unit (const std::shared_ptr< std::vector< std::string >> &nom) |
| Add a vector of units to the vector of nominator strings of the Unit, so they can be processed later. More...
|
|
void | add_denominator_unit (const std::string &denom) |
| Add a unit to the vector of denominator strings of the Unit, so it can be processed later. More...
|
|
void | add_denominator_unit (const std::shared_ptr< std::vector< std::string >> &denom) |
| Add a vector of units to the vector of denominator strings of the Unit, so they can be processed later. More...
|
|
void | mul_factor (double double_factor) |
| Multiply Unit's factor with a double factor. More...
|
|
void | add_fraction (const std::string &nominator, const std::string &denominator) |
| Parse a fraction given as string and store the result to the factor of the Unit. More...
|
|
const std::vector< std::string > & | get_nominator_unit () const noexcept |
| Getter for the vector of nominators of the Unit. More...
|
|
const std::vector< std::string > & | get_denominator_unit () const noexcept |
| Getter for the vector of denominators of the Unit. More...
|
|
const std::string & | get_name () const noexcept |
| Getter for the name of the Unit. More...
|
|
double | get_factor () const |
| Getter for the double factor of the Unit. More...
|
|
const std::array< int, MAX_DIMS > & | get_dimensions () const noexcept |
| Getter for the array of Unit's dimensions. More...
|
|
|
| Unit ()=default |
| Default constructor of Unit. More...
|
|
| Unit (std::string name) |
| Constructor for simply creating a Unit with a given name. More...
|
|
| Unit (const double factor, const std::array< int, MAX_DIMS > &dimensions, std::string name) |
| Constructor that instantiates a Unit with its factor, dimensions and name. More...
|
|
double nmodl::units::Unit::parse_double |
( |
std::string |
double_string | ) |
|
|
static |
Parse a double number given as string.
Double numbers in the nrnunits.lib
file are defined in the form [.0-9]+[-+][0-9]+ To make sure they are parsed in the correct way and similarly to the NEURON parser we convert this string to a string compliant to scientific notation to be able to be parsed from std::stod().
The double can be positive or negative and have all kinds of representations
To do that we have to add an e
in case there is -+
in the number string if it doesn't exist.
Definition at line 105 of file units.cpp.