ÅÆÇø´¿¡ Àç¹ÌºÙÀ̱â
¸ñÀû #
ÀÔÃâ·ÂÀ» ´õ ÆíÇÏ°Ô ÇÏ°í ½Í´Ù. ¾î¶² key¿¡ ´ëÇÑ dbÀÇ ³»¿ëÀ» ¹Ù·Î ´ã°í½Í°í, ¶Ç ¹Ù·Î ÀúÀåÇÏ°í ½Í´Ù.
main() #
ÀÌ·¸°Ô ¾²°í ½ÍÀº °ÍÀÌ´Ù.
// key¶ó´Â Çʵ带 °¡Áö´Â ±¸Á¶Ã¼¸¦ Çϳª ¼±¾ðÇÏ°í,
typedef struct _mydata
{
char key[32];
char email[80];
} RMyData;
int main(void)
{
// RMyDataÇü½ÄÀ» ÀÐ°í ¾µ DB¸¦ ÁغñÇÑ´Ù.
TDBData<RMyData> mdata("test.db");
RMyData dw ={ "hello", "hello@world" };
RMyData dw2 ={ "hello" };
// Å×½ºÆ® writing
mdata.Write(dw);
// Àß ¾²¿©Áø°ÇÁö Å×½ºÆ® reading
mdata.Read(dw2);
cout << dw2.email << endl;
}
class TDBData
{
protected :
TDB *db;
public :
TDBData(const char *dbname){
db = new TDB(dbname);
};
~TDBData()
{
delete db;
};
int Read(T &outdata)
{
return db->Read(outdata.key, (char *)&outdata);
};
int Read(const char *key, T &outdata)
{
return db->Read(key, (char *)&outdata);
};
int Write(T &indata)
{
return db->Update(indata.key, (char *)&indata, sizeof(T));
};
TDBData &operator << (const T &dw)
{
db->Update(dw.key, (char *)&dw, sizeof(T));
return (*this);
};
};
°³¼±°èȹ #
ÇöÀçÀÇ ÇÁ·Î±×·¥À¸·Î´Â µð½ºÅ© °ø°£ ³¶ºñ°¡ ½ÉÇϹǷÎ, ÆÐÅ·ÇÏ¿© º¸°üÇϰųª Àд ±¸Á¶·Î °³¼±
TDBVarData