te::common::UnitsOfMeasureManager Class Reference

A singleton class for dealing with units of measure in the TerraLib environment. More...

#include <UnitsOfMeasureManager.h>

Inheritance diagram for te::common::UnitsOfMeasureManager:
te::common::Singleton< UnitsOfMeasureManager >

Public Types

typedef std::map< unsigned int, UnitOfMeasurePtr >::const_iterator const_iterator
 
typedef std::map< unsigned int, UnitOfMeasurePtr >::iterator iterator
 

Public Member Functions

bool areConvertible (const std::string &unitFromName, const std::string &unitToName) const
 Check if two units of measure are compatible. More...
 
const_iterator begin () const
 It returns an iterator to the beginning of the conteiner. More...
 
iterator begin ()
 It returns an iterator to the beginning of the conteiner. More...
 
void clear ()
 Removes all units from the catalogue. More...
 
const_iterator end () const
 It returns an iterator to the end of the conteiner. More...
 
iterator end ()
 It returns an iterator to the end of the conteiner. More...
 
UnitOfMeasurePtr find (unsigned int id) const
 Returns a unit of measure identified by its identificaton. More...
 
UnitOfMeasurePtr find (const std::string &name) const
 Returns a unit of measure identified by its name. More...
 
UnitOfMeasurePtr findBySymbol (const std::string &symbol) const
 Returns a unit of measure identified by its symbol. More...
 
double getConversion (const std::string &unitFromName, const std::string &unitToName) const
 Calculates a multiplicative factor to convert from a given unit to its base unit and vice-versa. More...
 
void getNames (UnitOfMeasurePtr &uom, std::vector< std::string > &names) const
 Retrieves the alternative names for a unit of measure. More...
 
void init ()
 It initializes the list of well kown units of measure. More...
 
void insert (UnitOfMeasurePtr &uom)
 Inserts a new unit of measure to be managed. More...
 
void insert (UnitOfMeasurePtr &uom, const std::vector< std::string > &alternativeNames)
 Inserts a new unit of measure to be managed and its alternative names. More...
 
bool isInitialized ()
 
void remove (UnitOfMeasurePtr &uom)
 Removes a unit of measure from the manager. More...
 
std::size_t size () const
 It returns the number of units in the manager. More...
 

Static Public Member Functions

static UnitsOfMeasureManagergetInstance ()
 It returns a reference to the singleton instance. More...
 

Protected Member Functions

 UnitsOfMeasureManager ()
 It initializes the Singleton. More...
 
 ~UnitsOfMeasureManager ()
 Destructor. More...
 

Private Attributes

std::map< unsigned int, UnitOfMeasurePtrm_uoms
 
std::map< std::string, unsigned int > m_uomsIdxByName
 

Friends

class te::common::Singleton< UnitsOfMeasureManager >
 

Detailed Description

A singleton class for dealing with units of measure in the TerraLib environment.

This class manages a unique catalogue of known units of measure within the TerraLib environment.

See also
UnitOfMeasure

Definition at line 54 of file UnitsOfMeasureManager.h.

Member Typedef Documentation

Definition at line 61 of file UnitsOfMeasureManager.h.

Constructor & Destructor Documentation

te::common::UnitsOfMeasureManager::UnitsOfMeasureManager ( )
protected

It initializes the Singleton.

te::common::UnitsOfMeasureManager::~UnitsOfMeasureManager ( )
protected

Destructor.

Member Function Documentation

bool te::common::UnitsOfMeasureManager::areConvertible ( const std::string &  unitFromName,
const std::string &  unitToName 
) const

Check if two units of measure are compatible.

Check if a unit can be converted to another.

Parameters
unitFromNameA unit of measure name.
unitToNameThe name of unit to be converted to.
Returns
True if the UnitFrom can be converted to UnitTo false otherwise.
UnitsOfMeasureManager::const_iterator te::common::UnitsOfMeasureManager::begin ( ) const
inline

It returns an iterator to the beginning of the conteiner.

Returns
An iterator to the beginning of the conteiner.

Definition at line 222 of file UnitsOfMeasureManager.h.

References m_uoms.

UnitsOfMeasureManager::iterator te::common::UnitsOfMeasureManager::begin ( )
inline

It returns an iterator to the beginning of the conteiner.

Returns
An iterator to the beginning of the conteiner.

Definition at line 227 of file UnitsOfMeasureManager.h.

References m_uoms.

void te::common::UnitsOfMeasureManager::clear ( )

Removes all units from the catalogue.

UnitsOfMeasureManager::const_iterator te::common::UnitsOfMeasureManager::end ( ) const
inline

It returns an iterator to the end of the conteiner.

Returns
An iterator to the beginning of the conteiner.

Definition at line 232 of file UnitsOfMeasureManager.h.

References m_uoms.

UnitsOfMeasureManager::iterator te::common::UnitsOfMeasureManager::end ( )
inline

It returns an iterator to the end of the conteiner.

Returns
An iterator to the beginning of the conteiner.

Definition at line 237 of file UnitsOfMeasureManager.h.

References m_uoms.

UnitOfMeasurePtr te::common::UnitsOfMeasureManager::find ( unsigned int  id) const

Returns a unit of measure identified by its identificaton.

Parameters
idThe unit identification.
Returns
A pointer unit of measure if found; null pointer otherwise.
UnitOfMeasurePtr te::common::UnitsOfMeasureManager::find ( const std::string &  name) const

Returns a unit of measure identified by its name.

Parameters
idThe unit identification.
Returns
A unit of measure pointer if found; null pointer otherwise.
UnitOfMeasurePtr te::common::UnitsOfMeasureManager::findBySymbol ( const std::string &  symbol) const

Returns a unit of measure identified by its symbol.

Parameters
idThe unit symbol.
Returns
A unit of measure pointer if found; null pointer otherwise.
double te::common::UnitsOfMeasureManager::getConversion ( const std::string &  unitFromName,
const std::string &  unitToName 
) const

Calculates a multiplicative factor to convert from a given unit to its base unit and vice-versa.

Parameters
unitFromNameA unit of measure name.
unitToNameThe name of unit to be converted to.
Returns
A multiplicative factor to convert from a given unit to another.
Exceptions
ExceptionIf the conversion is not possible.
static UnitsOfMeasureManager & te::common::Singleton< UnitsOfMeasureManager >::getInstance ( )
staticinherited

It returns a reference to the singleton instance.

Returns
A reference to the singleton instance.
void te::common::UnitsOfMeasureManager::getNames ( UnitOfMeasurePtr uom,
std::vector< std::string > &  names 
) const

Retrieves the alternative names for a unit of measure.

Parameters
uomPointer to the unit of measure. Shouldn't be null;
altNamesReference to a vector of strings to return the alternative names (output).
void te::common::UnitsOfMeasureManager::init ( )

It initializes the list of well kown units of measure.

The list is read from the JSON file TERRALIB_DIR/resources/json/uom.json.

Exceptions
ExceptionIt throws an exception if it is not possible to initialize the UOM list.
void te::common::UnitsOfMeasureManager::insert ( UnitOfMeasurePtr uom)

Inserts a new unit of measure to be managed.

Parameters
uomPointer to unit of measure to be managed. Shouldn't be null. The manager takes the pointer ownership.
Exceptions
ExceptionIf the unit is already managed.
void te::common::UnitsOfMeasureManager::insert ( UnitOfMeasurePtr uom,
const std::vector< std::string > &  alternativeNames 
)

Inserts a new unit of measure to be managed and its alternative names.

Parameters
uomPointer to unit of measure to be managed. Shouldn't be null. The manager takes the pointer ownership.
alternativeNamesThe list of alternative (or auxiliary) names for identifying an unit of measure.
Exceptions
ExceptionIf the unit is already managed.
bool te::common::UnitsOfMeasureManager::isInitialized ( )
void te::common::UnitsOfMeasureManager::remove ( UnitOfMeasurePtr uom)

Removes a unit of measure from the manager.

Parameters
uomPointer to unit of measure to be managed. Shouldn't be null. The manager will delete the pointer.
Exceptions
te::common::ExceptionIf the unit is unknown to the manager.
std::size_t te::common::UnitsOfMeasureManager::size ( ) const
inline

It returns the number of units in the manager.

Returns
The number of units in the manager.

Definition at line 217 of file UnitsOfMeasureManager.h.

References m_uoms.

Friends And Related Function Documentation

Definition at line 56 of file UnitsOfMeasureManager.h.

Member Data Documentation

std::map<unsigned int, UnitOfMeasurePtr> te::common::UnitsOfMeasureManager::m_uoms
private

Definition at line 212 of file UnitsOfMeasureManager.h.

Referenced by begin(), end(), and size().

std::map<std::string, unsigned int> te::common::UnitsOfMeasureManager::m_uomsIdxByName
private

Definition at line 213 of file UnitsOfMeasureManager.h.


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