Skip to content

Commit d4e78f1

Browse files
committed
Added template interface to better define expected functions of UserState
- Created a template interface AStarState which defines all the necessary functions that AStarSearch will require of the UserState. This serves as a quick reference and can also ensure a properly implemented class is provided to AStarSearch (enforcable only with C++11 features).
1 parent 4f7013f commit d4e78f1

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎stlastar.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,16 @@ using namespace std;
4949
// occurs in stl headers
5050
#pragma warning( disable : 4786 )
5151

52+
template <class T> class AStarState;
53+
5254
// The AStar search class. UserState is the users state space type
5355
template <class UserState> class AStarSearch
5456
{
5557

58+
#if (defined(__cplusplus) && __cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1600)
59+
static_assert(is_base_of<AStarState<UserState>, UserState>::value, "UserState must be derived from AStarState!");
60+
#endif
61+
5662
public: // data
5763

5864
enum
@@ -778,6 +784,17 @@ template <class UserState> class AStarSearch
778784

779785
};
780786

787+
template <class T> class AStarState
788+
{
789+
public:
790+
virtual ~AStarState() {}
791+
virtual float GoalDistanceEstimate( T &nodeGoal ) = 0; // Heuristic function which computes the estimated cost to the goal node
792+
virtual bool IsGoal( T &nodeGoal ) = 0; // Returns true if this node is the goal node
793+
virtual bool GetSuccessors( AStarSearch<T> *astarsearch, T *parent_node ) = 0; // Retrieves all successors to this node and adds them via astarsearch.addSuccessor()
794+
virtual float GetCost( T &successor ) = 0; // Computes the cost of travelling from this node to the successor node
795+
virtual bool IsSameState( T &rhs ) = 0; // Returns true if this node is the same as the rhs node
796+
};
797+
781798
#endif
782799

783800

0 commit comments

Comments
 (0)