UnitOfMeasure.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/common/UnitOfMeasure.cpp
22 
23  \brief A class for representing a unit of measure.
24 */
25 
26 // TerraLib
27 #include "UnitOfMeasure.h"
28 
29 // STL
30 #include <cassert>
31 #include <sstream>
32 
33 // Boost
34 #include <boost/algorithm/string/case_conv.hpp>
35 
36 te::common::UnitOfMeasure::UnitOfMeasure(unsigned int id, const std::string& name, const std::string& symbol,
37  te::common::MeasureType type, const std::string& description)
38  : m_id(id),
39  m_symbol(symbol),
40  m_type(type),
41  m_description(description),
42  m_baseUnitId(id),
43  m_a(1.0),
44  m_b(0.0),
45  m_c(0.0),
46  m_d(1.0)
47 {
48  m_name = boost::to_upper_copy(name);
49 }
50 
51 te::common::UnitOfMeasure::UnitOfMeasure(unsigned int id, const std::string& name, const std::string& symbol,
52  te::common::MeasureType type, unsigned int baseUnitId,
53  double A, double B, double C , double D,
54  const std::string& description)
55  : m_id(id),
56  m_symbol(symbol),
57  m_type(type),
58  m_description(description),
59  m_baseUnitId(baseUnitId),
60  m_a(A),
61  m_b(B),
62  m_c(C),
63  m_d(D)
64 {
65  assert((m_c + m_d) != 0);
66 
67  m_name = boost::to_upper_copy(name);
68 }
69 
71 
73 {
74  return m_id;
75 }
76 
77 const std::string& te::common::UnitOfMeasure::getName() const
78 {
79  return m_name;
80 }
81 
82 void te::common::UnitOfMeasure::setDescription(const std::string& description)
83 {
84  m_description = description;
85 }
86 
88 {
89  return m_description;
90 }
91 
92 const std::string& te::common::UnitOfMeasure::getSymbol() const
93 {
94  return m_symbol;
95 }
96 
98 {
99  return m_type;
100 }
101 
103 {
104  return (m_id == m_baseUnitId);
105 }
106 
107 
109 {
110  return m_baseUnitId;
111 }
112 
113 
114 void te::common::UnitOfMeasure::getConversionFactors(double& A, double& B, double& C, double& D) const
115 {
116  A = m_a;
117  B = m_b;
118  C = m_c;
119  D = m_d;
120 }
121 
123 {
124  return ((m_a + m_b) / (m_c + m_d));
125 }
126 
128 {
129  double convf = (m_a + m_b) / (m_c + m_d);
130  std::string wkt;
131  wkt = "UNIT[\"";
132  wkt += this->getName();
133  wkt += "\", ";
134  std::ostringstream sstr;
135  sstr.precision(10);
136  sstr << convf;
137  wkt += sstr.str();
138  wkt += "]";
139  return wkt;
140 }
141 
~UnitOfMeasure()
Destructor.
MeasureType getType() const
Returns the unit of measure type.
UnitOfMeasure(unsigned int id, const std::string &name, const std::string &symbol, MeasureType type, const std::string &description="")
Creates a new base unit of measure.
void getConversionFactors(double &A, double &B, double &C, double &D) const
Returns the conversion factors to convert the unit to its base unit.
unsigned int getId() const
Returns the unit of measure identification.
unsigned int m_baseUnitId
Unique identification number of the base unit to which a conversion operation is provided.
std::string m_symbol
Unit symbol.
const std::string & getDescription() const
Returns the unit of measure description.
const std::string & getName() const
Returns the unit of measure oficial name.
unsigned int m_id
Unique identification number for a unit of measure.
MeasureType m_type
Unit type of measure.
A class for representing a unit of measure.
void setDescription(const std::string &description)
Sets the unit of measure description.
const std::string & getSymbol() const
Returns the unit of measure symbol.
std::string m_description
unit of measure description.
MeasureType
Defines the possible types of unit of measurements.
std::string m_name
unit of measure name according to SI.
double getConversionValue() const
Returns a multiplicative value to convert the unit to its base unit.
const unsigned int getBaseUnitId() const
Returns the base unit id from which this unit derives of.
bool isBaseUnit() const
Returns true if this is a base unit; otherwise returns false.
std::string getWKT() const
Returns the WKT description of a unit of measure.