IRSOL
C++ code implementing socket server for interacting with Baumer camera.
success.hpp
Go to the documentation of this file.
1
13#pragma once
14
15#include "irsol/macros.hpp"
18#include "irsol/traits.hpp"
19#include "irsol/types.hpp"
20
21#include <string>
22#include <type_traits>
23
24namespace irsol {
25namespace protocol {
26
38struct Success
39{
41 std::string identifier;
42
45
47 std::optional<irsol::types::protocol_value_t> body{};
48
53 std::string toString() const;
54
56 bool hasBody() const;
57
59 bool hasInt() const;
60
62 bool hasDouble() const;
63
65 bool hasString() const;
66
75 static Success from(
76 const Assignment& msg,
77 std::optional<irsol::types::protocol_value_t> overrideValue = std::nullopt)
78 {
79 return Success(
80 msg.identifier,
82 overrideValue.has_value() ? overrideValue : std::make_optional(msg.value));
83 }
84
90 static Success from(const Command& msg)
91 {
92 return Success(msg.identifier, InMessageKind::COMMAND);
93 }
94
102 {
103 return Success(msg.identifier, InMessageKind::INQUIRY, std::make_optional(result));
104 }
105
117 {
118 return Success(identifier, InMessageKind::INQUIRY, std::make_optional(value));
119 }
120
121private:
122 // Only allow construction through factory methods
123 Success(
124 const std::string& identifier,
126 std::optional<irsol::types::protocol_value_t> body = std::nullopt);
127};
128
129} // namespace protocol
130} // namespace irsol
InMessageKind
Represents the type of an incoming message.
Definition variants.hpp:45
Common portability and diagnostic macros for the irsol library.
std::variant< int, double, std::string > protocol_value_t
Variant type representing protocol values that can be one of several types.
Definition types.hpp:150
Represents an assignment operation in the protocol.
Represents a command invocation in the protocol.
Definition command.hpp:33
Represents a value inquiry in the protocol.
Definition inquiry.hpp:32
Represents a success response message from the server.
Definition success.hpp:39
static Success from(const Assignment &msg, std::optional< irsol::types::protocol_value_t > overrideValue=std::nullopt)
Creates a success message from an Assignment.
Definition success.hpp:75
bool hasDouble() const
Definition success.cpp:48
std::string identifier
The identifier associated with the success response.
Definition success.hpp:41
static Success asStatus(const std::string &identifier, irsol::types::protocol_value_t value)
Creates a standalone status message with a value.
Definition success.hpp:116
static Success from(const Command &msg)
Creates a success message from a Command.
Definition success.hpp:90
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
static Success from(const Inquiry &msg, irsol::types::protocol_value_t result)
Creates a success message from an Inquiry.
Definition success.hpp:101
auto value
auto result
auto msg
Template metaprogramming traits for type introspection in the irsol library.
Core type definitions for networking, time handling, and protocol values used throughout the irsol li...
Definitions and utilities for incoming and outgoing protocol messages.