]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_ModulusArray.hxx
Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/med.git] / src / MEDMEM / MEDMEM_ModulusArray.hxx
1 //  MED MEDMEM : MED files in memory
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : MEDMEM_ModulusArray.hxx
25 //  Module : MED
26
27 #ifndef __MEDMODULUSARRAY_H__
28 #define __MEDMODULUSARRAY_H__
29
30 #include "utilities.h"
31
32 /*
33   This class is use to set cyclic (modulus length) array.
34   (array[length+1]==array[1])
35
36   We use it in particular to compare faces nodes lists to know if
37   they are the same (positive or negative cycle) !
38 */
39
40
41 class MEDMODULUSARRAY {
42 private:
43   int   _length ;
44   const int * _array ;
45
46 public:
47   MEDMODULUSARRAY(int length, const int * array) ;
48   ~MEDMODULUSARRAY() ;
49   
50   const int & operator[](const int &i) const ;
51
52   int compare(const MEDMODULUSARRAY &modulusArray) const;
53
54 };
55
56 MEDMODULUSARRAY::MEDMODULUSARRAY(int length, const int * array) : 
57   _length(length), _array(array)
58 {
59 //    SCRUTE(_length);
60 //    for (int i=0;i<_length;i++){
61 //      MESSAGE("MEDMODULUSARRAY["<<i<<"]="<<_array[i]);
62 //    }
63 };
64
65 MEDMODULUSARRAY::~MEDMODULUSARRAY()
66 {
67   // do nothing because nothing is allocated !
68   //  MESSAGE("MEDMODULUSARRAY::~MEDMODULUSARRAY()") ;
69 };
70
71
72 const int & MEDMODULUSARRAY::operator[](const int &i) const
73 {
74   int position = i%_length ;
75   if (position<0)
76     position+=_length ;
77   return _array[position] ;
78 };
79
80 int MEDMODULUSARRAY::compare(const MEDMODULUSARRAY &modulusArray) const
81 {
82   int ret = 0 ;
83
84   if (modulusArray._length != _length)
85     return ret ;
86
87   if (_length==1)
88     if (_array[0]==modulusArray[0])
89       return 1;
90     else 
91       return 0;
92
93   if (_length==2)
94     if ((_array[0]==modulusArray[0])&(_array[1]==modulusArray[1]))
95       return 1;
96     else if ((_array[0]==modulusArray[1])&(_array[1]==modulusArray[0]))
97       return -1;
98     else
99       return 0;
100
101   //search if there is one start point in common in two array
102   for(int i=0;i<_length;i++)
103     if ( _array[0] == modulusArray[i] ) {
104       // we search if cycle is the same
105       if (_array[1]==modulusArray[i+1]){ // positive order
106         ret=1;
107         for(int j=2;j<_length;j++)
108           if (_array[j]!=modulusArray[i+j]) {
109             ret = 0 ;
110             break ;
111           }
112       } else if(_array[1]==modulusArray[i-1]) { //negative order
113         ret=-1;
114         for(int j=2;j<_length;j++)
115           if (_array[j]!=modulusArray[i-j]) {
116             ret = 0 ;
117             break ;
118           }
119       }
120       if (ret!=0) {// we have found it !
121         break ;
122       }
123       // else we continue if there is another start point i
124     }
125     return ret ;
126 }
127
128 # endif         /* # ifndef __MEDMODULUSARRAY_H__ */
129