[Pkg-running-devel] [antpm] 05/41: antpm: convert auto_ptr to unique_ptr, start using C++14 (make_unique)

Kristof Ralovich ralovich-guest at moszumanska.debian.org
Tue Feb 23 21:46:44 UTC 2016


This is an automated email from the git hooks/post-receive script.

ralovich-guest pushed a commit to branch upstream
in repository antpm.

commit 492a3fba86ca92b30853f00dec13db3a0ef1f5a4
Author: RALOVICH, Kristof <tade60 at freemail.hu>
Date:   Sat Oct 10 14:35:07 2015 +0200

    antpm: convert auto_ptr to unique_ptr, start using C++14 (make_unique)
    
    g++ 5.2 does not like it:
    tmp/buildd/antpm-1.17/src/LazySingleton.hpp:68:19: warning: 'template<class> class std::auto_ptr' is deprecated [-Wdeprecated-declarations]
           static std::auto_ptr<T> theObject;
---
 src/CMakeLists.txt               |  2 +-
 src/LazySingleton.hpp            | 15 ++++++---------
 src/Log.hpp                      | 18 +++++++++++++-----
 src/SerialTty.hpp                |  2 +-
 src/SerialUsb.hpp                |  2 +-
 src/antpm-downloader.cpp         |  6 +++---
 src/antpm-fit2gpx.cpp            | 12 +-----------
 src/antpm-usbmon2ant.cpp         | 13 +------------
 src/tests/lq1.cpp                | 15 ++-------------
 src/tests/sm1.cpp                |  9 ++-------
 src/tests/testDateTime.cpp       | 13 +------------
 src/tests/testDeviceSettings.cpp | 11 +----------
 12 files changed, 33 insertions(+), 85 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 43c7397..39c7b9f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -43,7 +43,7 @@ IF(MSVC)
 ENDIF()
 
 IF(CMAKE_COMPILER_IS_GNUCXX)
-  set(CMAKE_CXX_FLAGS                "${CMAKE_CXX_FLAGS} -fpermissive  -fms-extensions -std=c++0x -Wall")
+  set(CMAKE_CXX_FLAGS                "${CMAKE_CXX_FLAGS} -fpermissive  -fms-extensions -std=c++1y -Wall")
   SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O2 -g")
   SET(CMAKE_CXX_FLAGS_RELEASE        "${CMAKE_CXX_FLAGS_RELEASE} -O2")
   set(CMAKE_CXX_FLAGS_DEBUG          "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g3 -ggdb3")
diff --git a/src/LazySingleton.hpp b/src/LazySingleton.hpp
index c9a285d..65ac7f6 100644
--- a/src/LazySingleton.hpp
+++ b/src/LazySingleton.hpp
@@ -43,10 +43,7 @@ namespace antpm
     public:
       virtual    ~ClassInstantiator() {}
     protected:
-      static /*inline*/ T* instantiate();
-
-      // template < class P1 >
-      // static inline T* instantiate(P1 p1);
+      static std::unique_ptr<T> make_unique();
 
       template <class T1, class I1> friend class LazySingleton;
   };
@@ -65,11 +62,11 @@ namespace antpm
       LazySingleton(const LazySingleton<T>&); // no copy ctor
       const LazySingleton<T>& operator= (const LazySingleton<T>&); // no copy assignment
     private:
-      static std::auto_ptr<T> theObject;
+      static std::unique_ptr<T> theObject;
   };
 
   template<class T, class I>
-  std::auto_ptr<T> LazySingleton<T, I>::theObject(0);
+  std::unique_ptr<T> LazySingleton<T, I>::theObject;
 
   template<class T, class I>
   inline T&
@@ -93,10 +90,10 @@ namespace antpm
   {
     lazySingletonTrace();
   
-    if(!theObject.get())
+    if(!theObject)
     {
-      //theObject = std::auto_ptr<T>(create<T>());
-      theObject = std::auto_ptr<T>(I::instantiate());
+      // NOTE: not thread safe!
+      theObject = I::make_unique();
     }
 
     return theObject.get();
diff --git a/src/Log.hpp b/src/Log.hpp
index abb3639..3936cf5 100644
--- a/src/Log.hpp
+++ b/src/Log.hpp
@@ -108,9 +108,8 @@ namespace antpm
     : public ClassInstantiator<Log>
     , public LazySingleton<Log, Log>
   {
-  protected:
-    inline Log(const char* logFileName = NULL);
   public:
+    inline Log(const char* logFileName = nullptr);
     inline virtual ~Log();
 
 #ifdef __GNUC__
@@ -157,9 +156,6 @@ namespace antpm
     std::ofstream _ofs;
     SinkList      _sinks;
     LogLevel      _logReportingLevel;
-
-
-    friend class antpm::ClassInstantiator<Log>;
   };
 
   Log::Log(const char* logFileName)
@@ -370,3 +366,15 @@ namespace antpm
 //#define log(level) psoLog(level)
 
 }
+
+#define DEFAULT_LOG_INSTANTIATOR                \
+  namespace antpm {                             \
+  template<>                                    \
+  std::unique_ptr<Log>                          \
+  ClassInstantiator<Log>::make_unique()         \
+  {                                             \
+    return std::move(std::make_unique<Log>());  \
+  }                                             \
+  }
+    
+
diff --git a/src/SerialTty.hpp b/src/SerialTty.hpp
index 897d797..d98ae2c 100644
--- a/src/SerialTty.hpp
+++ b/src/SerialTty.hpp
@@ -59,7 +59,7 @@ private:
   void queueData();
 
 private:
-  std::auto_ptr<SerialTtyPrivate> m_p;
+  std::unique_ptr<SerialTtyPrivate> m_p;
 };
 
 }
diff --git a/src/SerialUsb.hpp b/src/SerialUsb.hpp
index e33874f..016c2a2 100644
--- a/src/SerialUsb.hpp
+++ b/src/SerialUsb.hpp
@@ -49,7 +49,7 @@ public:
   virtual bool         setWriteDelay(const size_t ms);
 
 private:
-  std::auto_ptr<SerialUsbPrivate> m_p;
+  std::unique_ptr<SerialUsbPrivate> m_p;
 };
 
 }
diff --git a/src/antpm-downloader.cpp b/src/antpm-downloader.cpp
index a2a0686..5327a92 100644
--- a/src/antpm-downloader.cpp
+++ b/src/antpm-downloader.cpp
@@ -46,12 +46,12 @@ namespace antpm
 {
 
 template<>
-Log*
-ClassInstantiator<Log>::instantiate()
+std::unique_ptr<Log>
+ClassInstantiator<Log>::make_unique()
 {
   mkDirNoLog(getConfigFolder().c_str());
   std::string l=getConfigFolder() + "/antpm_" + getDateString() + ".txt";
-  return new Log(l.c_str());
+  return std::move(std::make_unique<Log>(l.c_str()));
 }
 
 }
diff --git a/src/antpm-fit2gpx.cpp b/src/antpm-fit2gpx.cpp
index c5974f1..75e33c3 100644
--- a/src/antpm-fit2gpx.cpp
+++ b/src/antpm-fit2gpx.cpp
@@ -37,17 +37,7 @@ using namespace std;
 using namespace antpm;
 
 
-namespace antpm
-{
-
-template<>
-Log*
-ClassInstantiator<Log>::instantiate()
-{
-  return new Log(NULL);
-}
-
-}
+DEFAULT_LOG_INSTANTIATOR
 
 const
 std::vector<fs::path>
diff --git a/src/antpm-usbmon2ant.cpp b/src/antpm-usbmon2ant.cpp
index 68e4192..1bccc7e 100644
--- a/src/antpm-usbmon2ant.cpp
+++ b/src/antpm-usbmon2ant.cpp
@@ -33,18 +33,7 @@ namespace po = boost::program_options;
 using namespace std;
 using namespace antpm;
 
-namespace antpm
-{
-
-template<>
-Log*
-ClassInstantiator<Log>::instantiate()
-{
-  return new Log(NULL);
-}
-
-}
-
+DEFAULT_LOG_INSTANTIATOR
 
 int
 main(int argc, char** argv)
diff --git a/src/tests/lq1.cpp b/src/tests/lq1.cpp
index 5fafdbd..2acf880 100644
--- a/src/tests/lq1.cpp
+++ b/src/tests/lq1.cpp
@@ -39,25 +39,14 @@ using namespace antpm;
 
 
 
-namespace antpm
-{
-
-template<>
-Log*
-ClassInstantiator<Log>::instantiate()
-{
-  return new Log(NULL);
-}
-
-}
-
+DEFAULT_LOG_INSTANTIATOR
 
 struct Producer
 {
   lqueue2<int> _q;
 
   lqueue3<int> q;
-  std::auto_ptr<boost::thread> q_th;
+  std::unique_ptr<boost::thread> q_th;
 
   lqueue3_bg<double> q_bg;
   volatile bool die;
diff --git a/src/tests/sm1.cpp b/src/tests/sm1.cpp
index b49dc85..5052db8 100644
--- a/src/tests/sm1.cpp
+++ b/src/tests/sm1.cpp
@@ -187,16 +187,11 @@ BOOST_AUTO_TEST_CASE(test_asio)
 //# error Local sockets not available on this platform.
 #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
 
+DEFAULT_LOG_INSTANTIATOR
+
 namespace antpm
 {
 
-  template<>
-  Log*
-    ClassInstantiator<Log>::instantiate()
-  {
-    return new Log(NULL);
-  }
-
   class SerialTester0 : public Serial
   {
   public:
diff --git a/src/tests/testDateTime.cpp b/src/tests/testDateTime.cpp
index a60e272..dee06b7 100644
--- a/src/tests/testDateTime.cpp
+++ b/src/tests/testDateTime.cpp
@@ -44,18 +44,7 @@ using namespace std;
 using namespace antpm;
 namespace fs = boost::filesystem;
 
-namespace antpm
-{
-
-template<>
-Log*
-ClassInstantiator<Log>::instantiate()
-{
-  return new Log(NULL);
-}
-
-}
-
+DEFAULT_LOG_INSTANTIATOR
 
 BOOST_AUTO_TEST_CASE(load_fit_date)
 {
diff --git a/src/tests/testDeviceSettings.cpp b/src/tests/testDeviceSettings.cpp
index 4117d1e..ae79cbb 100644
--- a/src/tests/testDeviceSettings.cpp
+++ b/src/tests/testDeviceSettings.cpp
@@ -43,17 +43,8 @@ using namespace std;
 using namespace antpm;
 
 
-namespace antpm
-{
+DEFAULT_LOG_INSTANTIATOR
 
-template<>
-Log*
-ClassInstantiator<Log>::instantiate()
-{
-  return new Log(NULL);
-}
-
-}
 
 BOOST_AUTO_TEST_CASE( free_test_function )
 {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-running/antpm.git



More information about the Pkg-running-devel mailing list