Listing 2: Template class ObjFile<>
#include "isamfile.h"
// not shown: auxiliary type declarations -- mb
template <class T> class ObjFileIter; // iterator class
template < class ObjType >
class ObjFile : public ISAMFile {
friend class ObjFileIter<ObjType>;
public:
// not shown: selectors, file manipulations modifiers, index manipulation
// modifiers, read/write routines, and lock management routines -- mb
ISAMError GetCur(ObjType & obj, boolean lock = FALSE);
protected:
/* Protected Constructors */
ObjFile( const char * file_name, ObjFieldInfo * field_info,
int num_fields );
~ObjFile();
/* Protected Methods */
virtual int ConvertKey( ObjIndexKey & obj_key,
ISAMFile::IndexKey & isam_key );
virtual int ConvertKey( ISAMFile::IndexKey & isam_key,
ObjIndexKey & obj_key );
virtual boolean IsNull( const ObjType & obj ) const;
virtual void MakeNull( ObjType & obj );
private:
/* Private Implementation Methods */
CountType GetCurObjNum( AccessID file_id );
// not shown: file manipulation methods, index manipulation
// methods, read/write methods -- mb
ISAMError GetCur(Access ID file_id, ObjType & obj, boolean lock = FALSE);
/* Private Utility Methods */
virtual int ConvObjToRec( ObjType & obj, char * rec,
ObjIndexKey * key = 0 ) = 0;
virtual int ConvRecToObj( char * rec, ObjType & obj,
ObjIndexKey * key = 0 ) = 0;
/* Data Members */
ISAMFile::AccessID fileId_;
ObjIndexKey curIndex_;
ObjFieldInfo * fieldInfo_; // convert keys to/from isamFormat
int numFields_;
int recSize_;
char * isamRec_; // working buffer
/* Static Interface */
public:
static ObjIndexKey &GetPrimaryKey();
protected:
static int SetPrimaryKey( ObjIndexKey & primary_key );
private:
static ObjIndexKey sPrimaryKey_; // if none, primaryKey.nfields == 0
};
/* End of File */