1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
// This is a -*- c++ -*- header file.
// Copyright (c) 1997 by Jim Lynch.
// Copyright (c) 2010 by Philipp Schafft.
// This software comes with NO WARRANTY WHATSOEVER.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 dated June, 1991, or, at your
// option, any LATER version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301 USA
//
// On Debian Linux systems, the complete text of the GNU General
// Public License can be found in `/usr/doc/copyright/GPL'.
#ifndef Record_h
#define Record_h
#include "db4++-stuff.h"
#include "str-conversions.h"
// #include <gdbm.h>
#include <malloc.h>
#include <string>
#include <iostream>
class Record
{
protected:
virtual void Destroy(void)
{
}
virtual void SetNull(void)
{
}
virtual void SetFromDataString(const char *theDataString)
{
}
public:
Record() { }
virtual ~Record() { }
virtual const char *FormNewDataCString() const
{
}
virtual void Read(Db &handle, const std::string &theKey)
{
std::string theValue;
Destroy();
if(::Read(handle, theKey, theValue))
{
SetFromDataString(theValue.c_str());
}
else
{
SetNull();
}
// const char *key = theKey.c_str();
//
// Read(handle, key);
}
virtual void Read(Db &handle, const char *theKey)
{
std::string key(theKey);
Read(handle, key);
// Dbt key((void*) theKey, strlen(theKey) + 1);
// Dbt content;
// char * p;
//
// handle.get(NULL, &key, &content, 0);
// p = (char *) content.get_data();
//
// Destroy();
//
// if(p)
// {
// char *tmp = MakeCStringCopy(p);
//
// SetFromDataString(tmp);
// }
// else
// SetNull();
}
virtual void Write(Db &handle, const char *theKey) const
{
std::string p(FormNewDataCString());
std::string key(theKey);
int wrOK = ::Write(handle, key, p);
}
virtual void Print(std::ostream &out) const
{
const char *p = FormNewDataCString();
out << p;
delete[] p;
}
};
inline std::ostream &operator<<(std::ostream &out, const Record &it)
{
it.Print(out);
return out;
}
#endif
|