]> git.lyx.org Git - lyx.git/blob - src/support/convert.C
Add operator+ for ASCII characters and ASCII C strings
[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 template<>
57 docstring convert<docstring>(int i)
58 {
59         return lyx::from_ascii(lexical_cast<string>(i));
60 }
61
62 template<>
63 string convert<string>(unsigned int ui)
64 {
65         return lexical_cast<string>(ui);
66 }
67
68
69 template<>
70 string convert<string>(unsigned long ul)
71 {
72         return lexical_cast<string>(ul);
73 }
74
75
76 template<>
77 string convert<string>(long l)
78 {
79         return lexical_cast<string>(l);
80 }
81
82
83 template<>
84 string convert<string>(float f)
85 {
86         return lexical_cast<string>(f);
87 }
88
89
90 template<>
91 string convert<string>(double d)
92 {
93         return lexical_cast<string>(d);
94 }
95
96
97 template<>
98 int convert<int>(string const s)
99 {
100         return strtol(s.c_str(), 0, 10);
101 }
102
103
104 template<>
105 unsigned int convert<unsigned int>(string const s)
106 {
107         return strtoul(s.c_str(), 0, 10);
108 }
109
110
111 template<>
112 double convert<double>(string const s)
113 {
114         return strtod(s.c_str(), 0);
115 }
116
117
118 template<>
119 int convert<int>(char const * cptr)
120 {
121         return strtol(cptr, 0, 10);
122 }
123
124
125 template<>
126 double convert<double>(char const * cptr)
127 {
128         return strtod(cptr, 0);
129 }