Salome HOME
adding some castem mesh file to test the GIBI driver of Med Memory.
[modules/med.git] / src / MEDMEM / MEDMEM_ModulusArray.hxx
1 #ifndef __MEDMODULUSARRAY_H__
2 #define __MEDMODULUSARRAY_H__
3
4 #include "utilities.h"
5
6 /*
7   This class is use to set cyclic (modulus length) array.
8   (array[length+1]==array[1])
9
10   We use it in particular to compare faces nodes lists to know if
11   they are the same (positive or negative cycle) !
12 */
13
14
15 class MEDMODULUSARRAY {
16 private:
17   int   _length ;
18   const int * _array ;
19
20 public:
21   MEDMODULUSARRAY(int length, const int * array) ;
22   ~MEDMODULUSARRAY() ;
23   
24   const int & operator[](const int &i) const ;
25
26   int compare(const MEDMODULUSARRAY &modulusArray) const;
27
28 };
29
30 MEDMODULUSARRAY::MEDMODULUSARRAY(int length, const int * array) : 
31   _length(length), _array(array)
32 {
33 //    SCRUTE(_length);
34 //    for (int i=0;i<_length;i++){
35 //      MESSAGE("MEDMODULUSARRAY["<<i<<"]="<<_array[i]);
36 //    }
37 };
38
39 MEDMODULUSARRAY::~MEDMODULUSARRAY()
40 {
41   // do nothing because nothing is allocated !
42   //  MESSAGE("MEDMODULUSARRAY::~MEDMODULUSARRAY()") ;
43 };
44
45
46 const int & MEDMODULUSARRAY::operator[](const int &i) const
47 {
48   int position = i%_length ;
49   if (position<0)
50     position+=_length ;
51   return _array[position] ;
52 };
53
54 int MEDMODULUSARRAY::compare(const MEDMODULUSARRAY &modulusArray) const
55 {
56   int ret = 0 ;
57
58   if (modulusArray._length != _length)
59     return ret ;
60
61   if (_length==1)
62     if (_array[0]==modulusArray[0])
63       return 1;
64     else 
65       return 0;
66
67   if (_length==2)
68     if ((_array[0]==modulusArray[0])&(_array[1]==modulusArray[1]))
69       return 1;
70     else if ((_array[0]==modulusArray[1])&(_array[1]==modulusArray[0]))
71       return -1;
72     else
73       return 0;
74
75   //search if there is one start point in common in two array
76   for(int i=0;i<_length;i++)
77     if ( _array[0] == modulusArray[i] ) {
78       // we search if cycle is the same
79       if (_array[1]==modulusArray[i+1]){ // positive order
80         ret=1;
81         for(int j=2;j<_length;j++)
82           if (_array[j]!=modulusArray[i+j]) {
83             ret = 0 ;
84             break ;
85           }
86       } else if(_array[1]==modulusArray[i-1]) { //negative order
87         ret=-1;
88         for(int j=2;j<_length;j++)
89           if (_array[j]!=modulusArray[i-j]) {
90             ret = 0 ;
91             break ;
92           }
93       }
94       if (ret!=0) {// we have found it !
95         break ;
96       }
97       // else we continue if there is another start point i
98     }
99     return ret ;
100 }
101
102 # endif         /* # ifndef __MEDMODULUSARRAY_H__ */
103