diff options
Diffstat (limited to 'includes/image_io/extras/string_view_data_source.h')
-rw-r--r-- | includes/image_io/extras/string_view_data_source.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/includes/image_io/extras/string_view_data_source.h b/includes/image_io/extras/string_view_data_source.h new file mode 100644 index 0000000..0a90b44 --- /dev/null +++ b/includes/image_io/extras/string_view_data_source.h @@ -0,0 +1,33 @@ +#ifndef IMAGE_IO_EXTRAS_STRING_VIEW_DATA_SOURCE_H_ // NOLINT +#define IMAGE_IO_EXTRAS_STRING_VIEW_DATA_SOURCE_H_ // NOLINT + +#include "image_io/base/data_destination.h" +#include "image_io/base/data_range.h" +#include "image_io/base/data_segment_data_source.h" + +#include "third_party/absl/strings/string_view.h" + +namespace photos_editing_formats { +namespace image_io { + +/// A DataSource that reads bytes from a string_view. The underlying string data +/// must have a lifetime that exceeds the lifetime of this data source, and the +/// string contents must not change while the data source is referencing it. +class StringViewDataSource : public DataSegmentDataSource { + public: + /// Constructs a StringViewDataSource using the given string_view. + /// @param str The string_view to read from. + explicit StringViewDataSource(absl::string_view string_src); + + /// Returns the string view being used as the data source. + absl::string_view GetStringView() const { return string_src_; } + + private: + /// The string_view to read from. + absl::string_view string_src_; +}; + +} // namespace image_io +} // namespace photos_editing_formats + +#endif // IMAGE_IO_EXTRAS_STRING_VIEW_DATA_SOURCE_H_ // NOLINT |