ANNA Suite  2020b
Multipurpose development suite for Telco applications
SafeSortedVector.hpp
Go to the documentation of this file.
1 // ANNA - Anna is Not Nothingness Anymore //
2 // //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
4 // //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7 
8 
9 #ifndef anna_core_mt_SafeSortedVector_hpp
10 #define anna_core_mt_SafeSortedVector_hpp
11 
12 #include <vector>
13 
14 #include <anna/core/mt/Mutex.hpp>
15 #include <anna/core/mt/Guard.hpp>
17 
18 namespace anna {
19 
30 template < typename T, typename SortBy, typename TKey = int >
31 class SafeSortedVector : public SortedVector <T, SortBy, TKey>, public Mutex {
32 public:
36  SafeSortedVector() : SortedVector <T, SortBy, TKey> () {;}
37 
42  explicit SafeSortedVector(const SafeSortedVector& other) : SortedVector <T, SortBy, TKey> (other) {}
43 
51  bool contains(const T* t) const
52  {
53  if(t == NULL)
54  return false;
55 
56  Guard guard(this, "SafeSortedVector <T, SortBy, TKey>::contains");
58  }
59 
65  bool add(T* t)
66  noexcept(false) {
67  if(t == NULL)
68  return false;
69 
70  Guard guard(this, "SafeSortedVector <T, SortBy, TKey>::add");
72  }
73 
79  bool erase(T* t)
80  noexcept(false) {
81  if(t == NULL)
82  return false;
83 
84  Guard guard(this, "SafeSortedVector <T, SortBy, TKey>::erase");
86  }
87 
93  T* find(const TKey key)
94  {
95  Guard guard(this, "SafeSortedVector <T, SortBy, TKey>::find");
97  }
98 
104  const T* find(const TKey key) const {
105  return const_cast <SafeSortedVector <T, SortBy, TKey>*>(this)->find(key);
106  }
107 };
108 
109 }
110 
111 #endif
bool add(T *t) noexcept(false)
Definition: SafeSortedVector.hpp:65
T * find(const TKey key)
Definition: SafeSortedVector.hpp:93
const T * find(const TKey key) const
Definition: SafeSortedVector.hpp:104
Definition: SortedVector.hpp:30
SafeSortedVector()
Definition: SafeSortedVector.hpp:36
bool erase(T *t) noexcept(false)
Definition: SafeSortedVector.hpp:79
Definition: SafeSortedVector.hpp:31
Definition: app.hpp:12
Definition: Guard.hpp:35
Definition: Mutex.hpp:41
bool contains(const T *t) const
Definition: SafeSortedVector.hpp:51
SafeSortedVector(const SafeSortedVector &other)
Definition: SafeSortedVector.hpp:42