summaryrefslogtreecommitdiff
path: root/FL/Fl_Image.H
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2020-06-05 21:11:15 +0200
committerAlbrecht Schlosser <albrechts.fltk@online.de>2020-06-06 06:27:47 +0200
commit1dd492958567493c0e62f5d2614f1a46c50cb7e1 (patch)
tree97b82a3b0e853baee9ff9f5be01a1a8938bab740 /FL/Fl_Image.H
parent6481f954153d5419f82e3259bdaa9427dfc8bdc2 (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/Fl_Image.H')
-rw-r--r--FL/Fl_Image.H44
1 files changed, 44 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);