]> git.lyx.org Git - lyx.git/blob - src/support/convert.C
final compilation: wheel was already invented :(
[lyx.git] / src / support / convert.C
1 /**
2  * \file tostr.C
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 "convert.h"
15
16 #include "support/docstring.h"
17
18 #include <boost/lexical_cast.hpp>
19
20 #include <string>
21
22
23 namespace lyx {
24
25 using lyx::docstring;
26
27 using boost::lexical_cast;
28
29 using std::string;
30
31
32 template<>
33 string convert<string>(bool b)
34 {
35         return (b ? "true" : "false");
36 }
37
38
39 template<>
40 string convert<string>(char c)
41 {
42         return string(1, c);
43 }
44
45
46 template<>
47 string convert<string>(short unsigned int sui)
48 {
49         return lexical_cast<string>(sui);
50 }
51
52
53 template<>
54 string convert<string>(int i)
55 {
56         return lexical_cast<string>(i);
57 }
58
59
60 template<>
61 docstring convert<docstring>(int i)
62 {
63         return lyx::from_ascii(lexical_cast<string>(i));
64 }
65
66
67 template<>
68 string convert<string>(unsigned int ui)
69 {
70         return lexical_cast<string>(ui);
71 }
72
73
74 template<>
75 docstring convert<docstring>(unsigned int ui)
76 {
77         return lyx::from_ascii(lexical_cast<string>(ui));
78 }
79
80
81 template<>
82 string convert<string>(unsigned long ul)
83 {
84         return lexical_cast<string>(ul);
85 }
86
87
88 template<>
89 docstring convert<docstring>(unsigned long ul)
90 {
91         return lyx::from_ascii(lexical_cast<string>(ul));
92 }
93
94
95 template<>
96 string convert<string>(long l)
97 {
98         return lexical_cast<string>(l);
99 }
100
101
102 template<>
103 docstring convert<docstring>(long l)
104 {
105         return lyx::from_ascii(lexical_cast<string>(l));
106 }
107
108
109 template<>
110 string convert<string>(float f)
111 {
112         return lexical_cast<string>(f);
113 }
114
115
116 template<>
117 string convert<string>(double d)
118 {
119         return lexical_cast<string>(d);
120 }
121
122
123 template<>
124 int convert<int>(string const s)
125 {
126         return strtol(s.c_str(), 0, 10);
127 }
128
129
130 template<>
131 int convert<int>(docstring const s)
132 {
133         return strtol(lyx::to_ascii(s).c_str(), 0, 10);
134 }
135
136
137 template<>
138 unsigned int convert<unsigned int>(string const s)
139 {
140         return strtoul(s.c_str(), 0, 10);
141 }
142
143
144 template<>
145 double convert<double>(string const s)
146 {
147         return strtod(s.c_str(), 0);
148 }
149
150
151 template<>
152 int convert<int>(char const * cptr)
153 {
154         return strtol(cptr, 0, 10);
155 }
156
157
158 template<>
159 double convert<double>(char const * cptr)
160 {
161         return strtod(cptr, 0);
162 }
163
164
165 } // namespace lyx