removed gridSize from the template arguments

- not needed and code much cleaner
some minor changes
new test-cases
This commit is contained in:
2016-01-25 15:53:12 +01:00
parent 9947dced15
commit 5aedce47f1
16 changed files with 167 additions and 66 deletions

View File

@@ -14,20 +14,21 @@
#include "../misc/Debug.h"
/**
* grid of the given grid-size, storing some value which
* extends GridPoint and GridNode
* grid of a given-size, storing some user-data-value which
* - extends GridPoint and GridNode
*
* Usage:
* for (Node& n : grid) {...}
* for (Node& n2 : grid.neighbors(n)) {...}
*
*/
template <int gridSize_cm, typename T> class Grid {
template <typename T> class Grid {
static constexpr const char* name = "Grid";
#include "GridNeighborIterator.h"
/** UID for nodes */
typedef uint64_t UID;
private:
@@ -38,10 +39,13 @@ private:
/** UID -> index mapping */
std::unordered_map<UID, int> hashes;
/** the user-given grid-size */
const int gridSize_cm;
public:
/** ctor */
Grid() {
/** ctor with the grid's size (in cm) */
Grid(const int gridSize_cm) : gridSize_cm(gridSize_cm) {
static_assert((sizeof(T::_idx) > 0), "T must inherit from GridNode!");
static_assert((sizeof(T::x_cm) > 0), "T must inherit from GridPoint!");
}
@@ -52,12 +56,15 @@ public:
/** no-assign */
void operator = (const Grid& o) = delete;
/** allows for-each iteration over all included nodes */
decltype(nodes.begin()) begin() {return nodes.begin();}
/** allows for-each iteration over all included nodes */
decltype(nodes.end()) end() {return nodes.end();}
/** get the grid's size */
int getGridSize_cm() const {return gridSize_cm;}
/**
* add the given element to the grid.