File: convert.h

package info (click to toggle)
einstein 2.0.dfsg.2-10
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, trixie
  • size: 2,548 kB
  • sloc: cpp: 10,437; makefile: 78; sh: 1
file content (54 lines) | stat: -rw-r--r-- 1,188 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef __CONVERT_H__
#define __CONVERT_H__


#include <iostream>
#include <sstream>
#include <string>
#include <typeinfo>

#include "exceptions.h"
#include "unicode.h"


/// Convert value to string
/// \param x value
template <typename T>
inline std::wstring toString(const T &x)
{
#ifndef WIN32
    std::wostringstream o;
    if (! (o << x))
        throw Exception(L"Can't convert " + fromMbcs(typeid(x).name())
                + L" to string");
    return o.str();
#else   // Mingw doesn't support std::wostringstream yet :-(
    std::ostringstream o;
    if (! (o << x))
        throw Exception(L"Can't convert " + fromMbcs(typeid(x).name()) 
                + L" to string");
    return fromMbcs(o.str());
#endif
}


/// Convert string to lower case.
std::wstring toLowerCase(const std::wstring &s);

/// Convert string to upper case
std::wstring toUpperCase(const std::wstring &s);

/// Convert integer to string.
std::wstring numToStr(int num);

/// Convert unsigned integer to string.
std::wstring numToStr(unsigned int num);

/// Convert string to integer
int strToInt(const std::wstring &str);

/// Conver string to double
double strToDouble(const std::wstring &str);


#endif