42 Image getFromHashCode (
const int64 hashCode)
noexcept
46 for (
auto& item : images)
48 if (item.hashCode == hashCode)
58 void addImageToCache (
const Image& image,
const int64 hashCode)
76 for (
int i = images.
size(); --i >= 0;)
80 if (item.image.getReferenceCount() <= 1)
82 if (now > item.lastUseTime + cacheTimeout || now < item.lastUseTime - 1000)
87 item.lastUseTime = now;
95 void releaseUnusedImages()
99 for (
int i = images.
size(); --i >= 0;)
113 unsigned int cacheTimeout = 5000;
124 if (Pimpl::getInstanceWithoutCreating() !=
nullptr)
125 return Pimpl::getInstanceWithoutCreating()->
getFromHashCode (hashCode);
132 Pimpl::getInstance()->addImageToCache (image, hashCode);
166 Pimpl::getInstance()->cacheTimeout = (
unsigned int)
millisecs;
171 Pimpl::getInstance()->releaseUnusedImages();
Holds a resizable array of primitive or copy-by-value objects.
bool isEmpty() const noexcept
Returns true if the array is empty, false otherwise.
int size() const noexcept
Returns the current number of elements in the array.
void remove(int indexToRemove)
Removes an element from the array.
void add(const ElementType &newElement)
Appends a new element at the end of the array.
ElementType & getReference(int index) noexcept
Returns a direct reference to one of the elements in the array, without checking the index passed in.
Classes derived from this will be automatically deleted when the application exits.
Represents a local file or directory.
int64 hashCode64() const
Returns a 64-bit hash-code that identifies this file.
Automatically locks and unlocks a mutex object.
A global cache of images that have been loaded from files or memory.
static Image getFromMemory(const void *imageData, int dataSize)
Loads an image from an in-memory image file, (or just returns the image if it's already cached).
static void setCacheTimeout(int millisecs)
Changes the amount of time before an unused image will be removed from the cache.
static void addImageToCache(const Image &image, int64 hashCode)
Adds an image to the cache with a user-defined hash-code.
static void releaseUnusedImages()
Releases any images in the cache that aren't being referenced by active Image objects.
static Image getFromFile(const File &file)
Loads an image from a file, (or just returns the image if it's already cached).
static Image getFromHashCode(int64 hashCode)
Checks the cache for an image with a particular hashcode.
Holds a fixed-size bitmap.
int getReferenceCount() const noexcept
Returns the number of Image objects which are currently referring to the same internal shared image d...
static uint32 getApproximateMillisecondCounter() noexcept
Less-accurate but faster version of getMillisecondCounter().
Makes repeated callbacks to a virtual method at a specified time interval.
void stopTimer() noexcept
Stops the timer.
bool isTimerRunning() const noexcept
Returns true if the timer is currently running.
void startTimer(int intervalInMilliseconds) noexcept
Starts the timer and sets the length of interval required.
#define JUCE_IMPLEMENT_SINGLETON(Classname)
This is a counterpart to the JUCE_DECLARE_SINGLETON macros.
#define JUCE_DECLARE_SINGLETON(Classname, doNotRecreateAfterDeletion)
Macro to generate the appropriate methods and boilerplate for a singleton class.
int pointer_sized_int
A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
long long int64
A platform-independent 64-bit integer type.
void timerCallback() override
The user-defined callback routine that actually gets called periodically.