Okay the idea here is that I should have a central method in the class for loading files, say, which will auto detect the file format then call another function to actually load the data based on the format.
I want to avoid including too many API headers in my main class source files, and I want it to be fairly extensible.
Right now what seems to be the way to go would be something like this:
DataObject.h
DataObject.cppCode:// etc.. #include "DataObject_DAT.h" class DataObject { public: DataObject() : mData(0) {} ~DataObject() { if(mData){delete mData;mData=0;} } bool LoadFromFile( char const * filename ); private: friend bool DataUtils::LoadFromFileDAT( char const * filename ); char * mData; };
DataObject_DAT.hCode:#include "DataObject.h" bool DataObject::LoadFromFile( char const * filename ) { // determine file format if( format == eFORMAT_DAT ) return DataUtils::LoadFromDATFile( filename ); }
DataObject_DAT.cppCode:// etc.. namespace DataUtils { bool LoadFromDATFile( char const * filename ); };
What I like about this is that it keeps all of the "dat file sdk" out of the scope of DataObject.h which will be included anywhere that a DataObject is needed. This is nothing real at the moment, just a design idea compressed to not be too verbose.Code:#include "DataObject_DAT.h" #include <datfilesdk/datfilesdk.h> namespace DataUtils { bool LoadFromDATFile( char const * filename ) { datfileobject datfile; // etc... datfile.readData( (void**)&mData ); return (mData != NULL); } };
Is this a reasonable thing to do? Is there a better way?



LinkBack URL
About LinkBacks




