]> git.lyx.org Git - lyx.git/blobdiff - src/support/convert.cpp
Use HAVE_LONG_LONG_INT instead of LYX_USE_LONG_LONG
[lyx.git] / src / support / convert.cpp
index 58a56479a3abe377761d8a1afae8da3ace6ff322..9455643a667800f931143c8fd4dc060d1fb533a8 100644 (file)
 
 using namespace std;
 
-namespace lyx {
+namespace {
+
+// A version of lexical cast that does not throw. Useful for when we convert to string
+template<typename To, typename From>
+To lexical_cast(From const & value, To const & defaultResult = To())
+{
+       try {
+               return boost::lexical_cast<To>(value);
+       } catch(...) {
+               // Ignore all exceptions and use default.
+               return defaultResult;
+       }
+}
+
+} // namespace
+
 
-using boost::lexical_cast;
+namespace lyx {
 
 template<>
 string convert<string>(bool b)
@@ -90,7 +105,7 @@ docstring convert<docstring>(unsigned long ul)
 }
 
 
-#ifdef LYX_USE_LONG_LONG
+#ifdef HAVE_LONG_LONG_INT
 template<>
 string convert<string>(unsigned long long ull)
 {
@@ -120,7 +135,7 @@ docstring convert<docstring>(long l)
 }
 
 
-#ifdef LYX_USE_LONG_LONG
+#ifdef HAVE_LONG_LONG_INT
 template<>
 string convert<string>(long long ll)
 {
@@ -154,6 +169,13 @@ string convert<string>(double d)
 }
 
 
+template<>
+docstring convert<docstring>(double d)
+{
+       return from_ascii(convert<string>(d));
+}
+
+
 template<>
 int convert<int>(string const s)
 {