MOAB: Mesh Oriented datABase
(version 5.2.1)
|
00001 /** 00002 * MOAB, a Mesh-Oriented datABase, is a software component for creating, 00003 * storing and accessing finite element mesh data. 00004 * 00005 * Copyright 2004 Sandia Corporation. Under the terms of Contract 00006 * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 00007 * retains certain rights in this software. 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 2.1 of the License, or (at your option) any later version. 00013 * 00014 */ 00015 00016 #ifndef MOAB_READER_WRITER_SET_HPP 00017 #define MOAB_READER_WRITER_SET_HPP 00018 00019 #include <list> 00020 #include <string> 00021 #include "moab/Types.hpp" 00022 00023 namespace moab 00024 { 00025 00026 class ReaderIface; 00027 class WriterIface; 00028 class Core; 00029 00030 /** 00031 *\brief Maintain list of readers and writers. 00032 *\version 1.00 00033 *\date 2004-4-23 00034 *\author Jason Kraftcheck 00035 */ 00036 class ReaderWriterSet 00037 { 00038 00039 public: 00040 typedef ReaderIface* ( *reader_factory_t )( Interface* ); 00041 typedef WriterIface* ( *writer_factory_t )( Interface* ); 00042 00043 ReaderWriterSet( Core* mdb ); 00044 00045 ~ReaderWriterSet(); 00046 00047 /** 00048 * Regiseter a reader and/or writer 00049 * Either factory function may be NULL, but not both. 00050 * 00051 *\param reader_fact A factory method to create an instance of the reader 00052 *\param writer_fact A factory method to create an instance of the reader 00053 *\param description A short description of the file format. 00054 *\param extensions A null-terminated list of file extensions 00055 *\param name File format identifier string. 00056 */ 00057 ErrorCode register_factory( reader_factory_t reader_fact, writer_factory_t writer_fact, const char* description, 00058 const char* const* extensions, const char* name ); 00059 ErrorCode register_factory( reader_factory_t reader_fact, writer_factory_t writer_fact, const char* description, 00060 const char* extension, const char* name ); 00061 00062 /** 00063 * Create a reader object for the passed file name 00064 * according to the dot-extension of the file name. 00065 * Caller must delete the object when finished. 00066 * Returns null if no matching file extension. 00067 */ 00068 ReaderIface* get_file_extension_reader( const std::string& filename ) const; 00069 00070 /** 00071 * Create a writer object for the passed file name 00072 * according to the dot-extension of the file name. 00073 * Caller must delete the object when finished. 00074 * Returns null if no matching file extension. 00075 */ 00076 WriterIface* get_file_extension_writer( const std::string& filename ) const; 00077 00078 /** 00079 * Create a reader object for the passed file format type. 00080 * Caller is responsible for deletion of returned object. 00081 * Returns NULL if no match. 00082 */ 00083 ReaderIface* get_file_reader( const char* format_name ) const; 00084 00085 /** 00086 * Create a writer object for the passed file format type. 00087 * Caller is responsible for deletion of returned object. 00088 * Returns NULL if no match. 00089 */ 00090 WriterIface* get_file_writer( const char* format_name ) const; 00091 00092 /** 00093 * Get the file extension from a file name 00094 */ 00095 static std::string extension_from_filename( const std::string& filename ); 00096 00097 class Handler 00098 { 00099 00100 friend class ReaderWriterSet; 00101 00102 public: 00103 Handler( reader_factory_t read_f, writer_factory_t write_f, const char* name, const char* desc, 00104 const char* const* ext, int num_ext ); 00105 00106 inline const std::string& name() const 00107 { 00108 return mName; 00109 } 00110 inline const std::string& description() const 00111 { 00112 return mDescription; 00113 } 00114 inline void get_extensions( std::vector< std::string >& list_out ) const 00115 { 00116 list_out = mExtensions; 00117 } 00118 00119 inline bool have_reader() const 00120 { 00121 return NULL != mReader; 00122 } 00123 inline bool have_writer() const 00124 { 00125 return NULL != mWriter; 00126 } 00127 00128 inline ReaderIface* make_reader( Interface* iface ) const 00129 { 00130 return have_reader() ? mReader( iface ) : NULL; 00131 } 00132 00133 inline WriterIface* make_writer( Interface* iface ) const 00134 { 00135 return have_writer() ? mWriter( iface ) : NULL; 00136 } 00137 00138 bool reads_extension( const char* ext ) const; 00139 bool writes_extension( const char* ext ) const; 00140 00141 bool operator==( const char* name ) const; 00142 00143 private: 00144 reader_factory_t mReader; 00145 writer_factory_t mWriter; 00146 00147 std::string mName, mDescription; 00148 std::vector< std::string > mExtensions; 00149 }; 00150 00151 typedef std::list< Handler >::const_iterator iterator; 00152 00153 inline iterator begin() const 00154 { 00155 return handlerList.begin(); 00156 } 00157 00158 inline iterator end() const 00159 { 00160 return handlerList.end(); 00161 } 00162 00163 iterator handler_from_extension( const std::string& extension, bool with_reader = false, 00164 bool with_writer = false ) const; 00165 00166 iterator handler_by_name( const char* name ) const; 00167 00168 private: 00169 Core* mbCore; 00170 00171 std::list< Handler > handlerList; 00172 }; 00173 00174 } // namespace moab 00175 00176 #endif