PageRenderTime 21ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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