moab
ReaderWriterSet.hpp
Go to the documentation of this file.
00001 
00017 #ifndef MOAB_READER_WRITER_SET_HPP
00018 #define MOAB_READER_WRITER_SET_HPP
00019 
00020 #include <list>
00021 #include <string>
00022 #include "moab/Types.hpp"
00023 
00024 namespace moab {
00025 
00026 class ReaderIface;
00027 class WriterIface;
00028 class Core;
00029 class Error;
00030 
00037 class ReaderWriterSet
00038 {
00039 
00040   public:
00041     
00042     typedef ReaderIface* (*reader_factory_t)( Interface* );
00043     typedef WriterIface* (*writer_factory_t)( Interface* );
00044   
00045     ReaderWriterSet( Core* mdb, Error* handler );
00046   
00047     ~ReaderWriterSet();
00048     
00059     ErrorCode register_factory( reader_factory_t reader_fact,
00060                                   writer_factory_t writer_fact,
00061                                   const char* description,
00062                                   const char* const* extensions,
00063                                   const char* name );
00064     ErrorCode register_factory( reader_factory_t reader_fact,
00065                                   writer_factory_t writer_fact,
00066                                   const char* description,
00067                                   const char* extension,
00068                                   const char* name );
00069   
00076     ReaderIface* get_file_extension_reader( const std::string& filename ) const;
00077 
00084     WriterIface* get_file_extension_writer( const std::string& filename ) const;
00085     
00091     ReaderIface* get_file_reader( const char* format_name ) const; 
00092      
00098     WriterIface* get_file_writer( const char* format_name ) const; 
00099     
00103     static std::string extension_from_filename( const std::string& filename );
00104   
00105     class Handler {
00106       
00107       friend class ReaderWriterSet;
00108       
00109       public:
00110       
00111       Handler( reader_factory_t read_f,
00112                writer_factory_t write_f,
00113                const char* name,
00114                const char* desc, 
00115                const char* const* ext, 
00116                int num_ext );
00117       
00118       inline const std::string& name() const { return mName; }
00119       inline const std::string& description() const { return mDescription; }
00120       inline void get_extensions( std::vector<std::string>& list_out ) const
00121         { list_out = mExtensions; }
00122       
00123       inline bool have_reader() const { return NULL != mReader; }
00124       inline bool have_writer() const { return NULL != mWriter; }
00125       
00126       inline ReaderIface* make_reader( Interface* iface ) const
00127         { return have_reader() ? mReader(iface) : NULL; }
00128       
00129       inline WriterIface* make_writer( Interface* iface ) const
00130         { return have_writer() ? mWriter(iface) : NULL; }
00131 
00132       bool reads_extension(const char *ext) const;
00133       bool writes_extension(const char *ext) const;
00134       
00135       bool operator==( const char* name ) const;
00136       
00137       private:
00138       
00139       reader_factory_t mReader;
00140       writer_factory_t mWriter;
00141       
00142       std::string mName, mDescription;
00143       std::vector<std::string> mExtensions;
00144     };
00145     
00146     typedef std::list<Handler>::const_iterator iterator;
00147     
00148     inline iterator begin() const { return handlerList.begin(); }
00149     
00150     inline iterator end()   const { return handlerList.end();   }
00151     
00152     
00153     iterator handler_from_extension( const std::string& extension,
00154                                       bool with_reader = false, 
00155                                       bool with_writer = false) const;
00156     
00157     iterator handler_by_name( const char* name ) const;
00158     
00159   private:
00160   
00161     Core* mbCore;
00162     Error* mbError;
00163   
00164     std::list<Handler> handlerList;
00165 };
00166 
00167 } // namespace moab 
00168 
00169 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines