Skip to content

Commit bd5d6d5

Browse files
authored
Merge pull request #33 from tomasandrle/master
Make sure stlastar.h works without using namespace std
2 parents bbdcdd0 + ee5a115 commit bd5d6d5

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

cpp/8puzzle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
#include <ctype.h>
1616

17-
using namespace std;
18-
1917
// Configuration
2018

2119
#define NUM_TIMES_TO_RUN_SEARCH 1
@@ -27,6 +25,8 @@ using namespace std;
2725
// AStar search class
2826
#include "stlastar.h" // See header for copyright and usage information
2927

28+
using namespace std;
29+
3030
// Global data
3131

3232
#define BOARD_WIDTH (3)

cpp/findpath.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
#include <stdio.h>
1313
#include <math.h>
1414

15-
using namespace std;
16-
1715
#include "stlastar.h" // See header for copyright and usage information
1816

17+
using namespace std;
18+
1919
#define DEBUG_LISTS 0
2020
#define DEBUG_LIST_LENGTHS_ONLY 0
2121

cpp/min_path_to_Bucharest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
#include <vector>
2424
#include <stdio.h>
2525

26-
using namespace std;
27-
2826
#include "stlastar.h"
2927

28+
using namespace std;
29+
3030
#define DEBUG_LISTS 0
3131
#define DEBUG_LIST_LENGTHS_ONLY 0
3232

cpp/stlastar.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ template <class UserState> class AStarSearch
9696

9797
bool operator==(const Node& otherNode) const
9898
{
99-
return this->m_UserState.IsSameState(otherNode->m_UserState);
99+
return this->m_UserState.IsSameState(otherNode.m_UserState);
100100
}
101101

102102
UserState m_UserState;
@@ -268,7 +268,7 @@ template <class UserState> class AStarSearch
268268
if( !ret )
269269
{
270270

271-
typename vector< Node * >::iterator successor;
271+
typename std::vector< Node * >::iterator successor;
272272

273273
// free the nodes that may previously have been added
274274
for( successor = m_Successors.begin(); successor != m_Successors.end(); successor ++ )
@@ -287,7 +287,7 @@ template <class UserState> class AStarSearch
287287
}
288288

289289
// Now handle each successor to the current node ...
290-
for( typename vector< Node * >::iterator successor = m_Successors.begin(); successor != m_Successors.end(); successor ++ )
290+
for( typename std::vector< Node * >::iterator successor = m_Successors.begin(); successor != m_Successors.end(); successor ++ )
291291
{
292292
// The g value for this successor ...
293293
float newg = n->g + n->m_UserState.GetCost( (*successor)->m_UserState );
@@ -298,7 +298,7 @@ template <class UserState> class AStarSearch
298298

299299
// First linear search of open list to find node
300300

301-
typename vector< Node * >::iterator openlist_result;
301+
typename std::vector< Node * >::iterator openlist_result;
302302

303303
for( openlist_result = m_OpenList.begin(); openlist_result != m_OpenList.end(); openlist_result ++ )
304304
{
@@ -321,7 +321,7 @@ template <class UserState> class AStarSearch
321321
continue;
322322
}
323323
}
324-
typename unordered_set<Node*, NodeHash, NodeEqual>::iterator closedlist_result;
324+
typename std::unordered_set<Node*, NodeHash, NodeEqual>::iterator closedlist_result;
325325

326326
closedlist_result = m_ClosedList.find(*successor);
327327

@@ -664,7 +664,7 @@ template <class UserState> class AStarSearch
664664
void FreeAllNodes()
665665
{
666666
// iterate open list and delete all nodes
667-
typename vector< Node * >::iterator iterOpen = m_OpenList.begin();
667+
typename std::vector< Node * >::iterator iterOpen = m_OpenList.begin();
668668

669669
while( iterOpen != m_OpenList.end() )
670670
{
@@ -677,7 +677,7 @@ template <class UserState> class AStarSearch
677677
m_OpenList.clear();
678678

679679
// iterate closed list and delete unused nodes
680-
typename unordered_set<Node*, NodeHash, NodeEqual>::iterator iterClosed;
680+
typename std::unordered_set<Node*, NodeHash, NodeEqual>::iterator iterClosed;
681681

682682
for( iterClosed = m_ClosedList.begin(); iterClosed != m_ClosedList.end(); iterClosed ++ )
683683
{
@@ -699,7 +699,7 @@ template <class UserState> class AStarSearch
699699
void FreeUnusedNodes()
700700
{
701701
// iterate open list and delete unused nodes
702-
typename vector< Node * >::iterator iterOpen = m_OpenList.begin();
702+
typename std::vector< Node * >::iterator iterOpen = m_OpenList.begin();
703703

704704
while( iterOpen != m_OpenList.end() )
705705
{
@@ -718,7 +718,7 @@ template <class UserState> class AStarSearch
718718
m_OpenList.clear();
719719

720720
// iterate closed list and delete unused nodes
721-
typename unordered_set<Node*, NodeHash, NodeEqual>::iterator iterClosed;
721+
typename std::unordered_set<Node*, NodeHash, NodeEqual>::iterator iterClosed;
722722

723723
for( iterClosed = m_ClosedList.begin(); iterClosed != m_ClosedList.end(); iterClosed ++ )
724724
{
@@ -773,7 +773,7 @@ template <class UserState> class AStarSearch
773773
private: // data
774774

775775
// Heap (simple vector but used as a heap, cf. Steve Rabin's game gems article)
776-
vector< Node *> m_OpenList;
776+
std::vector< Node *> m_OpenList;
777777

778778
// Closed is an unordered_set
779779
struct NodeHash {
@@ -786,12 +786,12 @@ template <class UserState> class AStarSearch
786786
return a->m_UserState.IsSameState(b->m_UserState);
787787
}
788788
};
789-
unordered_set<Node*, NodeHash, NodeEqual> m_ClosedList;
789+
std::unordered_set<Node*, NodeHash, NodeEqual> m_ClosedList;
790790

791791

792792
// Successors is a vector filled out by the user each type successors to a node
793793
// are generated
794-
vector< Node * > m_Successors;
794+
std::vector< Node * > m_Successors;
795795

796796
// State
797797
unsigned int m_State;
@@ -812,8 +812,8 @@ template <class UserState> class AStarSearch
812812

813813
//Debug : need to keep these two iterators around
814814
// for the user Dbg functions
815-
typename vector< Node * >::iterator iterDbgOpen;
816-
typename vector< Node * >::iterator iterDbgClosed;
815+
typename std::vector< Node * >::iterator iterDbgOpen;
816+
typename std::vector< Node * >::iterator iterDbgClosed;
817817

818818
// debugging : count memory allocation and free's
819819
int m_AllocateNodeCount;

cpp/tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#include <stdlib.h>
55
#include <assert.h>
66

7-
using namespace std;
8-
97
#include "stlastar.h"
108

9+
using namespace std;
10+
1111
const int MAP_WIDTH = 20;
1212
const int MAP_HEIGHT = 20;
1313

0 commit comments

Comments
 (0)