Salome HOME
removing this useless file.
[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 namespace MEDMEM {
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 using namespace MEDMEM;
31
32 MEDMODULUSARRAY::MEDMODULUSARRAY(int length, const int * array) : 
33   _length(length), _array(array)
34 {
35 //    SCRUTE(_length);
36 //    for (int i=0;i<_length;i++){
37 //      MESSAGE("MEDMODULUSARRAY["<<i<<"]="<<_array[i]);
38 //    }
39 };
40
41 MEDMODULUSARRAY::~MEDMODULUSARRAY()
42 {
43   // do nothing because nothing is allocated !
44   //  MESSAGE("MEDMODULUSARRAY::~MEDMODULUSARRAY()") ;
45 };
46
47
48 const int & MEDMODULUSARRAY::operator[](const int &i) const
49 {
50   int position = i%_length ;
51   if (position<0)
52     position+=_length ;
53   return _array[position] ;
54 };
55
56 int MEDMODULUSARRAY::compare(const MEDMODULUSARRAY &modulusArray) const
57 {
58   int ret = 0 ;
59
60   if (modulusArray._length != _length)
61     return ret ;
62
63   if (_length==1)
64     if (_array[0]==modulusArray[0])
65       return 1;
66     else 
67       return 0;
68
69   if (_length==2)
70     if ((_array[0]==modulusArray[0])&(_array[1]==modulusArray[1]))
71       return 1;
72     else if ((_array[0]==modulusArray[1])&(_array[1]==modulusArray[0]))
73       return -1;
74     else
75       return 0;
76
77   //search if there is one start point in common in two array
78   for(int i=0;i<_length;i++)
79     if ( _array[0] == modulusArray[i] ) {
80       // we search if cycle is the same
81       if (_array[1]==modulusArray[i+1]){ // positive order
82         ret=1;
83         for(int j=2;j<_length;j++)
84           if (_array[j]!=modulusArray[i+j]) {
85             ret = 0 ;
86             break ;
87           }
88       } else if(_array[1]==modulusArray[i-1]) { //negative order
89         ret=-1;
90         for(int j=2;j<_length;j++)
91           if (_array[j]!=modulusArray[i-j]) {
92             ret = 0 ;
93             break ;
94           }
95       }
96       if (ret!=0) {// we have found it !
97         break ;
98       }
99       // else we continue if there is another start point i
100     }
101     return ret ;
102 }
103
104 # endif         /* # ifndef __MEDMODULUSARRAY_H__ */
105