Listing 3: The POBase template class

#ifndef POBBASE_H
#define POBBASE_H

#include <stdlib.h>
#include <sys/stat.h>
#include <time.h>
#include <string.h>
#include <fstream.h>
#include <iostream.h>

#include <slist>
#include <typeinfo>
#include <set>

#include "DskMBTree.h"
#include "GFactory.h"
#include "objAvl.h"
#include "POBException.h"


template <class T> class POBbase
{
public:
    enum ACCESS {
        RANDOM, SEQUENCE
    };

    typedef unsigned long OBJ_ID;    
    typedef pair<streampos, size_t> POS_SIZE_PAIR;
    typedef pair<OBJ_ID, POS_SIZE_PAIR> REF_PAIR;
    typedef map<long, REF_PAIR> REF_TBL;

    POBbase();
    ~POBbase() {};
    POBbase(const char*);

    void  openfile(const char*) throw (POBException*);
    bool  eof();

    bool   findObj(streampos&, OBJ_ID);
    OBJ_ID insertObj(const T&) throw (POBException*);
    bool   add2map(long, OBJ_ID, streampos, int);
    bool   POB_DEL_REF(T*);
    OBJ_ID changeObj(T*) throw (POBException*);
    bool   removeObj(OBJ_ID, T*&) throw (POBException*);
    void   maxmemory();

    OBJ_ID 
    read(ACCESS, int&, streampos&, T*&) throw (POBException*);
    int write(OBJ_ID, streampos&, T*) throw (POBException*);

    void 
    register_create_function(const char*, GFactory<T>::PFUNC);

private:
    void   init_oi();
    OBJ_ID new_oi();
    void   load_avl();
    void   update_avl(OBJ_ID);

private:
    const OBJ_ID _sysoi;
    OBJ_ID _sequence;
    streampos _markp, _markg;
    fstream _iof;
    GFactory<T> _factory;
    REF_TBL _refmap;
    DskMBTree  _bt;
    objAvl _avl;
};

#endif