[DEV] remove STL
This commit is contained in:
parent
24f752f79b
commit
965b951ee4
@ -26,7 +26,7 @@ ememory::Counter::~Counter() {
|
||||
int64_t ememory::Counter::incrementShared(bool _fromWeak) {
|
||||
int64_t out;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
ethread::UniqueLock lock(m_mutex);
|
||||
EMEMORY_DBG("shared++ (start) ==> w:" << m_counterWeak << " s:" << m_counterShared << " " << int64_t(this));
|
||||
if (m_counterShared != 0 || _fromWeak == false) {
|
||||
m_counterShared++;
|
||||
@ -38,7 +38,7 @@ int64_t ememory::Counter::incrementShared(bool _fromWeak) {
|
||||
}
|
||||
|
||||
ememory::Counter::remove ememory::Counter::decrementShared() {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
ethread::UniqueLock lock(m_mutex);
|
||||
EMEMORY_DBG("shared-- (start) ==> w:" << m_counterWeak << " s:" << m_counterShared << " " << int64_t(this));
|
||||
if (m_counterShared != 0) {
|
||||
m_counterShared--;
|
||||
@ -62,7 +62,7 @@ ememory::Counter::remove ememory::Counter::decrementShared() {
|
||||
int64_t ememory::Counter::incrementWeak() {
|
||||
int64_t out;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
ethread::UniqueLock lock(m_mutex);
|
||||
EMEMORY_DBG("weak++ (start) ==> w:" << m_counterWeak << " s:" << m_counterShared << " " << int64_t(this));
|
||||
m_counterWeak++;
|
||||
out = m_counterWeak;
|
||||
@ -72,7 +72,7 @@ int64_t ememory::Counter::incrementWeak() {
|
||||
}
|
||||
|
||||
ememory::Counter::remove ememory::Counter::decrementWeak() {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
ethread::UniqueLock lock(m_mutex);
|
||||
EMEMORY_DBG("weak-- (stop) ==> w:" << m_counterWeak << " s:" << m_counterShared << " " << int64_t(this));
|
||||
if (m_counterWeak != 0) {
|
||||
m_counterWeak--;
|
||||
@ -92,7 +92,7 @@ ememory::Counter::remove ememory::Counter::decrementWeak() {
|
||||
int64_t ememory::Counter::getCountWeak() const {
|
||||
int64_t out;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
ethread::UniqueLock lock(m_mutex);
|
||||
out = m_counterWeak;
|
||||
}
|
||||
return out;
|
||||
@ -101,7 +101,7 @@ int64_t ememory::Counter::getCountWeak() const {
|
||||
int64_t ememory::Counter::getCountShared() const {
|
||||
int64_t out;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
ethread::UniqueLock lock(m_mutex);
|
||||
out = m_counterShared;
|
||||
}
|
||||
return out;
|
||||
@ -110,7 +110,7 @@ int64_t ememory::Counter::getCountShared() const {
|
||||
int64_t ememory::Counter::getCount() const {
|
||||
int64_t out;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
ethread::UniqueLock lock(m_mutex);
|
||||
out = m_counterWeak + m_counterShared;
|
||||
}
|
||||
return out;
|
||||
|
@ -5,12 +5,13 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <ethread/Mutex.hpp>
|
||||
// define type : uintXX_t and intXX_t
|
||||
#define __STDC_LIMIT_MACROS
|
||||
// note in android include the macro of min max are overwitten
|
||||
#include <cstdint>
|
||||
|
||||
extern "C" {
|
||||
#include <stdint.h>
|
||||
}
|
||||
namespace ememory {
|
||||
/**
|
||||
* @brief Couter is an important part of the SharedPtr/WeakPtr implementation. This use a simple refcounting method dut thread-safe
|
||||
@ -29,7 +30,7 @@ namespace ememory {
|
||||
private:
|
||||
int64_t m_counterShared; //!< Count of the active SharedPtr
|
||||
int64_t m_counterWeak; //!< Count of the active WeakPtr
|
||||
mutable std::mutex m_mutex; //!< local counter mutex to prevent the thread concurent removing
|
||||
mutable ethread::Mutex m_mutex; //!< local counter mutex to prevent the thread concurent removing
|
||||
public:
|
||||
/**
|
||||
* @brief Contructor
|
||||
|
@ -6,7 +6,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <etk/Vector.hpp>
|
||||
#include <mutex>
|
||||
#include <ethread/Mutex.hpp>
|
||||
#include <ememory/SharedPtr.hpp>
|
||||
#include <ememory/WeakPtr.hpp>
|
||||
|
||||
|
@ -5,8 +5,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/Vector.hpp>
|
||||
#include <mutex>
|
||||
#include <etk/Function.hpp>
|
||||
#include <ememory/debug.hpp>
|
||||
#include <ememory/Counter.hpp>
|
||||
#include <ememory/EnableSharedFromThis.hpp>
|
||||
@ -14,7 +13,7 @@
|
||||
namespace ememory {
|
||||
template<typename> class WeakPtr;
|
||||
template<typename> class EnableSharedFromThis;
|
||||
using deleterCall = std::function<void(void* _data)>;
|
||||
using deleterCall = etk::Function<void(void* _data)>;
|
||||
/**
|
||||
* @brief ememory::SharedPtr is a smart pointer that retains shared ownership of an object through a pointer.
|
||||
* Several SharedPtr objects may own the same object. The object is destroyed and its memory deallocated when
|
||||
@ -47,13 +46,13 @@ namespace ememory {
|
||||
public:
|
||||
#ifndef PARSE_DOXYGEN
|
||||
template<class EMEMORY_TYPE2,
|
||||
typename std::enable_if< std::is_same<EMEMORY_TYPE2, EMEMORY_TYPE>::value
|
||||
&& std::is_base_of<ememory::EnableSharedFromThisBase, EMEMORY_TYPE2>::value
|
||||
typename etk::EnableIf< etk::IsSame<EMEMORY_TYPE2, EMEMORY_TYPE>::value
|
||||
&& etk::IsBaseOf<ememory::EnableSharedFromThisBase, EMEMORY_TYPE2>::value
|
||||
, int>::type = 0>
|
||||
SharedPtr(EMEMORY_TYPE2* _element);
|
||||
template<class EMEMORY_TYPE2,
|
||||
typename std::enable_if< std::is_same<EMEMORY_TYPE2, EMEMORY_TYPE>::value
|
||||
&& !std::is_base_of<ememory::EnableSharedFromThisBase, EMEMORY_TYPE2>::value
|
||||
typename etk::EnableIf< etk::IsSame<EMEMORY_TYPE2, EMEMORY_TYPE>::value
|
||||
&& !etk::IsBaseOf<ememory::EnableSharedFromThisBase, EMEMORY_TYPE2>::value
|
||||
, int>::type = 0>
|
||||
SharedPtr(EMEMORY_TYPE2* _element);
|
||||
#else
|
||||
@ -67,7 +66,7 @@ namespace ememory {
|
||||
/**
|
||||
* @brief Contructor on nullptr
|
||||
*/
|
||||
SharedPtr(std::nullptr_t);
|
||||
SharedPtr(etk::NullPtr);
|
||||
/**
|
||||
* @brief Contructor empty
|
||||
*/
|
||||
@ -102,15 +101,15 @@ namespace ememory {
|
||||
* @brief Asignement operator (asign nullptr)
|
||||
* @return Reference on this
|
||||
*/
|
||||
SharedPtr& operator= (std::nullptr_t);
|
||||
SharedPtr& operator= (etk::NullPtr);
|
||||
public:
|
||||
#ifndef PARSE_DOXYGEN
|
||||
template<class EMEMORY_TYPE2,
|
||||
typename std::enable_if< std::is_base_of<EMEMORY_TYPE, EMEMORY_TYPE2>::value
|
||||
typename etk::EnableIf< etk::IsBaseOf<EMEMORY_TYPE, EMEMORY_TYPE2>::value
|
||||
, int>::type = 0>
|
||||
SharedPtr(const SharedPtr<EMEMORY_TYPE2>& _obj);
|
||||
template<class EMEMORY_TYPE2,
|
||||
typename std::enable_if< std::is_base_of<EMEMORY_TYPE, EMEMORY_TYPE2>::value
|
||||
typename etk::EnableIf< etk::IsBaseOf<EMEMORY_TYPE, EMEMORY_TYPE2>::value
|
||||
, int>::type = 0>
|
||||
SharedPtr& operator= (const SharedPtr<EMEMORY_TYPE2>& _obj);
|
||||
#endif
|
||||
@ -128,7 +127,7 @@ namespace ememory {
|
||||
* @brief Check if the SharedPtr have an internal data (not nullptr)
|
||||
* @return true The pointer is not asigned, false otherwise
|
||||
*/
|
||||
bool operator==(std::nullptr_t) const;
|
||||
bool operator==(etk::NullPtr) const;
|
||||
/**
|
||||
* @brief Check if two SharedPtr are the same data (maybe not the same cast)
|
||||
* @param[in] _obj Object to compare
|
||||
@ -140,7 +139,7 @@ namespace ememory {
|
||||
* @brief Check if the SharedPtr have NOT an internal data (nullptr)
|
||||
* @return true The pointer is asigned, false otherwise
|
||||
*/
|
||||
bool operator!=(std::nullptr_t) const;
|
||||
bool operator!=(etk::NullPtr) const;
|
||||
/**
|
||||
* @brief Check if two SharedPtr are NOT the same data (maybe not the same cast)
|
||||
* @param[in] _obj Object to compare
|
||||
|
@ -17,6 +17,10 @@ namespace ememory {
|
||||
UniquePtr() :
|
||||
m_pointer(nullptr) {
|
||||
|
||||
}
|
||||
UniquePtr(etk::NullPtr) :
|
||||
m_pointer(nullptr) {
|
||||
|
||||
}
|
||||
explicit UniquePtr(EMEM_UPTR_TYPE* _obj) :
|
||||
m_pointer(_obj)
|
||||
@ -26,14 +30,19 @@ namespace ememory {
|
||||
~UniquePtr() {
|
||||
reset();
|
||||
}
|
||||
UniquePtr& operator=(etk::NullPtr) {
|
||||
reset();
|
||||
return *this;
|
||||
}
|
||||
UniquePtr& operator=(UniquePtr _obj) {
|
||||
reset(_obj.release());
|
||||
reset();
|
||||
m_pointer = etk::move(_obj.release());
|
||||
return *this;
|
||||
}
|
||||
template <class EMEM_UPTR_TYPE_2>
|
||||
UniquePtr& operator=(UniquePtr<EMEM_UPTR_TYPE_2> _obj){
|
||||
reset(_obj.release());
|
||||
m_pointer = etk::move(_obj.pointer);
|
||||
reset();
|
||||
m_pointer = etk::move(_obj.m_pointer);
|
||||
return *this;
|
||||
}
|
||||
EMEM_UPTR_TYPE operator*() const{
|
||||
@ -47,7 +56,7 @@ namespace ememory {
|
||||
}
|
||||
EMEM_UPTR_TYPE *release(){
|
||||
EMEM_UPTR_TYPE *tmp = m_pointer;
|
||||
m_pointer = 0;
|
||||
m_pointer = nullptr;
|
||||
return tmp;
|
||||
}
|
||||
void reset(){
|
||||
@ -55,7 +64,7 @@ namespace ememory {
|
||||
m_pointer = nullptr;
|
||||
}
|
||||
void swap(UniquePtr &_obj){
|
||||
std::swap(m_pointer, _obj.m_pointer);
|
||||
etk::swap(m_pointer, _obj.m_pointer);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <etk/Vector.hpp>
|
||||
#include <mutex>
|
||||
#include <ethread/Mutex.hpp>
|
||||
#include <ememory/debug.hpp>
|
||||
#include <ememory/Counter.hpp>
|
||||
|
||||
@ -31,7 +31,7 @@ namespace ememory {
|
||||
/**
|
||||
* @brief nullptr contructor
|
||||
*/
|
||||
WeakPtr(std::nullptr_t);
|
||||
WeakPtr(etk::NullPtr);
|
||||
private:
|
||||
/**
|
||||
* @brief Contructor of the Weak Ptr (specific for EnableSharedFromThis)
|
||||
@ -71,14 +71,14 @@ namespace ememory {
|
||||
* @brief nullptr asignement
|
||||
* @return Reference on this
|
||||
*/
|
||||
WeakPtr<EMEMORY_TYPE>& operator= (std::nullptr_t);
|
||||
WeakPtr<EMEMORY_TYPE>& operator= (etk::NullPtr);
|
||||
/**
|
||||
* @brief Copy contuctor of herited WeakPtr
|
||||
* @param[in] _obj Object to copy
|
||||
*/
|
||||
template<class EMEMORY_TYPE2,
|
||||
typename std::enable_if< std::is_void<EMEMORY_TYPE>::value
|
||||
&& !std::is_void<EMEMORY_TYPE2>::value
|
||||
typename etk::EnableIf< etk::IsVoid<EMEMORY_TYPE>::value
|
||||
&& !etk::IsVoid<EMEMORY_TYPE2>::value
|
||||
, int>::type = 0>
|
||||
WeakPtr(const SharedPtr<EMEMORY_TYPE2>& _obj);
|
||||
/**
|
||||
@ -87,18 +87,18 @@ namespace ememory {
|
||||
* @return Reference on this
|
||||
*/
|
||||
template<class EMEMORY_TYPE2,
|
||||
typename std::enable_if< std::is_void<EMEMORY_TYPE>::value
|
||||
&& !std::is_void<EMEMORY_TYPE2>::value
|
||||
typename etk::EnableIf< etk::IsVoid<EMEMORY_TYPE>::value
|
||||
&& !etk::IsVoid<EMEMORY_TYPE2>::value
|
||||
, int>::type = 0>
|
||||
WeakPtr<EMEMORY_TYPE>& operator= (const SharedPtr<EMEMORY_TYPE2>& _obj);
|
||||
public:
|
||||
/*
|
||||
template<class EMEMORY_TYPE2,
|
||||
typename std::enable_if< std::is_base_of<EMEMORY_TYPE, EMEMORY_TYPE2>::value
|
||||
typename etk::EnableIf< etk::IsBaseOf<EMEMORY_TYPE, EMEMORY_TYPE2>::value
|
||||
, int>::type = 0>
|
||||
WeakPtr(const WeakPtr<EMEMORY_TYPE2>& _obj);
|
||||
template<class EMEMORY_TYPE2,
|
||||
typename std::enable_if< std::is_base_of<EMEMORY_TYPE, EMEMORY_TYPE2>::value
|
||||
typename etk::EnableIf< etk::IsBaseOf<EMEMORY_TYPE, EMEMORY_TYPE2>::value
|
||||
, int>::type = 0>
|
||||
WeakPtr& operator= (const WeakPtr<EMEMORY_TYPE2>& _obj);
|
||||
*/
|
||||
@ -133,7 +133,7 @@ namespace ememory {
|
||||
* @brief Check if the WeakPtr have an internal data (not nullptr)
|
||||
* @return true The pointer is not asigned, false otherwise
|
||||
*/
|
||||
bool operator==(std::nullptr_t) const;
|
||||
bool operator==(etk::NullPtr) const;
|
||||
/**
|
||||
* @brief Check if two WeakPtr are different data
|
||||
* @param[in] _obj Object to compare
|
||||
@ -144,7 +144,7 @@ namespace ememory {
|
||||
* @brief Check if the SharedPtr have NOT an internal data (nullptr)
|
||||
* @return true The pointer is asigned, false otherwise
|
||||
*/
|
||||
bool operator!=(std::nullptr_t) const;
|
||||
bool operator!=(etk::NullPtr) const;
|
||||
/**
|
||||
* @brief Swap 2 Object inside the WeakPtr
|
||||
* @param[in] _obj Object to swap with
|
||||
|
@ -5,15 +5,13 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <ememory/debug.hpp>
|
||||
#include <ememory/WeakPtr.hpp>
|
||||
|
||||
template<typename EMEMORY_TYPE>
|
||||
template<class EMEMORY_TYPE2,
|
||||
typename std::enable_if< std::is_same<EMEMORY_TYPE2, EMEMORY_TYPE>::value
|
||||
&& std::is_base_of<ememory::EnableSharedFromThisBase, EMEMORY_TYPE2>::value
|
||||
typename etk::EnableIf< etk::IsSame<EMEMORY_TYPE2, EMEMORY_TYPE>::value
|
||||
&& etk::IsBaseOf<ememory::EnableSharedFromThisBase, EMEMORY_TYPE2>::value
|
||||
, int>::type>
|
||||
ememory::SharedPtr<EMEMORY_TYPE>::SharedPtr(EMEMORY_TYPE2* _element):
|
||||
m_element(_element),
|
||||
@ -35,8 +33,8 @@ ememory::SharedPtr<EMEMORY_TYPE>::SharedPtr(EMEMORY_TYPE2* _element):
|
||||
|
||||
template<typename EMEMORY_TYPE>
|
||||
template<class EMEMORY_TYPE2,
|
||||
typename std::enable_if< std::is_same<EMEMORY_TYPE2, EMEMORY_TYPE>::value
|
||||
&& !std::is_base_of<ememory::EnableSharedFromThisBase, EMEMORY_TYPE2>::value
|
||||
typename etk::EnableIf< etk::IsSame<EMEMORY_TYPE2, EMEMORY_TYPE>::value
|
||||
&& !etk::IsBaseOf<ememory::EnableSharedFromThisBase, EMEMORY_TYPE2>::value
|
||||
, int>::type>
|
||||
ememory::SharedPtr<EMEMORY_TYPE>::SharedPtr(EMEMORY_TYPE2* _element):
|
||||
m_element(_element),
|
||||
@ -58,7 +56,7 @@ ememory::SharedPtr<EMEMORY_TYPE>::SharedPtr():
|
||||
}
|
||||
|
||||
template<typename EMEMORY_TYPE>
|
||||
ememory::SharedPtr<EMEMORY_TYPE>::SharedPtr(std::nullptr_t):
|
||||
ememory::SharedPtr<EMEMORY_TYPE>::SharedPtr(etk::NullPtr):
|
||||
m_element(nullptr),
|
||||
m_counter(nullptr),
|
||||
m_deleter(createDeleter()) {
|
||||
@ -123,7 +121,7 @@ ememory::SharedPtr<EMEMORY_TYPE>& ememory::SharedPtr<EMEMORY_TYPE>::operator= (c
|
||||
}
|
||||
|
||||
template<typename EMEMORY_TYPE>
|
||||
ememory::SharedPtr<EMEMORY_TYPE>& ememory::SharedPtr<EMEMORY_TYPE>::operator= (std::nullptr_t) {
|
||||
ememory::SharedPtr<EMEMORY_TYPE>& ememory::SharedPtr<EMEMORY_TYPE>::operator= (etk::NullPtr) {
|
||||
reset();
|
||||
return *this;
|
||||
}
|
||||
@ -142,7 +140,7 @@ ememory::SharedPtr<EMEMORY_TYPE>::SharedPtr(ememory::SharedPtr<EMEMORY_TYPE>&& _
|
||||
|
||||
template<typename EMEMORY_TYPE>
|
||||
template<class EMEMORY_TYPE2,
|
||||
typename std::enable_if< std::is_base_of<EMEMORY_TYPE, EMEMORY_TYPE2>::value
|
||||
typename etk::EnableIf< etk::IsBaseOf<EMEMORY_TYPE, EMEMORY_TYPE2>::value
|
||||
, int>::type>
|
||||
ememory::SharedPtr<EMEMORY_TYPE>::SharedPtr(const ememory::SharedPtr<EMEMORY_TYPE2>& _obj):
|
||||
m_element(const_cast<EMEMORY_TYPE2*>(_obj.get())),
|
||||
@ -162,7 +160,7 @@ ememory::SharedPtr<EMEMORY_TYPE>::SharedPtr(const ememory::SharedPtr<EMEMORY_TYP
|
||||
|
||||
template<typename EMEMORY_TYPE>
|
||||
template<class EMEMORY_TYPE2,
|
||||
typename std::enable_if< std::is_base_of<EMEMORY_TYPE, EMEMORY_TYPE2>::value
|
||||
typename etk::EnableIf< etk::IsBaseOf<EMEMORY_TYPE, EMEMORY_TYPE2>::value
|
||||
, int>::type>
|
||||
ememory::SharedPtr<EMEMORY_TYPE>& ememory::SharedPtr<EMEMORY_TYPE>::operator= (const SharedPtr<EMEMORY_TYPE2>& _obj) {
|
||||
reset();
|
||||
@ -234,7 +232,7 @@ int64_t ememory::SharedPtr<EMEMORY_TYPE>::useCount() const {
|
||||
}
|
||||
|
||||
template<typename EMEMORY_TYPE>
|
||||
bool ememory::SharedPtr<EMEMORY_TYPE>::operator==(std::nullptr_t) const {
|
||||
bool ememory::SharedPtr<EMEMORY_TYPE>::operator==(etk::NullPtr) const {
|
||||
return m_counter == nullptr;
|
||||
}
|
||||
|
||||
@ -245,7 +243,7 @@ bool ememory::SharedPtr<EMEMORY_TYPE>::operator==(const SharedPtr<EMEMORY_TYPE2>
|
||||
}
|
||||
|
||||
template<typename EMEMORY_TYPE>
|
||||
bool ememory::SharedPtr<EMEMORY_TYPE>::operator!=(std::nullptr_t) const {
|
||||
bool ememory::SharedPtr<EMEMORY_TYPE>::operator!=(etk::NullPtr) const {
|
||||
return m_counter != nullptr;
|
||||
}
|
||||
|
||||
@ -329,14 +327,14 @@ namespace ememory {
|
||||
class SharedPtr<void> {
|
||||
friend class WeakPtr<void>;
|
||||
public:
|
||||
using deleterCall = std::function<void(void* _data)>;
|
||||
using deleterCall = etk::Function<void(void* _data)>;
|
||||
private:
|
||||
void* m_element;
|
||||
ememory::Counter* m_counter;
|
||||
public:
|
||||
SharedPtr(void* _element);
|
||||
public:
|
||||
SharedPtr(std::nullptr_t):
|
||||
SharedPtr(etk::NullPtr):
|
||||
m_element(nullptr),
|
||||
m_counter(nullptr) {
|
||||
EMEMORY_DBG("new shared<void>");
|
||||
@ -360,7 +358,7 @@ namespace ememory {
|
||||
}
|
||||
m_counter->incrementShared();
|
||||
}
|
||||
SharedPtr& operator= (std::nullptr_t) {
|
||||
SharedPtr& operator= (etk::NullPtr) {
|
||||
reset();
|
||||
return *this;
|
||||
}
|
||||
@ -434,14 +432,14 @@ namespace ememory {
|
||||
}
|
||||
return m_counter->getCountShared();
|
||||
}
|
||||
bool operator==(std::nullptr_t) const {
|
||||
bool operator==(etk::NullPtr) const {
|
||||
return m_counter == nullptr;
|
||||
}
|
||||
template<class EMEMORY_TYPE2>
|
||||
bool operator==(const SharedPtr<EMEMORY_TYPE2>& _obj) const {
|
||||
return m_counter == _obj.m_counter;
|
||||
}
|
||||
bool operator!=(std::nullptr_t) const {
|
||||
bool operator!=(etk::NullPtr) const {
|
||||
return m_counter != nullptr;
|
||||
}
|
||||
template<class EMEMORY_TYPE2>
|
||||
|
@ -6,7 +6,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <ethread/Mutex.hpp>
|
||||
#include <ememory/debug.hpp>
|
||||
#include <ememory/Counter.hpp>
|
||||
|
||||
@ -18,7 +18,7 @@ ememory::WeakPtr<EMEMORY_TYPE>::WeakPtr():
|
||||
}
|
||||
|
||||
template<typename EMEMORY_TYPE>
|
||||
ememory::WeakPtr<EMEMORY_TYPE>::WeakPtr(std::nullptr_t):
|
||||
ememory::WeakPtr<EMEMORY_TYPE>::WeakPtr(etk::NullPtr):
|
||||
m_element(nullptr),
|
||||
m_counter(nullptr) {
|
||||
|
||||
@ -75,7 +75,7 @@ ememory::WeakPtr<EMEMORY_TYPE>& ememory::WeakPtr<EMEMORY_TYPE>::operator= (const
|
||||
}
|
||||
|
||||
template<typename EMEMORY_TYPE>
|
||||
ememory::WeakPtr<EMEMORY_TYPE>& ememory::WeakPtr<EMEMORY_TYPE>::operator= (std::nullptr_t) {
|
||||
ememory::WeakPtr<EMEMORY_TYPE>& ememory::WeakPtr<EMEMORY_TYPE>::operator= (etk::NullPtr) {
|
||||
reset();
|
||||
return *this;
|
||||
}
|
||||
@ -126,8 +126,8 @@ ememory::WeakPtr<EMEMORY_TYPE>& ememory::WeakPtr<EMEMORY_TYPE>::operator= (const
|
||||
|
||||
template<typename EMEMORY_TYPE>
|
||||
template<class EMEMORY_TYPE2,
|
||||
typename std::enable_if< std::is_void<EMEMORY_TYPE>::value
|
||||
&& !std::is_void<EMEMORY_TYPE2>::value
|
||||
typename etk::EnableIf< etk::IsVoid<EMEMORY_TYPE>::value
|
||||
&& !etk::IsVoid<EMEMORY_TYPE2>::value
|
||||
, int>::type>
|
||||
ememory::WeakPtr<EMEMORY_TYPE>::WeakPtr(const ememory::SharedPtr<EMEMORY_TYPE2>& _obj):
|
||||
m_element((void*)_obj.get()),
|
||||
@ -147,8 +147,8 @@ ememory::WeakPtr<EMEMORY_TYPE>::WeakPtr(const ememory::SharedPtr<EMEMORY_TYPE2>&
|
||||
|
||||
template<typename EMEMORY_TYPE>
|
||||
template<class EMEMORY_TYPE2,
|
||||
typename std::enable_if< std::is_void<EMEMORY_TYPE>::value
|
||||
&& !std::is_void<EMEMORY_TYPE2>::value
|
||||
typename etk::EnableIf< etk::IsVoid<EMEMORY_TYPE>::value
|
||||
&& !etk::IsVoid<EMEMORY_TYPE2>::value
|
||||
, int>::type>
|
||||
ememory::WeakPtr<EMEMORY_TYPE>& ememory::WeakPtr<EMEMORY_TYPE>::operator= (const ememory::SharedPtr<EMEMORY_TYPE2>& _obj) {
|
||||
reset();
|
||||
@ -170,7 +170,7 @@ ememory::WeakPtr<EMEMORY_TYPE>& ememory::WeakPtr<EMEMORY_TYPE>::operator= (const
|
||||
|
||||
/*
|
||||
template<class EMEMORY_TYPE2,
|
||||
typename std::enable_if< std::is_base_of<EMEMORY_TYPE, EMEMORY_TYPE2>::value
|
||||
typename etk::EnableIf< etk::IsBaseOf<EMEMORY_TYPE, EMEMORY_TYPE2>::value
|
||||
, int>::type>
|
||||
WeakPtr(const WeakPtr<EMEMORY_TYPE2>& _obj):
|
||||
m_element(_obj.m_element),
|
||||
@ -188,7 +188,7 @@ WeakPtr(const WeakPtr<EMEMORY_TYPE2>& _obj):
|
||||
|
||||
}
|
||||
template<class EMEMORY_TYPE2,
|
||||
typename std::enable_if< std::is_base_of<EMEMORY_TYPE, EMEMORY_TYPE2>::value
|
||||
typename etk::EnableIf< etk::IsBaseOf<EMEMORY_TYPE, EMEMORY_TYPE2>::value
|
||||
, int>::type>
|
||||
WeakPtr& operator= (const WeakPtr<EMEMORY_TYPE2>& _obj) {
|
||||
reset();
|
||||
@ -268,7 +268,7 @@ bool ememory::WeakPtr<EMEMORY_TYPE>::operator==(const ememory::WeakPtr<EMEMORY_T
|
||||
}
|
||||
|
||||
template<typename EMEMORY_TYPE>
|
||||
bool ememory::WeakPtr<EMEMORY_TYPE>::operator==(std::nullptr_t) const {
|
||||
bool ememory::WeakPtr<EMEMORY_TYPE>::operator==(etk::NullPtr) const {
|
||||
return m_counter == nullptr;
|
||||
}
|
||||
|
||||
@ -278,7 +278,7 @@ bool ememory::WeakPtr<EMEMORY_TYPE>::operator!=(const ememory::WeakPtr<EMEMORY_T
|
||||
}
|
||||
|
||||
template<typename EMEMORY_TYPE>
|
||||
bool ememory::WeakPtr<EMEMORY_TYPE>::operator!=(std::nullptr_t) const {
|
||||
bool ememory::WeakPtr<EMEMORY_TYPE>::operator!=(etk::NullPtr) const {
|
||||
return m_counter != nullptr;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <etk/Vector.hpp>
|
||||
#include <mutex>
|
||||
#include <ethread/Mutex.hpp>
|
||||
#include <ememory/SharedPtr.hpp>
|
||||
#include <ememory/WeakPtr.hpp>
|
||||
#include <ememory/EnableSharedFromThis.hpp>
|
||||
|
@ -34,9 +34,10 @@ def configure(target, my_module):
|
||||
'test/testCasts.cpp'
|
||||
])
|
||||
my_module.add_depend([
|
||||
'cxx',
|
||||
'ememory',
|
||||
'gtest',
|
||||
'test-debug'
|
||||
'test-debug',
|
||||
'etest',
|
||||
])
|
||||
return True
|
||||
|
||||
|
@ -49,7 +49,7 @@ def configure(target, my_module):
|
||||
# build in C++ mode
|
||||
my_module.compile_version("c++", 2011)
|
||||
# add dependency of the generic C++ library:
|
||||
my_module.add_depend('cxx')
|
||||
my_module.add_depend('etk-base')
|
||||
my_module.add_optionnal_depend('elog')
|
||||
|
||||
my_module.add_path(".")
|
||||
|
@ -6,13 +6,13 @@
|
||||
|
||||
#include <test-debug/debug.hpp>
|
||||
#include <etk/Vector.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
#include <etk/etk.hpp>
|
||||
#include <etest/etest.hpp>
|
||||
//#include <etk/etk.hpp>
|
||||
|
||||
|
||||
int main(int _argc, const char *_argv[]) {
|
||||
::testing::InitGoogleTest(&_argc, const_cast<char **>(_argv));
|
||||
etk::init(_argc, _argv);
|
||||
//etk::init(_argc, _argv);
|
||||
etest::init(_argc, _argv);
|
||||
for (int32_t iii=0; iii<_argc ; ++iii) {
|
||||
etk::String data = _argv[iii];
|
||||
if ( data == "-h"
|
||||
|
@ -4,7 +4,7 @@
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <etest/etest.hpp>
|
||||
#include <ememory/memory.hpp>
|
||||
#include "main.hpp"
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <etest/etest.hpp>
|
||||
#include <ememory/memory.hpp>
|
||||
#include "main.hpp"
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <etest/etest.hpp>
|
||||
#include <ememory/memory.hpp>
|
||||
#include "main.hpp"
|
||||
|
||||
|
@ -6,11 +6,10 @@
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <etest/etest.hpp>
|
||||
|
||||
#include <ememory/UniquePtr.hpp>
|
||||
#include <test-debug/debug.hpp>
|
||||
#define NAME "UNIQUE-PTR"
|
||||
|
||||
TEST(TestEmemoryUniquePtr, Creation_1) {
|
||||
ememory::UniquePtr<uint32_t> testData;
|
||||
@ -44,7 +43,7 @@ class testCreateAndDestroy {
|
||||
};
|
||||
|
||||
TEST(TestEmemoryUniquePtr, reset) {
|
||||
vals = {0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
memset(vals, 0, sizeof(vals));
|
||||
EXPECT_EQ(vals[1], 0);
|
||||
ememory::UniquePtr<testCreateAndDestroy> testData = ememory::makeUniquePtr<testCreateAndDestroy>(1);
|
||||
EXPECT_NE(testData.get(), nullptr);
|
||||
@ -53,8 +52,18 @@ TEST(TestEmemoryUniquePtr, reset) {
|
||||
EXPECT_EQ(testData.get(), nullptr);
|
||||
EXPECT_EQ(vals[1], -1);
|
||||
}
|
||||
TEST(TestEmemoryUniquePtr, reset_2) {
|
||||
memset(vals, 0, sizeof(vals));
|
||||
EXPECT_EQ(vals[1], 0);
|
||||
ememory::UniquePtr<testCreateAndDestroy> testData = ememory::makeUniquePtr<testCreateAndDestroy>(1);
|
||||
EXPECT_NE(testData.get(), nullptr);
|
||||
EXPECT_EQ(vals[1], 1);
|
||||
testData = nullptr;
|
||||
EXPECT_EQ(testData.get(), nullptr);
|
||||
EXPECT_EQ(vals[1], -1);
|
||||
}
|
||||
TEST(TestEmemoryUniquePtr, overwrite) {
|
||||
vals = {0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
memset(vals, 0, sizeof(vals));
|
||||
ememory::UniquePtr<testCreateAndDestroy> testData = ememory::makeUniquePtr<testCreateAndDestroy>(1);
|
||||
EXPECT_NE(testData.get(), nullptr);
|
||||
EXPECT_EQ(vals[1], 1);
|
||||
|
@ -4,7 +4,7 @@
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <etest/etest.hpp>
|
||||
#include <ememory/memory.hpp>
|
||||
#include "main.hpp"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user