|
1 /* |
|
2 * Copyright 2004-2006 Intel Corporation |
|
3 * |
|
4 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 * you may not use this file except in compliance with the License. |
|
6 * You may obtain a copy of the License at |
|
7 * |
|
8 * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 * |
|
10 * Unless required by applicable law or agreed to in writing, software |
|
11 * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 * See the License for the specific language governing permissions and |
|
14 * limitations under the License. |
|
15 */ |
|
16 |
|
17 #ifndef _PERSISTENT_STORE_H_ |
|
18 #define _PERSISTENT_STORE_H_ |
|
19 |
|
20 |
|
21 #include <vector> |
|
22 #include <oasys/serialize/Serialize.h> |
|
23 |
|
24 namespace dtn { |
|
25 |
|
26 /** |
|
27 * The abstract base class implementing a persistent storage system. |
|
28 * Specific implementations (i.e. Berkeley DB or SQL) should derive |
|
29 * from this class. |
|
30 * |
|
31 * TODO: |
|
32 * * should the key be an int or a std::string? |
|
33 */ |
|
34 class PersistentStore { |
|
35 public: |
|
36 /** |
|
37 * Close and flush the store. |
|
38 */ |
|
39 virtual int close() = 0; |
|
40 |
|
41 /** |
|
42 * Fill in the fields of the object referred to by *obj with the |
|
43 * value stored at the given key. |
|
44 */ |
|
45 virtual int get(oasys::SerializableObject* obj, const int key) = 0; |
|
46 |
|
47 /** |
|
48 * Store the object with the given key. |
|
49 */ |
|
50 virtual int add(oasys::SerializableObject* obj, const int key) = 0; |
|
51 |
|
52 /** |
|
53 * Update the object with the given key. |
|
54 */ |
|
55 virtual int update(oasys::SerializableObject* obj, const int key) = 0; |
|
56 |
|
57 /** |
|
58 * Delete the object at the given key. |
|
59 */ |
|
60 virtual int del(const int key) = 0; |
|
61 |
|
62 /** |
|
63 * Return the number of elements in the table. |
|
64 */ |
|
65 virtual int num_elements() = 0; |
|
66 |
|
67 /** |
|
68 * Fill in the given vector with the keys currently stored in the |
|
69 * table. |
|
70 */ |
|
71 virtual void keys(std::vector<int> * v) = 0; |
|
72 |
|
73 virtual ~PersistentStore(); |
|
74 |
|
75 }; |
|
76 } // namespace dtn |
|
77 |
|
78 #endif /* _PERSISTENT_STORE_H_ */ |