blob: d99eeb69a54533b5e9bd3f5f0d73f961acf0d234 [file] [log] [blame]
Zhenkai Zhu7717d202012-12-29 18:01:36 -08001#ifndef OBJECT_DB_H
2#define OBJECT_DB_H
3
4#include <boost/exception/all.hpp>
5#include <vector>
6
7using namespace std;
8
9struct ObjectDBException : virtual boost::exception, virtual exception { };
10
11typedef unsigned char Byte;
12typedef vector<Byte> Bytes;
13
14// OK. This name is a bit miss-leading, but this ObjectDB is really some storage
15// that stores the Ccnx ContentObjects of a file. So unlike a normal database,
16// this DB is per file.
17
18// The assumption is, the ContentObjects will be write to ObjectDB sequentially
19// This guarantees that when read, the Nth ContentObject read has the sequence number N as the last component of its name
20class ObjectDB
21{
22public:
23 virtual ~ObjectDB(){}
24
25 // assume sequential
26 virtual void
27 append(const Bytes &co) = 0;
28
29 // get next CO
30 virtual Bytes
31 next() = 0;
32
33 // get n COs; if the remaining number of COs < n, return all;
34 virtual void
35 read(const vector<Bytes> &vco, int n) = 0;
36
37 // size in terms of number of COs
38 virtual int
39 size() = 0 const;
40
41 // the current index of in terms of COs
42 virtual int
43 pos() = 0 const;
44
45 // set the pos to be desired pos in terms of COs
46 // return true if success
47 virtual bool
48 seek(int pos) = 0;
49
50 // reset pos to be zero
51 virtual void
52 rewind() = 0;
53
54};
55
56#endif