summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libadhocutil/cache.impl.h10
-rw-r--r--libadhocutil/globalStatic.h5
-rw-r--r--libadhocutil/globalStatic.impl.h12
-rw-r--r--libadhocutil/lexer-regex.cpp2
-rw-r--r--libadhocutil/nvpParse.h2
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.