IRSOL
C++ code implementing socket server for interacting with Baumer camera.
assignment.cpp
Go to the documentation of this file.
2
3#include "irsol/assert.hpp"
5
6#include <sstream>
7
8namespace irsol {
9namespace protocol {
10
12 : identifier(utils::validateIdentifier(identifier)), value(value)
13{}
14
15std::string
17{
18 std::ostringstream oss;
19 oss << "Assignment{"
20 << "identifier: '" << identifier << "', value: ";
21 if(hasInt()) {
22 oss << "<int> " << std::get<int>(value);
23 } else if(hasDouble()) {
24 oss << "<double> " << std::get<double>(value);
25 } else if(hasString()) {
26 oss << "<string> \"" << std::get<std::string>(value) << "\"";
27 } else {
28 IRSOL_ASSERT_ERROR(false, "Invalid assignment value type");
29 throw std::runtime_error("Invalid assignment value type");
30 }
31 oss << '}';
32 return oss.str();
33}
34
35bool
37{
38 return std::holds_alternative<int>(value);
39}
40
41bool
43{
44 return std::holds_alternative<double>(value);
45}
46
47bool
49{
50 return std::holds_alternative<std::string>(value);
51}
52} // namespace protocol
53} // namespace irsol
Assertion macros and utilities based on the PPK_ASSERT library.
Protocol assignment operation representation.
#define IRSOL_ASSERT_ERROR
Error-level assertion macro.
Definition assert.hpp:134
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
Utility functions for protocol string handling and validation in the irsol library.
std::string toString() const
Converts the assignment to a human-readable string.
Assignment(const std::string &identifier, irsol::types::protocol_value_t value)
Constructs an Assignment.
irsol::types::protocol_value_t value
The value assigned to the identifier (int, double, or string).
std::string identifier
The variable or parameter name being assigned.
auto value