H3DImageLoaderNode.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
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

Generated on Thu Aug 24 12:38:32 2006 for H3D API by  doxygen 1.4.5