1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef __MEDMODULUSARRAY_H__
21 #define __MEDMODULUSARRAY_H__
23 #include "MEDMEM_Utilities.hxx"
26 This class is use to set cyclic (modulus length) array.
27 (array[length+1]==array[1])
29 We use it in particular to compare faces nodes lists to know if
30 they are the same (positive or negative cycle) !
34 class MEDMODULUSARRAY {
40 MEDMODULUSARRAY(int length, const int * array) ;
43 const int & operator[](const int &i) const ;
45 int compare(const MEDMODULUSARRAY &modulusArray) const;
49 MEDMODULUSARRAY::MEDMODULUSARRAY(int length, const int * array) :
50 _length(length), _array(array)
53 // for (int i=0;i<_length;i++){
54 // MESSAGE("MEDMODULUSARRAY["<<i<<"]="<<_array[i]);
58 MEDMODULUSARRAY::~MEDMODULUSARRAY()
60 // do nothing because nothing is allocated !
61 // MESSAGE("MEDMODULUSARRAY::~MEDMODULUSARRAY()") ;
65 const int & MEDMODULUSARRAY::operator[](const int &i) const
67 int position = i%_length ;
70 return _array[position] ;
73 int MEDMODULUSARRAY::compare(const MEDMODULUSARRAY &modulusArray) const
77 if (modulusArray._length != _length)
81 if (_array[0]==modulusArray[0])
87 if ((_array[0]==modulusArray[0])&(_array[1]==modulusArray[1]))
89 else if ((_array[0]==modulusArray[1])&(_array[1]==modulusArray[0]))
94 //search if there is one start point in common in two array
95 for(int i=0;i<_length;i++)
96 if ( _array[0] == modulusArray[i] ) {
97 // we search if cycle is the same
98 if (_array[1]==modulusArray[i+1]){ // positive order
100 for(int j=2;j<_length;j++)
101 if (_array[j]!=modulusArray[i+j]) {
105 } else if(_array[1]==modulusArray[i-1]) { //negative order
107 for(int j=2;j<_length;j++)
108 if (_array[j]!=modulusArray[i-j]) {
113 if (ret!=0) {// we have found it !
116 // else we continue if there is another start point i
122 # endif /* # ifndef __MEDMODULUSARRAY_H__ */