feat: Add new function GetEnabledTransports()

* Also clang-format
This commit is contained in:
Dennis Klein 2021-06-07 14:14:35 +02:00
parent 60f71388ca
commit 2b8a6b3223

View File

@ -1,5 +1,5 @@
/******************************************************************************** /********************************************************************************
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* * * *
* This software is distributed under the terms of the * * This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, * * GNU Lesser General Public Licence (LGPL) version 3, *
@ -10,15 +10,13 @@
#define FAIR_MQ_TRANSPORTS_H #define FAIR_MQ_TRANSPORTS_H
#include <fairmq/tools/Strings.h> #include <fairmq/tools/Strings.h>
#include <memory> #include <memory>
#include <ostream> #include <ostream>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
namespace fair::mq namespace fair::mq {
{
enum class Transport enum class Transport
{ {
@ -28,12 +26,10 @@ enum class Transport
OFI OFI
}; };
struct TransportError : std::runtime_error { using std::runtime_error::runtime_error; }; struct TransportError : std::runtime_error
} // namespace fair::mq
namespace fair::mq
{ {
using std::runtime_error::runtime_error;
};
static std::unordered_map<std::string, Transport> TransportTypes{ static std::unordered_map<std::string, Transport> TransportTypes{
{"default", Transport::DEFAULT}, {"default", Transport::DEFAULT},
@ -49,10 +45,7 @@ static std::unordered_map<Transport, std::string> TransportNames {
{Transport::OFI, "ofi"} {Transport::OFI, "ofi"}
}; };
inline std::string TransportName(Transport transport) inline std::string TransportName(Transport transport) { return TransportNames[transport]; }
{
return TransportNames[transport];
}
inline Transport TransportType(const std::string& transport) inline Transport TransportType(const std::string& transport)
try { try {
@ -66,6 +59,15 @@ inline std::ostream& operator<<(std::ostream& os, const Transport& transport)
return os << TransportName(transport); return os << TransportName(transport);
} }
inline auto GetEnabledTransports() -> std::vector<Transport>
{
#ifdef BUILD_OFI_TRANSPORT
return {Transport::ZMQ, Transport::SHM, Transport::OFI};
#else
return {Transport::ZMQ, Transport::SHM};
#endif
}
} // namespace fair::mq } // namespace fair::mq
#endif /* FAIR_MQ_TRANSPORTS_H */ #endif /* FAIR_MQ_TRANSPORTS_H */