00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00028
00030 #ifndef __H3DIMAGELOADERNODE_H__
00031 #define __H3DIMAGELOADERNODE_H__
00032
00033 #include "Image.h"
00034 #include "Node.h"
00035 #include <list>
00036
00037 namespace H3D {
00038
00048 class H3DAPI_API H3DImageLoaderNode : public Node {
00049 public:
00050 typedef H3DImageLoaderNode*( *CreateNodeFunc)();
00051
00053 typedef bool ( *SupportsFileFunc)( const string &url );
00054
00055 template< class N >
00056 static H3DImageLoaderNode *newImageLoaderNode() { return new N; };
00057
00059 struct H3DAPI_API FileReaderRegistration{
00060 public:
00062 FileReaderRegistration( const string &_name,
00063 CreateNodeFunc _create,
00064 SupportsFileFunc _supports ):
00065 name( _name ),
00066 create_func( _create ),
00067 supports_func( _supports ) {
00068
00069 if( !H3DImageLoaderNode::initialized ) {
00070 H3DImageLoaderNode::registered_file_readers =
00071 new list< FileReaderRegistration >;
00072 initialized = true;
00073 }
00074 H3DImageLoaderNode::registerFileReader( *this );
00075 }
00076
00077 string name;
00078 CreateNodeFunc create_func;
00079 SupportsFileFunc supports_func;
00080 };
00081
00083 H3DImageLoaderNode() {
00084 type_name = "H3DImageLoaderNode";
00085 }
00086
00091 virtual Image *loadImage( const string &url ) = 0;
00094
00098 virtual string defaultXMLContainerField() {
00099 return "imageLoader";
00100 }
00101
00105 static H3DImageLoaderNode *getSupportedFileReader( const string &url );
00106
00113 static void registerFileReader( const string &name,
00114 CreateNodeFunc create,
00115 SupportsFileFunc supports ) {
00116 registerFileReader( FileReaderRegistration( name, create, supports ) );
00117 }
00118
00121 static void registerFileReader( const FileReaderRegistration &fr ) {
00122 registered_file_readers->push_back( fr );
00123 }
00124
00125 protected:
00126 static list< FileReaderRegistration > *registered_file_readers;
00127 static bool initialized;
00128 };
00129 }
00130
00131 #endif