]> git.lyx.org Git - lyx.git/blob - src/support/convert.cpp
Remove unused macros USE_INCLUDED_STRING and STD_STRING_IS_GOOD
[lyx.git] / src / support / convert.cpp
1 /**
2  * \file convert.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "support/convert.h"
15 #include "support/docstring.h"
16
17 #include <boost/lexical_cast.hpp>
18
19 #include <string>
20
21 using namespace std;
22
23 namespace lyx {
24
25 using boost::lexical_cast;
26
27 template<>
28 string convert<string>(bool b)
29 {
30         return (b ? "true" : "false");
31 }
32
33
34 template<>
35 string convert<string>(char c)
36 {
37         return string(1, c);
38 }
39
40
41 template<>
42 string convert<string>(short unsigned int sui)
43 {
44         return lexical_cast<string>(sui);
45 }
46
47
48 template<>
49 string convert<string>(int i)
50 {
51         return lexical_cast<string>(i);
52 }
53
54
55 template<>
56 docstring convert<docstring>(int i)
57 {
58         return from_ascii(lexical_cast<string>(i));
59 }
60
61
62 template<>
63 string convert<string>(unsigned int ui)
64 {
65         return lexical_cast<string>(ui);
66 }
67
68
69 template<>
70 docstring convert<docstring>(unsigned int ui)
71 {
72         return from_ascii(lexical_cast<string>(ui));
73 }
74
75
76 template<>
77 string convert<string>(unsigned long ul)
78 {
79         return lexical_cast<string>(ul);
80 }
81
82
83 template<>
84 docstring convert<docstring>(unsigned long ul)
85 {
86         return from_ascii(lexical_cast<string>(ul));
87 }
88
89
90 template<>
91 string convert<string>(long l)
92 {
93         return lexical_cast<string>(l);
94 }
95
96
97 template<>
98 docstring convert<docstring>(long l)
99 {
100         return from_ascii(lexical_cast<string>(l));
101 }
102
103
104 template<>
105 string convert<string>(float f)
106 {
107         return lexical_cast<string>(f);
108 }
109
110
111 template<>
112 string convert<string>(double d)
113 {
114         return lexical_cast<string>(d);
115 }
116
117
118 template<>
119 int convert<int>(string const s)
120 {
121         return strtol(s.c_str(), 0, 10);
122 }
123
124
125 template<>
126 int convert<int>(docstring const s)
127 {
128         return strtol(to_ascii(s).c_str(), 0, 10);
129 }
130
131
132 template<>
133 unsigned int convert<unsigned int>(string const s)
134 {
135         return strtoul(s.c_str(), 0, 10);
136 }
137
138
139 template<>
140 unsigned long convert<unsigned long>(string const s)
141 {
142         return strtoul(s.c_str(), 0, 10);
143 }
144
145
146 template<>
147 double convert<double>(string const s)
148 {
149         return strtod(s.c_str(), 0);
150 }
151
152
153 template<>
154 int convert<int>(char const * cptr)
155 {
156         return strtol(cptr, 0, 10);
157 }
158
159
160 template<>
161 double convert<double>(char const * cptr)
162 {
163         return strtod(cptr, 0);
164 }
165
166
167 } // namespace lyx