return !sig.compare(0, sizeof(bmp_sig), bmp_sig, sizeof(bmp_sig));
}
-void BmpLoader::load(Image::Data &data)
+void BmpLoader::load_(Image::Data &data)
{
char bm_header[14];
read_full(io, bm_header+sig_bytes, sizeof(bm_header)-sig_bytes);
static unsigned get_signature_size() { return 2; }
static bool detect(const std::string &);
- virtual void load(Image::Data &);
+ virtual void load_(Image::Data &);
};
} // namespace Graphics
return type!=IL_TYPE_UNKNOWN;
}
-void DevilLoader::load(Image::Data &data)
+void DevilLoader::load_(Image::Data &data)
{
ilSetRead(0, 0, eof, get, read, seek, tell);
ilBindImage(id);
static unsigned get_signature_size() { return 128; }
static bool detect(const std::string &);
- virtual void load(Image::Data &);
+ virtual void load_(Image::Data &);
};
} // namespace Graphics
namespace Graphics {
ImageLoader::ImageLoader():
- source(0)
+ source(0),
+ state(INITIAL)
{ }
ImageLoader::~ImageLoader()
return loader;
}
+void ImageLoader::load(Image::Data &data)
+{
+ if(state>=FINISHED)
+ throw logic_error("already loaded");
+
+ load_(data);
+ state = FINISHED;
+}
+
ImageLoader::Registry &ImageLoader::get_registry()
{
static Registry registry;
class ImageLoader
{
+public:
+ enum State
+ {
+ INITIAL,
+ FINISHED
+ };
+
protected:
class RegisterBase
{
private:
IO::Base *source;
+ State state;
protected:
ImageLoader();
static ImageLoader *open_file(const std::string &);
static ImageLoader *open_io(IO::Seekable &);
- virtual void load(Image::Data &) = 0;
+ virtual void load(Image::Data &);
+protected:
+ virtual void load_(Image::Data &) = 0;
+
+public:
+ State get_state() const { return state; }
template<typename T>
static void register_loader();
return !sig.compare(0, sizeof(jpeg_sig), jpeg_sig, sizeof(jpeg_sig));
}
-void JpegLoader::load(Image::Data &data)
+void JpegLoader::load_(Image::Data &data)
{
if(setjmp(priv->err_mgr.jmp))
throw bad_image_data(priv->err_mgr.message);
static unsigned get_signature_size() { return 3; }
static bool detect(const std::string &);
- virtual void load(Image::Data &);
+ virtual void load_(Image::Data &);
};
} // namespace Graphics
return !png_sig_cmp(reinterpret_cast<png_byte *>(const_cast<char*>(sig.data())), 0, sig.size());
}
-void PngLoader::load(Image::Data &data)
+void PngLoader::load_(Image::Data &data)
{
png_byte **rows = 0;
static unsigned get_signature_size() { return 8; }
static bool detect(const std::string &);
- virtual void load(Image::Data &);
+ virtual void load_(Image::Data &);
};
} // namespace Graphics
return status==kCGImageStatusIncomplete || status==kCGImageStatusReadingHeader;
}
-void QuartzLoader::load(Image::Data &data)
+void QuartzLoader::load_(Image::Data &data)
{
CGImageRef image = CGImageSourceCreateImageAtIndex(priv->source, 0, 0);
if(!image)
static unsigned get_signature_size() { return 12; }
static bool detect(const std::string &);
- virtual void load(Image::Data &);
+ virtual void load_(Image::Data &);
};
} // namespace Graphics