3 #ifndef SHARECONTAINER_H
4 #define SHARECONTAINER_H
9 #include <boost/utility.hpp>
10 #include <boost/smart_ptr.hpp>
14 class ShareContainer : public noncopyable {
17 typedef std::vector<boost::shared_ptr<Share> > Params;
19 typedef typename Params::value_type value_type;
22 get(Share const & ps) const {
23 // First see if we already have this ps in the container
25 Params::iterator it = params.begin();
26 Params::iterator end = params.end();
27 for (; it != end; ++it) {
28 if (ps == *(*it).get())
32 Params::iterator it = std::find_if(params.begin(),
37 if (it == params.end()) {
38 // ok we don't have it so we should
40 tmp.reset(new Share(ps));
41 params.push_back(tmp);
42 // We clean here. This can cause us to have
43 // some (one) unique elemements some times
44 // but we should gain a lot in speed.
46 std::sort(params.rbegin(), params.rend(), comp());
48 // yes we have it already
56 isEqual(Share const & s) : p_(s) {}
57 bool operator()(value_type const & p1) const {
58 return *p1.get() == p_;
65 int operator()(value_type const & p1,
66 value_type const & p2) const {
67 return p1.use_count() < p2.use_count();
72 bool operator()(value_type const & p) const {
79 // Remove all unique items. (i.e. entries that only
80 // exists in the conatainer and does not have a
81 // corresponding paragrah.
82 Params::iterator it = std::remove_if(params.begin(),
85 params.erase(it, params.end());
89 mutable Params params;