
Jeremiah Willcock escribió:
On Mon, 12 Apr 2010, Emili Hernàndez wrote:
Jeremiah Willcock escribió:
On Fri, 9 Apr 2010, Emili Hernàndez wrote:
Hi all,
I've used mutable_queue with basic types (double and int) with no problem. Now I trying to do it with my own type:
typedef MyObject entry_t; typedef vector<entry_t> storage_t; typedef MySortingCriterion comp_t; typedef boost::identity_property_map prop_map_t; typedef boost::mutable_queue<entry_t, storage_t, comp_t, prop_map_t> queue_t;
identity_property_map is only for unsigned ints (it's that way for historical reasons). Use typed_identity_property_map<entry_t> as prop_map_t and see if that fixes your problem.
-- Jeremiah Willcock
Hi, I've tried what you suggested and another error apperars:
Could you please post the relevant part of the new code? It appears that the storage indexing is messed up in the property map, and it could be that you need a different index map (if you're using boost::shared_ptr<CAStarNode> as the index type in the property map).
it seams that the operator[] has to be defined but I don't understand why is it required if it is already specified to use a vector<entry_t> as storage type
Any suggestion? Is there a full example on how to use mutable_queue with non-basic types??
I doubt it -- mutable_queue is mostly used internally. If we end up working one out together I can put it in, though.
-- Jeremiah Willcock
Here's the code for the class I want to used the mutable_queue: class CAStarNode; #include <boost/shared_ptr.hpp> typedef boost::shared_ptr<CAStarNode> CAStarNodePtr; class CAStarNode { public: CAStarNode(const CVector2& point, const long int& g, const long int& h):point_(point),g_(g),h_(h),f_(g + h) {parent_.reset();}; CAStarNode(const CVector2& point, const long int& g, const long int& h, CAStarNodePtr parent) :point_(point),g_(g),h_(h),f_(g + h), parent_(parent){}; CAStarNode(const CAStarNode& n):point_(n.point_),g_(n.g_),h_(n.h_),f_(n.g_ + n.h_),parent_(n.parent_){}; void operator=(const CAStarNode& n) { // copy suff } bool operator<(const CAStarNode& n) const {return (f_ < n.f_);} bool operator>(const CAStarNode& n) const {return (f_ > n.f_);} CVector2 getPoint() const {return point_;}; long int getF() const {return f_;}; long int getH() const {return h_;}; long int getG() const {return g_;}; void setG(const long int g) { g_ = g; f_ = g_ + h_; }; CAStarNodePtr getParent() const {return parent_;}; void setParent(CAStarNodePtr parent) {parent_ = parent;}; private: CVector2 point_; long int g_, h_, f_; CAStarNodePtr parent_; // Backpointer }; // a criterion to sort a priority_queue /mutable_queue namespace astarnode { struct SGreater : std::binary_function<CAStarNodePtr&, CAStarNodePtr&, bool> { bool operator()(const CAStarNodePtr& n1, const CAStarNodePtr& n2) const { return (*n1 > *n2); } }; } typedef CAStarNodePtr entry_t; typedef vector<entry_t> storage_t; typedef astarnode::SGreater comp_t; typedef boost::typed_identity_property_map<entry_t> prop_map_t; typedef boost::mutable_queue<entry_t, storage_t, comp_t, prop_map_t> queue_t; Then in the cpp file: queue_t open(100, comp_t(), prop_map_t()); CAStarNodePtr currNode; currNode.reset(new CAStarNode(start_, 0, value)); open.push(currNode); Basically, I use the mutable_queue to keep sorted a vector of pointers of CAStarNode's. The project only fails to build when using the mutable_queue methods, not the definition itself. Thank you, Emili
------------------------------------------------------------------------
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost