Skip to content

Commit

Permalink
Revert "improve registry"
Browse files Browse the repository at this point in the history
This reverts commit e6d2065.
  • Loading branch information
philbucher committed Jun 2, 2021
1 parent 4fb26b8 commit 0f2c148
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions co_sim_io/impl/co_sim_io_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ This file contains the implementation of the functions defined in "co_sim_io.hpp
namespace CoSimIO {

namespace Internals {
// TODO make sure this is unique even across compilation units (test somehow)

// this function makes sure that the registry works correctly also across translation units / libraries
inline std::unordered_map<std::string, std::unique_ptr<Connection>>& GetRegistry()
{
static std::unordered_map<std::string, std::unique_ptr<Connection>> s_co_sim_connections;
return s_co_sim_connections;
}
#ifdef CO_SIM_IO_EXTERN
extern std::unordered_map<std::string, std::unique_ptr<Connection>> s_co_sim_connections;
#else
std::unordered_map<std::string, std::unique_ptr<Connection>> s_co_sim_connections;
#endif

static bool HasIO(const std::string& rConnectionName)
{
return GetRegistry().find(rConnectionName) != GetRegistry().end();
return s_co_sim_connections.find(rConnectionName) != s_co_sim_connections.end();
}

static Connection& GetConnection(const std::string& rConnectionName)
{
CO_SIM_IO_ERROR_IF_NOT(HasIO(rConnectionName)) << "Trying to use connection \"" << rConnectionName << "\" which does not exist!" << std::endl;
return *GetRegistry().at(rConnectionName);
return *s_co_sim_connections.at(rConnectionName);
}

} // namespace Internals
Expand Down Expand Up @@ -86,7 +86,7 @@ inline Info Connect(const Info& I_Settings)

CO_SIM_IO_ERROR_IF(HasIO(connection_name)) << "A connection from \"" << my_name << "\" to \"" << connect_to << "\"already exists!" << std::endl;

GetRegistry()[connection_name] = std::unique_ptr<Connection>(new Connection(I_Settings));
s_co_sim_connections[connection_name] = std::unique_ptr<Connection>(new Connection(I_Settings));

auto info = GetConnection(connection_name).Connect(I_Settings);
info.Set<std::string>("connection_name", connection_name);
Expand All @@ -101,7 +101,7 @@ inline Info Disconnect(const Info& I_Info)
CO_SIM_IO_ERROR_IF_NOT(HasIO(connection_name)) << "Trying to disconnect connection \"" << connection_name << "\" which does not exist!" << std::endl;

auto info = GetConnection(connection_name).Disconnect(I_Info);
GetRegistry().erase(connection_name);
s_co_sim_connections.erase(connection_name);

return info;
}
Expand Down

0 comments on commit 0f2c148

Please sign in to comment.