|
1 /* |
|
2 * Copyright 2007 Baylor University |
|
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 _PROPHET_NODE_LIST_H_ |
|
18 #define _PROPHET_NODE_LIST_H_ |
|
19 |
|
20 #include "prophet/Node.h" |
|
21 #include "prophet/Table.h" |
|
22 #include "storage/ProphetStore.h" |
|
23 #include <oasys/debug/Log.h> |
|
24 |
|
25 namespace dtn |
|
26 { |
|
27 |
|
28 /** |
|
29 * Maintain a one-to-one mapping of objects in memory to objects |
|
30 * in permanent store, much like a write-thru cache |
|
31 */ |
|
32 class ProphetNodeList |
|
33 { |
|
34 public: |
|
35 /** |
|
36 * Constructor |
|
37 */ |
|
38 ProphetNodeList(); |
|
39 |
|
40 /** |
|
41 * Destructor |
|
42 */ |
|
43 virtual ~ProphetNodeList(); |
|
44 |
|
45 /** |
|
46 * Deserialize from storage |
|
47 */ |
|
48 void load(const prophet::Node* n); |
|
49 |
|
50 /** |
|
51 * Update (or add new) node in permanent store |
|
52 */ |
|
53 void update(const prophet::Node* n); |
|
54 |
|
55 /** |
|
56 * Remove node from permanent store |
|
57 */ |
|
58 void del(const prophet::Node* n); |
|
59 |
|
60 /** |
|
61 * Retrieve node from permanent store; returns NULL if not found |
|
62 */ |
|
63 const prophet::Node* find(const std::string& dest_id) const; |
|
64 |
|
65 /** |
|
66 * Copy list of nodes from permanent store into prophet::Table |
|
67 */ |
|
68 void clone(prophet::Table* nodes, const prophet::NodeParams* params); |
|
69 |
|
70 /** |
|
71 * Clean up memory associated with this list (leaving permanent |
|
72 * store untouched) |
|
73 */ |
|
74 void clear(); |
|
75 |
|
76 ///@{ Accessors |
|
77 bool empty() const { return list_.empty(); } |
|
78 size_t size() const { return list_.size(); } |
|
79 ///@} |
|
80 |
|
81 protected: |
|
82 typedef std::list<prophet::Node*> List; |
|
83 typedef List::iterator iterator; |
|
84 typedef List::const_iterator const_iterator; |
|
85 |
|
86 /** |
|
87 * Given primary key, locate node in list |
|
88 */ |
|
89 bool find(const std::string& dest_id, iterator& i); |
|
90 |
|
91 List list_; ///< collection of prophet::Node's |
|
92 |
|
93 }; // class ProphetNodeList |
|
94 |
|
95 }; // namespace dtn |
|
96 |
|
97 #endif // _PROPHET_NODE_LIST_H_ |