Skip to content

Commit

Permalink
Merge pull request #204 from SylvainCorlay/xregistry_split
Browse files Browse the repository at this point in the history
Split xregistry
  • Loading branch information
SylvainCorlay committed Oct 24, 2020
2 parents 3b1d604 + 0e780b3 commit 24d08fc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ set(XWIDGETS_SOURCES
${XWIDGETS_SOURCE_DIR}/xpassword.cpp
${XWIDGETS_SOURCE_DIR}/xplay.cpp
${XWIDGETS_SOURCE_DIR}/xprogress.cpp
${XWIDGETS_SOURCE_DIR}/xregistry.cpp
${XWIDGETS_SOURCE_DIR}/xselect.cpp
${XWIDGETS_SOURCE_DIR}/xslider.cpp
${XWIDGETS_SOURCE_DIR}/xselectionslider.cpp
Expand Down
25 changes: 3 additions & 22 deletions include/xwidgets/xholder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,16 @@ namespace xw
template <class D>
void register_owning(xtransport<D>&& model);

void unregister(xeus::xguid id);
XWIDGETS_API void unregister(xeus::xguid id);

typename storage_type::mapped_type& find(xeus::xguid id);
XWIDGETS_API typename storage_type::mapped_type& find(xeus::xguid id);

private:

storage_type m_storage;
};

inline xregistry& get_transport_registry()
{
static xregistry instance;
return instance;
}
XWIDGETS_API xregistry& get_transport_registry();

/**************************
* holder implementations *
Expand Down Expand Up @@ -502,21 +498,6 @@ namespace xw
m_storage[model.id()] = make_owning_holder(std::move(model));
}

inline void xregistry::unregister(xeus::xguid id)
{
m_storage.erase(id);
}

inline auto xregistry::find(xeus::xguid id) -> typename storage_type::mapped_type&
{
auto it = m_storage.find(id);
if (it == m_storage.end())
{
throw std::runtime_error("Could not find specified id in transport registry");
}
return it->second;
}

/*****************************
* xholder_id implementation *
*****************************/
Expand Down
26 changes: 26 additions & 0 deletions src/xregistry.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "xwidgets/xholder.hpp"
// TODO: separate xregistry declaration in own header

namespace xw
{
void xregistry::unregister(xeus::xguid id)
{
m_storage.erase(id);
}

auto xregistry::find(xeus::xguid id) -> typename storage_type::mapped_type&
{
auto it = m_storage.find(id);
if (it == m_storage.end())
{
throw std::runtime_error("Could not find specified id in transport registry");
}
return it->second;
}

xregistry& get_transport_registry()
{
static xregistry instance;
return instance;
}
}

0 comments on commit 24d08fc

Please sign in to comment.