IRSOL
C++ code implementing socket server for interacting with Baumer camera.
variants.cpp
Go to the documentation of this file.
2
10
11#include <iomanip>
12#include <iostream>
13#include <sstream>
14
15namespace irsol {
16namespace protocol {
17
18std::string
20{
21 if(isAssignment(msg)) {
22 return std::get<Assignment>(msg).toString();
23 } else if(isInquiry(msg)) {
24 return std::get<Inquiry>(msg).toString();
25 } else if(isCommand(msg)) {
26 return std::get<Command>(msg).toString();
27 } else {
28 IRSOL_ASSERT_FALSE("Unknown in message type");
29 throw std::invalid_argument("Unknown in message type");
30 }
31}
32
33std::string
35{
36 if(isSuccess(msg)) {
37 return std::get<Success>(msg).toString();
38 } else if(isError(msg)) {
39 return std::get<Error>(msg).toString();
40 } else if(isBinaryDataBuffer(msg)) {
41 return std::get<BinaryDataBuffer>(msg).toString();
42 } else if(isImageBinaryData(msg)) {
43 return std::get<ImageBinaryData>(msg).toString();
44 } else if(isColorImageBinaryData(msg)) {
45 return std::get<ColorImageBinaryData>(msg).toString();
46 } else {
47 IRSOL_ASSERT_FALSE("Unknown out message type");
48 throw std::invalid_argument("Unknown out message type");
49 }
50}
51
54{
55 return std::visit(
56 [](auto&& value) -> InMessageKind {
57 using T = std::decay_t<decltype(value)>;
58 return getInMessageKind<T>(value);
59 },
60 msg);
61}
62
63bool
68
69bool
74
75bool
80
83{
84 return std::visit(
85 [](auto&& value) -> OutMessageKind {
86 using T = std::decay_t<decltype(value)>;
87 return getOutMessageKind<T>(value);
88 },
89 msg);
90}
91
92bool
97
98bool
103
104bool
109
110bool
115bool
120
121} // namespace protocol
122} // namespace irsol
Protocol assignment operation representation.
Protocol binary data types and attributes definitions.
Protocol command representation.
Protocol error message representation.
#define IRSOL_ASSERT_FALSE(message)
Assertion macro that always fails fatally.
Definition assert.hpp:136
constexpr bool isError(IRSOL_MAYBE_UNUSED T &msg)
Checks if a given outgoing message type is Error.
Definition variants.hpp:347
std::variant< Assignment, Inquiry, Command > InMessage
Variant type representing any incoming message.
Definition variants.hpp:86
constexpr OutMessageKind getOutMessageKind(IRSOL_MAYBE_UNUSED const T &msg)
Returns the OutMessageKind enum value corresponding to a given outgoing message type.
Definition variants.hpp:254
constexpr bool isCommand(IRSOL_MAYBE_UNUSED T &msg)
Checks if a given incoming message type is a Command.
Definition variants.hpp:237
constexpr bool isSuccess(IRSOL_MAYBE_UNUSED T &msg)
Checks if a given outgoing message type is Success.
Definition variants.hpp:287
constexpr bool isColorImageBinaryData(IRSOL_MAYBE_UNUSED T &msg)
Checks if a given outgoing message type is ColorImageBinaryData.
Definition variants.hpp:332
OutMessageKind
Represents the type of an outgoing message.
Definition variants.hpp:100
constexpr bool isInquiry(IRSOL_MAYBE_UNUSED T &msg)
Checks if a given incoming message type is an Inquiry.
Definition variants.hpp:222
constexpr bool isBinaryDataBuffer(IRSOL_MAYBE_UNUSED T &msg)
Checks if a given outgoing message type is BinaryDataBuffer.
Definition variants.hpp:302
constexpr bool isAssignment(IRSOL_MAYBE_UNUSED T &msg)
Checks if a given incoming message type is an Assignment.
Definition variants.hpp:207
constexpr bool isImageBinaryData(IRSOL_MAYBE_UNUSED T &msg)
Checks if a given outgoing message type is ImageBinaryData (black & white).
Definition variants.hpp:317
std::variant< Success, BinaryDataBuffer, ImageBinaryData, ColorImageBinaryData, Error > OutMessage
Variant type representing any outgoing message.
Definition variants.hpp:149
InMessageKind
Represents the type of an incoming message.
Definition variants.hpp:45
std::string toString(const InMessage &msg)
Converts an incoming message variant to a human-readable string.
Definition variants.cpp:19
constexpr InMessageKind getInMessageKind(IRSOL_MAYBE_UNUSED const T &msg)
Returns the InMessageKind enum value corresponding to a given incoming message type.
Definition variants.hpp:178
Protocol inquiry representation.
Utility functions for protocol string handling and validation in the irsol library.
Protocol success message representation.
auto value
auto msg
Definitions and utilities for incoming and outgoing protocol messages.