MOAB: Mesh Oriented datABase  (version 5.4.1)
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

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

Definition at line 161 of file ReaderWriterSet.hpp.


Constructor & Destructor Documentation

Definition at line 90 of file ReaderWriterSet.cpp.

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

                                            : mbCore( mdb )
{
#ifdef MOAB_HAVE_HDF5
    const char* hdf5_sufxs[] = { "h5m", "mhdf", NULL };
#ifdef MOAB_HAVE_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 MOAB_HAVE_NETCDF
    const char* exo_sufxs[] = { "exo", "exoII", "exo2", "g", "gen", NULL };
    register_factory( ReadNCDF::factory, WriteNCDF::factory, "Exodus II", exo_sufxs, "EXODUS" );
    register_factory( ReadNC::factory, WriteNC::factory, "Climate NC", "nc", "NC" );
#endif

#ifdef MOAB_HAVE_CGNS
    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( ReadRTT::factory, NULL, "RTT Mesh Format", "rtt", "Atilla RTT Mesh" );

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

    register_factory( ReadOBJ::factory, NULL, "OBJ mesh format", "obj", "OBJ mesh" );

    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 MOAB_HAVE_CGM_FACET
    const char* facet_sufxs[] = { "facet", NULL };
    register_factory( ReadCGM::factory, NULL, "Facet Engine Solid Model", facet_sufxs, "facet" );
#endif
#ifdef MOAB_HAVE_CGM_OCC
    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, "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 MOAB_HAVE_NETCDF
    register_factory( NULL, WriteSLAC::factory, "SLAC", "slac", "SLAC" );
#endif

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

#ifdef MOAB_HAVE_DAMSEL
    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* template_sufxs[] = { NULL };
    register_factory( ReadTemplate::factory, WriteTemplate::factory, "Template input files", template_sufxs,
                      "TEMPLATE" );
}

Member Function Documentation

Definition at line 163 of file ReaderWriterSet.hpp.

References handlerList.

Referenced by handler_by_name(), and handler_from_extension().

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

Get the file extension from a file name

Definition at line 238 of file ReaderWriterSet.cpp.

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

{
    std::string::size_type idx   = filename.find_last_of( "." );
    std::string::size_type idirx = filename.find_last_of( "\\/" );

    if( idx == std::string::npos ) return std::string( "" );
    if( ( idirx != std::string::npos ) && ( idirx > idx ) ) return std::string( "" );
    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 224 of file ReaderWriterSet.cpp.

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

{
    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 231 of file ReaderWriterSet.cpp.

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

{
    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 320 of file ReaderWriterSet.cpp.

References begin(), and end().

Referenced by register_factory().

{
    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 264 of file ReaderWriterSet.cpp.

References begin(), and end().

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

{
    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 178 of file ReaderWriterSet.cpp.

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

Referenced by ReaderWriterSet(), and register_factory().

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

    // check for duplicate names
    iterator h = handler_by_name( name );
    if( h != end() )
    {
        MB_SET_ERR( MB_FAILURE, "Conflicting string name for file formats: \"" << name << "\"" );
    }

    // 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() )
                MB_SET_ERR( MB_FAILURE, "Conflicting readers for file extension \""
                                            << *iter << "\": \"" << h->description() << "\" and \"" << description
                                            << "\"." );
            else if( NULL != writer && h->have_writer() )
                MB_SET_ERR( MB_FAILURE, "Conflicting writers for file extension \""
                                            << *iter << "\": \"" << h->description() << "\" and \"" << 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 214 of file ReaderWriterSet.cpp.

References register_factory().

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

Member Data Documentation

Definition at line 182 of file ReaderWriterSet.hpp.

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

List of all members.


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