User Guide
nmodl::units::UnitTable Class Reference

Class that stores all the units, prefixes and names of base units used. More...

Detailed Description

Class that stores all the units, prefixes and names of base units used.

The UnitTable encapsulates all the containers that are needed to store all the Units defined. Those containers are:

  • A table (hash map) that stores all the Units
  • A hash map that stores all the Prefixes
  • An array to store the base units names

The names and the design is based on the corresponding ones of MOD2C. The table is a hash map that uses as key the name of the Unit and as objects a shared_ptr to a Unit. This is needed as the parser passes to the UnitTable shared_ptrs, so that there is no need to allocate more space for the units or take care of the deallocation of the memory, which is done automatically by the smart pointer. A shared_ptr to a UnitTable is kept by the UnitDriver, to be able to populate the UnitTable by using multiple sources (files and strings). The UnitTable takes care of inserting Units, Prefixes and base units to the table calculating or the needed factors and dimensions.

Definition at line 240 of file units.hpp.

#include <units.hpp>

Public Member Functions

 UnitTable ()=default
 Default constructor for UnitTable. More...
 
void calc_nominator_dims (const std::shared_ptr< Unit > &unit, std::string nominator_name)
 Calculate unit's dimensions based on its nominator unit named nominator_name which is stored in the UnitTable's table. More...
 
void calc_denominator_dims (const std::shared_ptr< Unit > &unit, std::string denominator_name)
 Calculate unit's dimensions based on its denominator unit named denominator_name which is stored in the UnitTable's table. More...
 
void insert (const std::shared_ptr< Unit > &unit)
 Insert a unit to the UnitTable table and calculate its dimensions and factor based on the previously stored units in the UnitTable The unit can be a normal unit or unit based on just a base unit. More...
 
void insert_prefix (const std::shared_ptr< Prefix > &prfx)
 Insert a prefix to the prefixes of the UnitTable. More...
 
const std::shared_ptr< Unit > & get_unit (const std::string &unit_name) const
 Get the unit_name of the UnitTable's table. More...
 
void print_units_sorted (std::ostream &units_details) const
 Print the details of the units that are stored in the UnitTable to the output stream units_details in ascending order to be printed in tests in specific order. More...
 
void print_base_units (std::ostream &base_units_details) const
 Print the base units that are stored in the UnitTable to the output stream base_units_details. More...
 
const std::string & get_base_unit_name (int id) const noexcept
 Get base unit name based on the ID number of the dimension. More...
 

Private Attributes

std::unordered_map< std::string, std::shared_ptr< Unit > > table
 Hash map that stores all the Units. More...
 
std::unordered_map< std::string, double > prefixes
 Hash map that stores all the Prefixes. More...
 
std::array< std::string, MAX_DIMSbase_units_names
 Hash map that stores all the base units' names. More...
 

Constructor & Destructor Documentation

◆ UnitTable()

nmodl::units::UnitTable::UnitTable ( )
default

Default constructor for UnitTable.

Member Function Documentation

◆ calc_denominator_dims()

void nmodl::units::UnitTable::calc_denominator_dims ( const std::shared_ptr< Unit > &  unit,
std::string  denominator_name 
)

Calculate unit's dimensions based on its denominator unit named denominator_name which is stored in the UnitTable's table.

Definition at line 189 of file units.cpp.

◆ calc_nominator_dims()

void nmodl::units::UnitTable::calc_nominator_dims ( const std::shared_ptr< Unit > &  unit,
std::string  nominator_name 
)

Calculate unit's dimensions based on its nominator unit named nominator_name which is stored in the UnitTable's table.

Definition at line 115 of file units.cpp.

◆ get_base_unit_name()

const std::string& nmodl::units::UnitTable::get_base_unit_name ( int  id) const
inlinenoexcept

Get base unit name based on the ID number of the dimension.

Definition at line 288 of file units.hpp.

◆ get_unit()

const std::shared_ptr<Unit>& nmodl::units::UnitTable::get_unit ( const std::string &  unit_name) const
inline

Get the unit_name of the UnitTable's table.

Exceptions
std::out_of_rangeif unit_name is not found

Definition at line 274 of file units.hpp.

◆ insert()

void nmodl::units::UnitTable::insert ( const std::shared_ptr< Unit > &  unit)

Insert a unit to the UnitTable table and calculate its dimensions and factor based on the previously stored units in the UnitTable The unit can be a normal unit or unit based on just a base unit.

In the latter case, the base unit is also added to the base_units_name array of UnitTable

Definition at line 262 of file units.cpp.

◆ insert_prefix()

void nmodl::units::UnitTable::insert_prefix ( const std::shared_ptr< Prefix > &  prfx)

Insert a prefix to the prefixes of the UnitTable.

Definition at line 302 of file units.cpp.

◆ print_base_units()

void nmodl::units::UnitTable::print_base_units ( std::ostream &  base_units_details) const

Print the base units that are stored in the UnitTable to the output stream base_units_details.

Definition at line 318 of file units.cpp.

◆ print_units_sorted()

void nmodl::units::UnitTable::print_units_sorted ( std::ostream &  units_details) const

Print the details of the units that are stored in the UnitTable to the output stream units_details in ascending order to be printed in tests in specific order.

Definition at line 306 of file units.cpp.

Member Data Documentation

◆ base_units_names

std::array<std::string, MAX_DIMS> nmodl::units::UnitTable::base_units_names
private

Hash map that stores all the base units' names.

Definition at line 249 of file units.hpp.

◆ prefixes

std::unordered_map<std::string, double> nmodl::units::UnitTable::prefixes
private

Hash map that stores all the Prefixes.

Definition at line 246 of file units.hpp.

◆ table

std::unordered_map<std::string, std::shared_ptr<Unit> > nmodl::units::UnitTable::table
private

Hash map that stores all the Units.

Definition at line 243 of file units.hpp.


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