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;
19 get(Share const & ps) const {
20 // First see if we already have this ps in the container
21 Params::iterator it = params.begin();
22 Params::iterator end = params.end();
23 for (; it != end; ++it) {
24 if (ps == *(*it).get())
27 Params::value_type tmp;
29 // ok we don't have it so we should
31 tmp.reset(new Share(ps));
32 params.push_back(tmp);
33 // We clean here. This can cause us to have
34 // some (one) unique elemements some times
35 // but we should gain a lot in speed.
37 std::sort(params.rbegin(), params.rend(), comp());
39 // yes we have it already
47 int operator()(Params::value_type const & p1,
48 Params::value_type const & p2) {
49 return p1.use_count() < p2.use_count();
54 bool operator()(Params::value_type const & p) const {
61 // Remove all unique items. (i.e. entries that only
62 // exists in the conatainer and does not have a
63 // corresponding paragrah.
64 Params::iterator it = std::remove_if(params.begin(),
67 params.erase(it, params.end());
71 mutable Params params;