Skip to content

Commit

Permalink
CmptTraits : std::function -> function pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubpa committed Sep 22, 2020
1 parent ea14b33 commit 4bdf72e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

project(UECS VERSION 0.12.2)
project(UECS VERSION 0.13.0)
message(STATUS "[Project] ${PROJECT_NAME}")

include(cmake/InitUCMake.cmake)
Expand Down
20 changes: 10 additions & 10 deletions include/UECS/RTDCmptTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ namespace Ubpa::UECS {
RTDCmptTraits& RegisterAlignment(CmptType, size_t alignment);

// optional
RTDCmptTraits& RegisterDefaultConstructor(CmptType, std::function<void(void*)>);
RTDCmptTraits& RegisterDefaultConstructor(CmptType, void(*)(void*));

// optional
RTDCmptTraits& RegisterCopyConstructor(CmptType, std::function<void(void*, void*)>);
RTDCmptTraits& RegisterCopyConstructor(CmptType, void(*)(void*, void*));

// optional
RTDCmptTraits& RegisterMoveConstructor(CmptType, std::function<void(void*, void*)>);
RTDCmptTraits& RegisterMoveConstructor(CmptType, void(*)(void*, void*));

// optional
RTDCmptTraits& RegisterMoveAssignment(CmptType, std::function<void(void*, void*)>);
RTDCmptTraits& RegisterMoveAssignment(CmptType, void(*)(void*, void*));

// optional
RTDCmptTraits& RegisterDestructor(CmptType, std::function<void(void*)>);
RTDCmptTraits& RegisterDestructor(CmptType, void(*)(void*));

// optional
RTDCmptTraits& RegisterName(CmptType, std::string name);
Expand Down Expand Up @@ -85,11 +85,11 @@ namespace Ubpa::UECS {

std::unordered_map<CmptType, size_t> sizeofs;
std::unordered_map<CmptType, size_t> alignments;
std::unordered_map<CmptType, std::function<void(void*)>> default_constructors; // dst <- src
std::unordered_map<CmptType, std::function<void(void*, void*)>> copy_constructors; // dst <- src
std::unordered_map<CmptType, std::function<void(void*, void*)>> move_constructors; // dst <- src
std::unordered_map<CmptType, std::function<void(void*, void*)>> move_assignments; // dst <- src
std::unordered_map<CmptType, std::function<void(void*)>> destructors;
std::unordered_map<CmptType, void(*)(void*)> default_constructors; // dst <- src
std::unordered_map<CmptType, void(*)(void*, void*)> copy_constructors; // dst <- src
std::unordered_map<CmptType, void(*)(void*, void*)> move_constructors; // dst <- src
std::unordered_map<CmptType, void(*)(void*, void*)> move_assignments; // dst <- src
std::unordered_map<CmptType, void(*)(void*)> destructors;
std::unordered_map<CmptType, std::string> names;
};
}
Expand Down
25 changes: 13 additions & 12 deletions include/UECS/detail/RTDCmptTraits.inl
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ namespace Ubpa::UECS {
return *this;
}

inline RTDCmptTraits& RTDCmptTraits::RegisterDefaultConstructor(CmptType type, std::function<void(void*)> f) {
default_constructors.emplace(type, std::move(f));
inline RTDCmptTraits& RTDCmptTraits::RegisterDefaultConstructor(CmptType type, void(*f)(void*)) {
default_constructors.emplace(type, f);
return *this;
}

inline RTDCmptTraits& RTDCmptTraits::RegisterCopyConstructor(CmptType type, std::function<void(void*, void*)> f) {
copy_constructors.emplace(type, std::move(f));
inline RTDCmptTraits& RTDCmptTraits::RegisterCopyConstructor(CmptType type, void(*f)(void*, void*)) {
copy_constructors.emplace(type, f);
return *this;
}

inline RTDCmptTraits& RTDCmptTraits::RegisterMoveConstructor(CmptType type, std::function<void(void*, void*)> f) {
move_constructors.emplace(type, move(f));
inline RTDCmptTraits& RTDCmptTraits::RegisterMoveConstructor(CmptType type, void(*f)(void*, void*)) {
move_constructors.emplace(type, f);
return *this;
}

inline RTDCmptTraits& RTDCmptTraits::RegisterMoveAssignment(CmptType type, std::function<void(void*, void*)> f) {
move_assignments.emplace(type, std::move(f));
inline RTDCmptTraits& RTDCmptTraits::RegisterMoveAssignment(CmptType type, void(*f)(void*, void*)) {
move_assignments.emplace(type, f);
return *this;
}

inline RTDCmptTraits& RTDCmptTraits::RegisterDestructor(CmptType type, std::function<void(void*)> f) {
destructors.emplace(type, std::move(f));
inline RTDCmptTraits& RTDCmptTraits::RegisterDestructor(CmptType type, void(*f)(void*)) {
destructors.emplace(type, f);
return *this;
}

Expand All @@ -49,8 +49,9 @@ namespace Ubpa::UECS {
}

inline size_t RTDCmptTraits::Alignof(CmptType type) const {
assert(alignments.find(type) != alignments.end());
return alignments.find(type)->second;
auto target = alignments.find(type);

return target != alignments.end() ? target->second : default_alignment;
}

inline void RTDCmptTraits::DefaultConstruct(CmptType type, void* cmpt) const {
Expand Down
8 changes: 4 additions & 4 deletions include/UECS/detail/RTSCmptTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ namespace Ubpa::UECS {

std::unordered_map<CmptType, size_t> sizeofs;
std::unordered_map<CmptType, size_t> alignments;
std::unordered_map<CmptType, std::function<void(void*, void*)>> copy_constructors; // dst <- src
std::unordered_map<CmptType, std::function<void(void*, void*)>> move_constructors; // dst <- src
std::unordered_map<CmptType, std::function<void(void*, void*)>> move_assignments; // dst <- src
std::unordered_map<CmptType, std::function<void(void*)>> destructors;
std::unordered_map<CmptType, void(*)(void*, void*)> copy_constructors; // dst <- src
std::unordered_map<CmptType, void(*)(void*, void*)> move_constructors; // dst <- src
std::unordered_map<CmptType, void(*)(void*, void*)> move_assignments; // dst <- src
std::unordered_map<CmptType, void(*)(void*)> destructors;
};
}

Expand Down

0 comments on commit 4bdf72e

Please sign in to comment.