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