-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy patherror.hpp
More file actions
54 lines (45 loc) · 1.31 KB
/
error.hpp
File metadata and controls
54 lines (45 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef DYNAMIXEL_ERROR_HPP_
#define DYNAMIXEL_ERROR_HPP_
#ifdef USE_FTDI
#include <ftdi.h>
#endif
#include <string>
namespace dynamixel {
namespace errors {
class Error {
public:
Error() {}
Error(const char* msg) : _msg(msg) {}
Error(const std::string& msg) : _msg(msg) {}
#ifdef USE_FTDI
Error(const char* msg, struct ftdi_context* ftdic)
: _msg(std::string(msg) + std::string(": ") + std::string(ftdi_get_error_string(ftdic)))
{
}
#endif
const std::string& msg() const
{
return _msg;
}
virtual std::ostream& print(std::ostream& os) const
{
os << _msg;
return os;
}
protected:
std::string _msg;
};
inline void check(const char* file, int line, bool value,
const std::string& msg)
{
if (!value)
throw Error(msg + std::string("[") + std::string(file) + "]");
}
inline std::ostream& operator<<(std::ostream& os, const Error& err)
{
return err.print(os);
}
} // namespace errors
} // namespace dynamixel
#define CHECK(val, msg) check(__FILE__, __LINE__, (val), msg)
#endif