FairMQ  1.4.33
C++ Message Queuing Library and Framework
Transports.h
1 /********************************************************************************
2  * Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 #ifndef FAIR_MQ_TRANSPORTS_H
10 #define FAIR_MQ_TRANSPORTS_H
11 
12 #include <fairmq/tools/Strings.h>
13 
14 #include <memory>
15 #include <stdexcept>
16 #include <string>
17 #include <unordered_map>
18 
19 namespace fair::mq
20 {
21 
22 enum class Transport
23 {
24  DEFAULT,
25  ZMQ,
26  SHM,
27  OFI
28 };
29 
30 struct TransportError : std::runtime_error { using std::runtime_error::runtime_error; };
31 
32 } // namespace fair::mq
33 
34 namespace fair::mq
35 {
36 
37 static std::unordered_map<std::string, Transport> TransportTypes {
38  { "default", Transport::DEFAULT },
39  { "zeromq", Transport::ZMQ },
40  { "shmem", Transport::SHM },
41  { "ofi", Transport::OFI }
42 };
43 
44 static std::unordered_map<Transport, std::string> TransportNames {
45  { Transport::DEFAULT, "default" },
46  { Transport::ZMQ, "zeromq" },
47  { Transport::SHM, "shmem" },
48  { Transport::OFI, "ofi" }
49 };
50 
51 inline std::string TransportName(Transport transport)
52 {
53  return TransportNames[transport];
54 }
55 
56 inline Transport TransportType(const std::string& transport)
57 try {
58  return TransportTypes.at(transport);
59 } catch (std::out_of_range&) {
60  throw TransportError(tools::ToString("Unknown transport provided: ", transport));
61 }
62 
63 } // namespace fair::mq
64 
65 #endif /* FAIR_MQ_TRANSPORTS_H */
fair::mq
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23

privacy