|
DUDS
|
Distributed Update of Data from Something
|
An archive of BppImage objects keyed by a string name. More...
#include <BppImageArchive.hpp>
Public Types | |
| typedef std::unordered_map< std::string, BppImageSptr > | ImageMap |
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 BppImageSptr & | get (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< BppImageArchive > | make () |
| Returns a new empty BppImageArchive object in a shared pointer. More... | |
| 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 &). More... | |
| static std::shared_ptr< BppImageArchive > | make (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... | |
An archive of BppImage objects keyed by a string name.
This class is thread safe.
Definition at line 23 of file BppImageArchive.hpp.
| typedef std::unordered_map<std::string, BppImageSptr> duds::ui::graphics::BppImageArchive::ImageMap |
Definition at line 25 of file BppImageArchive.hpp.
|
default |
Makes an empty image archive.
|
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.
| path | The path of the archive file to load. |
| ImageArchiveStreamError | Failed to open the file. |
| ImageNotArchiveStreamError | The stream does not have an image archive stream. |
| ImageArchiveStreamTruncatedError | The stream appears to have an incomplete copy of the archive stream. Any images fully read prior to the error will be available. |
| ImageArchiveUnsupportedVersionError | The software does not support the claimed archive version. |
Definition at line 49 of file BppImageArchive.hpp.
|
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.
| is | The input stream that will provide the image archive. |
| ImageNotArchiveStreamError | The stream does not have an image archive stream. |
| ImageArchiveStreamTruncatedError | The stream appears to have an incomplete copy of the archive stream. Any images fully read prior to the error will be available. |
| ImageArchiveUnsupportedVersionError | The software does not support the claimed archive version. |
Definition at line 62 of file BppImageArchive.hpp.
| void duds::ui::graphics::BppImageArchive::add | ( | const std::string & | name, |
| const BppImageSptr & | img | ||
| ) |
Adds an image to the archive.
| name | The 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. |
| img | The image to store. |
Definition at line 43 of file BppImageArchive.cpp.
Referenced by make().
| void duds::ui::graphics::BppImageArchive::add | ( | const std::string & | name, |
| BppImageSptr && | img | ||
| ) |
Moves an image into the archive.
| name | The 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. |
| img | The image to store. The shared pointer will be moved. |
Definition at line 48 of file BppImageArchive.cpp.
|
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.
|
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.
| 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).
| name | The name of the image to find. |
| ImageNotFoundError | The image name is not in the archive. |
Definition at line 53 of file BppImageArchive.cpp.
| 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.
| path | The path of the archive file to load. |
| ImageArchiveStreamError | Failed to open the file. |
| ImageNotArchiveStreamError | The stream does not have an image archive stream. |
| ImageArchiveStreamTruncatedError | The stream appears to have an incomplete copy of the archive stream. Any images fully read prior to the error will be available. |
| ImageArchiveUnsupportedVersionError | The software does not support the claimed archive version. |
Definition at line 17 of file BppImageArchive.cpp.
Referenced by BppImageArchive(), and make().
| 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.
| is | The input stream that will provide the image archive. |
| ImageNotArchiveStreamError | The stream does not have an image archive stream. |
| ImageArchiveStreamTruncatedError | The stream appears to have an incomplete copy of the archive stream. Any images fully read prior to the error will be available. |
| ImageArchiveUnsupportedVersionError | The software does not support the claimed archive version. |
Definition at line 33 of file BppImageArchive.cpp.
|
inlinestatic |
Returns a new empty BppImageArchive object in a shared pointer.
Definition at line 43 of file BppImageArchive.hpp.
|
inlinestatic |
Returns a new BppImageArchive object in a shared pointer, and calls load(const std::string &).
Definition at line 56 of file BppImageArchive.hpp.
|
inlinestatic |
Returns a new BppImageArchive object in a shared pointer, and calls load(std::istream &).
Definition at line 69 of file BppImageArchive.hpp.
| 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.
| name | The name of the image to find. |
Definition at line 63 of file BppImageArchive.cpp.
Referenced by make().
|
private |
|
mutableprivate |