[MOAB-dev] Detecting file types

Steve Jackson sjackson at cae.wisc.edu
Wed Nov 25 17:42:04 CST 2009


Dagmc loads a file by calling MBInterface::load_file().  For several  
reasons, dagmc wants to know what type of file is thus loaded, but  
MBInterface does not provide an obvious way to find out.

Here is a roundabout way to test whether a file is handled by a given  
reader (in this case, the native MOAB reader):

> // variables in scope: MBInterface* MBI, char* filename

> // cast MBInterface to MBCore and extract reader-writer set
>   MBReaderWriterSet* rwset = (dynamic_cast<MBCore*>(MBI))- 
> >reader_writer_set();
> // get the MOAB handler
>   MBReaderWriterSet::iterator moab_reader  = rwset->handler_by_name 
> ("MOAB");
> // get the read handler for our file
>   MBReaderWriterSet::iterator cfile_reader = rwset- 
> >handler_from_extension( rwset->extension_from_filename( filename ),  
> true, false );
>
>   if( moab_reader == cfile_reader ){
>     ... special code for MOAB files ...
>   }

I have three questions:

1) Is the code above the best way for a MOAB client to check file  
types?  Is there a better way?

2) Should we wrap up this functionality into a more convenient  
function?  Perhaps something like  
MBReaderWriterSet::handler_name_from_filename(), or even  
MBInterface::detect_file_type().  (I realize the latter would be a  
substantial interface change, but it does express the operation I am  
looking for.)  Another option would be to provide a new optional  
argument to load_file, which would return a value indicating the file  
type that was loaded.

3) Handler names are currently specified by strings given directly in  
the code (e.g. "MOAB" in the above).  A handler name is initially  
passed to the MBReaderWriterSet::register_factory method; right now  
all calls to this method are found within MBReaderWriterSet.cpp.   
However, if we want to use these handler names to distinguish file  
types outside of the implementation of MBReaderWriterSet, it might  
make sense to #define the strings somewhere.  Would such defines be  
appropriate, and if so, where should they go?

Paul, Tim, and I discussed this earlier today, and we would value the  
input of Jason and any other interested users.  I'm happy to do the  
necessary implementation work, if we can agree on an approach.

Happy weekend to all,
~S


More information about the moab-dev mailing list