8 #include <pv/sharedPtr.h>
9 #include <epicsMutex.h>
10 #include <epicsGuard.h>
61 typedef std::tr1::shared_ptr<T> value_pointer;
62 typedef std::tr1::weak_ptr<T> value_weak_pointer;
63 typedef std::set<value_pointer> set_type;
64 typedef std::vector<value_pointer> vector_type;
66 typedef epicsMutex mutex_type;
67 typedef epicsGuard<epicsMutex> guard_type;
68 typedef epicsGuardRelease<epicsMutex> release_type;
71 bool operator()(
const value_weak_pointer& lhs,
72 const value_weak_pointer& rhs)
const
74 value_pointer LHS(lhs.lock()), RHS(rhs.lock());
75 return LHS && RHS && LHS.get() < RHS.get();
77 bool operator()(
const value_pointer& lhs,
78 const value_weak_pointer& rhs)
const
80 value_pointer RHS(rhs.lock());
81 return RHS && lhs.get() < RHS.get();
83 bool operator()(
const value_weak_pointer& lhs,
84 const value_pointer& rhs)
const
86 value_pointer LHS(lhs.lock());
87 return LHS && LHS.get() < rhs.get();
91 typedef std::set<value_weak_pointer, weak_less> store_t;
97 std::tr1::shared_ptr<data> _data;
103 std::tr1::weak_ptr<data> container;
104 value_pointer realself;
105 dtor(
const std::tr1::weak_ptr<data>& d,
106 const value_pointer& w)
107 :container(d), realself(w)
109 void operator()(value_type *)
114 std::tr1::shared_ptr<data> C(container.lock());
116 guard_type G(C->mutex);
152 guard_type G(_data->mutex);
153 return _data->store.clear();
160 guard_type G(_data->mutex);
161 return _data->store.empty();
169 guard_type G(_data->mutex);
170 return _data->store.size();
176 void insert(value_pointer&);
181 guard_type G(_data->mutex);
182 return _data->store.erase(v);
206 epicsGuard<epicsMutex> guard;
207 typename store_t::iterator it, end;
208 XIterator(
weak_set& S) :set(S), guard(S.
mutex()), it(S._data->store.begin()), end(S._data->store.end()) {}
213 ret = (it++)->lock();
223 typedef XIterator iterator;
230 throw std::invalid_argument(
"Only unique() references may be inserted");
232 guard_type G(_data->mutex);
233 typename store_t::const_iterator it = _data->store.find(v);
234 if(it==_data->store.end()) {
237 value_pointer chainptr(v.get(), dtor(_data, v));
239 _data->store.insert(chainptr);
247 v = value_pointer(*it);
252 typename weak_set<T>::set_type
256 guard_type G(_data->mutex);
257 for(
typename store_t::const_iterator it=_data->store.begin(),
258 end=_data->store.end(); it!=end; ++it)
260 value_pointer P(it->lock());
267 typename weak_set<T>::vector_type
278 guard_type G(_data->mutex);
279 ret.reserve(_data->store.size());
280 for(
typename store_t::const_iterator it=_data->store.begin(),
281 end=_data->store.end(); it!=end; ++it)
283 value_pointer P(it->lock());
284 if(P) ret.push_back(P);
set_type lock_set() const
size_t erase(value_pointer &v)
epicsMutex & mutex() const
value_pointer next()
yield the next live entry
weak_set()
Construct a new empty set.
a std::set-ish container where entries are removed when ref. counts fall to zero
vector_type lock_vector() const
an iterator-ish object which also locks the set during iteration
void insert(value_pointer &)