IRSOL
C++ code implementing socket server for interacting with Baumer camera.
irsol::protocol::Assignment Struct Reference

Represents an assignment operation in the protocol. More...

#include <assignment.hpp>

Public Member Functions

 Assignment (const std::string &identifier, irsol::types::protocol_value_t value)
 Constructs an Assignment.
 
std::string toString () const
 Converts the assignment to a human-readable string.
 
bool hasInt () const
 
bool hasDouble () const
 
bool hasString () const
 

Public Attributes

std::string identifier
 The variable or parameter name being assigned.
 
irsol::types::protocol_value_t value
 The value assigned to the identifier (int, double, or string).
 

Detailed Description

Represents an assignment operation in the protocol.

An assignment consists of an identifier and a value, which can be an integer, double, or string. Typically corresponds to input like x=42.

Can be stored in a irsol::protocol::InMessage variant.

Definition at line 31 of file assignment.hpp.

Constructor & Destructor Documentation

◆ Assignment()

irsol::protocol::Assignment::Assignment ( const std::string &  identifier,
irsol::types::protocol_value_t  value 
)

Constructs an Assignment.

Parameters
identifierThe identifier string; must start with a character and contain alphanumeric characters or underscores.
valueThe value to assign (int, double, or string).

Definition at line 11 of file assignment.cpp.

13{}
std::string validateIdentifier(const std::string &identifier)
Validate that a string is a valid protocol identifier.
Definition utils.hpp:55
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.

Member Function Documentation

◆ hasDouble()

bool irsol::protocol::Assignment::hasDouble ( ) const
Returns
true if the value is of type double.

Definition at line 42 of file assignment.cpp.

43{
44 return std::holds_alternative<double>(value);
45}

◆ hasInt()

bool irsol::protocol::Assignment::hasInt ( ) const
Returns
true if the value is of type int.

Definition at line 36 of file assignment.cpp.

37{
38 return std::holds_alternative<int>(value);
39}

◆ hasString()

bool irsol::protocol::Assignment::hasString ( ) const
Returns
true if the value is of type string.

Definition at line 48 of file assignment.cpp.

49{
50 return std::holds_alternative<std::string>(value);
51}

◆ toString()

std::string irsol::protocol::Assignment::toString ( ) const

Converts the assignment to a human-readable string.

Returns
A string representation of the assignment.

Definition at line 16 of file assignment.cpp.

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}
#define IRSOL_ASSERT_ERROR
Error-level assertion macro.
Definition assert.hpp:134

Member Data Documentation

◆ identifier

std::string irsol::protocol::Assignment::identifier

The variable or parameter name being assigned.

Definition at line 42 of file assignment.hpp.

◆ value

irsol::types::protocol_value_t irsol::protocol::Assignment::value

The value assigned to the identifier (int, double, or string).

Definition at line 45 of file assignment.hpp.


The documentation for this struct was generated from the following files: