[DEV] add basic memory interface

This commit is contained in:
Edouard DUPIN 2016-03-10 23:27:58 +01:00
parent b932fd9898
commit 6123df30e2
4 changed files with 134 additions and 0 deletions

15
ememory/debug.cpp Normal file
View File

@ -0,0 +1,15 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <ememory/debug.h>
int32_t ememory::getLogId() {
static int32_t g_val = elog::registerInstance("ememory");
return g_val;
}

45
ememory/debug.h Normal file
View File

@ -0,0 +1,45 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <elog/log.h>
#include <assert.h>
namespace ememory {
int32_t getLogId();
};
#define EMEMORY_BASIC(info,data) EMEMORY_BASE(ememory::getLogId(),info,data)
#define EMEMORY_PRINT(data) EMEMORY_BASIC(-1, data)
#define EMEMORY_CRITICAL(data) EMEMORY_BASIC(1, data)
#define EMEMORY_ERROR(data) EMEMORY_BASIC(2, data)
#define EMEMORY_WARNING(data) EMEMORY_BASIC(3, data)
#ifdef DEBUG
#define EMEMORY_INFO(data) EMEMORY_BASIC(4, data)
#define EMEMORY_DEBUG(data) EMEMORY_BASIC(5, data)
#define EMEMORY_VERBOSE(data) EMEMORY_BASIC(6, data)
#define EMEMORY_TODO(data) EMEMORY_BASIC(4, "TODO : " << data)
#else
#define EMEMORY_INFO(data) do { } while(false)
#define EMEMORY_DEBUG(data) do { } while(false)
#define EMEMORY_VERBOSE(data) do { } while(false)
#define EMEMORY_TODO(data) do { } while(false)
#endif
#define EMEMORY_HIDDEN(data) do { } while(false)
#define EMEMORY_ASSERT(cond,data) \
do { \
if (!(cond)) { \
EMEMORY_CRITICAL(data); \
assert(!#cond); \
} \
} while (0)

26
ememory/memory.h Normal file
View File

@ -0,0 +1,26 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <vector>
#include <mutex>
#include <memory>
namespace ememory {
template<class TYPE>
using SharedPtr = std::shared_ptr<TYPE>;
template<class TYPE>
using WeakPtr = std::weak_ptr<TYPE>;
template<class TYPE>
using EnableSharedFromThis = std::enable_shared_from_this<TYPE>;
/*
template<class TYPE>
using DynamicPointerCastZZ = std::dynamic_pointer_cast<TYPE>;
*/
}

48
lutin_ememory.py Normal file
View File

@ -0,0 +1,48 @@
#!/usr/bin/python
import lutin.module as module
import lutin.tools as tools
def get_type():
return "LIBRARY"
def get_desc():
return "Ewol memory basic interface (have a thread safe shared_ptr with constness)"
def get_licence():
return "APACHE-2"
def get_compagny_type():
return "com"
def get_compagny_name():
return "atria-soft"
def get_maintainer():
return ["Mr DUPIN Edouard <yui.heero@gmail.com>"]
def get_version():
return [0,1,"dev"]
def create(target, module_name):
my_module = module.Module(__file__, module_name, get_type())
my_module.add_extra_compile_flags()
# add the file to compile:
my_module.add_src_file([
'ememory/debug.cpp'
])
my_module.add_header_file([
'ememory/memory.h',
])
# build in C++ mode
my_module.compile_version("c++", 2011)
# add dependency of the generic C++ library:
my_module.add_module_depend('cxx')
my_module.add_optionnal_module_depend('elog')
my_module.add_path(tools.get_current_path(__file__))
return my_module