1 #pragma once
2
3 #ifndef TCONVERT_INCLUDED
4 #define TCONVERT_INCLUDED
5
6 #include "tcommon.h"
7 class TFilePath;
8
9 //
10 // Nota: il file tconvert.cpp esiste gia' in rop.
11 // l'implementazione di queste funzioni si trova in tstring.cpp
12 //
13
14 #undef DVAPI
15 #ifdef TNZCORE_EXPORTS // TNZCORE_DLL
16 #define DVAPI DV_EXPORT_API
17 #else
18 #define DVAPI DV_IMPORT_API
19 #endif
20
21 DVAPI bool isInt(std::string s);
22 DVAPI bool isDouble(std::string s);
23
24 DVAPI std::string to_string(double v, int prec);
25 DVAPI std::string to_string(std::wstring s);
26 DVAPI std::string to_string(const TFilePath &fp);
27 DVAPI std::string to_string(void *p);
28
29 DVAPI bool isInt(std::wstring s);
30 DVAPI bool isDouble(std::wstring s);
31
32 DVAPI std::wstring to_wstring(std::string s);
33
fromStr(int & v,std::string s)34 inline bool fromStr(int &v, std::string s) {
35 if (isInt(s)) {
36 v = std::stoi(s);
37 return true;
38 } else
39 return false;
40 }
41
fromStr(double & v,std::string s)42 inline bool fromStr(double &v, std::string s) {
43 if (isDouble(s)) {
44 v = std::stod(s);
45 return true;
46 } else
47 return false;
48 }
49
fromStr(std::string & out,std::string s)50 inline bool fromStr(std::string &out, std::string s) {
51 out = s;
52 return true;
53 }
54
55 DVAPI std::string toUpper(std::string a);
56 DVAPI std::string toLower(std::string a);
57
58 DVAPI std::wstring toUpper(std::wstring a);
59 DVAPI std::wstring toLower(std::wstring a);
60
61 #ifndef TNZCORE_LIGHT
62 #include <QString>
63
fromStr(int & v,QString s)64 inline bool fromStr(int &v, QString s) {
65 bool ret;
66 v = s.toInt(&ret);
67 return ret;
68 }
69
fromStr(double & v,QString s)70 inline bool fromStr(double &v, QString s) {
71 bool ret;
72 v = s.toDouble(&ret);
73 return ret;
74 }
75
76 #endif
77
78 #endif
79