16 #ifndef __VOM_INST_DB_H__ 17 #define __VOM_INST_DB_H__ 31 template <
typename KEY,
typename OBJ>
49 const_iterator
cbegin() {
return m_map.cbegin(); }
54 const_iterator
cend() {
return m_map.cend(); }
63 template <
typename DERIVED>
64 std::shared_ptr<OBJ>
find_or_add(
const KEY& key,
const DERIVED& obj)
66 auto search = m_map.find(key);
68 if (search == m_map.end()) {
69 std::shared_ptr<OBJ> sp = std::make_shared<DERIVED>(obj);
77 return (search->second.lock());
83 std::shared_ptr<OBJ>
find(
const KEY& key)
85 auto search = m_map.find(key);
87 if (search == m_map.end()) {
88 std::shared_ptr<OBJ> sp(
NULL);
93 return (search->second.lock());
99 void release(
const KEY& key,
const OBJ* obj)
101 auto search = m_map.find(key);
103 if (search != m_map.end()) {
104 if (search->second.expired()) {
107 std::shared_ptr<OBJ> sp = m_map[key].lock();
109 if (sp.get() == obj) {
119 void add(
const KEY& key, std::shared_ptr<OBJ> sp) { m_map[key] = sp; }
126 for (
auto entry : m_map) {
127 os <<
"key: " << entry.first << std::endl;
128 os <<
" " << entry.second.lock()->to_string() << std::endl;
137 for (
auto entry : m_map) {
138 entry.second.lock()->replay();
146 std::map<const KEY, std::weak_ptr<OBJ>> m_map;
void add(const KEY &key, std::shared_ptr< OBJ > sp)
Find the object to the store.
std::shared_ptr< OBJ > find(const KEY &key)
Find the object to the store.
void release(const KEY &key, const OBJ *obj)
Release the object from the DB store, if it's the one we have stored.
static const log_level_t DEBUG
std::shared_ptr< OBJ > find_or_add(const KEY &key, const DERIVED &obj)
Find or add the object to the store.
A Database to store the unique 'singular' instances of a single object type.
std::map< key_t, std::weak_ptr< VOM::ACL::list > >::const_iterator const_iterator
Iterator.
singular_db()
Constructor.
const_iterator cend()
Get iterator to the beginning of the DB.
const_iterator cbegin()
Get iterator to the beginning of the DB.
The VPP Object Model (VOM) library.
void replay()
Populate VPP from current state, on VPP restart.
void dump(std::ostream &os)
Print each of the object in the DB into the stream provided.