eis/inc/zlib/DB2Mem_old.hpp

77 lines
1.2 KiB
C++
Raw Normal View History

#ifndef _DATABASE_TO_MEM_CACHE_HPP_
#define _DATABASE_TO_MEM_CACHE_HPP_
#include <glob/GlobMem.h>
template <class T,typename S> class DB2Mem
{
private:
long* p_size;
S* p_ptr;
public:
DB2Mem(const string& tableName)
{
char* ptr = (char*)GlobMem::GetInstancePtr()->GetTablePtr(tableName);
if(ptr == NULL)
{
p_ptr = NULL;
p_size = NULL;
return;
}
p_size = (long*)ptr;
p_ptr = (S*)(ptr + sizeof(long));
}
~DB2Mem()
{
return;
}
public:
S* operator()(void)
{
return p_ptr;
};
S* operator[](int i)
{
if(p_ptr == NULL) return NULL;
return p_ptr+i;
};
long count(void)
{
if(p_size == NULL)return 0;
return *p_size;
};
/* Read DB Table Data to memory */
int readDB(char* dbwhere = NULL,char* order = NULL)
{
if( p_ptr == NULL ) {
return -1;
}
*p_size = 0;
T tb;
char* dbMsg = tb.openSetDB(dbwhere,order);
if( dbMsg != NULL)
{
tb.closeSetDB();
return -1;
}
while( ( dbMsg = tb.getSetDB()) == NULL )
{
tb.fillStructure();
memcpy(p_ptr+*p_size,&tb.structTable,sizeof(S));
*p_size = *p_size+1;
}
return NULL;
}
};
#endif