diff options
author | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2019-01-31 17:20:30 +0000 |
---|---|---|
committer | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2019-01-31 17:20:30 +0000 |
commit | 74ab788024c3a740b158c56594ac3d46e53c87b3 (patch) | |
tree | c8451cd04e752116a5cf5ba060578b7768ba2d0a | |
parent | Remove unrequired BOOST_TEST_DONT_PRINT_LOG_VALUE (diff) | |
download | libadhocutil-74ab788024c3a740b158c56594ac3d46e53c87b3.tar.bz2 libadhocutil-74ab788024c3a740b158c56594ac3d46e53c87b3.tar.xz libadhocutil-74ab788024c3a740b158c56594ac3d46e53c87b3.zip |
Remove calls to naked new
-rw-r--r-- | libadhocutil/cache.impl.h | 10 | ||||
-rw-r--r-- | libadhocutil/globalStatic.h | 5 | ||||
-rw-r--r-- | libadhocutil/globalStatic.impl.h | 12 | ||||
-rw-r--r-- | libadhocutil/lexer-regex.cpp | 2 | ||||
-rw-r--r-- | libadhocutil/nvpParse.h | 2 |
5 files changed, 16 insertions, 15 deletions
diff --git a/libadhocutil/cache.impl.h b/libadhocutil/cache.impl.h index 8fdc958..d1929a9 100644 --- a/libadhocutil/cache.impl.h +++ b/libadhocutil/cache.impl.h @@ -19,7 +19,7 @@ Cacheable<T, K>::Cacheable(const K & k, time_t vu) : template<typename T, typename K> ObjectCacheable<T, K>::ObjectCacheable(const T & t, const K & k, time_t vu) : Cacheable<T, K>(k, vu), - value(new T(t)) + value(std::make_shared<T>(t)) { } @@ -90,7 +90,7 @@ void Cache<T, K>::add(const K & k, const T & t, time_t validUntil) { Lock(lock); - cached.insert(Element(new ObjectCacheable<T, K>(t, k, validUntil))); + cached.insert(std::make_shared<ObjectCacheable<T, K>>(t, k, validUntil)); } template<typename T, typename K> @@ -98,7 +98,7 @@ void Cache<T, K>::addPointer(const K & k, Value & t, time_t validUntil) { Lock(lock); - cached.insert(Element(new ObjectCacheable<T, K>(t, k, validUntil))); + cached.insert(std::make_shared<ObjectCacheable<T, K>>(t, k, validUntil)); } template<typename T, typename K> @@ -106,7 +106,7 @@ void Cache<T, K>::addFactory(const K & k, const Factory & tf, time_t validUntil) { Lock(lock); - cached.insert(Element(new CallCacheable<T, K>(tf, k, validUntil))); + cached.insert(std::make_shared<CallCacheable<T, K>>(tf, k, validUntil)); } template<typename T, typename K> @@ -114,7 +114,7 @@ void Cache<T, K>::addPointerFactory(const K & k, const PointerFactory & tf, time_t validUntil) { Lock(lock); - cached.insert(Element(new PointerCallCacheable<T, K>(tf, k, validUntil))); + cached.insert(std::make_shared<PointerCallCacheable<T, K>>(tf, k, validUntil)); } template<typename T, typename K> diff --git a/libadhocutil/globalStatic.h b/libadhocutil/globalStatic.h index d379146..5808551 100644 --- a/libadhocutil/globalStatic.h +++ b/libadhocutil/globalStatic.h @@ -1,6 +1,8 @@ #ifndef ADHOCUTIL_GLOBALSTATIC_H #define ADHOCUTIL_GLOBALSTATIC_H +#include <memory> + namespace AdHoc { /** * Wrapper class for initialising/destroying a global static object via @@ -16,10 +18,11 @@ namespace AdHoc { static Object * get(); private: + typedef std::unique_ptr<Object> Ptr; static void createObject() __attribute__((constructor(101))); static void deleteObject() __attribute__((destructor(101))); - inline static Object * & instance(); + inline static Ptr & instance(); }; } diff --git a/libadhocutil/globalStatic.impl.h b/libadhocutil/globalStatic.impl.h index 2a5cf05..fcd8096 100644 --- a/libadhocutil/globalStatic.impl.h +++ b/libadhocutil/globalStatic.impl.h @@ -7,27 +7,25 @@ namespace AdHoc { template<typename Object> Object * GlobalStatic<Object>::get() { - return instance(); + return instance().get(); } template<typename Object> void GlobalStatic<Object>::createObject() { - instance() = new Object(); + instance() = std::make_unique<Object>(); } template<typename Object> void GlobalStatic<Object>::deleteObject() { - auto & i = instance(); - delete i; - i = nullptr; + instance().reset(); } template<typename Object> - Object * & GlobalStatic<Object>::instance() + typename GlobalStatic<Object>::Ptr & GlobalStatic<Object>::instance() { - static Object * _instance = nullptr; + static Ptr _instance; return _instance; } }; diff --git a/libadhocutil/lexer-regex.cpp b/libadhocutil/lexer-regex.cpp index c283798..9b2be79 100644 --- a/libadhocutil/lexer-regex.cpp +++ b/libadhocutil/lexer-regex.cpp @@ -71,7 +71,7 @@ namespace AdHoc { Lexer::PatternPtr regex(const Glib::ustring & pattern, GRegexCompileFlags compile, GRegexMatchFlags match) { - return Lexer::PatternPtr(new Regex(pattern, compile, match)); + return std::make_shared<Regex>(pattern, compile, match); } } } diff --git a/libadhocutil/nvpParse.h b/libadhocutil/nvpParse.h index ce851a6..3c6b03a 100644 --- a/libadhocutil/nvpParse.h +++ b/libadhocutil/nvpParse.h @@ -61,7 +61,7 @@ class NvpParse : public yyFlexLexer { /// @endcond #define NvpTarget(T) std::map<std::string, std::shared_ptr<::AdHoc::NvpParse::TargetBase<T>>> -#define NvpValue(c, m) { #m, std::shared_ptr<::AdHoc::NvpParse::Target<c, decltype(c::m)>>(new ::AdHoc::NvpParse::Target<c, decltype(c::m)>(&c::m)) } +#define NvpValue(c, m) { #m, std::make_shared<::AdHoc::NvpParse::Target<c, decltype(c::m)>>(&c::m) } /** Parse an input stream into the given object. * @param in The input stream. |