Skip to content

Commit

Permalink
[DXFC-402] Implement adding multiple symbols and removing symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyKalin committed May 22, 2023
1 parent 3ba39ee commit db84275
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions include/dxfeed_graal_cpp_api/internal/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#pragma once

#define DXFCPP_DEBUG_ISOLATES

#ifdef __cpp_lib_bit_cast
# include <bit>
#endif
Expand Down
38 changes: 32 additions & 6 deletions include/dxfeed_graal_cpp_api/internal/managers/EntityManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@ namespace dxfcpp {

template <typename EntityType> struct EntityManager : private NonCopyable<EntityManager<EntityType>> {
// TODO: Boost.Bimap
std::unordered_map<Id<EntityType>, std::shared_ptr<EntityType>> entitiesById_{};
std::unordered_map<std::shared_ptr<EntityType>, Id<EntityType>> idsByEntities_{};
std::mutex mutex_{};
std::unordered_map<Id<EntityType>, std::shared_ptr<EntityType>> entitiesById_;
std::unordered_map<std::shared_ptr<EntityType>, Id<EntityType>> idsByEntities_;
std::mutex mutex_;

EntityManager() : entitiesById_{}, idsByEntities_{}, mutex_{} {
if constexpr (isDebug) {
auto name = typeid(EntityType).name();

debug("EntityManager<{}>()", name);
}
}

public:
Id<EntityType> registerEntity(std::shared_ptr<EntityType> entity) {
if constexpr (isDebug) {
debug("EntityManager::registerEntity({})", entity->toString());
auto name = typeid(EntityType).name();

debug("EntityManager<{}>::registerEntity({})", name, entity->toString());
}

std::lock_guard lockGuard{mutex_};
Expand All @@ -40,7 +50,9 @@ template <typename EntityType> struct EntityManager : private NonCopyable<Entity

bool unregisterEntity(std::shared_ptr<EntityType> entity) {
if constexpr (isDebug) {
debug("EntityManager::unregisterEntity({})", entity->toString());
auto name = typeid(EntityType).name();

debug("EntityManager<{}>::unregisterEntity({})", name, entity->toString());
}

std::lock_guard lockGuard{mutex_};
Expand All @@ -57,7 +69,9 @@ template <typename EntityType> struct EntityManager : private NonCopyable<Entity

bool unregisterEntity(Id<EntityType> id) {
if constexpr (isDebug) {
debug("EntityManager::unregisterEntity(id = {})", id.getValue());
auto name = typeid(EntityType).name();

debug("EntityManager<{}>::unregisterEntity(id = {})", name, id.getValue());
}

std::lock_guard lockGuard{mutex_};
Expand All @@ -73,6 +87,12 @@ template <typename EntityType> struct EntityManager : private NonCopyable<Entity
}

std::shared_ptr<EntityType> getEntity(Id<EntityType> id) {
if constexpr (isDebug) {
auto name = typeid(EntityType).name();

debug("EntityManager<{}>::getEntity(id = {})", name, id.getValue());
}

std::lock_guard lockGuard{mutex_};

if (auto it = entitiesById_.find(id); it != entitiesById_.end()) {
Expand All @@ -83,6 +103,12 @@ template <typename EntityType> struct EntityManager : private NonCopyable<Entity
}

std::optional<Id<EntityType>> getId(std::shared_ptr<EntityType> entity) {
if constexpr (isDebug) {
auto name = typeid(EntityType).name();

debug("EntityManager<{}>::getId({})", name, entity->toString());
}

std::lock_guard lockGuard{mutex_};

if (auto it = idsByEntities_.find(entity); it != idsByEntities_.end()) {
Expand Down

0 comments on commit db84275

Please sign in to comment.