]> git.lyx.org Git - lyx.git/blob - src/support/convert.C
MacOSX compile fix.
[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 using lyx::docstring;
23
24 using boost::lexical_cast;
25
26 using std::string;
27
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 lyx::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 lyx::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 lyx::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 lyx::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 unsigned int convert<unsigned int>(string const s)
129 {
130         return strtoul(s.c_str(), 0, 10);
131 }
132
133
134 template<>
135 double convert<double>(string const s)
136 {
137         return strtod(s.c_str(), 0);
138 }
139
140
141 template<>
142 int convert<int>(char const * cptr)
143 {
144         return strtol(cptr, 0, 10);
145 }
146
147
148 template<>
149 double convert<double>(char const * cptr)
150 {
151         return strtod(cptr, 0);
152 }