IRSOL
C++ code implementing socket server for interacting with Baumer camera.
success.cpp
Go to the documentation of this file.
1
3
5
6#include <sstream>
7
8namespace irsol {
9namespace protocol {
11 const std::string& identifier,
12 InMessageKind source,
13 std::optional<irsol::types::protocol_value_t> body)
14 : identifier(utils::validateIdentifier(identifier)), source(source), body(body)
15{}
16
17std::string
19{
20 std::ostringstream oss;
21 oss << "Success{"
22 << "identifier: '" << identifier << "', source: " << InMessageKindToString(source);
23 if(hasBody()) {
24 oss << ", body: ";
25 if(hasInt()) {
26 oss << "<int> " << std::get<int>(*body);
27 } else if(hasDouble()) {
28 oss << "<double> " << std::get<double>(*body);
29 } else if(hasString()) {
30 oss << "<string> \"" << std::get<std::string>(*body) << "\"";
31 }
32 }
33 oss << "}";
34 return oss.str();
35}
36
37bool
39{
40 return body.has_value();
41}
42bool
44{
45 return hasBody() && std::holds_alternative<int>(*body);
46}
47bool
49{
50 return hasBody() && std::holds_alternative<double>(*body);
51}
52bool
54{
55 return hasBody() && std::holds_alternative<std::string>(*body);
56}
57
58} // namespace protocol
59} // namespace irsol
constexpr const char * InMessageKindToString(InMessageKind kind)
Converts an InMessageKind enum to a human-readable string.
Definition variants.hpp:59
InMessageKind
Represents the type of an incoming message.
Definition variants.hpp:45
Utility functions for protocol string handling and validation in the irsol library.
bool hasDouble() const
Definition success.cpp:48
std::string identifier
The identifier associated with the success response.
Definition success.hpp:41
Success(const std::string &identifier, InMessageKind source, std::optional< irsol::types::protocol_value_t > body=std::nullopt)
Definition success.cpp:10
std::string toString() const
Converts the success message to a human-readable string.
Definition success.cpp:18
std::optional< irsol::types::protocol_value_t > body
Optional result or data associated with the response.
Definition success.hpp:47
InMessageKind source
The kind of the incoming message that triggered this response.
Definition success.hpp:44
bool hasString() const
Definition success.cpp:53
Protocol success message representation.