IRSOL
C++ code implementing socket server for interacting with Baumer camera.
error.hpp
Go to the documentation of this file.
1
12#pragma once
13
14#include "irsol/macros.hpp"
17#include "irsol/traits.hpp"
18#include "irsol/types.hpp"
19
20#include <string>
21
22namespace irsol {
23namespace protocol {
24
35struct Error
36{
38 std::string identifier;
39
42
44 std::string description;
45
50 std::string toString() const;
51
62 template<typename T, std::enable_if_t<irsol::traits::is_type_in_variant_v<T, InMessage>, int> = 0>
63 static Error from(const T& msg, const std::string& description)
64 {
65 if constexpr(std::is_same_v<T, Assignment>) {
67 } else if constexpr(std::is_same_v<T, Inquiry>) {
68 return Error(msg.identifier, InMessageKind::INQUIRY, description);
69 } else if constexpr(std::is_same_v<T, Command>) {
70 return Error(msg.identifier, InMessageKind::COMMAND, description);
71 } else {
72 IRSOL_MISSING_TEMPLATE_SPECIALIZATION(T, "Error::from<T>()");
73 }
74 }
75
82 static Error from(const InMessage& message, const std::string& description);
83
84private:
85 // Construction is only permitted through factory methods
86 Error(const std::string& identifier, InMessageKind source, const std::string& description);
87};
88
89} // namespace protocol
90} // namespace irsol
std::variant< Assignment, Inquiry, Command > InMessage
Variant type representing any incoming message.
Definition variants.hpp:86
InMessageKind
Represents the type of an incoming message.
Definition variants.hpp:45
Common portability and diagnostic macros for the irsol library.
#define IRSOL_MISSING_TEMPLATE_SPECIALIZATION(T, funcNameLiteral)
Emits a compile-time error when no template specialization is available.
Definition macros.hpp:173
Represents an error response message from the server.
Definition error.hpp:36
InMessageKind source
The kind of input message that triggered the error.
Definition error.hpp:41
std::string identifier
The identifier related to the failed operation (e.g., the variable or command name).
Definition error.hpp:38
std::string description
A descriptive message explaining the cause of the error.
Definition error.hpp:44
static Error from(const T &msg, const std::string &description)
Creates an error from a specific incoming message type.
Definition error.hpp:63
std::string toString() const
Converts the error to a human-readable string.
Definition error.cpp:15
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.