From 6f9e4d540167785235cd2f3e8203de43f83b9851 Mon Sep 17 00:00:00 2001 From: Ubpa <641614112@qq.com> Date: Fri, 5 Jun 2020 20:09:25 +0800 Subject: [PATCH] RTDCmptsView::CmptHandle::Mode -> CmptTag::Mode --- include/UECS/CmptTag.h | 6 ++++++ include/UECS/EntityLocator.h | 2 ++ include/UECS/RTDCmptsView.h | 33 ++++++++++----------------------- src/core/EntityLocator.cpp | 10 ++++++++++ src/core/RTDCmptsView.cpp | 21 +++++++++------------ 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/include/UECS/CmptTag.h b/include/UECS/CmptTag.h index 43a0910..06a4f59 100644 --- a/include/UECS/CmptTag.h +++ b/include/UECS/CmptTag.h @@ -6,6 +6,12 @@ namespace Ubpa { namespace CmptTag { // LastFrame -> Write -> Latest + enum class Mode { + LAST_FRAME, + WRITE, + LATEST + }; + template class LastFrame { public: diff --git a/include/UECS/EntityLocator.h b/include/UECS/EntityLocator.h index e2f06d8..cb50a2e 100644 --- a/include/UECS/EntityLocator.h +++ b/include/UECS/EntityLocator.h @@ -27,6 +27,8 @@ namespace Ubpa { const std::set& LatestCmptTypes() const noexcept { return latestCmptTypes; } const std::set& CmptTypes() const noexcept { return cmptTypes; } + CmptTag::Mode GetCmptTagMode(CmptType type) const; + bool operator==(const EntityLocator& locator) const noexcept; private: size_t GenHashCode() const noexcept; diff --git a/include/UECS/RTDCmptsView.h b/include/UECS/RTDCmptsView.h index d2a066f..7c17f4b 100644 --- a/include/UECS/RTDCmptsView.h +++ b/include/UECS/RTDCmptsView.h @@ -2,6 +2,7 @@ #include "CmptPtr.h" #include "CmptType.h" +#include "CmptTag.h" #include @@ -16,35 +17,28 @@ namespace Ubpa { // for read/write control class CmptHandle { public: - enum class Mode { - INVALID, - LAST_FRAME, - WRITE, - LATEST - }; - - CmptHandle(CmptType type, void* cmpt, Mode mode) + CmptHandle(CmptType type, void* cmpt, CmptTag::Mode mode) : type{ type }, cmpt{ cmpt }, mode{ mode }{} CmptType GetCmptType() const noexcept { return type; } - Mode GetMode() const noexcept { return mode; } + CmptTag::Mode GetMode() const noexcept { return mode; } CmptCPtr AsLastFrame() const noexcept { - assert(mode == Mode::LAST_FRAME); + assert(mode == CmptTag::Mode::LAST_FRAME); return { type, cmpt }; } CmptPtr AsWrite() const noexcept { - assert(mode == Mode::WRITE); + assert(mode == CmptTag::Mode::WRITE); return { type, cmpt }; } CmptCPtr AsLatest() const noexcept { - assert(mode == Mode::LATEST); + assert(mode == CmptTag::Mode::LATEST); return { type, cmpt }; } private: CmptType type; void* cmpt; - Mode mode; + CmptTag::Mode mode; }; // forward @@ -64,25 +58,18 @@ namespace Ubpa { bool operator!=(const Iterator& rhs) const noexcept { return ptr_cmpt != rhs.ptr_cmpt; } - CmptHandle operator*() const { - return { *typeIter, *ptr_cmpt, GetMode() }; - } - const CmptHandle* operator->() const noexcept { - handle = { *typeIter, *ptr_cmpt, GetMode() }; - return &handle; - } + CmptHandle operator*() const; + const CmptHandle* operator->() const noexcept; Iterator& operator++() { typeIter++; ptr_cmpt++; return *this; } private: - CmptHandle::Mode GetMode() const; - EntityLocator* locator; std::set::iterator typeIter; void* const* ptr_cmpt; - mutable CmptHandle handle{ CmptType::Invalid(), nullptr, CmptHandle::Mode::INVALID }; + mutable CmptHandle handle{ CmptType::Invalid(), nullptr, CmptTag::Mode{} }; }; RTDCmptsView(EntityLocator* locator, void** cmpts) diff --git a/src/core/EntityLocator.cpp b/src/core/EntityLocator.cpp index 9e505bf..3a14c65 100644 --- a/src/core/EntityLocator.cpp +++ b/src/core/EntityLocator.cpp @@ -29,3 +29,13 @@ bool EntityLocator::operator==(const EntityLocator& locator) const noexcept { && writeCmptTypes == locator.writeCmptTypes && latestCmptTypes == latestCmptTypes; } + +CmptTag::Mode EntityLocator::GetCmptTagMode(CmptType type) const { + assert(cmptTypes.find(type) != cmptTypes.end()); + if (lastFrameCmptTypes.find(type) != lastFrameCmptTypes.end()) + return CmptTag::Mode::LAST_FRAME; + else if (writeCmptTypes.find(type) != writeCmptTypes.end()) + return CmptTag::Mode::WRITE; + else // lastestCmptTypes.find(type) != lastestCmptTypes.end()) + return CmptTag::Mode::LATEST; +} diff --git a/src/core/RTDCmptsView.cpp b/src/core/RTDCmptsView.cpp index c023983..c65859b 100644 --- a/src/core/RTDCmptsView.cpp +++ b/src/core/RTDCmptsView.cpp @@ -5,18 +5,6 @@ using namespace Ubpa; using namespace std; -RTDCmptsView::CmptHandle::Mode RTDCmptsView::Iterator::GetMode() const { - auto type = *typeIter; - if (locator->LastFrameCmptTypes().find(type) != locator->LastFrameCmptTypes().end()) - return CmptHandle::Mode::LAST_FRAME; - else if (locator->WriteCmptTypes().find(type) != locator->WriteCmptTypes().end()) - return CmptHandle::Mode::WRITE; - else if (locator->LatestCmptTypes().find(type) != locator->LatestCmptTypes().end()) - return CmptHandle::Mode::LATEST; - else - return CmptHandle::Mode::INVALID; -} - RTDCmptsView::Iterator RTDCmptsView::begin() const noexcept { return { locator, locator->CmptTypes().begin(), cmpts }; } @@ -28,3 +16,12 @@ RTDCmptsView::Iterator RTDCmptsView::end() const noexcept { const set& RTDCmptsView::CmptTypes() const noexcept { return locator->CmptTypes(); } + +RTDCmptsView::CmptHandle RTDCmptsView::Iterator::operator*() const { + return { *typeIter, *ptr_cmpt, locator->GetCmptTagMode(*typeIter) }; +} + +const RTDCmptsView::CmptHandle* RTDCmptsView::Iterator::operator->() const noexcept { + handle = { *typeIter, *ptr_cmpt, locator->GetCmptTagMode(*typeIter) }; + return &handle; +}