DUDS
Distributed Update of Data from Something
duds::ui::graphics::BppImageArchive Class Reference

An archive of BppImage objects keyed by a string name. More...

#include <BppImageArchive.hpp>

Inheritance diagram for duds::ui::graphics::BppImageArchive:
Collaboration diagram for duds::ui::graphics::BppImageArchive:

Public Types

typedef std::unordered_map< std::string, BppImageSptrImageMap
 

Public Member Functions

 BppImageArchive ()=default
 Makes an empty image archive. More...
 
 BppImageArchive (const std::string &path)
 Loads images from an image archive in the specified file. More...
 
 BppImageArchive (std::istream &is)
 Loads images from the given input stream. More...
 
void add (const std::string &name, const BppImageSptr &img)
 Adds an image to the archive. More...
 
void add (const std::string &name, BppImageSptr &&img)
 Moves an image into the archive. More...
 
ImageMap::const_iterator begin () const
 Returns a begining iterator to inspect the images within the archive. More...
 
ImageMap::const_iterator end () const
 Returns an end iterator to inspect the images within the archive. More...
 
const BppImageSptrget (const std::string &name) const
 Returns the image with the given name. More...
 
void load (const std::string &path)
 Loads images from an image archive in the specified file. More...
 
void load (std::istream &is)
 Loads images from the given input stream. More...
 
BppImageSptr tryGet (const std::string &name) const
 Returns the image with the given name. More...
 

Static Public Member Functions

static std::shared_ptr< BppImageArchivemake ()
 Returns a new empty BppImageArchive object in a shared pointer. More...
 
static std::shared_ptr< BppImageArchivemake (const std::string &path)
 Returns a new BppImageArchive object in a shared pointer, and calls load(const std::string &). More...
 
static std::shared_ptr< BppImageArchivemake (std::istream &is)
 Returns a new BppImageArchive object in a shared pointer, and calls load(std::istream &). More...
 

Private Attributes

ImageMap arc
 The images keyed by name. More...
 
duds::general::Spinlock block
 Used for thread safety. More...
 

Detailed Description

An archive of BppImage objects keyed by a string name.

This class is thread safe.

Author
Jeff Jackowski
Examples:
bppmenu.cpp, clockLCD.cpp, and st7920.cpp.

Definition at line 23 of file BppImageArchive.hpp.

Member Typedef Documentation

◆ ImageMap

typedef std::unordered_map<std::string, BppImageSptr> duds::ui::graphics::BppImageArchive::ImageMap

Definition at line 25 of file BppImageArchive.hpp.

Constructor & Destructor Documentation

◆ BppImageArchive() [1/3]

duds::ui::graphics::BppImageArchive::BppImageArchive ( )
default

Makes an empty image archive.

◆ BppImageArchive() [2/3]

duds::ui::graphics::BppImageArchive::BppImageArchive ( const std::string &  path)
inline

Loads images from an image archive in the specified file.

If the archive stream has an image with the same name as one already inside this object, the already loaded image will be replaced by putting a new BppImage object in a new shared pointer in the old one's place. This does not modify the previously loaded image of the same name.

Parameters
pathThe path of the archive file to load.
Exceptions
ImageArchiveStreamErrorFailed to open the file.
ImageNotArchiveStreamErrorThe stream does not have an image archive stream.
ImageArchiveStreamTruncatedErrorThe stream appears to have an incomplete copy of the archive stream. Any images fully read prior to the error will be available.
ImageArchiveUnsupportedVersionErrorThe software does not support the claimed archive version.

Definition at line 49 of file BppImageArchive.hpp.

◆ BppImageArchive() [3/3]

duds::ui::graphics::BppImageArchive::BppImageArchive ( std::istream &  is)
inline

Loads images from the given input stream.

Seeking is not performed. If the archive stream has an image with the same name as one already inside this object, the already loaded image will be replaced by putting a new BppImage object in a new shared pointer in the old one's place. This does not modify the previously loaded image of the same name.

Parameters
isThe input stream that will provide the image archive.
Exceptions
ImageNotArchiveStreamErrorThe stream does not have an image archive stream.
ImageArchiveStreamTruncatedErrorThe stream appears to have an incomplete copy of the archive stream. Any images fully read prior to the error will be available.
ImageArchiveUnsupportedVersionErrorThe software does not support the claimed archive version.

Definition at line 62 of file BppImageArchive.hpp.

Member Function Documentation

◆ add() [1/2]

void duds::ui::graphics::BppImageArchive::add ( const std::string &  name,
const BppImageSptr img 
)

Adds an image to the archive.

Parameters
nameThe name to give the image. If there is already an image by that name in this archive, it will be replaced, but the image object will not be modified.
imgThe image to store.

Definition at line 43 of file BppImageArchive.cpp.

Referenced by make().

◆ add() [2/2]

void duds::ui::graphics::BppImageArchive::add ( const std::string &  name,
BppImageSptr &&  img 
)

Moves an image into the archive.

Parameters
nameThe name to give the image. If there is already an image by that name in this archive, it will be replaced, but the image object will not be modified.
imgThe image to store. The shared pointer will be moved.

Definition at line 48 of file BppImageArchive.cpp.

◆ begin()

ImageMap::const_iterator duds::ui::graphics::BppImageArchive::begin ( ) const
inline

Returns a begining iterator to inspect the images within the archive.

Using the iterator is not a thread-safe operation.

Definition at line 148 of file BppImageArchive.hpp.

◆ end()

ImageMap::const_iterator duds::ui::graphics::BppImageArchive::end ( ) const
inline

Returns an end iterator to inspect the images within the archive.

Using the iterator is not a thread-safe operation.

Definition at line 155 of file BppImageArchive.hpp.

◆ get()

const BppImageSptr & duds::ui::graphics::BppImageArchive::get ( const std::string &  name) const

Returns the image with the given name.

If there is no image for the name, an exception will be thrown. The advantage is that the shared pointer to the image is not copied (better performance if an error is unlikely) and there is no need for a conditional to check for the lack of an image (possibly cleaner code).

Parameters
nameThe name of the image to find.
Returns
A shared pointer to the requested image.
Exceptions
ImageNotFoundErrorThe image name is not in the archive.
Examples:
bppmenu.cpp, clockLCD.cpp, and st7920.cpp.

Definition at line 53 of file BppImageArchive.cpp.

◆ load() [1/2]

void duds::ui::graphics::BppImageArchive::load ( const std::string &  path)

Loads images from an image archive in the specified file.

If the archive stream has an image with the same name as one already inside this object, the already loaded image will be replaced by putting a new BppImage object in a new shared pointer in the old one's place. This does not modify the previously loaded image of the same name.

Parameters
pathThe path of the archive file to load.
Exceptions
ImageArchiveStreamErrorFailed to open the file.
ImageNotArchiveStreamErrorThe stream does not have an image archive stream.
ImageArchiveStreamTruncatedErrorThe stream appears to have an incomplete copy of the archive stream. Any images fully read prior to the error will be available.
ImageArchiveUnsupportedVersionErrorThe software does not support the claimed archive version.
Examples:
bppmenu.cpp, clockLCD.cpp, and st7920.cpp.

Definition at line 17 of file BppImageArchive.cpp.

Referenced by BppImageArchive(), and make().

◆ load() [2/2]

void duds::ui::graphics::BppImageArchive::load ( std::istream &  is)

Loads images from the given input stream.

Seeking is not performed. If the archive stream has an image with the same name as one already inside this object, the already loaded image will be replaced by putting a new BppImage object in a new shared pointer in the old one's place. This does not modify the previously loaded image of the same name.

Parameters
isThe input stream that will provide the image archive.
Exceptions
ImageNotArchiveStreamErrorThe stream does not have an image archive stream.
ImageArchiveStreamTruncatedErrorThe stream appears to have an incomplete copy of the archive stream. Any images fully read prior to the error will be available.
ImageArchiveUnsupportedVersionErrorThe software does not support the claimed archive version.

Definition at line 33 of file BppImageArchive.cpp.

◆ make() [1/3]

static std::shared_ptr<BppImageArchive> duds::ui::graphics::BppImageArchive::make ( )
inlinestatic

Returns a new empty BppImageArchive object in a shared pointer.

Definition at line 43 of file BppImageArchive.hpp.

◆ make() [2/3]

static std::shared_ptr<BppImageArchive> duds::ui::graphics::BppImageArchive::make ( const std::string &  path)
inlinestatic

Returns a new BppImageArchive object in a shared pointer, and calls load(const std::string &).

Definition at line 56 of file BppImageArchive.hpp.

◆ make() [3/3]

static std::shared_ptr<BppImageArchive> duds::ui::graphics::BppImageArchive::make ( std::istream &  is)
inlinestatic

Returns a new BppImageArchive object in a shared pointer, and calls load(std::istream &).

Definition at line 69 of file BppImageArchive.hpp.

◆ tryGet()

BppImageSptr duds::ui::graphics::BppImageArchive::tryGet ( const std::string &  name) const

Returns the image with the given name.

If there is no image for the name, an empty shared pointer is returned. The advantage is that no exception handling is required, which can provide better performance when the lack of an image is a common occurance.

Parameters
nameThe name of the image to find.
Returns
A shared pointer to the requested image.

Definition at line 63 of file BppImageArchive.cpp.

Referenced by make().

Member Data Documentation

◆ arc

ImageMap duds::ui::graphics::BppImageArchive::arc
private

The images keyed by name.

Definition at line 30 of file BppImageArchive.hpp.

Referenced by add(), get(), load(), and tryGet().

◆ block

duds::general::Spinlock duds::ui::graphics::BppImageArchive::block
mutableprivate

Used for thread safety.

Definition at line 34 of file BppImageArchive.hpp.

Referenced by add(), get(), load(), and tryGet().


The documentation for this class was generated from the following files: