109 lines
2.5 KiB
C++
Executable File
109 lines
2.5 KiB
C++
Executable File
/*
|
||
* © Copyright 2014 – Urheberrechtshinweis
|
||
* Alle Rechte vorbehalten / All Rights Reserved
|
||
*
|
||
* Programmcode ist urheberrechtlich geschuetzt.
|
||
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
|
||
* Keine Verwendung ohne explizite Genehmigung.
|
||
* (vgl. § 106 ff UrhG / § 97 UrhG)
|
||
*/
|
||
|
||
#ifndef GRIDNODE_H
|
||
#define GRIDNODE_H
|
||
|
||
#include "GridNodeBBox.h"
|
||
#include "GridPoint.h"
|
||
|
||
#include <functional>
|
||
|
||
/** forward decl. */
|
||
template<typename> class Grid;
|
||
|
||
|
||
/**
|
||
* INTERNAL DATASTRUCTURE
|
||
* this data-structure is internally used by the Grid
|
||
* to store additional information for each node besides
|
||
* the user's requested data-structure
|
||
*/
|
||
struct GridNode {
|
||
|
||
private:
|
||
|
||
static int constexpr MAX_NEIGHBORS = 10;
|
||
|
||
private:
|
||
|
||
/** grant full access to the grid */
|
||
template<typename> friend class Grid;
|
||
|
||
/** INTERNAL: node's index array-index */
|
||
int _idx;
|
||
|
||
/** INTERNAL: store neighbors (via index) */
|
||
int _neighbors[MAX_NEIGHBORS];
|
||
|
||
/** INTERNAL: number of neighbors */
|
||
uint8_t _numNeighbors;
|
||
|
||
/** semantic annotation for this node */
|
||
uint8_t _type;
|
||
|
||
|
||
|
||
static std::vector<std::function<void(std::ostream&)>> serializers;
|
||
static std::vector<std::function<void(std::istream&)>> deserializers;
|
||
|
||
|
||
public:
|
||
|
||
static const uint8_t TYPE_FLOOR = 0;
|
||
static const uint8_t TYPE_STAIR = 1;
|
||
static const uint8_t TYPE_ELEVATOR = 2;
|
||
static const uint8_t TYPE_DOOR = 3;
|
||
|
||
static const uint8_t TYPE_OUTDOOR = 100;
|
||
|
||
|
||
public:
|
||
|
||
/** ctor */
|
||
GridNode() : _idx(-1), _neighbors(), _numNeighbors(0), _type(0) {;}
|
||
|
||
|
||
/** get the node's index within its grid */
|
||
int getIdx() const {return _idx;}
|
||
|
||
/** get the x-th neighbor's index within its grid */
|
||
int getNeighborIdx(const int x) const {return _neighbors[x];}
|
||
|
||
/** get the number of neighbors for this node */
|
||
int getNumNeighbors() const {return _numNeighbors;}
|
||
|
||
/** reached neighbor limit? */
|
||
bool fullyConnected() const {return _numNeighbors >= MAX_NEIGHBORS;}
|
||
|
||
/** is this node connected to the given index? */
|
||
bool hasNeighbor(const int idx) const {
|
||
for (int i = 0; i < _numNeighbors; ++i) {
|
||
if (_neighbors[i] == idx) {return true;}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
/** get the node's semantic type */
|
||
uint8_t getType() const {return _type;}
|
||
|
||
/** set the node's semantic type */
|
||
void setType(const uint8_t type) {this->_type = type;}
|
||
|
||
|
||
// /** get the n-th neighbor for this node */
|
||
// template <int gridSize_cm, typename T> inline T& getNeighbor(const int nth, const Grid<gridSize_cm, T>& grid) const {
|
||
// return grid.getNeighbor(_idx, nth);
|
||
// }
|
||
|
||
};
|
||
|
||
#endif // GRIDNODE_H
|