summaryrefslogtreecommitdiffstats
path: root/noatun-plugins/oblique/kdbt.h
blob: 4ecc71a44d1716a144b7d20d2915e8aff2548d2f (plain)
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
// Author: Eray Ozkural (exa) <erayo@cs.bilkent.edu.tr>, (c) 2002
//
// Copyright: GNU LGPL: http://www.gnu.org/licenses/lgpl.html


#ifndef KDbt_Interface
#define KDbt_Interface

#include <db_cxx.h>
#include <tqdatastream.h>
#include <tqbuffer.h>
#include "kbuffer.h"

/**A generic wrapper for "database thang" class that abstracts binary streaming operations.
  *@author Eray Ozkural (exa)
  */

template <typename T>
class KDbt : public Dbt {
public:
  /* assume streaming operators on QDataStream
  TQDataStream & operator>> ( TQDataStream& >>, T &);
  TQDataStream & operator<< ( TQDataStream& >>, T &);
  */
  KDbt() {
  }
  /** construct a Dbt from obj */
  KDbt(const T& obj) {
    set(obj);
  }
//  operator Dbt() {
//    return Dbt(thang.data(), thang.size());
//  }
  /** set "thang" to the contents of obj */
  void set(const T& obj) {
//    KBuffer buffer(thang);
    TQDataStream ds(&thang);
    ds << obj;
//    std::cerr << "thang size " << thang.size() << endl;
//    buffer.close();
//    set_data(thang.data());
//    set_size(buffer.size());
    set_data(thang.data());
    set_size(thang.size());
  }
  void get(T& obj) {
    TQByteArray buffer;
    buffer.setRawData((char*)get_data(),get_size());
    TQDataStream ds(buffer,IO_ReadWrite);
    ds >> obj;
    buffer.resetRawData((char*)get_data(),get_size());
  }
private:
  /** Internal data */
//  TQByteArray thang;
  KBuffer thang;
};

#endif