[gnote] Do not use boost::lexical_cast if C++11 is supported



commit ffa8dea8f19126acdcb11ac1caf2c72c1d7b39c5
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sat Aug 3 00:59:25 2013 +0300

    Do not use boost::lexical_cast if C++11 is supported

 configure.ac                                       |    2 +-
 src/addins/bugzilla/bugzillanoteaddin.cpp          |    6 ++----
 .../filesystemsyncserviceaddin.cpp                 |    3 +--
 src/addins/statistics/statisticswidget.cpp         |    5 ++---
 src/base/macros.hpp                                |   10 ++++++++++
 src/gnome_keyring/ring.cpp                         |    2 +-
 src/note.cpp                                       |   17 ++++++++---------
 src/notetag.cpp                                    |    9 +++------
 src/preferencesdialog.cpp                          |    3 +--
 src/sharp/timespan.cpp                             |   14 +++++++-------
 src/synchronization/filesystemsyncserver.cpp       |   17 +++++++----------
 src/synchronization/fusesyncserviceaddin.cpp       |    3 +--
 src/synchronization/gnotesyncclient.cpp            |    9 ++++-----
 src/synchronization/syncdialog.cpp                 |    3 +--
 14 files changed, 49 insertions(+), 54 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9e2b355..a5b1614 100644
--- a/configure.ac
+++ b/configure.ac
@@ -89,7 +89,6 @@ PKG_CHECK_MODULES(LIBSECRET, [libsecret-1 >= $LIBSECRET_VERSION])
 
 BOOST_REQUIRE([$BOOST_VERSION])
 BOOST_BIND
-BOOST_CONVERSION
 BOOST_FOREACH
 BOOST_FORMAT
 BOOST_TEST([s])
@@ -102,6 +101,7 @@ if test $HAVE_CXX11 == 1; then
   cxx11_support="yes";
 else
   cxx11_support="no";
+  BOOST_CONVERSION
 fi
 
 
diff --git a/src/addins/bugzilla/bugzillanoteaddin.cpp b/src/addins/bugzilla/bugzillanoteaddin.cpp
index 8cb34fe..ddb3647 100644
--- a/src/addins/bugzilla/bugzillanoteaddin.cpp
+++ b/src/addins/bugzilla/bugzillanoteaddin.cpp
@@ -21,8 +21,6 @@
 
 
 
-#include <boost/lexical_cast.hpp>
-
 #include <glib.h>
 
 
@@ -141,7 +139,7 @@ namespace bugzilla {
 
     if(re->match(uriString, match_info) && match_info.get_match_count() >= 3) {
       try {
-        int bugId = boost::lexical_cast<int>(match_info.fetch(2));
+        int bugId = STRING_TO_INT(match_info.fetch(2));
 
         if (insert_bug (x, y, uriString, bugId)) {
           context->drag_finish(true, false, time);
@@ -173,7 +171,7 @@ namespace bugzilla {
       get_window()->editor()->get_iter_at_location(cursor, x, y);
       buffer->place_cursor (cursor);
 
-      std::string string_id = boost::lexical_cast<std::string>(id);
+      std::string string_id = TO_STRING(id);
       buffer->undoer().add_undo_action (new InsertBugAction (cursor, 
                                                              string_id, 
                                                              link_tag));
diff --git a/src/addins/filesystemsyncservice/filesystemsyncserviceaddin.cpp 
b/src/addins/filesystemsyncservice/filesystemsyncserviceaddin.cpp
index 36c9d96..e16b052 100644
--- a/src/addins/filesystemsyncservice/filesystemsyncserviceaddin.cpp
+++ b/src/addins/filesystemsyncservice/filesystemsyncserviceaddin.cpp
@@ -21,7 +21,6 @@
 #include <fstream>
 #include <stdexcept>
 
-#include <boost/lexical_cast.hpp>
 #include <glibmm/i18n.h>
 #include <gtkmm/label.h>
 #include <gtkmm/table.h>
@@ -151,7 +150,7 @@ bool FileSystemSyncServiceAddin::save_configuration()
 
     // Get unique new file name
     while(sharp::file_exists(testPath)) {
-      testPath = testPathBase + boost::lexical_cast<std::string>(++count);
+      testPath = testPathBase + TO_STRING(++count);
     }
 
     // Test ability to create and write
diff --git a/src/addins/statistics/statisticswidget.cpp b/src/addins/statistics/statisticswidget.cpp
index 2b467c4..495461f 100644
--- a/src/addins/statistics/statisticswidget.cpp
+++ b/src/addins/statistics/statisticswidget.cpp
@@ -19,7 +19,6 @@
 
 
 #include <boost/format.hpp>
-#include <boost/lexical_cast.hpp>
 
 #include <glibmm/i18n.h>
 #include <gtkmm/treestore.h>
@@ -91,13 +90,13 @@ private:
       Gtk::TreeIter iter = append();
       std::string stat = _("Total Notes:");
       iter->set_value(0, stat);
-      iter->set_value(1, boost::lexical_cast<std::string>(notes.size()));
+      iter->set_value(1, TO_STRING(notes.size()));
 
       Glib::RefPtr<Gtk::TreeModel> notebooks = gnote::notebooks::NotebookManager::obj().get_notebooks();
       iter = append();
       stat = _("Total Notebooks:");
       iter->set_value(0, stat);
-      iter->set_value(1, boost::lexical_cast<std::string>(notebooks->children().size()));
+      iter->set_value(1, TO_STRING(notebooks->children().size()));
 
       Gtk::TreeIter notebook = notebooks->children().begin();
       std::map<gnote::notebooks::Notebook::Ptr, int> notebook_notes;
diff --git a/src/base/macros.hpp b/src/base/macros.hpp
index 16e4b7b..0220587 100644
--- a/src/base/macros.hpp
+++ b/src/base/macros.hpp
@@ -29,6 +29,11 @@
 #ifndef __BASE_MACROS_
 #define __BASE_MACROS_
 
+#if __cplusplus < 201103L
+  #include <boost/lexical_cast.hpp>
+#else
+  #include <string>
+#endif
 
 #if __GNUC__
 #define _PRINTF_FORMAT(f,a) \
@@ -41,6 +46,11 @@
 #if __cplusplus < 201103L
   #define final
   #define override
+  #define TO_STRING(x) boost::lexical_cast<std::string>(x)
+  #define STRING_TO_INT(x) boost::lexical_cast<int>(x)
+#else
+  #define TO_STRING(x) std::to_string(x)
+  #define STRING_TO_INT(x) std::stoi(x)
 #endif
 
 #endif
diff --git a/src/gnome_keyring/ring.cpp b/src/gnome_keyring/ring.cpp
index e9eaaab..277a1da 100644
--- a/src/gnome_keyring/ring.cpp
+++ b/src/gnome_keyring/ring.cpp
@@ -19,7 +19,7 @@
 
 
 
-#include <boost/lexical_cast.hpp>
+#include <cstring>
 
 #include "keyringexception.hpp"
 #include "ring.hpp"
diff --git a/src/note.cpp b/src/note.cpp
index 8c3e5eb..b82d506 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -28,7 +28,6 @@
 
 #include <boost/format.hpp>
 #include <boost/bind.hpp>
-#include <boost/lexical_cast.hpp>
 #include <boost/algorithm/string/find.hpp>
 
 #include <libxml/parser.h>
@@ -1200,16 +1199,16 @@ namespace gnote {
             sharp::XmlConvert::to_date_time (xml.read_string());
         }
         else if(name == "cursor-position") {
-          note->set_cursor_position(boost::lexical_cast<int>(xml.read_string()));
+          note->set_cursor_position(STRING_TO_INT(xml.read_string()));
         }
         else if(name == "selection-bound-position") {
-          note->set_selection_bound_position(boost::lexical_cast<int>(xml.read_string()));
+          note->set_selection_bound_position(STRING_TO_INT(xml.read_string()));
         }
         else if(name == "width") {
-          note->width() = boost::lexical_cast<int>(xml.read_string());
+          note->width() = STRING_TO_INT(xml.read_string());
         }
         else if(name == "height") {
-          note->height() = boost::lexical_cast<int>(xml.read_string());
+          note->height() = STRING_TO_INT(xml.read_string());
         }
         else if(name == "tags") {
           xmlDocPtr doc2 = xmlParseDoc((const xmlChar*)xml.read_outer_xml().c_str());
@@ -1335,19 +1334,19 @@ namespace gnote {
     }
 
     xml.write_start_element ("", "cursor-position", "");
-    xml.write_string (boost::lexical_cast<std::string>(note.cursor_position()));
+    xml.write_string(TO_STRING(note.cursor_position()));
     xml.write_end_element ();
 
     xml.write_start_element("", "selection-bound-position", "");
-    xml.write_string(boost::lexical_cast<std::string>(note.selection_bound_position()));
+    xml.write_string(TO_STRING(note.selection_bound_position()));
     xml.write_end_element();
 
     xml.write_start_element ("", "width", "");
-    xml.write_string (boost::lexical_cast<std::string>(note.width()));
+    xml.write_string(TO_STRING(note.width()));
     xml.write_end_element ();
 
     xml.write_start_element("", "height", "");
-    xml.write_string(boost::lexical_cast<std::string>(note.height()));
+    xml.write_string(TO_STRING(note.height()));
     xml.write_end_element();
 
     if (note.tags().size() > 0) {
diff --git a/src/notetag.cpp b/src/notetag.cpp
index 8629af4..4130019 100644
--- a/src/notetag.cpp
+++ b/src/notetag.cpp
@@ -20,8 +20,6 @@
 
 
 
-#include <boost/lexical_cast.hpp>
-
 #include <gtk/gtk.h>
 #include <gtkmm/image.h>
 
@@ -350,8 +348,8 @@ namespace gnote {
   }
   
   DepthNoteTag::DepthNoteTag(int depth, Pango::Direction direction)
-    : NoteTag("depth:" + boost::lexical_cast<std::string>(depth) 
-              + ":" + boost::lexical_cast<std::string>((int)direction))
+    : NoteTag("depth:" + TO_STRING(depth) 
+              + ":" + TO_STRING((int)direction))
     , m_depth(depth)
     , m_direction(direction)
   {
@@ -573,8 +571,7 @@ namespace gnote {
 
   DepthNoteTag::Ptr NoteTagTable::get_depth_tag(int depth, Pango::Direction direction)
   {
-    std::string name = "depth:" + boost::lexical_cast<std::string>(depth) 
-      + ":" + boost::lexical_cast<std::string>((int)direction);
+    std::string name = "depth:" + TO_STRING(depth) + ":" + TO_STRING((int)direction);
 
     DepthNoteTag::Ptr tag = DepthNoteTag::Ptr::cast_dynamic(lookup(name));
 
diff --git a/src/preferencesdialog.cpp b/src/preferencesdialog.cpp
index 382b69f..1367c5d 100644
--- a/src/preferencesdialog.cpp
+++ b/src/preferencesdialog.cpp
@@ -27,7 +27,6 @@
 
 #include <boost/bind.hpp>
 #include <boost/format.hpp>
-#include <boost/lexical_cast.hpp>
 
 #include <glibmm/i18n.h>
 #include <gtkmm/accelgroup.h>
@@ -1048,7 +1047,7 @@ namespace gnote {
     PangoFontDescription *desc = pango_font_description_from_string(font_desc.c_str());
 
     // Set the size label
-    font_size->set_text(boost::lexical_cast<std::string>(pango_font_description_get_size(desc) / 
PANGO_SCALE));
+    font_size->set_text(TO_STRING(pango_font_description_get_size(desc) / PANGO_SCALE));
 
     pango_font_description_unset_fields(desc, PANGO_FONT_MASK_SIZE);
 
diff --git a/src/sharp/timespan.cpp b/src/sharp/timespan.cpp
index 8bb1a4f..f319e75 100644
--- a/src/sharp/timespan.cpp
+++ b/src/sharp/timespan.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012 Aurimas Cernius
+ * Copyright (C) 2012-2013 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,8 +19,8 @@
 
 
 #include <boost/format.hpp>
-#include <boost/lexical_cast.hpp>
 
+#include "base/macros.hpp"
 #include "string.hpp"
 #include "timespan.hpp"
 
@@ -112,11 +112,11 @@ namespace sharp {
     if(tokens.size() != 5) {
       return TimeSpan(0, 0, 0, 0, 0);
     }
-    int days = boost::lexical_cast<int>(tokens[0]);
-    int hours = boost::lexical_cast<int>(tokens[1]);
-    int mins = boost::lexical_cast<int>(tokens[2]);
-    int secs = boost::lexical_cast<int>(tokens[3]);
-    int usecs = boost::lexical_cast<int>(tokens[4]);
+    int days = STRING_TO_INT(tokens[0]);
+    int hours = STRING_TO_INT(tokens[1]);
+    int mins = STRING_TO_INT(tokens[2]);
+    int secs = STRING_TO_INT(tokens[3]);
+    int usecs = STRING_TO_INT(tokens[4]);
     boost::format fmt("%1%:%2%:%3%:%4%:%5%");
     fmt % days % hours % mins % secs % usecs;
     if(str(fmt) != s) {
diff --git a/src/synchronization/filesystemsyncserver.cpp b/src/synchronization/filesystemsyncserver.cpp
index 8a0181e..c3b41a5 100644
--- a/src/synchronization/filesystemsyncserver.cpp
+++ b/src/synchronization/filesystemsyncserver.cpp
@@ -23,7 +23,6 @@
 #include <stdexcept>
 
 #include <boost/format.hpp>
-#include <boost/lexical_cast.hpp>
 #include <glibmm/i18n.h>
 
 #include "debug.hpp"
@@ -41,7 +40,7 @@ namespace {
 int str_to_int(const std::string & s)
 {
   try {
-    return boost::lexical_cast<int>(s);
+    return STRING_TO_INT(s);
   }
   catch(...) {
     return 0;
@@ -282,7 +281,7 @@ bool FileSystemSyncServer::commit_sync_transaction()
     try {
       xml->write_start_document();
       xml->write_start_element("", "sync", "");
-      xml->write_attribute_string("", "revision", "", boost::lexical_cast<std::string>(m_new_revision));
+      xml->write_attribute_string("", "revision", "", TO_STRING(m_new_revision));
       xml->write_attribute_string("", "server-id", "", m_server_id);
 
       for(std::map<std::string, std::string>::iterator iter = notes.begin(); iter != notes.end(); ++iter) {
@@ -306,7 +305,7 @@ bool FileSystemSyncServer::commit_sync_transaction()
       for(std::list<std::string>::iterator iter = m_updated_notes.begin(); iter != m_updated_notes.end(); 
++iter) {
         xml->write_start_element("", "note", "");
         xml->write_attribute_string("", "id", "", *iter);
-        xml->write_attribute_string("", "rev", "", boost::lexical_cast<std::string>(m_new_revision));
+        xml->write_attribute_string("", "rev", "", TO_STRING(m_new_revision));
         xml->write_end_element();
       }
 
@@ -423,7 +422,7 @@ int FileSystemSyncServer::latest_revision()
       if(latestRevDir >= 0) {
         directories.clear();
         sharp::directory_get_directories(
-          Glib::build_filename(m_server_path, boost::lexical_cast<std::string>(latestRevDir)),
+          Glib::build_filename(m_server_path, TO_STRING(latestRevDir)),
           directories);
         for(std::list<std::string>::iterator iter = directories.begin(); iter != directories.end(); ++iter) {
           try {
@@ -535,9 +534,7 @@ std::string FileSystemSyncServer::id()
 
 std::string FileSystemSyncServer::get_revision_dir_path(int rev)
 {
-  return Glib::build_filename(m_server_path,
-                              boost::lexical_cast<std::string>(rev/100),
-                              boost::lexical_cast<std::string>(rev));
+  return Glib::build_filename(m_server_path, TO_STRING(rev/100), TO_STRING(rev));
 }
 
 
@@ -557,7 +554,7 @@ void FileSystemSyncServer::update_lock_file(const SyncLockInfo & syncLockInfo)
     xml.write_end_element();
 
     xml.write_start_element("", "renew-count", "");
-    xml.write_string(boost::lexical_cast<std::string>(syncLockInfo.renew_count));
+    xml.write_string(TO_STRING(syncLockInfo.renew_count));
     xml.write_end_element();
 
     xml.write_start_element("", "lock-expiration-duration", "");
@@ -565,7 +562,7 @@ void FileSystemSyncServer::update_lock_file(const SyncLockInfo & syncLockInfo)
     xml.write_end_element();
 
     xml.write_start_element("", "revision", "");
-    xml.write_string(boost::lexical_cast<std::string>(syncLockInfo.revision));
+    xml.write_string(TO_STRING(syncLockInfo.revision));
     xml.write_end_element();
 
     xml.write_end_element();
diff --git a/src/synchronization/fusesyncserviceaddin.cpp b/src/synchronization/fusesyncserviceaddin.cpp
index a5836a8..6112c54 100644
--- a/src/synchronization/fusesyncserviceaddin.cpp
+++ b/src/synchronization/fusesyncserviceaddin.cpp
@@ -20,7 +20,6 @@
 #include <fstream>
 
 #include <boost/format.hpp>
-#include <boost/lexical_cast.hpp>
 #include <glibmm/i18n.h>
 #include <sigc++/signal.h>
 
@@ -134,7 +133,7 @@ bool FuseSyncServiceAddin::save_configuration()
 
       // Get unique new file name
       while(sharp::file_exists(testPath)) {
-        testPath = testPathBase + boost::lexical_cast<std::string>(++count);
+        testPath = testPathBase + TO_STRING(++count);
       }
 
       // Test ability to create and write
diff --git a/src/synchronization/gnotesyncclient.cpp b/src/synchronization/gnotesyncclient.cpp
index 21ed5d1..3046a1d 100644
--- a/src/synchronization/gnotesyncclient.cpp
+++ b/src/synchronization/gnotesyncclient.cpp
@@ -22,7 +22,6 @@
 #define _SYNCHRONIZATION_GNOTESYNCCLIENT_HPP_
 
 
-#include <boost/lexical_cast.hpp>
 #include <glibmm/i18n.h>
 
 #include "debug.hpp"
@@ -86,7 +85,7 @@ namespace sync {
     }
     int revision = -1;
     try {
-      revision = boost::lexical_cast<int>(rev);
+      revision = STRING_TO_INT(rev);
     }
     catch(...) {}
     if(guid != "") {
@@ -158,7 +157,7 @@ namespace sync {
        else if(reader.get_name() == "last-sync-rev") {
          std::string value = reader.read_string();
          try {
-           m_last_sync_rev = boost::lexical_cast<int>(value);
+           m_last_sync_rev = STRING_TO_INT(value);
          }
          catch(...) {
             /* TRANSLATORS: %s is file */
@@ -192,7 +191,7 @@ namespace sync {
       xml.write_end_element();
 
       xml.write_start_element("", "last-sync-rev", "");
-      xml.write_string(boost::lexical_cast<std::string>(m_last_sync_rev));
+      xml.write_string(TO_STRING(m_last_sync_rev));
       xml.write_end_element();
 
       xml.write_start_element("", "server-id", "");
@@ -205,7 +204,7 @@ namespace sync {
           noteGuid != m_file_revisions.end(); ++noteGuid) {
        xml.write_start_element("", "note", "");
        xml.write_attribute_string("", "guid", "", noteGuid->first);
-       xml.write_attribute_string("", "latest-revision", "", 
boost::lexical_cast<std::string>(noteGuid->second));
+       xml.write_attribute_string("", "latest-revision", "", TO_STRING(noteGuid->second));
        xml.write_end_element();
       }
 
diff --git a/src/synchronization/syncdialog.cpp b/src/synchronization/syncdialog.cpp
index e8b3a33..791cdf4 100644
--- a/src/synchronization/syncdialog.cpp
+++ b/src/synchronization/syncdialog.cpp
@@ -22,7 +22,6 @@
 
 #include <boost/bind.hpp>
 #include <boost/format.hpp>
-#include <boost/lexical_cast.hpp>
 #include <glibmm/i18n.h>
 #include <gtkmm/scrolledwindow.h>
 #include <gtkmm/stock.h>
@@ -71,7 +70,7 @@ public:
       std::string suggestedRenameBase = existingNote->get_title() + old;
       std::string suggestedRename = suggestedRenameBase;
       for(int i = 1; !is_note_title_available(suggestedRename); i++) {
-        suggestedRename = suggestedRenameBase + " " + boost::lexical_cast<std::string>(i);
+        suggestedRename = suggestedRenameBase + " " + TO_STRING(i);
       }
 
       Gtk::Grid *outerVBox = manage(new Gtk::Grid);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]