Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
moab::ReaderWriterSet Class Reference

Maintain list of readers and writers. More...

#include <ReaderWriterSet.hpp>

+ Collaboration diagram for moab::ReaderWriterSet:

Classes

class  Handler
 

Public Types

typedef ReaderIface *(* reader_factory_t) (Interface *)
 
typedef WriterIface *(* writer_factory_t) (Interface *)
 
typedef std::list< Handler >::const_iterator iterator
 

Public Member Functions

 ReaderWriterSet (Core *mdb)
 
 ~ReaderWriterSet ()
 
ErrorCode register_factory (reader_factory_t reader_fact, writer_factory_t writer_fact, const char *description, const char *const *extensions, const char *name)
 
ErrorCode register_factory (reader_factory_t reader_fact, writer_factory_t writer_fact, const char *description, const char *extension, const char *name)
 
ReaderIfaceget_file_extension_reader (const std::string &filename) const
 
WriterIfaceget_file_extension_writer (const std::string &filename) const
 
ReaderIfaceget_file_reader (const char *format_name) const
 
WriterIfaceget_file_writer (const char *format_name) const
 
iterator begin () const
 
iterator end () const
 
iterator handler_from_extension (const std::string &extension, bool with_reader=false, bool with_writer=false) const
 
iterator handler_by_name (const char *name) const
 

Static Public Member Functions

static std::string extension_from_filename (const std::string &filename)
 

Private Attributes

CorembCore
 
std::list< HandlerhandlerList
 

Detailed Description

Maintain list of readers and writers.

Version
1.00
Date
2004-4-23
Author
Jason Kraftcheck

Definition at line 36 of file ReaderWriterSet.hpp.

Member Typedef Documentation

◆ iterator

typedef std::list< Handler >::const_iterator moab::ReaderWriterSet::iterator

Definition at line 161 of file ReaderWriterSet.hpp.

◆ reader_factory_t

typedef ReaderIface*( * moab::ReaderWriterSet::reader_factory_t) (Interface *)

Definition at line 40 of file ReaderWriterSet.hpp.

◆ writer_factory_t

typedef WriterIface*( * moab::ReaderWriterSet::writer_factory_t) (Interface *)

Definition at line 41 of file ReaderWriterSet.hpp.

Constructor & Destructor Documentation

◆ ReaderWriterSet()

moab::ReaderWriterSet::ReaderWriterSet ( Core mdb)

Definition at line 87 of file ReaderWriterSet.cpp.

87  : mbCore( mdb )
88 {
89 #ifdef MOAB_HAVE_HDF5
90  const char* hdf5_sufxs[] = { "h5m", "mhdf", NULL };
91 #ifdef MOAB_HAVE_HDF5_PARALLEL
92  register_factory( ReadHDF5::factory, WriteHDF5Parallel::factory, "MOAB native (HDF5)", hdf5_sufxs, "MOAB" );
93 #else
94  register_factory( ReadHDF5::factory, WriteHDF5::factory, "MOAB native (HDF5)", hdf5_sufxs, "MOAB" );
95 #endif
96 #endif
97 
98 #ifdef MOAB_HAVE_NETCDF
99  const char* exo_sufxs[] = { "exo", "exoII", "exo2", "g", "gen", NULL };
100  register_factory( ReadNCDF::factory, WriteNCDF::factory, "Exodus II", exo_sufxs, "EXODUS" );
101  register_factory( ReadNC::factory, WriteNC::factory, "Climate NC", "nc", "NC" );
102 #endif
103 
104 #ifdef MOAB_HAVE_CGNS
105  const char* cgns_sufxs[] = { "cgns", NULL };
106  register_factory( ReadCGNS::factory, WriteCGNS::factory, "CGNS", cgns_sufxs, "CGNS" );
107 #endif
108 
109  register_factory( ReadIDEAS::factory, NULL, "IDEAS format", "unv", "UNV" );
110 
111  register_factory( ReadMCNP5::factory, NULL, "MCNP5 format", "meshtal", "MESHTAL" );
112 
113  const char* nastran_sufxs[] = { "nas", "bdf", NULL };
114  register_factory( ReadNASTRAN::factory, NULL, "NASTRAN format", nastran_sufxs, "NAS" );
115 
116  register_factory( ReadABAQUS::factory, NULL, "ABAQUS INP mesh format", "abq", "Abaqus mesh" );
117 
118  register_factory( ReadRTT::factory, NULL, "RTT Mesh Format", "rtt", "Atilla RTT Mesh" );
119 
120  register_factory( ReadVtk::factory, WriteVtk::factory, "Kitware VTK", "vtk", "VTK" );
121 
122  register_factory( ReadOBJ::factory, NULL, "OBJ mesh format", "obj", "OBJ mesh" );
123 
124  register_factory( ReadSms::factory, NULL, "RPI SMS", "sms", "SMS" );
125 
126  register_factory( Tqdcfr::factory, NULL, "Cubit", "cub", "CUBIT" );
127 
128  register_factory( ReadSmf::factory, WriteSmf::factory, "QSlim format", "smf", "SMF" );
129 
130 #ifdef MOAB_HAVE_NETCDF
131  register_factory( NULL, WriteSLAC::factory, "SLAC", "slac", "SLAC" );
132 #endif
133 
134 #ifdef MOAB_HAVE_CCMIO
135  const char* ccmio_sufxs[] = { "ccm", "ccmg", NULL };
136  register_factory( ReadCCMIO::factory, WriteCCMIO::factory, "CCMIO files", ccmio_sufxs, "CCMIO" );
137 #endif
138 
139 #ifdef MOAB_HAVE_DAMSEL
140  const char* damsel_sufxs[] = { "h5", NULL };
141  register_factory( ReadDamsel::factory, WriteDamsel::factory, "Damsel files", damsel_sufxs, "DAMSEL" );
142 #endif
143 
144  register_factory( NULL, WriteGMV::factory, "GMV", "gmv", "GMV" );
145 
146  register_factory( NULL, WriteAns::factory, "Ansys", "ans", "ANSYS" );
147 
148  const char* gmsh_sufxs[] = { "msh", "gmsh", NULL };
149  register_factory( ReadGmsh::factory, WriteGmsh::factory, "Gmsh mesh file", gmsh_sufxs, "GMSH" );
150 
151  register_factory( ReadSTL::factory, WriteSTL::factory, "Stereo Lithography File (STL)", "stl", "STL" );
152 
153  const char* tetgen_sufxs[] = { "node", "ele", "face", "edge", NULL };
154  register_factory( ReadTetGen::factory, 0, "TetGen output files", tetgen_sufxs, "TETGEN" );
155 
156  const char* template_sufxs[] = { NULL };
157  register_factory( ReadTemplate::factory, WriteTemplate::factory, "Template input files", template_sufxs,
158  "TEMPLATE" );
159 }

References moab::ReadABAQUS::factory(), moab::ReadCCMIO::factory(), moab::ReadCGNS::factory(), moab::ReadDamsel::factory(), moab::ReadGmsh::factory(), moab::ReadHDF5::factory(), moab::ReadIDEAS::factory(), moab::ReadMCNP5::factory(), moab::ReadNASTRAN::factory(), moab::ReadNC::factory(), moab::ReadNCDF::factory(), moab::ReadOBJ::factory(), moab::ReadRTT::factory(), moab::ReadSmf::factory(), moab::ReadSms::factory(), moab::ReadSTL::factory(), moab::ReadTemplate::factory(), moab::ReadTetGen::factory(), moab::ReadVtk::factory(), moab::Tqdcfr::factory(), moab::WriteAns::factory(), moab::WriteCCMIO::factory(), moab::WriteCGNS::factory(), moab::WriteGmsh::factory(), moab::WriteGMV::factory(), moab::WriteHDF5::factory(), moab::WriteNC::factory(), moab::WriteNCDF::factory(), moab::WriteSLAC::factory(), moab::WriteSmf::factory(), moab::WriteSTL::factory(), moab::WriteTemplate::factory(), moab::WriteVtk::factory(), moab::WriteHDF5Parallel::factory(), moab::WriteDamsel::factory(), and register_factory().

◆ ~ReaderWriterSet()

moab::ReaderWriterSet::~ReaderWriterSet ( )

Definition at line 161 of file ReaderWriterSet.cpp.

161 {}

Member Function Documentation

◆ begin()

iterator moab::ReaderWriterSet::begin ( ) const
inline

Definition at line 163 of file ReaderWriterSet.hpp.

164  {
165  return handlerList.begin();
166  }

References handlerList.

Referenced by handler_by_name(), handler_from_extension(), list_formats(), moab::Core::serial_load_file(), and moab::Core::serial_read_tag().

◆ end()

iterator moab::ReaderWriterSet::end ( ) const
inline

◆ extension_from_filename()

std::string moab::ReaderWriterSet::extension_from_filename ( const std::string &  filename)
static

Get the file extension from a file name

Definition at line 223 of file ReaderWriterSet.cpp.

224 {
225  std::string::size_type idx = filename.find_last_of( "." );
226  std::string::size_type idirx = filename.find_last_of( "\\/" );
227 
228  if( idx == std::string::npos ) return std::string( "" );
229  if( ( idirx != std::string::npos ) && ( idirx > idx ) ) return std::string( "" );
230  return filename.substr( idx + 1 );
231 }

Referenced by get_file_extension_reader(), get_file_extension_writer(), moab::Core::serial_load_file(), and moab::Core::write_file().

◆ get_file_extension_reader()

ReaderIface * moab::ReaderWriterSet::get_file_extension_reader ( const std::string &  filename) const

Create a reader object for the passed file name according to the dot-extension of the file name. Caller must delete the object when finished. Returns null if no matching file extension.

Definition at line 209 of file ReaderWriterSet.cpp.

210 {
211  std::string ext = extension_from_filename( filename );
212  iterator handler = handler_from_extension( ext, true, false );
213  return handler == end() ? NULL : handler->make_reader( mbCore );
214 }

References end(), extension_from_filename(), handler_from_extension(), and mbCore.

Referenced by moab::Core::serial_read_tag().

◆ get_file_extension_writer()

WriterIface * moab::ReaderWriterSet::get_file_extension_writer ( const std::string &  filename) const

Create a writer object for the passed file name according to the dot-extension of the file name. Caller must delete the object when finished. Returns null if no matching file extension.

Definition at line 216 of file ReaderWriterSet.cpp.

217 {
218  std::string ext = extension_from_filename( filename );
219  iterator handler = handler_from_extension( ext, false, true );
220  return handler == end() ? NULL : handler->make_writer( mbCore );
221 }

References end(), extension_from_filename(), handler_from_extension(), and mbCore.

◆ get_file_reader()

ReaderIface* moab::ReaderWriterSet::get_file_reader ( const char *  format_name) const

Create a reader object for the passed file format type. Caller is responsible for deletion of returned object. Returns NULL if no match.

◆ get_file_writer()

WriterIface* moab::ReaderWriterSet::get_file_writer ( const char *  format_name) const

Create a writer object for the passed file format type. Caller is responsible for deletion of returned object. Returns NULL if no match.

◆ handler_by_name()

ReaderWriterSet::iterator moab::ReaderWriterSet::handler_by_name ( const char *  name) const

Definition at line 305 of file ReaderWriterSet.cpp.

306 {
307  return std::find( begin(), end(), nm );
308 }

References begin(), and end().

Referenced by register_factory().

◆ handler_from_extension()

ReaderWriterSet::iterator moab::ReaderWriterSet::handler_from_extension ( const std::string &  extension,
bool  with_reader = false,
bool  with_writer = false 
) const

Definition at line 249 of file ReaderWriterSet.cpp.

252 {
253  iterator iter;
254  std::vector< std::string >::const_iterator siter;
255 
256  // try case-sensitive compare
257  for( iter = begin(); iter != end(); ++iter )
258  {
259  if( ( with_reader && !iter->have_reader() ) || ( with_writer && !iter->have_writer() ) ) continue;
260 
261  for( siter = iter->mExtensions.begin(); siter != iter->mExtensions.end(); ++siter )
262  if( *siter == ext ) return iter;
263  }
264 
265  // try case-insensitive compare
266  for( iter = begin(); iter != end(); ++iter )
267  {
268  if( ( with_reader && !iter->have_reader() ) || ( with_writer && !iter->have_writer() ) ) continue;
269 
270  for( siter = iter->mExtensions.begin(); siter != iter->mExtensions.end(); ++siter )
271  if( 0 == strcasecmp( siter->c_str(), ext.c_str() ) ) return iter;
272  }
273 
274  return end();
275 }

References begin(), and end().

Referenced by get_file_extension_reader(), get_file_extension_writer(), and register_factory().

◆ register_factory() [1/2]

ErrorCode moab::ReaderWriterSet::register_factory ( reader_factory_t  reader_fact,
writer_factory_t  writer_fact,
const char *  description,
const char *const *  extensions,
const char *  name 
)

Regiseter a reader and/or writer Either factory function may be NULL, but not both.

Parameters
reader_factA factory method to create an instance of the reader
writer_factA factory method to create an instance of the reader
descriptionA short description of the file format.
extensionsA null-terminated list of file extensions
nameFile format identifier string.

Definition at line 163 of file ReaderWriterSet.cpp.

168 {
169  if( !reader && !writer ) return MB_FAILURE;
170 
171  // check for duplicate names
172  iterator h = handler_by_name( name );
173  if( h != end() )
174  {
175  MB_SET_ERR( MB_FAILURE, "Conflicting string name for file formats: \"" << name << "\"" );
176  }
177 
178  // count extensions and check for duplicates
179  const char* const* iter;
180  for( iter = extensions; *iter; ++iter )
181  {
182  h = handler_from_extension( *iter );
183  if( h != end() )
184  {
185  if( NULL != reader && h->have_reader() )
186  MB_SET_ERR( MB_FAILURE, "Conflicting readers for file extension \""
187  << *iter << "\": \"" << h->description() << "\" and \"" << description
188  << "\"." );
189  else if( NULL != writer && h->have_writer() )
190  MB_SET_ERR( MB_FAILURE, "Conflicting writers for file extension \""
191  << *iter << "\": \"" << h->description() << "\" and \"" << description
192  << "\"." );
193  }
194  }
195  handlerList.push_back( Handler( reader, writer, name, description, extensions, iter - extensions ) );
196  return MB_SUCCESS;
197 }

References end(), handler_by_name(), handler_from_extension(), handlerList, MB_SET_ERR, and MB_SUCCESS.

Referenced by ReaderWriterSet(), and register_factory().

◆ register_factory() [2/2]

ErrorCode moab::ReaderWriterSet::register_factory ( reader_factory_t  reader_fact,
writer_factory_t  writer_fact,
const char *  description,
const char *  extension,
const char *  name 
)

Definition at line 199 of file ReaderWriterSet.cpp.

204 {
205  const char* extensions[2] = { extension, NULL };
206  return register_factory( reader, writer, description, extensions, name );
207 }

References register_factory().

Member Data Documentation

◆ handlerList

std::list< Handler > moab::ReaderWriterSet::handlerList
private

Definition at line 182 of file ReaderWriterSet.hpp.

Referenced by begin(), end(), and register_factory().

◆ mbCore

Core* moab::ReaderWriterSet::mbCore
private

Definition at line 180 of file ReaderWriterSet.hpp.

Referenced by get_file_extension_reader(), and get_file_extension_writer().


The documentation for this class was generated from the following files: