3 #ifndef SHARECONTAINER_H
4 #define SHARECONTAINER_H
8 #include <boost/utility.hpp>
9 #include <boost/smart_ptr.hpp>
13 class ShareContainer : public noncopyable {
16 typedef std::vector<boost::shared_ptr<Share> > Params;
18 typedef typename Params::value_type value_type;
21 get(Share const & ps) const {
22 // First see if we already have this ps in the container
23 Params::iterator it = params.begin();
24 Params::iterator end = params.end();
25 for (; it != end; ++it) {
26 if (ps == *(*it).get())
31 // ok we don't have it so we should
33 tmp.reset(new Share(ps));
34 params.push_back(tmp);
35 // We clean here. This can cause us to have
36 // some (one) unique elemements some times
37 // but we should gain a lot in speed.
39 std::sort(params.rbegin(), params.rend(), comp());
41 // yes we have it already
49 int operator()(value_type const & p1,
50 value_type const & p2) {
51 return p1.use_count() < p2.use_count();
56 bool operator()(value_type const & p) const {
63 // Remove all unique items. (i.e. entries that only
64 // exists in the conatainer and does not have a
65 // corresponding paragrah.
66 Params::iterator it = std::remove_if(params.begin(),
69 params.erase(it, params.end());
73 mutable Params params;