• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef IMAGE_IO_BASE_MESSAGE_WRITER_H_  // NOLINT
2 #define IMAGE_IO_BASE_MESSAGE_WRITER_H_  // NOLINT
3 
4 #include "image_io/base/message.h"
5 
6 namespace photos_editing_formats {
7 namespace image_io {
8 
9 /// A message writer is used by MessageHandler to write messages as they are
10 /// reported via the ReportMessage function. The main function, WriteMessage
11 /// must be implemented by subclasses. Subclasses can also override any or all
12 /// of the other virtual functions, GetFormattedMessage(), GetTypeCategory()
13 /// and GetTypeDescription() to suit their needs.
14 class MessageWriter {
15  public:
16   virtual ~MessageWriter() = default;
17 
18   /// This function is called to write a message. Implementations can call the
19   /// GetFormattedMessage function and write it wherever it needs to go, or
20   /// do something else entirely.
21   /// @param message The message to write.
22   virtual void WriteMessage(const Message& message) = 0;
23 
24   /// Formats the message into a single string suitable for writing. This
25   /// implementation returns a string that has the format
26   /// <GetTypeCategory()><GetTypeDescription()>:text
27   /// @param message The message for which a formatted string is wanted.
28   /// @return A string describing the message.
29   virtual std::string GetFormattedMessage(const Message& message) const;
30 
31   /// @param type The type of message to get the category of.
32   /// @return A string describing the type category; this implementation returns
33   ///     (the obviously nonlocalized strings) "STATUS" or "ERROR"
34   virtual std::string GetTypeCategory(Message::Type type) const;
35 
36   /// @param type The type of message to get the description of.
37   /// @param system_errno Used for kStdLibError type messages.
38   /// @return A (non-localized) string description of the type.
39   virtual std::string GetTypeDescription(Message::Type type,
40                                          int system_errno) const;
41 };
42 
43 }  // namespace image_io
44 }  // namespace photos_editing_formats
45 
46 #endif // IMAGE_IO_BASE_MESSAGE_WRITER_H_  // NOLINT
47