[MOAB-dev] some proposed moab:::Interface API changes

Jason Kraftcheck kraftche at cae.wisc.edu
Fri Mar 26 09:20:04 CDT 2010


Interface::query_interface (and release_interface) pointer type
---------------------------------------------------------------

This function passes back a void* for the requested interface.  It would be
safer and more C++-like to define some base class that all interfaces
query-able via this function are subclasses of (e.g. the existing
UnknownInterface class in MOAB).  A pointer of that type could be used in
place of the void* type, allowing dynamic_cast to be used on the result.


Interface::query_interface (and release_interface) template
-----------------------------------------------------------

If each interface class query-able via Interface::query_interface provide a
static method to return a string class name, we could provide a template
version of the query_interface function that did not require the
specification of a class name explicitly.  For example:
  template <typename T> inline ErrorCode query_interface(T*& ptr) {
    void* vptr;
    ErrorCode c = query_interface( T::name(), vptr );
    ptr = (MB_SUCCESS == c) ? reinterpret_cast<T*>(vtpr) : 0;
    return c;
  }


Combine tag_create and tag_get_handle for better type safety
------------------------------------------------------------

I think we should replace the current tag_get_handle and tag_create with a
single function with flags.  This results in one less API function,
eliminates an 'expected failure vs. exception' design issue in the API, and
provides better type safety for the application.

enum TagFlags {
  TAG_CREATE = 0x1,        //!< Fail if tag already exists
  TAG_EXISTS = 0x2,        //!< Fail if tag does not exist
  TAG_OPAQUE_OK  = 0x4,    //!< Do not fail if data type is opaque
                           //!  as long as it is of the correct size
  TAG_STORAGE = 0x8,       //!< Fail if storage type does not match
  TAG_ANY_DATA_TYPE = 0x16 //!< Do not fail on data type or size mismatch
};

MBErrorCode tag_get_handle( const char* name,
                            TagType storage,
                            DataType type,
                            int size_in_bytes,
                            Tag& handle,
                            unsigned flags = 0,
                            const void* default_value = 0 );

The TAG_ANY_DATA_TYPE is clearly a bad idea and hopefully no application
will ever use it, but it is necessary to support the iMesh API.

For normal use, where one often doesn't care whether or not the tag already
exists, one can make a single call that creates the tag if it does not exist
and returns an existing tag if there is one *and* the type and size are the
same.  For more obscure cases, the option exists to fail if the tag already
exists, does not exist, does not have the correct storage type, etc.




More information about the moab-dev mailing list