Skip to content
Snippets Groups Projects
Commit 4ed98ea7 authored by Jean Meurice's avatar Jean Meurice
Browse files

added "err_out"

parent 5b49cc13
No related branches found
No related tags found
No related merge requests found
#pragma once
/*
This header should be used as an abstraction in an autopilot in order to:
- throw errors
- print error messages (cerr)
- print information messages (cout)
The goal is that the hardware_emulator can substitute its own function calls (dynamically loaded)
in order to properly transmit messages and errors from the autopilot.
In order to use the different implementations (standalone_err_out.cpp, ...) the correct file has to be compiled into the autopilot.
*/
#ifdef __cplusplus
extern "C" {
#endif
void throw_error(const char* type, const char* message);
void print_cout(const char *message);
void print_cerr(const char *message);
#ifdef __cplusplus
}
#endif
#include "err_out.h"
#include <exception>
#include <string>
#include <iostream>
/*
This "backend" for err_out.h just uses the standard outputs and throws a standard c++ exception.
*/
class StandaloneException : public std::exception {
std::string msg;
public:
StandaloneException(const char* type, const char* message) : msg((std::string(type) + ": ") + message) {}
virtual const char* what() const throw()
{
return msg.c_str();
}
};
void throw_error(const char* type, const char* message) {
throw StandaloneException(type, message);
}
void print_cout(const char *message) {
std::cout << message;
}
void print_cerr(const char *message) {
std::cerr << message;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment