DUDS
Distributed Update of Data from Something
BppImageArchiveSequence.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2019 Jeff Jackowski
9  */
11 #include <boost/noncopyable.hpp>
12 #include <fstream>
13 
14 namespace duds { namespace ui { namespace graphics {
15 
21 class BppImageArchiveSequence : boost::noncopyable {
22 protected:
27  std::istream *is;
34  std::pair<std::string, BppImageSptr> deref;
38  BppImageArchiveSequence() = default;
39 public:
46  BppImageArchiveSequence(std::istream &str) : is(&str) { }
54  class iterator {
59  public:
66  iterator(BppImageArchiveSequence *parent) : bias(parent) { }
70  constexpr iterator() : bias(nullptr) { }
74  bool operator==(const iterator &i) const {
75  return (bias == i.bias);
76  }
80  bool operator!=(const iterator &i) const {
81  return (bias != i.bias);
82  }
95  iterator i(*this);
96  operator++();
97  return i;
98  }
102  const std::pair<std::string, BppImageSptr> &operator*() const {
103  return bias->deref;
104  }
109  const std::pair<std::string, BppImageSptr> *operator->() const {
110  return &(bias->deref);
111  }
115  const std::string &name() const {
116  return bias->deref.first;
117  }
121  const BppImageSptr &image() const {
122  return bias->deref.second;
123  }
124  };
125  friend iterator;
136  iterator begin();
140  static constexpr iterator end() {
141  return iterator();
142  }
156  void readHeader();
157 };
158 
170  std::ifstream inf;
171 public:
187  BppImageArchiveFile(const std::string &path);
188 };
189 
190 } } }
std::ifstream inf
The input file stream.
iterator begin()
Parses the first image in the stream and returns an iterator to that data.
iterator operator++(int)
Post-increment operator; involves making a copy of this iterator.
std::pair< std::string, BppImageSptr > deref
Stores the last parsed image data.
iterator(BppImageArchiveSequence *parent)
Makes a new iterator, but does not prepare the BppImageArchiveSequence object to use the iterator...
An input iterator that will parse and supply image data from the stream.
static constexpr iterator end()
Returns the end iterator.
bool operator!=(const iterator &i) const
Inequality operator.
void readHeader()
Parses the headers used in BppImageArchive files.
Provides an input iterator to a sequence of named bit-per-pixel images read from an archive file...
std::shared_ptr< BppImage > BppImageSptr
Definition: BppImage.hpp:1777
const std::pair< std::string, BppImageSptr > & operator*() const
Provides a std::pair with the name of the image and the image itself.
BppImageArchiveSequence()=default
Only use when a derived class will set is.
std::istream * is
The stream which contains image data.
BppImageArchiveSequence(std::istream &str)
Constructs the sequence parser to use the stream str.
constexpr iterator()
Equivalent to the end iterator.
iterator & operator++()
Pre-increment operator; parses the next image.
Provides an input iterator to a sequence of named bit-per-pixel images read from an input stream...
bool operator==(const iterator &i) const
Equality operator.
const BppImageSptr & image() const
Returns the image.
General graphics related code.
Definition: HD44780.hpp:15
const std::string & name() const
Returns the name of the image.
const std::pair< std::string, BppImageSptr > * operator->() const
Provides a pointer to a std::pair with the name of the image and the image itself.
BppImageArchiveSequence * bias
The object containing the data required for this iterator to work.