|
DUDS
|
Distributed Update of Data from Something
|
Maintains a cache for rendered strings that helps avoid re-rendering strings that may need to be shown many times. More...
#include <BppStringCache.hpp>
Classes | |
| struct | BppString |
| Stores an image and the data used to create it using the font. More... | |
Public Member Functions | |
| BppStringCache (const BppFontSptr &font, unsigned int maxBytes=256 *1024, unsigned int maxStrings=-1) | |
| Creates a cache of rendered strings made using the given font. More... | |
| BppStringCache (BppFontSptr &&font, unsigned int maxBytes=256 *1024, unsigned int maxStrings=-1) | |
| Creates a cache of rendered strings made using the given font. More... | |
| BppStringCache (const std::string &path, unsigned int maxBytes=256 *1024, unsigned int maxStrings=-1) | |
| Creates a cache of rendered strings made using a font created from the given image archive path. More... | |
| unsigned int | bytes () const |
| Returns the total size in bytes of all the cached images. More... | |
| void | clear () |
| Clears all text images from the cache. More... | |
| const BppFontSptr & | font () const |
| Returns the font object used by this cache to render text. More... | |
| unsigned int | maxBytes () const |
| Returns the maximum size of the cached images in bytes. More... | |
| unsigned int | maxStrings () const |
| Returns the maximum number of cached images. More... | |
| unsigned int | strings () const |
| Returns the number of currently stored cached strings. More... | |
| ConstBppImageSptr | text (const std::string &str, BppFont::Flags flags=BppFont::AlignLeft) |
| Returns an image of the requested string either from a pre-rendered item in the cache or by rendering a new image. More... | |
| ConstBppImageSptr | text (const std::u32string &str, BppFont::Flags flags=BppFont::AlignLeft) |
| Returns an image of the requested string either from a pre-rendered item in the cache or by rendering a new image. More... | |
Static Public Member Functions | |
| static std::shared_ptr< BppStringCache > | make (const BppFontSptr &font, unsigned int maxBytes=256 *1024, unsigned int maxStrings=-1) |
| Creates a cache of rendered strings made using the given font. More... | |
| static std::shared_ptr< BppStringCache > | make (BppFontSptr &&font, unsigned int maxBytes=256 *1024, unsigned int maxStrings=-1) |
| Creates a cache of rendered strings made using the given font. More... | |
| static std::shared_ptr< BppStringCache > | make (const std::string &path, unsigned int maxBytes=256 *1024, unsigned int maxStrings=-1) |
| Creates a cache of rendered strings made using a font created from the given image archive path. More... | |
Private Types | |
| typedef boost::multi_index::multi_index_container< BppString, boost::multi_index::indexed_by< boost::multi_index::hashed_non_unique< boost::multi_index::tag< struct index_text >, boost::multi_index::composite_key< BppString, boost::multi_index::member< BppString, std::u32string, &BppString::text >, boost::multi_index::member< BppString, BppFont::Flags, &BppString::flags > > >, boost::multi_index::sequenced< boost::multi_index::tag< struct index_seq > > > > | Cache |
| The container type for the rendered strings. More... | |
Private Attributes | |
| duds::general::Spinlock | block |
| Used for thread safety. More... | |
| Cache | cache |
| The cache of rendered strings. More... | |
| unsigned int | curB = 0 |
| The current size of all rendered text images in the cache. More... | |
| BppFontSptr | fnt |
| The font to use for rendering. More... | |
| unsigned int | maxB |
| The maximum size of rendered text images, in bytes, the cache may hold. More... | |
| unsigned int | maxS |
| The maximum number of strings the cache may hold. More... | |
Maintains a cache for rendered strings that helps avoid re-rendering strings that may need to be shown many times.
The cache is limited in size by the number of strings and the total size of all the rendered images in bytes. All operations are thread-safe.
Definition at line 28 of file BppStringCache.hpp.
|
private |
The container type for the rendered strings.
It has two indices:
Definition at line 81 of file BppStringCache.hpp.
| duds::ui::graphics::BppStringCache::BppStringCache | ( | const BppFontSptr & | font, |
| unsigned int | maxBytes = 256 * 1024, |
||
| unsigned int | maxStrings = -1 |
||
| ) |
Creates a cache of rendered strings made using the given font.
| font | The font to use to render the cached text. |
| maxBytes | The maximum size of the rendered string images in bytes. If this value is very low, even zero, then only one rendered image will be cached. |
| maxStrings | The maximum number of rendered strings that may be held by the cache. This value cannot be zero. |
| StringCacheZeroSize | The cache size limits prevent any image from being kept in the cache. maxBytes is zero. |
Definition at line 17 of file BppStringCache.cpp.
| duds::ui::graphics::BppStringCache::BppStringCache | ( | BppFontSptr && | font, |
| unsigned int | maxBytes = 256 * 1024, |
||
| unsigned int | maxStrings = -1 |
||
| ) |
Creates a cache of rendered strings made using the given font.
| font | The font to use to render the cached text. This object will take ownership of the font. |
| maxBytes | The maximum size of the rendered string images in bytes. If this value is very low, even zero, then only one rendered image will be cached. |
| maxStrings | The maximum number of rendered strings that may be held by the cache. This value cannot be zero. |
| StringCacheZeroSize | The cache size limits prevent any image from being kept in the cache. maxBytes is zero. |
Definition at line 27 of file BppStringCache.cpp.
|
inline |
Creates a cache of rendered strings made using a font created from the given image archive path.
| path | The image archive used to create the font that will be used to render the cached text. This object will take ownership of the font. |
| maxBytes | The maximum size of the rendered string images in bytes. If this value is very low, even zero, then only one rendered image will be cached. |
| maxStrings | The maximum number of rendered strings that may be held by the cache. This value cannot be zero. |
| StringCacheZeroSize | The cache size limits prevent any image from being kept in the cache. maxBytes is zero. |
| 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 163 of file BppStringCache.hpp.
|
inline |
Returns the total size in bytes of all the cached images.
Definition at line 268 of file BppStringCache.hpp.
| void duds::ui::graphics::BppStringCache::clear | ( | ) |
Clears all text images from the cache.
Definition at line 37 of file BppStringCache.cpp.
Referenced by strings().
|
inline |
Returns the font object used by this cache to render text.
Definition at line 250 of file BppStringCache.hpp.
Referenced by make().
|
inlinestatic |
Creates a cache of rendered strings made using the given font.
| font | The font to use to render the cached text. |
| maxBytes | The maximum size of the rendered string images in bytes. If this value is very low, even zero, then only one rendered image will be cached. |
| maxStrings | The maximum number of rendered strings that may be held by the cache. This value cannot be zero. |
| StringCacheZeroSize | The cache size limits prevent any image from being kept in the cache. maxBytes is zero. |
Definition at line 180 of file BppStringCache.hpp.
Referenced by duds::ui::graphics::BppFontPool::addWithCache().
|
inlinestatic |
Creates a cache of rendered strings made using the given font.
| font | The font to use to render the cached text. This object will take ownership of the font. |
| maxBytes | The maximum size of the rendered string images in bytes. If this value is very low, even zero, then only one rendered image will be cached. |
| maxStrings | The maximum number of rendered strings that may be held by the cache. This value cannot be zero. |
| StringCacheZeroSize | The cache size limits prevent any image from being kept in the cache. maxBytes is zero. |
Definition at line 200 of file BppStringCache.hpp.
|
inlinestatic |
Creates a cache of rendered strings made using a font created from the given image archive path.
| path | The image archive used to create the font that will be used to render the cached text. This object will take ownership of the font. |
| maxBytes | The maximum size of the rendered string images in bytes. If this value is very low, even zero, then only one rendered image will be cached. |
| maxStrings | The maximum number of rendered strings that may be held by the cache. This value cannot be zero. |
| StringCacheZeroSize | The cache size limits prevent any image from being kept in the cache. maxBytes is zero. |
| 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 236 of file BppStringCache.hpp.
|
inline |
Returns the maximum size of the cached images in bytes.
Definition at line 256 of file BppStringCache.hpp.
Referenced by make().
|
inline |
Returns the maximum number of cached images.
Definition at line 262 of file BppStringCache.hpp.
Referenced by make().
|
inline |
Returns the number of currently stored cached strings.
Definition at line 274 of file BppStringCache.hpp.
| ConstBppImageSptr duds::ui::graphics::BppStringCache::text | ( | const std::string & | str, |
| BppFont::Flags | flags = BppFont::AlignLeft |
||
| ) |
Returns an image of the requested string either from a pre-rendered item in the cache or by rendering a new image.
If the text is rendered, it is done by calling BppFont::render() on this object's font. After rendering, the cache size limits are enforced by removing the cached item(s) that were last requested farthest in the past until maximums are not exceeded. Returning a copy of the image's shared pointer prevents cache evictions from destroying images before they are used.
| str | The UTF-8 string to render. |
| flags | The option flags. The default is to render varying width, fixed height text with each line aligned to the left. |
| GlyphNotFoundError | A glyph in str is not provided by the font. |
Definition at line 106 of file BppStringCache.cpp.
| ConstBppImageSptr duds::ui::graphics::BppStringCache::text | ( | const std::u32string & | str, |
| BppFont::Flags | flags = BppFont::AlignLeft |
||
| ) |
Returns an image of the requested string either from a pre-rendered item in the cache or by rendering a new image.
If the text is rendered, it is done by calling BppFont::render() on this object's font. After rendering, the cache size limits are enforced by removing the cached item(s) that were last requested farthest in the past until maximums are not exceeded. Returning a copy of the image's shared pointer prevents cache evictions from destroying images before they are used.
| str | The UTF-32 string to render. Internally the UTF-8 representation is used for the cache. This may not be the best way to do it. |
| flags | The option flags. The default is to render varying width, fixed height text with each line aligned to the left. |
| GlyphNotFoundError | A glyph in str is not provided by the font. |
Definition at line 43 of file BppStringCache.cpp.
|
private |
Used for thread safety.
Definition at line 101 of file BppStringCache.hpp.
|
private |
The cache of rendered strings.
Definition at line 85 of file BppStringCache.hpp.
|
private |
The current size of all rendered text images in the cache.
Definition at line 97 of file BppStringCache.hpp.
|
private |
The font to use for rendering.
Definition at line 32 of file BppStringCache.hpp.
|
private |
The maximum size of rendered text images, in bytes, the cache may hold.
Definition at line 93 of file BppStringCache.hpp.
Referenced by maxBytes(), and text().
|
private |
The maximum number of strings the cache may hold.
Definition at line 89 of file BppStringCache.hpp.
Referenced by BppStringCache(), maxStrings(), and text().