DUDS
Distributed Update of Data from Something
BppImageArchive.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) 2018 Jeff Jackowski
9  */
12 #include <unordered_map>
13 
14 namespace duds { namespace ui { namespace graphics {
15 
23 class BppImageArchive : boost::noncopyable {
24 public:
25  typedef std::unordered_map<std::string, BppImageSptr> ImageMap;
26 private:
30  ImageMap arc;
35 public:
39  BppImageArchive() = default;
43  static std::shared_ptr<BppImageArchive> make() {
44  return std::make_shared<BppImageArchive>();
45  }
49  BppImageArchive(const std::string &path) {
50  load(path);
51  }
56  static std::shared_ptr<BppImageArchive> make(const std::string &path) {
57  return std::make_shared<BppImageArchive>(path);
58  }
62  BppImageArchive(std::istream &is) {
63  load(is);
64  }
69  static std::shared_ptr<BppImageArchive> make(std::istream &is) {
70  return std::make_shared<BppImageArchive>(is);
71  }
89  void load(const std::string &path);
106  void load(std::istream &is);
114  void add(const std::string &name, const BppImageSptr &img);
122  void add(const std::string &name, BppImageSptr &&img);
133  const BppImageSptr &get(const std::string &name) const;
143  BppImageSptr tryGet(const std::string &name) const;
148  ImageMap::const_iterator begin() const {
149  return arc.cbegin();
150  }
155  ImageMap::const_iterator end() const {
156  return arc.cend();
157  }
158 };
159 
160 typedef std::shared_ptr<BppImageArchive> BppImageArchiveSptr;
161 typedef std::weak_ptr<BppImageArchive> BppImageArchiveWptr;
162 
163 } } }
ImageMap::const_iterator begin() const
Returns a begining iterator to inspect the images within the archive.
static std::shared_ptr< BppImageArchive > make()
Returns a new empty BppImageArchive object in a shared pointer.
void add(const std::string &name, const BppImageSptr &img)
Adds an image to the archive.
void load(const std::string &path)
Loads images from an image archive in the specified file.
duds::general::Spinlock block
Used for thread safety.
static std::shared_ptr< BppImageArchive > make(const std::string &path)
Returns a new BppImageArchive object in a shared pointer, and calls load(const std::string &)...
BppImageArchive(std::istream &is)
Loads images from the given input stream.
std::shared_ptr< BppImage > BppImageSptr
Definition: BppImage.hpp:1777
An archive of BppImage objects keyed by a string name.
std::weak_ptr< BppImageArchive > BppImageArchiveWptr
ImageMap::const_iterator end() const
Returns an end iterator to inspect the images within the archive.
static std::shared_ptr< BppImageArchive > make(std::istream &is)
Returns a new BppImageArchive object in a shared pointer, and calls load(std::istream &)...
std::unordered_map< std::string, BppImageSptr > ImageMap
BppImageArchive(const std::string &path)
Loads images from an image archive in the specified file.
A simple spinlock following the lockable and timed lockable concepts so that it can be used with std:...
Definition: Spinlock.hpp:52
BppImageArchive()=default
Makes an empty image archive.
ImageMap arc
The images keyed by name.
General graphics related code.
Definition: HD44780.hpp:15
std::shared_ptr< BppImageArchive > BppImageArchiveSptr
BppImageSptr tryGet(const std::string &name) const
Returns the image with the given name.