OpenASIP 2.2
Loading...
Searching...
No Matches
Conversion.hh
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file Conversion.hh
26 *
27 * Conversion static class contains functions for converting between
28 * different types, e.g. from any (possible) type to a string.
29 *
30 * Declarations.
31 *
32 * @author Pekka Jääskeläinen 2003 (pjaaskel-no.spam-cs.tut.fi)
33 *
34 */
35
36#ifndef TTA_CONVERSION_HH
37#define TTA_CONVERSION_HH
38
39#include <string>
40#include <iostream>
41
42#include <xercesc/util/XMLString.hpp>
43
44
45#include "Exception.hh"
46#include "BaseType.hh"
47
48#if _XERCES_VERSION >= 20200
49XERCES_CPP_NAMESPACE_USE
50#endif
51
53public:
54 template <typename T>
55 static std::string toString(const T& source);
56 static std::string toString(double source, unsigned precision);
57 static std::string toString(bool source);
58
59 static std::string XMLChToString(const XMLCh* source);
60 static XMLCh* toXMLCh(const std::string& string);
61
62 template <typename T>
63 static int toInt(const T& source);
64
65 template <typename T>
66 static SLongWord toLong(const T& source);
67
68 static int toInt(const double& source);
69
70 static SLongWord toLong(const double& source);
71
72 template <typename T>
73 static unsigned int toUnsignedInt(const T& source);
74
75 template <typename T>
76 static ULongWord toUnsignedLong(const T& source);
77
78 template <typename T>
79 static double toDouble(const T& source);
80
81 template <typename T>
82 static float toFloat(const T& source);
83
84 static std::string toBinString(int source);
85 static std::string toBinString(double source);
86 static std::string toBinary(
87 unsigned int source,
88 unsigned int stringWidth = 0);
89
90 template <typename T>
91 static std::string toHexString(
92 T source, std::size_t digits = 0, bool include0x = true);
93 static std::string floatToHexString(float source, bool include0x = true);
94 static std::string doubleToHexString(double source, bool include0x = true);
95
96 static void toRawData(
97 const std::string& hexSource, unsigned char* target);
98
99private:
100 template <typename SourceType, typename DestType, bool destIsNumeric>
101 static void convert(const SourceType& source, DestType& dest);
102
103 static bool restWhiteSpace(std::istream& str);
104};
105#include "Conversion.icc"
106
107#endif
unsigned long ULongWord
Definition BaseType.hh:51
long SLongWord
Definition BaseType.hh:52
static std::string toBinString(int source)
Definition Conversion.cc:81
static std::string XMLChToString(const XMLCh *source)
static SLongWord toLong(const T &source)
static float toFloat(const T &source)
static std::string floatToHexString(float source, bool include0x=true)
static void toRawData(const std::string &hexSource, unsigned char *target)
static std::string doubleToHexString(double source, bool include0x=true)
static std::string toHexString(T source, std::size_t digits=0, bool include0x=true)
static std::string toBinary(unsigned int source, unsigned int stringWidth=0)
static double toDouble(const T &source)
static std::string toString(double source, unsigned precision)
static std::string toString(const T &source)
static std::string toString(bool source)
static XMLCh * toXMLCh(const std::string &string)
static int toInt(const double &source)
static int toInt(const T &source)
static bool restWhiteSpace(std::istream &str)
Definition Conversion.cc:57
static SLongWord toLong(const double &source)
static ULongWord toUnsignedLong(const T &source)
static unsigned int toUnsignedInt(const T &source)
static void convert(const SourceType &source, DestType &dest)