]> git.tdb.fi Git - libs/gui.git/blobdiff - source/graphics/imageloader.h
Implement automatic registration of image loaders
[libs/gui.git] / source / graphics / imageloader.h
index 06532753b3e535d152c84c6ad75abae80230167b..c06a7592fcf75bc1cf9ea918ceae470424ad785d 100644 (file)
@@ -24,15 +24,42 @@ public:
 class ImageLoader
 {
 private:
-       IO::Base *source;
+       class RegisterBase
+       {
+       protected:
+               RegisterBase();
+       public:
+               virtual ~RegisterBase() { }
+
+               virtual unsigned get_signature_size() const = 0;
+               virtual bool detect(const std::string &) const = 0;
+               virtual ImageLoader *create(IO::Seekable &) const = 0;
+       };
+
 protected:
+       template<typename T>
+       class Register: 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 T *create(IO::Seekable &io) const { return new T(io); }
+       };
+
+private:
+       IO::Base *source;
 
+       static std::list<RegisterBase *> &get_registered_loaders();
+       static bool registered_loaders_changed;
+       static bool signature_size_compare(RegisterBase *, RegisterBase *);
+
+protected:
        ImageLoader();
 public:
        virtual ~ImageLoader();
 
        static ImageLoader *open_file(const std::string &);
-       static ImageLoader *open_io(IO::Base &);
+       static ImageLoader *open_io(IO::Seekable &);
 
        virtual void load(Image::Data &) = 0;
 };