All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 {
72 }
73 
75 {
76  return m_id;
77 }
78 
79 const std::string& te::common::UnitOfMeasure::getName() const
80 {
81  return m_name;
82 }
83 
84 void te::common::UnitOfMeasure::setDescription(const std::string& description)
85 {
86  m_description = description;
87 }
88 
90 {
91  return m_description;
92 }
93 
94 const std::string& te::common::UnitOfMeasure::getSymbol() const
95 {
96  return m_symbol;
97 }
98 
100 {
101  return m_type;
102 }
103 
105 {
106  return (m_id == m_baseUnitId);
107 }
108 
109 
111 {
112  return m_baseUnitId;
113 }
114 
115 
116 void te::common::UnitOfMeasure::getConversionFactors(double& A, double& B, double& C, double& D) const
117 {
118  A = m_a;
119  B = m_b;
120  C = m_c;
121  D = m_d;
122 }
123 
125 {
126  return ((m_a + m_b) / (m_c + m_d));
127 }
128 
130 {
131  double convf = (m_a + m_b) / (m_c + m_d);
132  std::string wkt;
133  wkt = "UNIT[\"";
134  wkt += this->getName();
135  wkt += "\", ";
136  std::ostringstream sstr;
137  sstr.precision(10);
138  sstr << convf;
139  wkt += sstr.str();
140  wkt += "]";
141  return wkt;
142 }
143 
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.
const std::string & getDescription() const
Returns the unit of measure description.
const std::string & getName() const
Returns the unit of measure oficial name.
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.
MeasureType
Defines the possible types of unit of measurements.
Definition: Enums.h:76
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.