blob: 8c314185eb488052c8d2a74167a4d291aa8d7f4f [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 { };
Zhenkai Zhu772c7072012-12-30 12:40:23 -080010typedef boost::error_info<struct tag_errmsg, std::string> error_info_str;
11
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080012inline void throwException(const string &msg) { boost::throw_exception(ObjectDBException() << error_info_str(msg)); }
Zhenkai Zhu7717d202012-12-29 18:01:36 -080013
14typedef unsigned char Byte;
15typedef vector<Byte> Bytes;
16
17// OK. This name is a bit miss-leading, but this ObjectDB is really some storage
18// that stores the Ccnx ContentObjects of a file. So unlike a normal database,
19// this DB is per file.
20
21// The assumption is, the ContentObjects will be write to ObjectDB sequentially
22// This guarantees that when read, the Nth ContentObject read has the sequence number N as the last component of its name
23class ObjectDB
24{
25public:
26 virtual ~ObjectDB(){}
27
28 // assume sequential
29 virtual void
30 append(const Bytes &co) = 0;
31
32 // get next CO
33 virtual Bytes
34 next() = 0;
35
Zhenkai Zhu7717d202012-12-29 18:01:36 -080036 // size in terms of number of COs
37 virtual int
Zhenkai Zhu6204d472013-01-02 13:16:22 -080038 size() = 0;
Zhenkai Zhu7717d202012-12-29 18:01:36 -080039
Zhenkai Zhu7717d202012-12-29 18:01:36 -080040};
41
42#endif