16 #ifndef __VOM_INST_DB_H__ 17 #define __VOM_INST_DB_H__ 32 template <
typename KEY,
typename OBJ>
50 const_iterator
begin()
const {
return m_map.cbegin(); }
55 const_iterator
end()
const {
return m_map.cend(); }
64 template <
typename DERIVED>
65 std::shared_ptr<OBJ>
find_or_add(
const KEY& key,
const DERIVED& obj)
67 auto search = m_map.find(key);
69 if (search == m_map.end()) {
70 std::shared_ptr<OBJ> sp = std::make_shared<DERIVED>(obj);
78 return (search->second.lock());
84 std::shared_ptr<OBJ>
find(
const KEY& key)
86 auto search = m_map.find(key);
88 if (search == m_map.end()) {
89 std::shared_ptr<OBJ> sp(
NULL);
94 return (search->second.lock());
102 auto search = m_map.find(key);
104 if (search != m_map.end()) {
105 if (search->second.expired()) {
108 std::shared_ptr<OBJ> sp = m_map[key].lock();
110 if (sp.get() == obj) {
120 void add(
const KEY& key, std::shared_ptr<OBJ> sp) { m_map[key] = sp; }
127 for (
auto entry : m_map) {
128 entry.second.lock()->replay();
136 std::map<const KEY, std::weak_ptr<OBJ>> m_map;
const_iterator end() const
Get iterator to the beginning of the DB.
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.
const_iterator begin() const
Get iterator to the beginning of the DB.
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.
The VPP Object Model (VOM) library.
void replay()
Populate VPP from current state, on VPP restart.