User Guide
nmodl::units::Unit Class Reference

Class that stores all the data of a Unit. More...

Detailed Description

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.

#include <units.hpp>

Public Member Functions

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...
 
Ctor & dtor
 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...
 

Static Public Member Functions

static double parse_double (std::string double_string)
 Parse a double number given as string. More...
 

Private Attributes

double unit_factor = 1.0
 Double factor of the Unit. More...
 
std::array< int, MAX_DIMSunit_dimensions {{0}}
 Array of MAX_DIMS size that keeps the Unit's dimensions. More...
 
std::string unit_name
 Name of the Unit. More...
 
std::vector< std::string > nominator
 Vector of nominators of the Unit. More...
 
std::vector< std::string > denominator
 Vector of denominators of the Unit. More...
 

Constructor & Destructor Documentation

◆ Unit() [1/3]

nmodl::units::Unit::Unit ( )
default

Default constructor of Unit.

◆ Unit() [2/3]

nmodl::units::Unit::Unit ( std::string  name)
inlineexplicit

Constructor for simply creating a Unit with a given name.

Definition at line 98 of file units.hpp.

◆ Unit() [3/3]

nmodl::units::Unit::Unit ( const double  factor,
const std::array< int, MAX_DIMS > &  dimensions,
std::string  name 
)
inline

Constructor that instantiates a Unit with its factor, dimensions and name.

Definition at line 102 of file units.hpp.

Member Function Documentation

◆ add_base_unit()

void nmodl::units::Unit::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.

m *a* => m has dimension 0)

Definition at line 42 of file units.cpp.

◆ add_denominator_dims()

void nmodl::units::Unit::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.

Definition at line 64 of file units.cpp.

◆ add_denominator_unit() [1/2]

void nmodl::units::Unit::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.

Definition at line 84 of file units.cpp.

◆ add_denominator_unit() [2/2]

void nmodl::units::Unit::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.

Definition at line 80 of file units.cpp.

◆ add_fraction()

void nmodl::units::Unit::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.

Definition at line 92 of file units.cpp.

◆ add_nominator_dims()

void nmodl::units::Unit::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.

Definition at line 56 of file units.cpp.

◆ add_nominator_double()

void nmodl::units::Unit::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.

Definition at line 52 of file units.cpp.

◆ add_nominator_unit() [1/2]

void nmodl::units::Unit::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.

Definition at line 76 of file units.cpp.

◆ add_nominator_unit() [2/2]

void nmodl::units::Unit::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.

Definition at line 72 of file units.cpp.

◆ add_unit()

void nmodl::units::Unit::add_unit ( const std::string &  name)

Add unit name to the Unit.

Definition at line 38 of file units.cpp.

◆ get_denominator_unit()

const std::vector<std::string>& nmodl::units::Unit::get_denominator_unit ( ) const
inlinenoexcept

Getter for the vector of denominators of the Unit.

Definition at line 158 of file units.hpp.

◆ get_dimensions()

const std::array<int, MAX_DIMS>& nmodl::units::Unit::get_dimensions ( ) const
inlinenoexcept

Getter for the array of Unit's dimensions.

Definition at line 173 of file units.hpp.

◆ get_factor()

double nmodl::units::Unit::get_factor ( ) const
inline

Getter for the double factor of the Unit.

Definition at line 168 of file units.hpp.

◆ get_name()

const std::string& nmodl::units::Unit::get_name ( ) const
inlinenoexcept

Getter for the name of the Unit.

Definition at line 163 of file units.hpp.

◆ get_nominator_unit()

const std::vector<std::string>& nmodl::units::Unit::get_nominator_unit ( ) const
inlinenoexcept

Getter for the vector of nominators of the Unit.

Definition at line 153 of file units.hpp.

◆ mul_factor()

void nmodl::units::Unit::mul_factor ( double  double_factor)

Multiply Unit's factor with a double factor.

Definition at line 88 of file units.cpp.

◆ parse_double()

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.

Member Data Documentation

◆ denominator

std::vector<std::string> nmodl::units::Unit::denominator
private

Vector of denominators of the Unit.

Definition at line 88 of file units.hpp.

◆ nominator

std::vector<std::string> nmodl::units::Unit::nominator
private

Vector of nominators of the Unit.

Definition at line 85 of file units.hpp.

◆ unit_dimensions

std::array<int, MAX_DIMS> nmodl::units::Unit::unit_dimensions {{0}}
private

Array of MAX_DIMS size that keeps the Unit's dimensions.

Definition at line 79 of file units.hpp.

◆ unit_factor

double nmodl::units::Unit::unit_factor = 1.0
private

Double factor of the Unit.

Definition at line 76 of file units.hpp.

◆ unit_name

std::string nmodl::units::Unit::unit_name
private

Name of the Unit.

Definition at line 82 of file units.hpp.


The documentation for this class was generated from the following files: