Node.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*!
  2. * \file Node.h
  3. * \author The VLE Development Team
  4. * See the AUTHORS or Authors.txt file
  5. * \version 2.0
  6. * \date 3 juin 2013
  7. */
  8. /*
  9. * Copyright (C) 2012-2013 ULCO http://www.univ-littoral.fr
  10. * Copyright (C) 2012-2013 INRA http://www.inra.fr
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. #ifndef NODE_H_
  26. #define NODE_H_
  27. #include "Coordinates.h"
  28. #include <list>
  29. class Node
  30. {
  31. protected :
  32. Coordinates _coord;
  33. Node * _father;
  34. Node * _child;
  35. Node * _brother;
  36. public :
  37. Node(): _coord()
  38. {
  39. _father = NULL;
  40. _child = NULL;
  41. _brother = NULL;
  42. }
  43. Node(const Node & n)
  44. {
  45. _coord = n.getCoord();
  46. _father = n.getFather();
  47. _child = n.getChild();
  48. _brother = n.getBrother();
  49. }
  50. Node(const Coordinates & c, Node * father) :_coord(c)
  51. {
  52. _father = father;
  53. _child = NULL;
  54. _brother = NULL;
  55. }
  56. virtual ~Node(){}
  57. void setPere(Node * pere)
  58. {
  59. _father = pere;
  60. }
  61. void setCoord(const Coordinates& coord)
  62. {
  63. _coord = coord;
  64. }
  65. const Coordinates& getCoord() const
  66. {
  67. return _coord;
  68. }
  69. Node * getChild() const
  70. {
  71. return _child;
  72. }
  73. Node * getBrother() const
  74. {
  75. return _brother;
  76. }
  77. Node * getFather() const
  78. {
  79. return _father;
  80. }
  81. void setChild(Node * child)
  82. {
  83. _child = child;
  84. }
  85. void setBrother(Node * brother)
  86. {
  87. _brother = brother;
  88. }
  89. const std::string toString() const
  90. {
  91. std::stringstream ss;
  92. ss <<"coordonnes du noeud : "<<_coord.toString()<<"\n";
  93. if(_child !=NULL)
  94. ss<<"coordonnes du fils : "<<_child->getCoord().toString()<<"\n";
  95. if(_brother !=NULL)
  96. ss<<"coordonnes du frere : "<<_brother->getCoord().toString()<<"\n";
  97. return ss.str();
  98. }
  99. char getNeighbourId(const Node * n) const
  100. {
  101. char c ='X';
  102. short diffi = _coord.getLine() - n->getCoord().getLine() ;
  103. short diffj = _coord.getColumn() - n->getCoord().getColumn();
  104. if (diffi == 1 && diffj == 0)
  105. c ='1';
  106. else if (diffi == 1 && diffj == -1)
  107. c = '2' ;
  108. else if(diffi == 0 && diffj == -1)
  109. c = '3' ;
  110. else if (diffi == -1 && diffj == -1)
  111. c = '4' ;
  112. else if (diffi == -1 && diffj == 0)
  113. c = '5' ;
  114. else if (diffi == -1 && diffj == 1)
  115. c = '6' ;
  116. else if (diffi == 0 && diffj == 1)
  117. c = '7' ;
  118. else if (diffi == 1 && diffj == 1)
  119. c = '8' ;
  120. return c;
  121. }
  122. };
  123. #endif /* NODE_H_ */