[DEV] only move .... ==> not work ....

This commit is contained in:
Edouard DUPIN 2017-09-09 23:52:12 +02:00
parent ee2ee1b9b9
commit a19a120987
5 changed files with 80 additions and 49 deletions

View File

@ -98,7 +98,6 @@ void etest::init(int32_t _argc, const char** _argv) {
ETEST_INFO("ETEST system init (BEGIN) ");
for (int32_t iii=0; iii<_argc ; ++iii) {
etk::String data = _argv[iii];
ETEST_PRINT("Parameter : " << data << " " << data.startWith("--etest-filter="));
if ( data == "-h"
|| data == "--help") {
ETEST_PRINT("etest - help : ");
@ -119,9 +118,11 @@ void etest::init(int32_t _argc, const char** _argv) {
if (tmp.size() == 1) {
// Filter only the groups
filterGroup = filter;
ETEST_VERBOSE("filter group:" << filterGroup);
} else if (tmp.size() == 2) {
filterGroup = tmp[0];
filterTest = tmp[1];
ETEST_VERBOSE("filter group:" << filterGroup << " & test:" << filterTest);
} else {
ETEST_CRITICAL("Can not parse the argument : '" << data << "' ==> more than 1 '.'");
}

View File

@ -4,12 +4,11 @@
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
//#include <ememory/UniquePtr.hpp>
//TODO: Mission commando
#pragma once
//#define ETK_FUNCTION_ENABLE_NEW
namespace etk {
template <typename ETK_TYPE_FUNCTION>
@ -35,9 +34,11 @@ namespace etk {
private:
// function pointer types for the type-erasure behaviors
// all these char* parameters are actually casted from some functor type
typedef ETK_TYPE_FUNCTION_RETURN (*invoke_fn_t)(char*, ETK_TYPE_FUNCTION_ARGS&&...);
typedef void (*construct_fn_t)(char*, char*);
typedef void (*destroy_fn_t)(char*);
typedef ETK_TYPE_FUNCTION_RETURN (*invoke_fn_t)(void*, ETK_TYPE_FUNCTION_ARGS&&...);
#ifdef ETK_FUNCTION_ENABLE_NEW
typedef void* (*construct_fn_t)();
#endif
typedef void (*destroy_fn_t)(void*);
// type-aware generic functions for invoking
// the specialization of these functions won't be capable with
// the above function pointer types, so we need some cast
@ -46,41 +47,46 @@ namespace etk {
ETK_TYPE_FUNCTION_ARGS&&... _args) {
return (*_functor)(etk::forward<ETK_TYPE_FUNCTION_ARGS>(_args)...);
}
template <typename ETK_TYPE_FUNCTION_FUNCTOR>
static void construct_fn(ETK_TYPE_FUNCTION_FUNCTOR* _constructDestination,
ETK_TYPE_FUNCTION_FUNCTOR* _constructSource) {
// the functor type must be copy-constructible
new (_constructDestination) ETK_TYPE_FUNCTION_FUNCTOR(*_constructSource);
}
#ifdef ETK_FUNCTION_ENABLE_NEW
template <typename ETK_TYPE_FUNCTION_FUNCTOR>
static void* construct_fn() {
// the functor type must be copy-constructible
return new ETK_TYPE_FUNCTION_FUNCTOR();
}
#endif
template <typename ETK_TYPE_FUNCTION_FUNCTOR>
static void destroy_fn(ETK_TYPE_FUNCTION_FUNCTOR* _functor) {
_functor->~ETK_TYPE_FUNCTION_FUNCTOR();
}
// These pointers are storing behaviors.
invoke_fn_t invoke_f;
construct_fn_t construct_f;
#ifdef ETK_FUNCTION_ENABLE_NEW
construct_fn_t construct_f;
#endif
destroy_fn_t destroy_f;
// Erase the type of any functor and store it into a char*
// so the storage size should be obtained as well
char* m_dataPointer;
size_t m_dataSize;
void* m_dataPointer;
public:
FunctionPrivateSpecific():
invoke_f(nullptr),
construct_f(nullptr),
#ifdef ETK_FUNCTION_ENABLE_NEW
construct_f(nullptr),
#endif
destroy_f(nullptr),
m_dataPointer(nullptr),
m_dataSize(0) {
m_dataPointer(nullptr) {
}
FunctionPrivateSpecific(etk::NullPtr):
invoke_f(nullptr),
construct_f(nullptr),
#ifdef ETK_FUNCTION_ENABLE_NEW
construct_f(nullptr),
#endif
destroy_f(nullptr),
m_dataPointer(nullptr),
m_dataSize(0) {
m_dataPointer(nullptr) {
}
#ifdef ETK_FUNCTION_ENABLE_NEW
// construct from any functor type
template <typename ETK_TYPE_FUNCTION_FUNCTOR>
FunctionPrivateSpecific(ETK_TYPE_FUNCTION_FUNCTOR _functor):
@ -88,11 +94,8 @@ namespace etk {
invoke_f(reinterpret_cast<invoke_fn_t>(invoke_fn<ETK_TYPE_FUNCTION_FUNCTOR>)),
construct_f(reinterpret_cast<construct_fn_t>(construct_fn<ETK_TYPE_FUNCTION_FUNCTOR>)),
destroy_f(reinterpret_cast<destroy_fn_t>(destroy_fn<ETK_TYPE_FUNCTION_FUNCTOR>)),
m_dataPointer(nullptr),
m_dataSize(sizeof(ETK_TYPE_FUNCTION_FUNCTOR)) {
m_dataPointer = new char[sizeof(ETK_TYPE_FUNCTION_FUNCTOR)];
// copy the functor to internal storage
construct_f(m_dataPointer, reinterpret_cast<char*>(&_functor));
m_dataPointer(nullptr) {
m_dataPointer = construct_f();
}
// copy constructor
/*
@ -109,10 +112,25 @@ namespace etk {
}
}
*/
#else
// move from any functor type
template <typename ETK_TYPE_FUNCTION_FUNCTOR>
FunctionPrivateSpecific(ETK_TYPE_FUNCTION_FUNCTOR&& _functor):
// specialize functions and erase their type info by casting
invoke_f(reinterpret_cast<invoke_fn_t>(invoke_fn<ETK_TYPE_FUNCTION_FUNCTOR>)),
#ifdef ETK_FUNCTION_ENABLE_NEW
construct_f(reinterpret_cast<construct_fn_t>(construct_fn<ETK_TYPE_FUNCTION_FUNCTOR>)),
#endif
destroy_f(reinterpret_cast<destroy_fn_t>(destroy_fn<ETK_TYPE_FUNCTION_FUNCTOR>)),
m_dataPointer(nullptr) {
m_dataPointer = etk::move(_functor);
}
#endif
~FunctionPrivateSpecific() {
if (m_dataPointer != nullptr) {
destroy_f(m_dataPointer);
delete m_dataPointer;
m_dataPointer = nullptr;
}
}
// other constructors, from nullptr, from function pointers
@ -145,19 +163,28 @@ namespace etk {
m_pointerPrivate(nullptr) {
}
// construct from any functor type
template <typename ETK_TYPE_FUNCTION_FUNCTOR>
Function(ETK_TYPE_FUNCTION_FUNCTOR _functor):
m_pointerPrivate(new FunctionPrivateSpecific<ETK_TYPE_FUNCTION_RETURN(ETK_TYPE_FUNCTION_ARGS...)>(_functor)) {
}
// copy constructor
Function(const Function& _obj):
m_pointerPrivate(nullptr) {
if (_obj.m_pointerPrivate != nullptr) {
m_pointerPrivate = _obj.m_pointerPrivate->copy();
#ifdef ETK_FUNCTION_ENABLE_NEW
// construct from any functor type
template <typename ETK_TYPE_FUNCTION_FUNCTOR>
Function(ETK_TYPE_FUNCTION_FUNCTOR _functor):
m_pointerPrivate(new FunctionPrivateSpecific<ETK_TYPE_FUNCTION_RETURN(ETK_TYPE_FUNCTION_ARGS...)>(_functor)) {
}
}
// copy constructor
Function(const Function& _obj):
m_pointerPrivate(nullptr) {
if (_obj.m_pointerPrivate != nullptr) {
m_pointerPrivate = _obj.m_pointerPrivate->copy();
}
}
#else
// construct from any functor type
template <typename ETK_TYPE_FUNCTION_FUNCTOR>
Function(ETK_TYPE_FUNCTION_FUNCTOR&& _functor):
m_pointerPrivate(new FunctionPrivateSpecific<ETK_TYPE_FUNCTION_RETURN(ETK_TYPE_FUNCTION_ARGS...)>(_functor)) {
}
#endif
// copy constructor
Function(Function&& _obj):
m_pointerPrivate(_obj.m_pointerPrivate) {
@ -181,6 +208,7 @@ namespace etk {
bool operator== (etk::NullPtr) const {
return m_pointerPrivate == nullptr;
}
#ifdef ETK_FUNCTION_ENABLE_NEW
Function& operator= (const Function& _obj) {
delete m_pointerPrivate;
m_pointerPrivate = nullptr;
@ -189,9 +217,11 @@ namespace etk {
}
return *this;
}
#endif
Function& operator= (Function&& _obj) {
delete m_pointerPrivate;
m_pointerPrivate = etk::move(_obj.m_pointerPrivate);
m_pointerPrivate = _obj.m_pointerPrivate;
_obj.m_pointerPrivate = nullptr;
return *this;
}
};

View File

@ -450,7 +450,7 @@ bool etk::String::startWith(const etk::String& _val, bool _caseSensitive) const
}
if (_caseSensitive == true) {
for( size_t iii = 0;
iii < size()-1;
iii < _val.size();
iii++) {
if (m_data[iii] != _val[iii]) {
return false;
@ -459,7 +459,7 @@ bool etk::String::startWith(const etk::String& _val, bool _caseSensitive) const
return true;
}
for( size_t iii = 0;
iii < _val.size()-1;
iii < _val.size();
iii++) {
if (etk::toLower(_val[iii]) != etk::toLower(m_data[iii])) {
return false;

View File

@ -426,7 +426,7 @@ bool etk::UString::startWith(const etk::UString& _val, bool _caseSensitive) cons
}
if (_caseSensitive == true) {
for( size_t iii = 0;
iii < size();
iii < _val.size();
iii++) {
if (m_data[iii] != _val[iii]) {
return false;

View File

@ -30,21 +30,21 @@ TEST(TestFunction, NullFunction) {
etk::Function<void(int)> f_display = nullptr;
EXPECT_EQ(f_display, nullptr);
}
/*
TEST(TestFunction, setAFreeFunction) {
globalValue = 0;
// Test contructor value
etk::Function<void(int)> f_display = print_num;
etk::Function<void(int32_t)> f_display = print_num;
EXPECT_NE(f_display, nullptr);
}
TEST(TestFunction, callAFreeFunction) {
globalValue = 0;
// Test contructor value
etk::Function<void(int)> f_display = print_num;
etk::Function<void(int32_t)> f_display = print_num;
f_display(235);
EXPECT_EQ(globalValue, 235 + 1000);
}
TEST(TestFunction, setALambda) {
globalValue = 0;
// Test contructor value
@ -74,4 +74,4 @@ TEST(TestFunction, callAMemberFunction) {
f_display(foo, 16);
EXPECT_EQ(globalValue, 16 + 70000);
}
*/