• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef IMAGE_IO_BASE_MESSAGE_H_  // NOLINT
2 #define IMAGE_IO_BASE_MESSAGE_H_  // NOLINT
3 
4 #include <string>
5 
6 namespace photos_editing_formats {
7 namespace image_io {
8 
9 /// A message that is reported to and managed by the MessageHandler, and
10 /// possibly written by a MessageWriter.
11 class Message {
12  public:
13   /// The types of Messages.
14   enum Type {
15     /// A Status message.
16     kStatus,
17 
18     /// A Warning message.
19     kWarning,
20 
21     /// An error from the stdlib was detected. The std::errno variable can be
22     /// used to programmatically decide what to do, or use the std::strerror
23     /// function to get a string description of the error.
24     kStdLibError,
25 
26     /// A premature end of the data being processed was found.
27     kPrematureEndOfDataError,
28 
29     /// An expected string value was not found in the data being processed.
30     kStringNotFoundError,
31 
32     /// An error occurred while decoding the data being processed.
33     kDecodingError,
34 
35     /// An error occurred while parsing the data.
36     kSyntaxError,
37 
38     /// An error occurred while using the data.
39     kValueError,
40 
41     /// An internal error of some sort occurred.
42     kInternalError
43   };
44 
45   /// @param type The type of message to create.
46   /// @param system_errno The errno value to use for kStdLibError type messages.
47   /// @param text The text of the message.
Message(Type type,int system_errno,const std::string & text)48   Message(Type type, int system_errno, const std::string& text)
49       : type_(type), system_errno_(system_errno), text_(text) {}
50 
51   Message() = delete;
52 
53   bool operator==(const Message& rhs) const {
54     return type_ == rhs.type_ && system_errno_ == rhs.system_errno_ &&
55            text_ == rhs.text_;
56   }
57 
58   bool operator!=(const Message& rhs) const {
59     return type_ != rhs.type_ || system_errno_ != rhs.system_errno_ ||
60            text_ != rhs.text_;
61   }
62 
63   /// @return The type of message.
GetType()64   Type GetType() const { return type_; }
65 
66   /// @return The system errno value used for kStdLibError messages.
GetSystemErrno()67   int GetSystemErrno() const { return system_errno_; }
68 
69   /// @return The text of the message.
GetText()70   const std::string& GetText() const { return text_; }
71 
72   /// @return Whether the message is an error message.
IsError()73   bool IsError() const {
74     return type_ != Message::kStatus && type_ != Message::kWarning;
75   }
76 
77   /// @return Whether the message is a warning message.
IsWarning()78   bool IsWarning() const { return type_ == Message::kWarning; }
79 
80   /// @return Whether the message is a status message.
IsStatus()81   bool IsStatus() const { return type_ == Message::kStatus; }
82 
83  private:
84   /// The type of message.
85   Type type_;
86 
87   /// If type == kStdLibError, the system's errno value at the time
88   /// the error was reported, else it's value is 0.
89   int system_errno_;
90 
91   /// The text associated with the message.
92   std::string text_;
93 };
94 
95 }  // namespace image_io
96 }  // namespace photos_editing_formats
97 
98 #endif // IMAGE_IO_BASE_MESSAGE_H_  // NOLINT
99