]> git.tdb.fi Git - libs/gui.git/blobdiff - source/graphics/imageloader.h
Convert empty default constructors and destructors to defaulted
[libs/gui.git] / source / graphics / imageloader.h
index 031ecb411667da36a505da084fad0ff2d66ba341..d824291eb65086aefdad641e2d9ef5dbca873a56 100644 (file)
@@ -2,81 +2,99 @@
 #define MSP_GRAPHICS_IMAGELOADER_H_
 
 #include "image.h"
+#include "mspgui_api.h"
 
 namespace Msp {
 namespace Graphics {
 
-class unsupported_image_format: public std::runtime_error
+class MSPGUI_API unsupported_image_format: public std::runtime_error
 {
 public:
        unsupported_image_format(const std::string &w): std::runtime_error(w) { }
-       virtual ~unsupported_image_format() throw() { }
 };
 
-class bad_image_data: public std::runtime_error
+class MSPGUI_API bad_image_data: public std::runtime_error
 {
 public:
        bad_image_data(const std::string &w): std::runtime_error(w) { }
-       virtual ~bad_image_data() throw() { }
 };
 
 
-class ImageLoader
+class MSPGUI_API ImageLoader
 {
+public:
+       enum State
+       {
+               INITIAL,
+               HEADERS_LOADED,
+               FINISHED
+       };
+
 protected:
        class RegisterBase
        {
        protected:
-               RegisterBase();
+               RegisterBase() = default;
        public:
-               virtual ~RegisterBase() { }
+               virtual ~RegisterBase() = default;
 
                virtual unsigned get_signature_size() const = 0;
                virtual bool detect(const std::string &) const = 0;
                virtual ImageLoader *create(IO::Seekable &) const = 0;
        };
 
-private:
-       IO::Base *source;
+       template<typename T>
+       class RegisteredLoader: public RegisterBase
+       {
+       public:
+               unsigned get_signature_size() const override { return T::get_signature_size(); }
+               bool detect(const std::string &s) const override { return T::detect(s); }
+               ImageLoader *create(IO::Seekable &io) const override { return new T(io); }
+       };
+
+       struct Registry
+       {
+               std::vector<RegisterBase *> loaders;
+               bool changed = false;
 
-       static std::list<RegisterBase *> &get_registered_loaders();
-       static bool registered_loaders_changed;
-       static bool signature_size_compare(RegisterBase *, RegisterBase *);
+               ~Registry();
+       };
+
+private:
+       IO::Base *source = nullptr;
+       State state = INITIAL;
 
 protected:
-       ImageLoader();
+       ImageLoader() = default;
 public:
        virtual ~ImageLoader();
 
+       static bool detect_signature(const std::string &);
        static ImageLoader *open_file(const std::string &);
        static ImageLoader *open_io(IO::Seekable &);
 
-       virtual void load(Image::Data &) = 0;
-};
-
+       virtual void load(Image::Data &);
+       virtual void load_headers(Image::Data &);
+protected:
+       virtual void load_headers_(Image::Data &) = 0;
+       virtual void load_pixels_(Image::Data &) = 0;
 
-template<typename T>
-class RegisteredImageLoader: public ImageLoader
-{
-       friend class ImageLoader;
+public:
+       State get_state() const { return state; }
 
+       template<typename T>
+       static void register_loader();
 private:
-       class Register: public RegisterBase
-       {
-       public:
-               virtual unsigned get_signature_size() const { return T::get_signature_size(); }
-               virtual bool detect(const std::string &s) const { return T::detect(s); }
-               virtual ImageLoader *create(IO::Seekable &io) const { return new T(io); }
-       };
-
-       static Register reg;
-
-protected:
-       RegisteredImageLoader() { (void)reg; }
+       static Registry &get_registry();
 };
 
 template<typename T>
-typename RegisteredImageLoader<T>::Register RegisteredImageLoader<T>::reg;
+void ImageLoader::register_loader()
+{
+       Registry &registry = get_registry();
+       registry.loaders.push_back(new RegisteredLoader<T>);
+       registry.changed = true;
+}
 
 } // namespace Graphics
 } // namespace Msp