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