[DEV] only move .... ==> not work ....
This commit is contained in:
parent
ee2ee1b9b9
commit
a19a120987
@ -98,7 +98,6 @@ void etest::init(int32_t _argc, const char** _argv) {
|
|||||||
ETEST_INFO("ETEST system init (BEGIN) ");
|
ETEST_INFO("ETEST system init (BEGIN) ");
|
||||||
for (int32_t iii=0; iii<_argc ; ++iii) {
|
for (int32_t iii=0; iii<_argc ; ++iii) {
|
||||||
etk::String data = _argv[iii];
|
etk::String data = _argv[iii];
|
||||||
ETEST_PRINT("Parameter : " << data << " " << data.startWith("--etest-filter="));
|
|
||||||
if ( data == "-h"
|
if ( data == "-h"
|
||||||
|| data == "--help") {
|
|| data == "--help") {
|
||||||
ETEST_PRINT("etest - help : ");
|
ETEST_PRINT("etest - help : ");
|
||||||
@ -119,9 +118,11 @@ void etest::init(int32_t _argc, const char** _argv) {
|
|||||||
if (tmp.size() == 1) {
|
if (tmp.size() == 1) {
|
||||||
// Filter only the groups
|
// Filter only the groups
|
||||||
filterGroup = filter;
|
filterGroup = filter;
|
||||||
|
ETEST_VERBOSE("filter group:" << filterGroup);
|
||||||
} else if (tmp.size() == 2) {
|
} else if (tmp.size() == 2) {
|
||||||
filterGroup = tmp[0];
|
filterGroup = tmp[0];
|
||||||
filterTest = tmp[1];
|
filterTest = tmp[1];
|
||||||
|
ETEST_VERBOSE("filter group:" << filterGroup << " & test:" << filterTest);
|
||||||
} else {
|
} else {
|
||||||
ETEST_CRITICAL("Can not parse the argument : '" << data << "' ==> more than 1 '.'");
|
ETEST_CRITICAL("Can not parse the argument : '" << data << "' ==> more than 1 '.'");
|
||||||
}
|
}
|
||||||
|
108
etk/Function.hpp
108
etk/Function.hpp
@ -4,12 +4,11 @@
|
|||||||
* @license MPL v2.0 (see license file)
|
* @license MPL v2.0 (see license file)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
#include <etk/types.hpp>
|
#include <etk/types.hpp>
|
||||||
//#include <ememory/UniquePtr.hpp>
|
//#include <ememory/UniquePtr.hpp>
|
||||||
|
|
||||||
//TODO: Mission commando
|
//#define ETK_FUNCTION_ENABLE_NEW
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace etk {
|
namespace etk {
|
||||||
template <typename ETK_TYPE_FUNCTION>
|
template <typename ETK_TYPE_FUNCTION>
|
||||||
@ -35,9 +34,11 @@ namespace etk {
|
|||||||
private:
|
private:
|
||||||
// function pointer types for the type-erasure behaviors
|
// function pointer types for the type-erasure behaviors
|
||||||
// all these char* parameters are actually casted from some functor type
|
// 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 ETK_TYPE_FUNCTION_RETURN (*invoke_fn_t)(void*, ETK_TYPE_FUNCTION_ARGS&&...);
|
||||||
typedef void (*construct_fn_t)(char*, char*);
|
#ifdef ETK_FUNCTION_ENABLE_NEW
|
||||||
typedef void (*destroy_fn_t)(char*);
|
typedef void* (*construct_fn_t)();
|
||||||
|
#endif
|
||||||
|
typedef void (*destroy_fn_t)(void*);
|
||||||
// type-aware generic functions for invoking
|
// type-aware generic functions for invoking
|
||||||
// the specialization of these functions won't be capable with
|
// the specialization of these functions won't be capable with
|
||||||
// the above function pointer types, so we need some cast
|
// the above function pointer types, so we need some cast
|
||||||
@ -46,41 +47,46 @@ namespace etk {
|
|||||||
ETK_TYPE_FUNCTION_ARGS&&... _args) {
|
ETK_TYPE_FUNCTION_ARGS&&... _args) {
|
||||||
return (*_functor)(etk::forward<ETK_TYPE_FUNCTION_ARGS>(_args)...);
|
return (*_functor)(etk::forward<ETK_TYPE_FUNCTION_ARGS>(_args)...);
|
||||||
}
|
}
|
||||||
template <typename ETK_TYPE_FUNCTION_FUNCTOR>
|
#ifdef ETK_FUNCTION_ENABLE_NEW
|
||||||
static void construct_fn(ETK_TYPE_FUNCTION_FUNCTOR* _constructDestination,
|
template <typename ETK_TYPE_FUNCTION_FUNCTOR>
|
||||||
ETK_TYPE_FUNCTION_FUNCTOR* _constructSource) {
|
static void* construct_fn() {
|
||||||
// the functor type must be copy-constructible
|
// the functor type must be copy-constructible
|
||||||
new (_constructDestination) ETK_TYPE_FUNCTION_FUNCTOR(*_constructSource);
|
return new ETK_TYPE_FUNCTION_FUNCTOR();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
template <typename ETK_TYPE_FUNCTION_FUNCTOR>
|
template <typename ETK_TYPE_FUNCTION_FUNCTOR>
|
||||||
static void destroy_fn(ETK_TYPE_FUNCTION_FUNCTOR* _functor) {
|
static void destroy_fn(ETK_TYPE_FUNCTION_FUNCTOR* _functor) {
|
||||||
_functor->~ETK_TYPE_FUNCTION_FUNCTOR();
|
_functor->~ETK_TYPE_FUNCTION_FUNCTOR();
|
||||||
}
|
}
|
||||||
// These pointers are storing behaviors.
|
// These pointers are storing behaviors.
|
||||||
invoke_fn_t invoke_f;
|
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;
|
destroy_fn_t destroy_f;
|
||||||
// Erase the type of any functor and store it into a char*
|
// Erase the type of any functor and store it into a char*
|
||||||
// so the storage size should be obtained as well
|
// so the storage size should be obtained as well
|
||||||
char* m_dataPointer;
|
void* m_dataPointer;
|
||||||
size_t m_dataSize;
|
|
||||||
public:
|
public:
|
||||||
FunctionPrivateSpecific():
|
FunctionPrivateSpecific():
|
||||||
invoke_f(nullptr),
|
invoke_f(nullptr),
|
||||||
construct_f(nullptr),
|
#ifdef ETK_FUNCTION_ENABLE_NEW
|
||||||
|
construct_f(nullptr),
|
||||||
|
#endif
|
||||||
destroy_f(nullptr),
|
destroy_f(nullptr),
|
||||||
m_dataPointer(nullptr),
|
m_dataPointer(nullptr) {
|
||||||
m_dataSize(0) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
FunctionPrivateSpecific(etk::NullPtr):
|
FunctionPrivateSpecific(etk::NullPtr):
|
||||||
invoke_f(nullptr),
|
invoke_f(nullptr),
|
||||||
construct_f(nullptr),
|
#ifdef ETK_FUNCTION_ENABLE_NEW
|
||||||
|
construct_f(nullptr),
|
||||||
|
#endif
|
||||||
destroy_f(nullptr),
|
destroy_f(nullptr),
|
||||||
m_dataPointer(nullptr),
|
m_dataPointer(nullptr) {
|
||||||
m_dataSize(0) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#ifdef ETK_FUNCTION_ENABLE_NEW
|
||||||
// construct from any functor type
|
// construct from any functor type
|
||||||
template <typename ETK_TYPE_FUNCTION_FUNCTOR>
|
template <typename ETK_TYPE_FUNCTION_FUNCTOR>
|
||||||
FunctionPrivateSpecific(ETK_TYPE_FUNCTION_FUNCTOR _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>)),
|
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>)),
|
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>)),
|
destroy_f(reinterpret_cast<destroy_fn_t>(destroy_fn<ETK_TYPE_FUNCTION_FUNCTOR>)),
|
||||||
m_dataPointer(nullptr),
|
m_dataPointer(nullptr) {
|
||||||
m_dataSize(sizeof(ETK_TYPE_FUNCTION_FUNCTOR)) {
|
m_dataPointer = construct_f();
|
||||||
m_dataPointer = new char[sizeof(ETK_TYPE_FUNCTION_FUNCTOR)];
|
|
||||||
// copy the functor to internal storage
|
|
||||||
construct_f(m_dataPointer, reinterpret_cast<char*>(&_functor));
|
|
||||||
}
|
}
|
||||||
// copy constructor
|
// 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() {
|
~FunctionPrivateSpecific() {
|
||||||
if (m_dataPointer != nullptr) {
|
if (m_dataPointer != nullptr) {
|
||||||
destroy_f(m_dataPointer);
|
destroy_f(m_dataPointer);
|
||||||
delete m_dataPointer;
|
m_dataPointer = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// other constructors, from nullptr, from function pointers
|
// other constructors, from nullptr, from function pointers
|
||||||
@ -145,19 +163,28 @@ namespace etk {
|
|||||||
m_pointerPrivate(nullptr) {
|
m_pointerPrivate(nullptr) {
|
||||||
|
|
||||||
}
|
}
|
||||||
// construct from any functor type
|
#ifdef ETK_FUNCTION_ENABLE_NEW
|
||||||
template <typename ETK_TYPE_FUNCTION_FUNCTOR>
|
// construct from any functor type
|
||||||
Function(ETK_TYPE_FUNCTION_FUNCTOR _functor):
|
template <typename ETK_TYPE_FUNCTION_FUNCTOR>
|
||||||
m_pointerPrivate(new FunctionPrivateSpecific<ETK_TYPE_FUNCTION_RETURN(ETK_TYPE_FUNCTION_ARGS...)>(_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();
|
|
||||||
}
|
}
|
||||||
}
|
// 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
|
// copy constructor
|
||||||
Function(Function&& _obj):
|
Function(Function&& _obj):
|
||||||
m_pointerPrivate(_obj.m_pointerPrivate) {
|
m_pointerPrivate(_obj.m_pointerPrivate) {
|
||||||
@ -181,6 +208,7 @@ namespace etk {
|
|||||||
bool operator== (etk::NullPtr) const {
|
bool operator== (etk::NullPtr) const {
|
||||||
return m_pointerPrivate == nullptr;
|
return m_pointerPrivate == nullptr;
|
||||||
}
|
}
|
||||||
|
#ifdef ETK_FUNCTION_ENABLE_NEW
|
||||||
Function& operator= (const Function& _obj) {
|
Function& operator= (const Function& _obj) {
|
||||||
delete m_pointerPrivate;
|
delete m_pointerPrivate;
|
||||||
m_pointerPrivate = nullptr;
|
m_pointerPrivate = nullptr;
|
||||||
@ -189,9 +217,11 @@ namespace etk {
|
|||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
Function& operator= (Function&& _obj) {
|
Function& operator= (Function&& _obj) {
|
||||||
delete m_pointerPrivate;
|
delete m_pointerPrivate;
|
||||||
m_pointerPrivate = etk::move(_obj.m_pointerPrivate);
|
m_pointerPrivate = _obj.m_pointerPrivate;
|
||||||
|
_obj.m_pointerPrivate = nullptr;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -450,7 +450,7 @@ bool etk::String::startWith(const etk::String& _val, bool _caseSensitive) const
|
|||||||
}
|
}
|
||||||
if (_caseSensitive == true) {
|
if (_caseSensitive == true) {
|
||||||
for( size_t iii = 0;
|
for( size_t iii = 0;
|
||||||
iii < size()-1;
|
iii < _val.size();
|
||||||
iii++) {
|
iii++) {
|
||||||
if (m_data[iii] != _val[iii]) {
|
if (m_data[iii] != _val[iii]) {
|
||||||
return false;
|
return false;
|
||||||
@ -459,7 +459,7 @@ bool etk::String::startWith(const etk::String& _val, bool _caseSensitive) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for( size_t iii = 0;
|
for( size_t iii = 0;
|
||||||
iii < _val.size()-1;
|
iii < _val.size();
|
||||||
iii++) {
|
iii++) {
|
||||||
if (etk::toLower(_val[iii]) != etk::toLower(m_data[iii])) {
|
if (etk::toLower(_val[iii]) != etk::toLower(m_data[iii])) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -426,7 +426,7 @@ bool etk::UString::startWith(const etk::UString& _val, bool _caseSensitive) cons
|
|||||||
}
|
}
|
||||||
if (_caseSensitive == true) {
|
if (_caseSensitive == true) {
|
||||||
for( size_t iii = 0;
|
for( size_t iii = 0;
|
||||||
iii < size();
|
iii < _val.size();
|
||||||
iii++) {
|
iii++) {
|
||||||
if (m_data[iii] != _val[iii]) {
|
if (m_data[iii] != _val[iii]) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -30,21 +30,21 @@ TEST(TestFunction, NullFunction) {
|
|||||||
etk::Function<void(int)> f_display = nullptr;
|
etk::Function<void(int)> f_display = nullptr;
|
||||||
EXPECT_EQ(f_display, nullptr);
|
EXPECT_EQ(f_display, nullptr);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
TEST(TestFunction, setAFreeFunction) {
|
TEST(TestFunction, setAFreeFunction) {
|
||||||
globalValue = 0;
|
globalValue = 0;
|
||||||
// Test contructor value
|
// 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);
|
EXPECT_NE(f_display, nullptr);
|
||||||
}
|
}
|
||||||
TEST(TestFunction, callAFreeFunction) {
|
TEST(TestFunction, callAFreeFunction) {
|
||||||
globalValue = 0;
|
globalValue = 0;
|
||||||
// Test contructor value
|
// Test contructor value
|
||||||
etk::Function<void(int)> f_display = print_num;
|
etk::Function<void(int32_t)> f_display = print_num;
|
||||||
f_display(235);
|
f_display(235);
|
||||||
EXPECT_EQ(globalValue, 235 + 1000);
|
EXPECT_EQ(globalValue, 235 + 1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TestFunction, setALambda) {
|
TEST(TestFunction, setALambda) {
|
||||||
globalValue = 0;
|
globalValue = 0;
|
||||||
// Test contructor value
|
// Test contructor value
|
||||||
@ -74,4 +74,4 @@ TEST(TestFunction, callAMemberFunction) {
|
|||||||
f_display(foo, 16);
|
f_display(foo, 16);
|
||||||
EXPECT_EQ(globalValue, 16 + 70000);
|
EXPECT_EQ(globalValue, 16 + 70000);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user