Zhenkai Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 1 | #ifndef OBJECT_DB_H |
| 2 | #define OBJECT_DB_H |
| 3 | |
| 4 | #include <boost/exception/all.hpp> |
| 5 | #include <vector> |
| 6 | |
| 7 | using namespace std; |
| 8 | |
| 9 | struct ObjectDBException : virtual boost::exception, virtual exception { }; |
Zhenkai Zhu | 772c707 | 2012-12-30 12:40:23 -0800 | [diff] [blame] | 10 | typedef boost::error_info<struct tag_errmsg, std::string> error_info_str; |
| 11 | |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 12 | inline void throwException(const string &msg) { boost::throw_exception(ObjectDBException() << error_info_str(msg)); } |
Zhenkai Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 13 | |
| 14 | typedef unsigned char Byte; |
| 15 | typedef 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 |
| 23 | class ObjectDB |
| 24 | { |
| 25 | public: |
| 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 Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 36 | // size in terms of number of COs |
| 37 | virtual int |
Zhenkai Zhu | 6204d47 | 2013-01-02 13:16:22 -0800 | [diff] [blame] | 38 | size() = 0; |
Zhenkai Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 39 | |
Zhenkai Zhu | 7717d20 | 2012-12-29 18:01:36 -0800 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | #endif |