diff options
author | Eino-Ville Talvala <etalvala@google.com> | 2018-11-15 16:07:46 -0800 |
---|---|---|
committer | Eino-Ville Talvala <etalvala@google.com> | 2018-11-15 16:07:46 -0800 |
commit | 2d6d3250dcb304c8ad081dedc8eef6ea48fd669d (patch) | |
tree | 68cc8d5a9bf5a558f46025d740c47cb292eea9f0 /includes/image_io/base/message_store.h | |
parent | 840fc3b66a9e6593d542ada6fe14d91107fab98d (diff) | |
download | image_io-2d6d3250dcb304c8ad081dedc8eef6ea48fd669d.tar.gz |
Initial commit of libimage_io
Image_io is a library for manipulating image files, especially XMP
metadata within them.
Test: m libimage_io
Bug: 109735087
Bug: 119211681
Change-Id: I657f307be0459fe40154806c7cd388b97bcb0ea5
Diffstat (limited to 'includes/image_io/base/message_store.h')
-rw-r--r-- | includes/image_io/base/message_store.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/includes/image_io/base/message_store.h b/includes/image_io/base/message_store.h new file mode 100644 index 0000000..1d492f1 --- /dev/null +++ b/includes/image_io/base/message_store.h @@ -0,0 +1,80 @@ +#ifndef IMAGE_IO_BASE_MESSAGE_STORE_H_ // NOLINT +#define IMAGE_IO_BASE_MESSAGE_STORE_H_ // NOLINT + +#include <vector> +#include "image_io/base/message.h" + +namespace photos_editing_formats { +namespace image_io { + +/// An abstract base class for storing and reporting on Messages. +class MessageStore { + public: + virtual ~MessageStore() = default; + + /// Clears the messages maintained by the store. + virtual void ClearMessages() = 0; + + // @message The message to add to the store. + virtual void AddMessage(const Message& message) = 0; + + /// @return A vector of messages maintained by the store; this vector may be + /// empty even if the AddMessage function was called, depending on the + /// concrete subclass is implemented. + virtual std::vector<Message> GetMessages() const = 0; + + /// @return Whether the store has error messages or not. This value is + /// guarenteed to be accurate based on the latest calls to the + /// ClearMessages and AddMessage functions. + virtual bool HasErrorMessages() const = 0; +}; + +/// A MessageStore that saves the messages in a vector. The implementation of +/// this class is not thread safe. +class VectorMessageStore : public MessageStore { + public: + void ClearMessages() override { messages_.clear(); } + void AddMessage(const Message& message) override { + messages_.push_back(message); + } + std::vector<Message> GetMessages() const override { return messages_; } + bool HasErrorMessages() const override { + for (const auto& message : messages_) { + if (message.GetType() != Message::kStatus) { + return true; + } + } + return false; + } + + private: + std::vector<Message> messages_; +}; + +/// A MessageStore that simply keeps track of whether error messages have been +/// added or not, but does not store the messages themselves. The implementation +/// of this class is should not cause any crashes if run in a multi-threaded +/// environment, though there may be some cases where erroneous results are +/// returned by the HasErrorMessages function. +class ErrorFlagMessageStore : public MessageStore { + public: + ErrorFlagMessageStore() : has_error_(false) {} + void ClearMessages() override { has_error_ = false; } + void AddMessage(const Message& message) override { + if (message.GetType() != Message::kStatus) { + has_error_ = true; + } + } + std::vector<Message> GetMessages() const override { + return std::vector<Message>(); + } + bool HasErrorMessages() const override { return has_error_; } + + private: + bool has_error_; +}; + +} // namespace image_io +} // namespace photos_editing_formats + +#endif // IMAGE_IO_BASE_MESSAGE_STORE_H_ // NOLINT |