]> git.lyx.org Git - lyx.git/blob - src/support/convert.C
Consistent use of preprocessor guards;
[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 <boost/lexical_cast.hpp>
17
18 #include <string>
19
20 using boost::lexical_cast;
21
22 using std::string;
23
24
25 template<>
26 string convert<string>(bool b)
27 {
28         return (b ? "true" : "false");
29 }
30
31
32 template<>
33 string convert<string>(char c)
34 {
35         return string(1, c);
36 }
37
38
39 template<>
40 string convert<string>(short unsigned int sui)
41 {
42         return lexical_cast<string>(sui);
43 }
44
45
46 template<>
47 string convert<string>(int i)
48 {
49         return lexical_cast<string>(i);
50 }
51
52
53 template<>
54 string convert<string>(unsigned int ui)
55 {
56         return lexical_cast<string>(ui);
57 }
58
59
60 template<>
61 string convert<string>(unsigned long ul)
62 {
63         return lexical_cast<string>(ul);
64 }
65
66
67 template<>
68 string convert<string>(long l)
69 {
70         return lexical_cast<string>(l);
71 }
72
73
74 template<>
75 string convert<string>(float f)
76 {
77         return lexical_cast<string>(f);
78 }
79
80
81 template<>
82 string convert<string>(double d)
83 {
84         return lexical_cast<string>(d);
85 }
86
87
88 template<>
89 int convert<int>(string const s)
90 {
91         return strtol(s.c_str(), 0, 10);
92 }
93
94
95 template<>
96 unsigned int convert<unsigned int>(string const s)
97 {
98         return strtoul(s.c_str(), 0, 10);
99 }
100
101
102 template<>
103 double convert<double>(string const s)
104 {
105         return strtod(s.c_str(), 0);
106 }
107
108
109 template<>
110 int convert<int>(char const * cptr)
111 {
112         return strtol(cptr, 0, 10);
113 }
114
115
116 template<>
117 double convert<double>(char const * cptr)
118 {
119         return strtod(cptr, 0);
120 }