/test/language/unclassified/aux_jlp8_matrix.e

http://github.com/tybor/Liberty · Specman e · 126 lines · 87 code · 17 blank · 22 comment · 1 complexity · eb1f7295b3aba4c6544d94a25a0f6afc MD5 · raw file

  1. -- This file is part of SmartEiffel The GNU Eiffel Compiler Tools and Libraries.
  2. -- See the Copyright notice at the end of this file.
  3. --
  4. deferred class AUX_JLP8_MATRIX[E -> NUMERIC]
  5. inherit
  6. AUX_JLP8_EPEE_ARRAY[E]
  7. rename item as array_item,
  8. put as array_put,
  9. make as array_make
  10. end
  11. feature {ANY}
  12. make (nb_r, nb_c: INTEGER)
  13. do
  14. array_make(nb_c * nb_r)
  15. end
  16. make_unit (nb_r, nb_c: INTEGER)
  17. local
  18. index: INTEGER; value: E; max_index: INTEGER
  19. do
  20. make(nb_r, nb_c)
  21. if nb_row > nb_column then
  22. max_index := nb_column
  23. else
  24. max_index := nb_row
  25. end
  26. from
  27. index := 0
  28. until
  29. index = max_index
  30. loop
  31. put(value.one, index, index)
  32. index := index + 1
  33. end
  34. end
  35. item (l, c: INTEGER): E
  36. do
  37. Result := array_item(translate_indexes(l, c))
  38. end
  39. put (v: E; l, c: INTEGER)
  40. do
  41. array_put(v, translate_indexes(l, c))
  42. end
  43. row (l: INTEGER): AUX_JLP8_ROW_PROVIDER[E]
  44. do
  45. create Result.make(Current, l)
  46. end
  47. rows: AUX_JLP8_PROVIDER[AUX_JLP8_PROVIDER[E]]
  48. -- MATRIX_ROWS[E]
  49. local
  50. p: AUX_JLP8_MATRIX_ROWS[E]
  51. do
  52. create p
  53. p.make(Current)
  54. Result := p
  55. end
  56. set_row (l: INTEGER; p: AUX_JLP8_PROVIDER[E])
  57. local
  58. index: INTEGER
  59. do
  60. from
  61. p.start
  62. index := 0
  63. until
  64. p.exhausted or index >= nb_column
  65. loop
  66. put(p.item, l, index)
  67. p.next
  68. index := index + incr_column
  69. end
  70. end
  71. feature {ANY}
  72. nb_row: INTEGER
  73. valid_row (r: INTEGER): BOOLEAN
  74. do
  75. Result := r < nb_row
  76. end
  77. valid_column (c: INTEGER): BOOLEAN
  78. do
  79. Result := c < nb_column
  80. end
  81. valid_indexes (l, c: INTEGER): BOOLEAN
  82. do
  83. Result := valid_row(l) and valid_column(c)
  84. end
  85. nb_column: INTEGER
  86. incr_row: INTEGER
  87. incr_column: INTEGER
  88. translate_indexes (l, c: INTEGER): INTEGER
  89. deferred
  90. end
  91. end -- class AUX_JLP8_MATRIX
  92. --
  93. -- ------------------------------------------------------------------------------------------------------------------------------
  94. -- Copyright notice below. Please read.
  95. --
  96. -- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
  97. -- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
  98. -- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
  99. -- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
  100. -- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
  101. -- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  102. --
  103. -- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE
  104. -- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
  105. --
  106. -- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
  107. --
  108. -- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
  109. -- ------------------------------------------------------------------------------------------------------------------------------