IRSOL
C++ code implementing socket server for interacting with Baumer camera.
binary.cpp
Go to the documentation of this file.
2
3#include "irsol/assert.hpp"
5
6#include <sstream>
7
8namespace irsol {
9namespace protocol {
11 const std::string& identifier,
13 : identifier(utils::validateIdentifier(identifier)), value(value)
14{}
15
16std::string
18{
19 std::ostringstream oss;
20 oss << "BinaryDataAttribute{"
21 << "identifier: '" << identifier << "', value: ";
22 if(hasInt()) {
23 oss << "<int> " << std::get<int>(value);
24 } else if(hasDouble()) {
25 oss << "<double> " << std::get<double>(value);
26 } else if(hasString()) {
27 oss << "<string> \"" << std::get<std::string>(value) << "\"";
28 } else {
29 IRSOL_ASSERT_ERROR(false, "Invalid binary data attribute value type");
30 throw std::runtime_error("Invalid binary data attribute value type");
31 }
32 oss << '}';
33 return oss.str();
34}
35
36bool
38{
39 return std::holds_alternative<int>(value);
40}
41
42bool
44{
45 return std::holds_alternative<double>(value);
46}
47
48bool
50{
51 return std::holds_alternative<std::string>(value);
52}
53
54}
55}
Assertion macros and utilities based on the PPK_ASSERT library.
Protocol binary data types and attributes definitions.
#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 identifier
Identifier of the binary data attribute.
Definition binary.hpp:44
std::string toString() const
Returns a string representation of the binary data attribute.
Definition binary.cpp:17
irsol::types::protocol_value_t value
Value associated with the attribute.
Definition binary.hpp:47
BinaryDataAttribute(const std::string &identifier, irsol::types::protocol_value_t value)
Constructs a BinaryDataAttribute.
Definition binary.cpp:10
auto value