All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
BooleanConverters.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/datatype/BooleanConverters.cpp
22 
23  \brief A set of function that convert an Boolean type to other types.
24 */
25 
26 // TerraLib
27 #include "../common/Translator.h"
28 #include "Enums.h"
29 #include "Exception.h"
30 #include "BooleanConverters.h"
31 #include "SimpleData.h"
32 
33 // Boost
34 #include <boost/lexical_cast.hpp>
35 
37 {
38  AssertBoolean(d);
39  return new Char(boost::lexical_cast<char>(static_cast<const Boolean*>(d)->getValue()));
40 }
41 
43 {
44  AssertBoolean(d);
45  return new UChar(boost::lexical_cast<unsigned char>(static_cast<const Boolean*>(d)->getValue()));
46 }
47 
49 {
50  AssertBoolean(d);
51  return new Int16(static_cast<int16_t>(static_cast<const Boolean*>(d)->getValue()));
52 }
53 
55 {
56  AssertBoolean(d);
57  return new UInt16(boost::lexical_cast<uint16_t>(static_cast<const Boolean*>(d)->getValue()));
58 }
59 
61 {
62  AssertBoolean(d);
63  return new Int32(static_cast<int32_t>(static_cast<const Boolean*>(d)->getValue()));
64 }
65 
67 {
68  AssertBoolean(d);
69  return new UInt32(boost::lexical_cast<uint32_t>(static_cast<const Boolean*>(d)->getValue()));
70 }
71 
73 {
74  AssertBoolean(d);
75  return new Int64(static_cast<int64_t>(static_cast<const Boolean*>(d)->getValue()));
76 }
77 
79 {
80  AssertBoolean(d);
81  return new UInt64(boost::lexical_cast<uint64_t>(static_cast<const Boolean*>(d)->getValue()));
82 }
83 
85 {
86  AssertBoolean(d);
87  return new Float(boost::lexical_cast<float>(static_cast<const Boolean*>(d)->getValue()));
88 }
89 
91 {
92  AssertBoolean(d);
93  return new Double(boost::lexical_cast<double>(static_cast<const Boolean*>(d)->getValue()));
94 }
95 
97 {
98  AssertBoolean(d);
99  return new Numeric(boost::lexical_cast<std::string>(static_cast<const Boolean*>(d)->getValue()));
100 }
101 
103 {
104  AssertBoolean(d);
105  return new String(boost::lexical_cast<std::string>(static_cast<const Boolean*>(d)->getValue()));
106 }
107 
108 void te::dt::AssertBoolean(AbstractData* d) throw(Exception)
109 {
110  if(d->getTypeCode() != BOOLEAN_TYPE)
111  throw Exception(TE_TR("The input data type is not a boolean!"));
112 }
AbstractData * BooleanToStringConverter(AbstractData *d)
It converts an Boolean data value to a string data value.
SimpleData< std::string, STRING_TYPE > String
Definition: SimpleData.h:229
SimpleData< unsigned char, UCHAR_TYPE > UChar
Definition: SimpleData.h:218
AbstractData * BooleanToInt64Converter(AbstractData *d)
It converts an Boolean data value to a Int64 data value.
An exception class for the DataType module.
AbstractData * BooleanToInt16Converter(AbstractData *d)
It converts an Boolean data value to a Int16 data value.
SimpleData< boost::int64_t, INT64_TYPE > Int64
Definition: SimpleData.h:223
SimpleData< boost::int32_t, INT32_TYPE > Int32
Definition: SimpleData.h:221
SimpleData< float, FLOAT_TYPE > Float
Definition: SimpleData.h:226
void AssertBoolean(AbstractData *d)
Auxiliary method that asserts that the given data is an Boolean type.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
AbstractData * BooleanToDoubleConverter(AbstractData *d)
It converts an Boolean data value to a double data value.
AbstractData * BooleanToUInt16Converter(AbstractData *d)
It converts an Boolean data value to an unsigned Int16 data value.
AbstractData * BooleanToFloatConverter(AbstractData *d)
It converts an Boolean data value to a float data value.
AbstractData * BooleanToUInt32Converter(AbstractData *d)
It converts an Boolean data value to an unsigned Int32 data value.
SimpleData< std::string, NUMERIC_TYPE > Numeric
Definition: SimpleData.h:228
AbstractData * BooleanToUInt64Converter(AbstractData *d)
It converts an Boolean data value to an unsigned Int64 data value.
AbstractData * BooleanToNumericConverter(AbstractData *d)
It converts an Boolean data value to a Numeric data value.
AbstractData * BooleanToCharConverter(AbstractData *d)
It converts an Boolean data value to a char data value.
SimpleData< boost::uint64_t, UINT64_TYPE > UInt64
Definition: SimpleData.h:224
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
AbstractData * BooleanToInt32Converter(AbstractData *d)
It converts an Boolean data value to a Int32 data value.
A set of function that convert an Boolean type to other types.
SimpleData< double, DOUBLE_TYPE > Double
Definition: SimpleData.h:227
SimpleData< char, CHAR_TYPE > Char
Definition: SimpleData.h:217
SimpleData< boost::uint16_t, UINT16_TYPE > UInt16
Definition: SimpleData.h:220
General enumerations for the data type module.
AbstractData * BooleanToUCharConverter(AbstractData *d)
It converts an Boolean data value to an unsigned char data value.
This file contains several implementations for atomic data types (integers, floats, strings and others).
SimpleData< boost::int16_t, INT16_TYPE > Int16
Definition: SimpleData.h:219
SimpleData< boost::uint32_t, UINT32_TYPE > UInt32
Definition: SimpleData.h:222