moab
moab::ReaderWriterSet Class Reference

Maintain list of readers and writers. More...

#include <ReaderWriterSet.hpp>

List of all members.

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, Error *handler)
 ~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
ErrormbError
std::list< HandlerhandlerList

Detailed Description

Maintain list of readers and writers.

Version:
1.00
Date:
2004-4-23
Author:
Jason Kraftcheck

Definition at line 37 of file ReaderWriterSet.hpp.


Member Typedef Documentation

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

Definition at line 146 of file ReaderWriterSet.hpp.


Constructor & Destructor Documentation

Definition at line 90 of file ReaderWriterSet.cpp.

  : mbCore( mdb ), mbError( handler )
{
#ifdef HDF5_FILE
  const char* hdf5_sufxs[] = { "h5m", "mhdf", NULL };
#ifdef HDF5_PARALLEL
  register_factory(  ReadHDF5::factory, WriteHDF5Parallel::factory,
                     "MOAB native (HDF5)", hdf5_sufxs, "MOAB" );
#else
  register_factory(  ReadHDF5::factory, WriteHDF5::factory,
                     "MOAB native (HDF5)", hdf5_sufxs, "MOAB" );
#endif
#endif

#ifdef NETCDF_FILE
  const char* exo_sufxs[] = { "exo", "exoII", "exo2", "g", "gen", NULL };
  register_factory( ReadNCDF::factory, WriteNCDF::factory, "Exodus II", exo_sufxs, "EXODUS" );
  register_factory( ReadGCRM::factory, NULL, "GCRM NC", "nc", "GCRM" );
  register_factory( ReadNC::factory, NULL, "Climate NC", "nc", "NC" );
#endif

#ifdef CGNS_FILE
  const char* cgns_sufxs[] = { "cgns", NULL };
  register_factory( ReadCGNS::factory, WriteCGNS::factory, "CGNS", cgns_sufxs, "CGNS" );
#endif

  register_factory( ReadIDEAS::factory, NULL, "IDEAS format", "unv", "UNV" );

  register_factory( ReadMCNP5::factory, NULL, "MCNP5 format", "meshtal", "MESHTAL" );

  const char* nastran_sufxs[] = { "nas", "bdf", NULL };
  register_factory( ReadNASTRAN::factory, NULL, "NASTRAN format", nastran_sufxs, "NAS" );

  register_factory( ReadABAQUS::factory, NULL, "ABAQUS INP mesh format", "abq", "Abaqus mesh" );

  register_factory( ReadVtk::factory, WriteVtk::factory, "Kitware VTK", "vtk", "VTK" );

  register_factory( ReadSms::factory, NULL, "RPI SMS", "sms", "SMS" );

  register_factory( Tqdcfr::factory, NULL, "Cubit", "cub", "CUBIT" );

  register_factory( ReadSmf::factory, WriteSmf::factory , "QSlim format", "smf", "SMF");

#ifdef CGM
  const char* acis_sufxs[] = { "sat", "sab", NULL };
  const char* occ_sufxs[] = { "brep", "occ", NULL };
  const char* step_sufxs[] = { "step", "stp", NULL };
  const char* iges_sufxs[] = { "iges", "igs", NULL };
  register_factory( ReadCGM::factory, NULL, "ACIS solid model", acis_sufxs, "ACIS");
  register_factory( ReadCGM::factory, NULL, "OpenCascade solid model", occ_sufxs, "OCC");
  register_factory( ReadCGM::factory, NULL, "STEP B-Rep exchange", step_sufxs, "STEP");
  register_factory( ReadCGM::factory, NULL, "IGES B-Rep exchange", iges_sufxs, "IGES");
#endif

#ifdef NETCDF_FILE
  register_factory( NULL, WriteSLAC::factory, "SLAC", "slac", "SLAC" );
#endif

#ifdef CCMIO_FILE
  const char* ccmio_sufxs[] = { "ccm", "ccmg", NULL };
  register_factory( ReadCCMIO::factory, WriteCCMIO::factory, "CCMIO files", ccmio_sufxs, "CCMIO");
#endif

#ifdef DAMSEL_FILE
  const char* damsel_sufxs[] = { "h5", NULL };
  register_factory( ReadDamsel::factory, WriteDamsel::factory, "Damsel files", damsel_sufxs, "DAMSEL");
#endif

  register_factory( NULL, WriteGMV::factory, "GMV", "gmv", "GMV" );

  register_factory( NULL, WriteAns::factory, "Ansys", "ans", "ANSYS" );

  const char* gmsh_sufxs[] = { "msh", "gmsh", NULL };
  register_factory( ReadGmsh::factory, WriteGmsh::factory, "Gmsh mesh file", gmsh_sufxs, "GMSH" );

  register_factory( ReadSTL::factory, WriteSTL::factory, "Stereo Lithography File (STL)", "stl", "STL" );

  const char* tetgen_sufxs[] = { "node", "ele", "face", "edge", NULL };
  register_factory( ReadTetGen::factory, 0, "TetGen output files", tetgen_sufxs, "TETGEN" );

  const char* txt_sufxs[] = { "txt", NULL };
  register_factory( ReadTxt::factory, 0, "Txt input files", txt_sufxs, "TXT" );

  const char* template_sufxs[] = { NULL };
  register_factory( ReadTemplate::factory, WriteTemplate::factory, "Template input files", template_sufxs, "TEMPLATE" );

}

Member Function Documentation

Definition at line 148 of file ReaderWriterSet.hpp.

{ return handlerList.begin(); }

Definition at line 150 of file ReaderWriterSet.hpp.

{ return handlerList.end();   }
std::string moab::ReaderWriterSet::extension_from_filename ( const std::string &  filename) [static]

Get the file extension from a file name

Definition at line 248 of file ReaderWriterSet.cpp.

{
  std::string::size_type idx = filename.find_last_of( "." );
  if (idx == std::string::npos)
    return std::string("");
  else
    return filename.substr( idx + 1 );
}
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 232 of file ReaderWriterSet.cpp.

{
  std::string ext = extension_from_filename( filename );
  iterator handler = handler_from_extension( ext, true, false );
  return handler == end() ? NULL : handler->make_reader(mbCore);
}
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 240 of file ReaderWriterSet.cpp.

{
  std::string ext = extension_from_filename( filename );
  iterator handler = handler_from_extension( ext, false, true );
  return handler == end() ? NULL : handler->make_writer(mbCore);
}
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.

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.

Definition at line 334 of file ReaderWriterSet.cpp.

{
  return std::find( begin(), end(), nm );
}
ReaderWriterSet::iterator moab::ReaderWriterSet::handler_from_extension ( const std::string &  extension,
bool  with_reader = false,
bool  with_writer = false 
) const

Definition at line 275 of file ReaderWriterSet.cpp.

{
  iterator iter;
  std::vector<std::string>::const_iterator siter;

    // try case-sensitive compare
  for (iter = begin(); iter != end(); ++iter)
  {
    if ((with_reader && !iter->have_reader()) ||
        (with_writer && !iter->have_writer()))
      continue;

    for (siter = iter->mExtensions.begin(); siter != iter->mExtensions.end(); ++siter)
      if (*siter == ext)
        return iter;
  }

    // try case-insensitive compare
  for (iter = begin(); iter != end(); ++iter)
  {
    if ((with_reader && !iter->have_reader()) ||
        (with_writer && !iter->have_writer()))
      continue;

    for (siter = iter->mExtensions.begin(); siter != iter->mExtensions.end(); ++siter)
      if (0 == strcasecmp( siter->c_str(), ext.c_str() ))
        return iter;
  }

  return end();
}
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 183 of file ReaderWriterSet.cpp.

{
  if (!reader && !writer)
    return MB_FAILURE;

    // check for duplicate names
  iterator h = handler_by_name( name );
  if (h != end()) {
    mbError->set_last_error( "Conflicting string name for file formats: \"%s\"",
                             name );
    return MB_FAILURE;
  }

    // count extensions and check for duplicates
  const char* const* iter;
  for (iter = extensions; *iter; ++iter)
  {
    h = handler_from_extension( *iter );
    if (h != end())
    {
      if (NULL != reader && h->have_reader())
        mbError->set_last_error( "Conflicting readers for file extension \"%s\":"
                                 " \"%s\" and \"%s\".",
                                 *iter, h->description().c_str(), description );
      else if(NULL != writer && h->have_writer())
        mbError->set_last_error( "Conflicting writers for file extension \"%s\":"
                                 " \"%s\" and \"%s\".",
                                 *iter, h->description().c_str(), description );
    }
  }
  handlerList.push_back( Handler(reader, writer, name, description, extensions, iter - extensions) );
  return MB_SUCCESS;
}
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 221 of file ReaderWriterSet.cpp.

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

Member Data Documentation

Definition at line 164 of file ReaderWriterSet.hpp.

Definition at line 161 of file ReaderWriterSet.hpp.

Definition at line 162 of file ReaderWriterSet.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines