diff --git a/FL/Fl_Image.H b/FL/Fl_Image.H index c6fb55967509bf0c412db7e7e1ea7e2f5ad19021..aafd39742a66496e5c62402cfc0010d1106fa4b0 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 89d40d9ac9d445af701b96d13029768391ced489..f68ec7af0ae75505478403510a50bfdc759f70d0 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);