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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#ifndef IMAGE_IO_BASE_MESSAGE_H_ // NOLINT
#define IMAGE_IO_BASE_MESSAGE_H_ // NOLINT
#include <string>
namespace photos_editing_formats {
namespace image_io {
/// A message that is reported to and managed by the MessageHandler, and
/// possibly written by a MessageWriter.
class Message {
public:
/// The types of Messages.
enum Type {
/// A Status message.
kStatus,
/// An error from the stdlib was detected. The std::errno variable can be
/// used to programmatically decide what to do, or use the std::strerror
/// function to get a string description of the error.
kStdLibError,
/// A premature end of the data being processed was found.
kPrematureEndOfDataError,
/// An expected string value was not found in the data being processed.
kStringNotFoundError,
/// An error occurred while decoding the data being processed.
kDecodingError,
/// An error occurred while parsing the data.
kSyntaxError,
/// An error occurred while using the data.
kValueError,
/// An internal error of some sort occurred.
kInternalError
};
/// @param type The type of message to create.
/// @param system_errno The errno value to use for kStdLibError type messages.
/// @param text The text of the message.
Message(Type type, int system_errno, const std::string& text)
: type_(type), system_errno_(system_errno), text_(text) {}
Message() = delete;
bool operator==(const Message& rhs) const {
return type_ == rhs.type_ && system_errno_ == rhs.system_errno_ &&
text_ == rhs.text_;
}
bool operator!=(const Message& rhs) const {
return type_ != rhs.type_ || system_errno_ != rhs.system_errno_ ||
text_ != rhs.text_;
}
/// @return The type of message.
Type GetType() const { return type_; }
/// @return The system errno value used for kStdLibError messages.
int GetSystemErrno() const { return system_errno_; }
/// @return The text of the message.
const std::string& GetText() const { return text_; }
private:
/// The type of message.
Type type_;
/// If type == kStdLibError, the system's errno value at the time
/// the error was reported, else it's value is 0.
int system_errno_;
/// The text associated with the message.
std::string text_;
};
} // namespace image_io
} // namespace photos_editing_formats
#endif // IMAGE_IO_BASE_MESSAGE_H_ // NOLINT
|