diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2020-06-05 21:11:15 +0200 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2020-06-06 06:27:47 +0200 |
| commit | 1dd492958567493c0e62f5d2614f1a46c50cb7e1 (patch) | |
| tree | 97b82a3b0e853baee9ff9f5be01a1a8938bab740 /FL | |
| parent | 6481f954153d5419f82e3259bdaa9427dfc8bdc2 (diff) | |
Add two virtual methods to class Fl_Image
(1) The new virtual method Fl_Image::release() which is equivalent to
'delete this' automatically extends to Fl_Shared_Image::release()
which makes the latter method virtual.
This new method in the base class makes Fl_Image::release() callable
on all objects derived from Fl_Image.
(2) Add virtual method Fl_Shared_Image *Fl_Image::as_shared_image()
This new method can be used to detect whether an Fl_Image instance
is an Fl_Shared_Image or not.
Diffstat (limited to 'FL')
| -rw-r--r-- | FL/Fl_Image.H | 44 | ||||
| -rw-r--r-- | FL/Fl_Shared_Image.H | 4 |
2 files changed, 48 insertions, 0 deletions
diff --git a/FL/Fl_Image.H b/FL/Fl_Image.H index c6fb55967..aafd39742 100644 --- a/FL/Fl_Image.H +++ b/FL/Fl_Image.H @@ -164,6 +164,50 @@ public: */ const char * const *data() const {return data_;} int fail(); + /** + Releases an Fl_Image - the same as '\p delete \p this'. + + This virtual method is for almost all image classes the same as calling + \code + delete image; + \endcode + where image is an \p Fl_Image \p * pointer. + + However, for subclass Fl_Shared_Image this virtual method is + reimplemented and maintains shared images. + + This virtual method makes it possible to \p delete all image types in + the same way by calling + \code + image->release(); + \endcode + + Reasoning: If you have an 'Fl_Image *' pointer and don't know if the + object is one of the class Fl_Shared_Image or any other subclass of + Fl_Image (for instance Fl_RGB_Image) then you can't just use operator + delete since this is not appropriate for Fl_Shared_Image objects. + + The virtual method release() handles this properly. + + \since 1.4.0 in the base class Fl_Image and virtual in Fl_Shared_Image + */ + virtual void release() { + delete this; + } + + /** Returns whether an image is an Fl_Shared_Image or not. + + This virtual method returns a pointer to an Fl_Shared_Image if this + object is an instance of Fl_Shared_Image or NULL if not. This can be + used to detect if a given Fl_Image object is a shared image, i.e. + derived from Fl_Shared_Image. + + \since 1.4.0 + */ + virtual class Fl_Shared_Image *as_shared_image() { + return 0; + } + Fl_Image(int W, int H, int D); virtual ~Fl_Image(); virtual Fl_Image *copy(int W, int H); diff --git a/FL/Fl_Shared_Image.H b/FL/Fl_Shared_Image.H index 89d40d9ac..f68ec7af0 100644 --- a/FL/Fl_Shared_Image.H +++ b/FL/Fl_Shared_Image.H @@ -99,6 +99,10 @@ public: void release(); void reload(); + virtual Fl_Shared_Image *as_shared_image() { + return this; + } + virtual Fl_Image *copy(int W, int H); Fl_Image *copy() { return Fl_Image::copy(); } virtual void color_average(Fl_Color c, float i); |
