[DEV] continue removing STL
This commit is contained in:
parent
965b951ee4
commit
e64b7496b7
@ -6,7 +6,7 @@ EMEMORY library {#mainpage}
|
||||
What is EMEMORY, and how can I use it?
|
||||
======================================
|
||||
|
||||
EMEMORY, or Ewol Memory interface is a simple abstraction layer over std::shared_ptr.
|
||||
EMEMORY, or Ewol Memory interface implementing ememory::SharedPtr and ememory::UniquePtr.
|
||||
|
||||
EMEMORY is designed for:
|
||||
- Permit to change the backend of shered_ptr when we want
|
||||
|
@ -5,9 +5,10 @@
|
||||
namespace ememory {
|
||||
template <class EMEM_UPTR_TYPE>
|
||||
class UniquePtr {
|
||||
private:
|
||||
//private: Do it better ...
|
||||
public:
|
||||
EMEM_UPTR_TYPE* m_pointer;
|
||||
|
||||
private:
|
||||
template <class EMEM_UPTR_TYPE_2>
|
||||
UniquePtr(UniquePtr<EMEM_UPTR_TYPE_2> &) = delete;
|
||||
|
||||
@ -23,10 +24,16 @@ namespace ememory {
|
||||
|
||||
}
|
||||
explicit UniquePtr(EMEM_UPTR_TYPE* _obj) :
|
||||
m_pointer(_obj)
|
||||
{
|
||||
m_pointer(_obj) {
|
||||
|
||||
}
|
||||
template <class EMEM_UPTR_TYPE_2>
|
||||
UniquePtr(UniquePtr<EMEM_UPTR_TYPE_2>&& _obj) :
|
||||
m_pointer(nullptr) {
|
||||
// TODO: Better: _obj.swap(*this);
|
||||
m_pointer = _obj.m_pointer;
|
||||
_obj.m_pointer = nullptr;
|
||||
}
|
||||
~UniquePtr() {
|
||||
reset();
|
||||
}
|
||||
@ -66,6 +73,26 @@ namespace ememory {
|
||||
void swap(UniquePtr &_obj){
|
||||
etk::swap(m_pointer, _obj.m_pointer);
|
||||
}
|
||||
/**
|
||||
* @brief Check if the UniquePtr have an internal data (not nullptr)
|
||||
* @return true The pointer is not asigned, false otherwise
|
||||
*/
|
||||
bool operator==(etk::NullPtr) const {
|
||||
return m_pointer == nullptr;
|
||||
}
|
||||
/**
|
||||
* @brief Check if the UniquePtr have not an internal data (equal nullptr)
|
||||
* @return true The pointer is asigned, false otherwise
|
||||
*/
|
||||
bool operator!=(etk::NullPtr) const {
|
||||
return m_pointer != nullptr;
|
||||
}
|
||||
/*
|
||||
template <class EMEM_UPTR_TYPE_2>
|
||||
void swap(UniquePtr<EMEM_UPTR_TYPE_2>& _obj) {
|
||||
etk::swap(m_pointer, _obj.m_pointer);
|
||||
}
|
||||
*/
|
||||
};
|
||||
|
||||
template<class EMEM_UPTR_TYPE, class... EMEM_UPTR_ARG>
|
||||
|
@ -8,7 +8,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <elog/log.hpp>
|
||||
#include <cassert>
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
}
|
||||
|
||||
namespace ememory {
|
||||
int32_t getLogId();
|
||||
|
@ -194,7 +194,6 @@ void ememory::SharedPtr<EMEMORY_TYPE>::reset() {
|
||||
delete m_counter;
|
||||
if (m_deleter != nullptr) {
|
||||
if (m_element != nullptr) {
|
||||
//EMEMORY_ERROR("FREE 1 : " << std::hex << (uint64_t)m_element);
|
||||
m_deleter((void*)m_element);
|
||||
}
|
||||
} else {
|
||||
@ -204,7 +203,6 @@ void ememory::SharedPtr<EMEMORY_TYPE>::reset() {
|
||||
case ememory::Counter::remove::data:
|
||||
if (m_deleter != nullptr) {
|
||||
if (m_element != nullptr) {
|
||||
//EMEMORY_ERROR("FREE 2 : " << std::hex << (uint64_t)m_element);
|
||||
m_deleter((void*)m_element);
|
||||
}
|
||||
} else {
|
||||
|
@ -5,7 +5,6 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <ethread/Mutex.hpp>
|
||||
#include <ememory/debug.hpp>
|
||||
#include <ememory/Counter.hpp>
|
||||
@ -259,7 +258,7 @@ ememory::SharedPtr<EMEMORY_TYPE> ememory::WeakPtr<EMEMORY_TYPE>::lock() {
|
||||
}
|
||||
out.m_counter = m_counter;
|
||||
out.m_element = m_element;
|
||||
return std::move(out);
|
||||
return etk::move(out);
|
||||
}
|
||||
|
||||
template<typename EMEMORY_TYPE>
|
||||
|
@ -22,7 +22,7 @@ namespace ememory {
|
||||
*/
|
||||
template<class EMEMORY_TYPE, typename... EMEMORY_ARGS>
|
||||
static ememory::SharedPtr<EMEMORY_TYPE> makeShared(EMEMORY_ARGS && ..._args) {
|
||||
return ememory::SharedPtr<EMEMORY_TYPE>(new EMEMORY_TYPE(std::forward<EMEMORY_ARGS>(_args)...));
|
||||
return ememory::SharedPtr<EMEMORY_TYPE>(new EMEMORY_TYPE(etk::forward<EMEMORY_ARGS>(_args)...));
|
||||
}
|
||||
/**
|
||||
* @brief Cast in Dynamic the input SharedPtr into an other type like dynamic_cast on pointer
|
||||
|
Loading…
x
Reference in New Issue
Block a user