so here is the error I'm getting:
Expand|Select|Wrap|Line Numbers
- TwoDMap.cpp: In member function 'void TwoDMap::setArc(const Line&, uint32_t)':
- TwoDMap.cpp:17: error: passing 'const NodeInfo' as 'this' argument of 'void NodeInfo::modifyArc(const Point&, uint32_t)' discards qualifiers
- TwoDMap.cpp: In member function 'uint32_t TwoDMap::getArcCost(const Line&) const':
- TwoDMap.cpp:35: error: passing 'const NodeInfo' as 'this' argument of 'Internal::hashtable_iterator<std::pair<const Point, unsigned int>, false, false> NodeInfo::getArc(const Point&)' discards qualifiers
Expand|Select|Wrap|Line Numbers
- #include "TwoDMap.h"
- TwoDMap::TwoDMap()
- {
- }
- void TwoDMap::addNode(const NodeInfo& newinfo)
- {
- nodes.insert(newinfo);
- }
- void TwoDMap::setArc(const Line& arc, const uint32_t newcost)
- {
- NodeInfo keynode(arc.from);
- NodeContainer::iterator origin(nodes.find(keynode));
- // if origin = nodes.end() throw an error
- origin->modifyArc(arc.to, newcost);
- }
- //return a pointer to a constant?
- const NodeInfo& TwoDMap::getNodeInfo(const Point& node)const
- {
- NodeInfo keynode(node);
- NodeContainer::iterator origin(nodes.find(keynode));
- return *origin;
- }
- //return a pinter to a constant?
- uint32_t TwoDMap::getArcCost(const Line& arc)const
- {
- NodeInfo keynode(arc.from);
- NodeContainer::iterator origin(nodes.find(keynode));
- // if origin = nodes.end() throw an error
- ArcContainer::iterator destination(origin->getArc(arc.to));
- return destination->second;
- }
Expand|Select|Wrap|Line Numbers
- #include "NodeInfo.h"
- NodeInfo::NodeInfo()
- {
- backpointer.x=0;
- backpointer.y=0;
- name.x=0;
- name.y=0;
- hvalue = 4294967295U;
- tag = NEW;
- }
- NodeInfo::NodeInfo(const Point& newname)
- {
- name = newname;
- backpointer.x=0;
- backpointer.y=0;
- hvalue = 4294967295U;
- tag = NEW;
- }
- void NodeInfo::setBP(const Point& newbp)
- {
- backpointer = newbp;
- }
- void NodeInfo::setHV(const uint32_t nhv)
- {
- hvalue = nhv;
- }
- Point NodeInfo::getBP(void) const
- {
- return backpointer;
- }
- state NodeInfo::getState(void) const
- {
- return tag;
- }
- uint32_t NodeInfo::getHV(void) const
- {
- return hvalue;
- }
- Point NodeInfo::getName(void) const
- {
- return name;
- }
- void NodeInfo::open(void)
- {
- tag = OPEN;
- }
- void NodeInfo::close(void)
- {
- tag = CLOSSED;
- }
- void NodeInfo::openwith(const Point& newbp)
- {
- tag = OPEN;
- backpointer = newbp;
- }
- void NodeInfo::closewith(const Point& newbp)
- {
- tag = CLOSSED;
- backpointer = newbp;
- }
- void NodeInfo::modifyArc(const Point& toarc, const uint32_t arcCost)
- {
- arcs[toarc]=arcCost;
- }
- ArcContainer::iterator NodeInfo::getArc(const Point& toarc)
- {
- return arcs.find(toarc);
- }
- ArcContainer::iterator NodeInfo::inspectB()
- {
- return arcs.begin();
- }
- ArcContainer::iterator NodeInfo::inspectE()
- {
- return arcs.end();
- }
- bool NodeInfo::isopen()
- {
- return (tag == OPEN);
- }
- bool NodeInfo::isclosed()
- {
- return (tag == CLOSSED);
- }
- bool NodeInfo::isnew()
- {
- return (tag == NEW);
- }
- //end of NodeInfo but to define the structs
- bool NodeInfoEq::operator()(const NodeInfo& lhs, const NodeInfo& rhs) const
- {
- return (lhs.getName() == rhs.getName());
- }
- bool operator>(const NodeInfo& lhs, const NodeInfo& rhs)
- {
- return (lhs.hvalue > rhs.hvalue);
- }
- bool operator<(const NodeInfo& lhs, const NodeInfo& rhs)
- {
- return (lhs.hvalue < rhs.hvalue);
- }
Expand|Select|Wrap|Line Numbers
- struct NodeInfoHash
- {
- size_t operator()(NodeInfo key) const
- {
- std::tr1::hash<Point> phash;
- return (phash(key.getName()) );
- }
- };
- struct NodeInfoEq
- {
- bool operator()(const NodeInfo&, const NodeInfo&) const;
- };
Expand|Select|Wrap|Line Numbers
- typedef std::tr1::unordered_set<NodeInfo, NodeInfoHash, NodeInfoEq> NodeContainer;
Expand|Select|Wrap|Line Numbers
- #ifndef _MAPTYPES_H_
- #define _MAPTYPES_H_
- #include <stdint.h>
- #include <tr1/functional>
- #include <tr1/unordered_map>
- struct Point
- {
- int x;
- int y;
- Point(int nx=0, int ny=0): x(nx), y(ny){}
- Point(const Point& np): x(np.x), y(np.y){}
- friend int operator==(const Point& left, const Point& right)
- {return left.x==right.x && left.y==right.y;}
- };
- struct Line
- {
- Point from;
- Point to;
- };
- namespace std {
- namespace tr1 {
- template <>
- struct hash<Point>
- {
- std::size_t operator()(const Point& p) const
- {
- hash<int> mkhash;
- return ( mkhash(p.x) + mkhash(p.y) );
- }
- };
- template <>
- struct hash<Line>
- {
- std::size_t operator()(const Line& l) const
- {
- hash<int> mkhash;
- return ( mkhash(l.to.x) + mkhash(l.to.y) + mkhash(l.from.x) + mkhash(l.from.y) );
- }
- };
- }}//std and tr1
- typedef std::tr1::unordered_map<Point, uint32_t> ArcContainer;
- #endif