All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
StringConverters.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/StringConverters.cpp
22 
23  \brief A set of function that convert an String type to other types.
24 */
25 
26 // TerraLib
27 #include "../common/Translator.h"
28 #include "Enums.h"
29 #include "Exception.h"
30 #include "StringConverters.h"
31 #include "SimpleData.h"
32 
33 // Boost
34 #include <boost/lexical_cast.hpp>
35 
37 {
38  AssertString(d);
39  return new Int16(boost::lexical_cast<int16_t>(static_cast<const String*>(d)->getValue()));
40 }
41 
43 {
44  AssertString(d);
45  return new UInt16(boost::lexical_cast<uint16_t>(static_cast<const String*>(d)->getValue()));
46 }
47 
49 {
50  AssertString(d);
51  return new Int32(boost::lexical_cast<int32_t>(static_cast<const String*>(d)->getValue()));
52 }
53 
55 {
56  AssertString(d);
57  return new UInt32(boost::lexical_cast<uint32_t>(static_cast<const String*>(d)->getValue()));
58 }
59 
61 {
62  AssertString(d);
63  return new Int64(boost::lexical_cast<int64_t>(static_cast<const String*>(d)->getValue()));
64 }
65 
67 {
68  AssertString(d);
69  return new UInt64(boost::lexical_cast<uint64_t>(static_cast<const String*>(d)->getValue()));
70 }
71 
73 {
74  AssertString(d);
75  return new Float(boost::lexical_cast<float>(static_cast<const String*>(d)->getValue()));
76 }
77 
79 {
80  AssertString(d);
81  return new Double(boost::lexical_cast<double>(static_cast<const String*>(d)->getValue()));
82 }
83 
85 {
86  AssertString(d);
87  return new Numeric(static_cast<const String*>(d)->getValue());
88 }
89 
90 void te::dt::AssertString(AbstractData* d) throw(Exception)
91 {
92  if(d->getTypeCode() != STRING_TYPE)
93  throw Exception(TE_TR("The input data type is not a string!"));
94 }
AbstractData * StringToDoubleConverter(AbstractData *d)
It converts an String data value to a double data value.
AbstractData * StringToUInt32Converter(AbstractData *d)
It converts an String data value to an unsigned Int32 data value.
An exception class for the DataType module.
AbstractData * StringToUInt16Converter(AbstractData *d)
It converts an String data value to an unsigned 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
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
SimpleData< std::string, NUMERIC_TYPE > Numeric
Definition: SimpleData.h:228
AbstractData * StringToFloatConverter(AbstractData *d)
It converts an String data value to a float data value.
AbstractData * StringToInt16Converter(AbstractData *d)
It converts an String data value to a Int16 data value.
void AssertString(AbstractData *d)
Auxiliary method that asserts that the given data is an String type.
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 * StringToInt64Converter(AbstractData *d)
It converts an String data value to a Int64 data value.
SimpleData< double, DOUBLE_TYPE > Double
Definition: SimpleData.h:227
SimpleData< boost::uint16_t, UINT16_TYPE > UInt16
Definition: SimpleData.h:220
General enumerations for the data type module.
AbstractData * StringToInt32Converter(AbstractData *d)
It converts an String data value to a Int32 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
A set of function that convert an String type to other types.
AbstractData * StringToUInt64Converter(AbstractData *d)
It converts an String data value to an unsigned Int64 data value.
SimpleData< boost::uint32_t, UINT32_TYPE > UInt32
Definition: SimpleData.h:222
AbstractData * StringToNumericConverter(AbstractData *d)
It converts an String data value to a Numeric data value.