Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/med.git] / src / MEDMEM / MEDMEM_ArrayInterface.hxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef MEDMEM_ARRAYINTERFACE_HXX
24 #define MEDMEM_ARRAYINTERFACE_HXX
25
26 #include "MEDMEM_nArray.hxx"
27 #include "MEDMEM_InterlacingTraits.hxx"
28
29 // L'astuce d'une classe d'interface consiste en 
30 // 1) La déclaration d'un type qui est celui de la classe d'implémentation
31 // 2) D'utiliser ce nouveau nom de type comme paramètres de toutes
32 //     les méthodes de l'interface.
33 // L'inconvenient est qu'il faut justement passer en argument une instance de
34 // le classe d'implémentation dans toutes les méthodes et que la classe
35 // appelante aura aussi à faire ce travail.
36 //  Ne surtout pas oublier inline sinon l'interface couterait cher à l'appel
37 //  des méthodes !
38 namespace MEDMEM {
39
40 template < class ARRAY_ELEMENT_TYPE,
41            class INTERLACE_TAG,
42            class GAUSS_TAG,
43            class CHECKING_POLICY=IndexCheckPolicy>
44            //NoIndexCheckPolicy>
45 class MEDMEM_EXPORT MEDMEM_ArrayInterface  {
46
47 public:
48
49   // Les type ElementType et Array sont a définir aussi dans les classes utilisatrice
50   // par une déclaration du type : typedef typename ArrayInterface::Array Array;
51
52   typedef  ARRAY_ELEMENT_TYPE  ElementType;
53   typedef  INTERLACE_TAG       Interlacing;
54   typedef  GAUSS_TAG           GaussPresence;
55   typedef  typename MEDMEM_InterlacingTraits<Interlacing,GaussPresence>::Type InterlacingPolicy;
56   typedef  CHECKING_POLICY     CheckingPolicy;
57   typedef  MEDMEM_Array<ElementType,InterlacingPolicy,CheckingPolicy> Array;
58
59   static inline int getNbGauss(int i, const Array & array)  {
60     return array.getNbGauss(i);
61   };
62
63   static inline ElementType * getPtr( Array & array)  {
64     return array.getPtr();
65   };
66
67   static inline void setPtr( ElementType * arrayptr,  Array & array, 
68                              bool shallowCopy=false,
69                              bool ownershipOfValues=false )  {
70     array.setPtr(arrayptr,shallowCopy,ownershipOfValues);
71   };
72
73   static inline const ElementType * getRow(int i, const Array & array ) {
74     return array.getRow(i);
75   }
76
77   static inline void setRow(int i, const ElementType & value, const Array & array ) {
78     return array.setRow(i,value);
79   }
80
81   static inline const ElementType * getColumn(int j, const Array & array ) {
82     return array.getColumn(j);
83   }
84
85   static inline void setColumn(int j, const ElementType & value, const Array & array ) {
86     return array.setColumn(j,value);
87   }
88
89   static inline const ElementType & getIJ(int i, int j, const Array & array) {
90     return array.getIJ(i,j);
91   }
92
93   static inline const ElementType & getIJK(int i, int j, int k, const Array & array) {
94     return array.getIJK(i,j,k);
95   }
96
97   static inline void setIJ(int i, int j, const ElementType & value, Array & array) {
98     array.setIJ(i,j,value);
99   }
100
101   static inline void setIJK(int i, int j, int k, const ElementType & value, Array & array) {
102     array.setIJK(i,j,k,value);
103   }
104
105 };
106
107 } //END NAMESPACE
108 #endif