Scroom 0.14-49-gb7ae7a6d
Loading...
Searching...
No Matches
Scroom::Bookkeeping::MapBase< K, V > Class Template Reference

#include <bookkeeping.hh>

Inheritance diagram for Scroom::Bookkeeping::MapBase< K, V >:
Inheritance graph
Collaboration diagram for Scroom::Bookkeeping::MapBase< K, V >:
Collaboration graph

Public Member Functions

Token reserve (const K &k)
 
Token reReserve (const K &k)
 
void remove (const K &k)
 
void remove (const K &k, const WeakToken &t)
 
Detail::LValue< Vat (const K &k)
 
void set (const K &k, const V &v)
 
V get (const K &k)
 
std::list< K > keys () const
 
std::list< Vvalues () const
 
- Public Member Functions inherited from Scroom::Utils::Base
 Base ()=default
 
 Base (const Base &)=delete
 
 Base (Base &&)=delete
 
Baseoperator= (const Base &)=delete
 
Baseoperator= (Base &&)=delete
 
virtual ~Base ()=default
 
template<typename R >
std::shared_ptr< R > shared_from_this ()
 
template<typename R >
std::shared_ptr< R const > shared_from_this () const
 

Private Types

using MapType = typename Detail::MapType< K, V >::Type
 

Private Attributes

MapType map
 
boost::mutex mut
 

Member Typedef Documentation

◆ MapType

template<typename K , typename V >
using Scroom::Bookkeeping::MapBase< K, V >::MapType = typename Detail::MapType<K, V>::Type
private

Member Function Documentation

◆ at()

template<typename K , typename V >
Detail::LValue< V > Scroom::Bookkeeping::MapBase< K, V >::at ( const K &  k)
inline
296 {
297 boost::mutex::scoped_lock const lock(mut);
298 auto i = map.find(k);
299
300 if(map.end() != i)
301 {
302 typename Detail::ValueType<V>::Ptr const pv = i->second.lock();
303 if(pv)
304 {
305 return Detail::LValue<V>(pv);
306 }
307 }
308
309 throw std::invalid_argument("Invalid key");
310 }
std::shared_ptr< ValueType< V > > Ptr
Definition bookkeepingimpl.hh:120
MapType map
Definition bookkeeping.hh:78
boost::mutex mut
Definition bookkeeping.hh:79

◆ get()

template<typename K , typename V >
V Scroom::Bookkeeping::MapBase< K, V >::get ( const K &  k)
inline
333 {
334 boost::mutex::scoped_lock const lock(mut);
335 auto i = map.find(k);
336
337 if(map.end() != i)
338 {
339 typename Detail::ValueType<V>::Ptr const pv = i->second.lock();
340 if(pv)
341 {
342 return pv->value;
343 }
344 }
345
346 throw std::invalid_argument("Invalid key");
347 }

◆ keys()

template<typename K , typename V >
std::list< K > Scroom::Bookkeeping::MapBase< K, V >::keys ( ) const
inline
351 {
352 boost::mutex::scoped_lock const lock(mut);
353 std::list<K> result;
354 for(const typename MapType::value_type& el: map)
355 {
356 result.push_back(el.first);
357 }
358 return result;
359 }
SampleIterator< const uint8_t > result
Definition sampleiterator-tests.cc:94

◆ remove() [1/2]

template<typename K , typename V >
void Scroom::Bookkeeping::MapBase< K, V >::remove ( const K &  k)
inline
284 {
285 boost::mutex::scoped_lock lock(mut);
286 typename MapType::iterator i = map.find(k);
287
288 if(map.end() != i)
289 {
290 map.erase(i);
291 }
292 }

◆ remove() [2/2]

template<typename K , typename V >
void Scroom::Bookkeeping::MapBase< K, V >::remove ( const K &  k,
const WeakToken t 
)
inline
259 {
260 boost::mutex::scoped_lock const lock(mut);
261 auto i = map.find(k);
262
263 if(map.end() != i)
264 {
265 typename Detail::ValueType<V>::Ptr const pv = i->second.lock();
266 if(pv)
267 {
268 Token const t(wt.lock());
269 Token const t_orig(pv->token.lock());
270 if(t == t_orig)
271 {
272 map.erase(i);
273 }
274 }
275 else
276 {
277 map.erase(i);
278 }
279 }
280 }
ThreadPool t(0)

◆ reReserve()

template<typename K , typename V >
Token Scroom::Bookkeeping::MapBase< K, V >::reReserve ( const K &  k)
inline
229 {
230 boost::mutex::scoped_lock const lock(mut);
231 auto i = map.find(k);
232
233 if(map.end() == i)
234 {
235 map[k] = typename Detail::ValueType<V>::WeakPtr();
236 i = map.find(k);
237 }
238
239 typename Detail::ValueType<V>::Ptr pv = i->second.lock();
240 if(!pv)
241 {
243 i->second = pv;
244 }
245
246 Token t(pv->token.lock());
247 if(!t)
248 {
250 t.add(pv);
251 pv->token = t;
252 }
253
254 return t;
255 }
barrier2 V()
static Scroom::Bookkeeping::Token create()
Definition bookkeepingimpl.hh:65
std::weak_ptr< ValueType< V > > WeakPtr
Definition bookkeepingimpl.hh:121
static Ptr create(V value)
Definition bookkeepingimpl.hh:134
std::shared_ptr< R > shared_from_this()
Definition utilities.hh:48
ThreadPtr add()
Definition threadpoolimpl.cc:241
Here is the call graph for this function:

◆ reserve()

template<typename K , typename V >
Token Scroom::Bookkeeping::MapBase< K, V >::reserve ( const K &  k)
inline
211 {
212 boost::mutex::scoped_lock const lock(mut);
213 if(map.end() != map.find(k))
214 {
215 throw std::invalid_argument("Key already exists");
216 }
217
219 map[k] = pv;
220
222 t.add(pv);
223 pv->token = t;
224 return t;
225 }
Here is the call graph for this function:

◆ set()

template<typename K , typename V >
void Scroom::Bookkeeping::MapBase< K, V >::set ( const K &  k,
const V v 
)
inline
314 {
315 boost::mutex::scoped_lock const lock(mut);
316 auto i = map.find(k);
317
318 if(map.end() != i)
319 {
320 typename Detail::ValueType<V>::Ptr const pv = i->second.lock();
321 if(pv)
322 {
323 pv->value = v;
324 return;
325 }
326 }
327
328 throw std::invalid_argument("Invalid key");
329 }

◆ values()

template<typename K , typename V >
std::list< V > Scroom::Bookkeeping::MapBase< K, V >::values ( ) const
inline
363 {
364 boost::mutex::scoped_lock const lock(mut);
365 std::list<V> result;
366 for(const typename MapType::value_type& el: map)
367 {
368 typename Detail::ValueType<V>::Ptr const pv = el.second.lock();
369 if(pv)
370 {
371 result.push_back(pv->value);
372 }
373 }
374 return result;
375 }

Member Data Documentation

◆ map

template<typename K , typename V >
MapType Scroom::Bookkeeping::MapBase< K, V >::map
private

◆ mut

template<typename K , typename V >
boost::mutex Scroom::Bookkeeping::MapBase< K, V >::mut
mutableprivate

The documentation for this class was generated from the following files: