diff options
author | Kozoriz <kozorizandriy@gmail.com> | 2016-04-11 16:42:45 +0300 |
---|---|---|
committer | Kozoriz <kozorizandriy@gmail.com> | 2016-04-25 12:15:47 +0300 |
commit | 48f4d233ec6ee321292187df48f0adbfe1e3a52e (patch) | |
tree | 329e61f56fad01a07bc8cbcf9b2824fa7bf006e7 /src/components/include | |
parent | c162d521ccb09d956d14c76f875a5b774223348a (diff) | |
download | sdl_core-48f4d233ec6ee321292187df48f0adbfe1e3a52e.tar.gz |
Utils, Resumption, Security correctives after singletons removing
Diffstat (limited to 'src/components/include')
-rw-r--r-- | src/components/include/utils/make_shared.h | 38 | ||||
-rw-r--r-- | src/components/include/utils/shared_ptr.h | 31 |
2 files changed, 63 insertions, 6 deletions
diff --git a/src/components/include/utils/make_shared.h b/src/components/include/utils/make_shared.h index dc817e362d..665344737c 100644 --- a/src/components/include/utils/make_shared.h +++ b/src/components/include/utils/make_shared.h @@ -69,6 +69,43 @@ SharedPtr<T> MakeShared() { } template<typename T, typename Arg1> +SharedPtr<T> MakeShared(Arg1& arg1) { + T* t = new (std::nothrow) T(arg1); + return Initialize(t); +} + +template<typename T, typename Arg1, typename Arg2> +SharedPtr<T> MakeShared(Arg1& arg1, Arg2& arg2) { + T* t = new (std::nothrow) T(arg1, arg2); + return Initialize(t); +} + +template<typename T, typename Arg1, typename Arg2, typename Arg3> +SharedPtr<T> MakeShared(Arg1& arg1, Arg2& arg2, Arg3& arg3) { + T* t = new (std::nothrow) T(arg1, arg2, arg3); + return Initialize(t); +} + +template<typename T, typename Arg1, typename Arg2, typename Arg3, typename Arg4> +SharedPtr<T> MakeShared(Arg1& arg1, Arg2& arg2, Arg3& arg3, Arg4& arg4) { + T* t = new (std::nothrow) T(arg1, arg2, arg3, arg4); + return Initialize(t); +} + +template<typename T, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> +SharedPtr<T> MakeShared(Arg1& arg1, Arg2& arg2, Arg3& arg3, Arg4& arg4, Arg5& arg5) { + T* t = new (std::nothrow) T(arg1, arg2, arg3, arg4, arg5); + return Initialize(t); +} + +template<typename T, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6> +SharedPtr<T> MakeShared(Arg1& arg1, Arg2& arg2, Arg3& arg3, Arg4& arg4, Arg5& arg5, Arg6& arg6) { + T* t = new (std::nothrow) T(arg1, arg2, arg3, arg4, arg5, arg6); + return Initialize(t); +} + + +template<typename T, typename Arg1> SharedPtr<T> MakeShared(const Arg1& arg1) { T* t = new (std::nothrow) T(arg1); return Initialize(t); @@ -104,5 +141,6 @@ SharedPtr<T> MakeShared(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, co return Initialize(t); } + } // namespace utils; #endif // SRC_COMPONENTS_INCLUDE_UTILS_MAKE_SHARED_H_ diff --git a/src/components/include/utils/shared_ptr.h b/src/components/include/utils/shared_ptr.h index d8701eb1f3..a8afd93d19 100644 --- a/src/components/include/utils/shared_ptr.h +++ b/src/components/include/utils/shared_ptr.h @@ -41,6 +41,9 @@ #include "utils/atomic.h" namespace utils { + + + /** * @brief Shared pointer. * @@ -52,9 +55,13 @@ namespace utils { **/ template<typename ObjectType> class SharedPtr { + static void DummyDeleter(ObjectType* t) { + delete t; + } public: //std smart pointer compatibility typedef ObjectType element_type; + typedef void (*Deleter)(ObjectType*) ; /** * @brief Constructor. * @@ -65,6 +72,13 @@ class SharedPtr { **/ SharedPtr(ObjectType* Object); + SharedPtr(ObjectType* Object, Deleter deleter): + mObject(Object), + mReferenceCounter(new uint32_t(1)), + deleter_(deleter) { + + } + SharedPtr(); /** @@ -198,18 +212,21 @@ class SharedPtr { **/ ObjectType* mObject; + /** * @brief Pointer to reference counter. **/ uint32_t* mReferenceCounter; + Deleter deleter_; void release(); }; template<typename ObjectType> inline utils::SharedPtr<ObjectType>::SharedPtr(ObjectType* Object) : mObject(NULL), - mReferenceCounter(new uint32_t(1)) { + mReferenceCounter(new uint32_t(1)), + deleter_(DummyDeleter) { DCHECK(Object != NULL); mObject = Object; } @@ -217,14 +234,16 @@ inline utils::SharedPtr<ObjectType>::SharedPtr(ObjectType* Object) template<typename ObjectType> inline utils::SharedPtr<ObjectType>::SharedPtr() : mObject(0), - mReferenceCounter(0) { + mReferenceCounter(0), + deleter_(DummyDeleter) { } template<typename ObjectType> inline utils::SharedPtr<ObjectType>::SharedPtr( const SharedPtr<ObjectType>& Other) : mObject(0), - mReferenceCounter(0) { + mReferenceCounter(0), + deleter_(DummyDeleter) { *this = Other; } @@ -233,7 +252,8 @@ template<typename OtherObjectType> inline utils::SharedPtr<ObjectType>::SharedPtr( const SharedPtr<OtherObjectType>& Other) : mObject(0), - mReferenceCounter(0) { + mReferenceCounter(0), + deleter_(DummyDeleter) { *this = Other; } @@ -337,8 +357,7 @@ utils::SharedPtr<ObjectType>::reset(ObjectType* other) { template<typename ObjectType> void SharedPtr<ObjectType>::release() { - - delete mObject; + deleter_(mObject); mObject = 0; delete mReferenceCounter; |