Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/med.git] / src / MedClient / src / UtilClient.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 UTILCLIENT_HXX_
24 #define UTILCLIENT_HXX_
25
26 #include <vector>
27 #include <utilities.h>
28 #include "MEDMEM_PointerOf.hxx"
29
30 namespace MEDMEM {
31 template <typename TLocal, 
32           typename TCorbaSeq,
33           typename Tint>
34 inline void convertCorbaArray (TLocal * & T, Tint &nT, const TCorbaSeq & S)
35 {
36   Tint i, n = S->length();
37
38   nT = n;
39   T = n > 0 ? new TLocal[n] : NULL;
40
41   for (i=0; i<n; i++) {
42     T[i] = (*S)[i];
43   }
44 }
45
46 template <typename TLocal, 
47           typename TCorbaSeq,
48           typename Tint>
49 inline void convertCorbaArray2 (TLocal& tab, Tint &nT, const TCorbaSeq s)
50 {
51   Tint i, n = s.length();
52
53   nT = n;
54   tab.set(n);
55   for (i=0; i<n; i++) {
56     tab[i] = s[i];
57   }
58 }
59
60 template <typename TCorba,
61           typename TLocal,
62           typename TCorbaSeq>
63 inline void convertCorbaArray (TLocal * & T, long &nT, const TCorbaSeq & S,
64                                void *f)
65 {
66   int i, n = S->length();
67   SCRUTE(n);
68
69   nT = n;
70   T = n > 0 ? new TLocal[n] : NULL;
71
72   typedef TLocal (*pfn) (const TCorba &T);
73
74   pfn convert = pfn(f);
75   for (i=0; i<n; i++) {
76     SCRUTE((*S)[i]);
77     T[i] = convert((*S)[i]);
78     SCRUTE(T[i]);
79   }
80 }
81
82 template <typename TLocal,
83           typename TCorbaSeq>
84 inline void convertCorbaArray (std::vector<TLocal> & T, int &nT, 
85                                const TCorbaSeq & S)
86 {
87   int i, n = S->length();
88   SCRUTE(n);
89
90   nT = n;
91   T.resize(nT);
92
93   for (i=0; i<nT; i++) {
94     SCRUTE((*S)[i]);
95     T[i] = convert((*S)[i]);
96     SCRUTE(T[i]);
97   }
98 }
99
100
101 template <typename TCorba,
102           typename TLocal,
103           typename TCorbaSeq>
104 inline void convertCorbaArray (std::vector<TLocal> & T, int &nT, 
105                                const TCorbaSeq & S,
106                                void *f)
107 {
108   int i, n = S->length();
109   SCRUTE(n);
110
111   nT = n;
112   T.resize(nT);
113
114   typedef TLocal (*pfn) (const TCorba &T);
115
116   pfn convert = pfn(f);
117   for (i=0; i<nT; i++) {
118     SCRUTE((*S)[i]);
119     T[i] = convert((*S)[i]);
120     SCRUTE(T[i]);
121   }
122  
123 }
124
125
126 template <typename TCorba,
127           typename TLocal,
128           typename TCorbaSeq,
129           typename TInfo>
130 inline void convertCorbaArray (std::vector<TLocal> & T, 
131                                const TCorbaSeq & S,
132                                void *f, TInfo M)
133 {
134   int i, n = S->length();
135   SCRUTE(n);
136
137   int nT = n;
138   T.resize(nT);
139
140   typedef TLocal (*pfn) (const TCorba & , TInfo);
141
142   pfn convert = pfn(f);
143   for (i=0; i<nT; i++) {
144     SCRUTE((*S)[i]);
145     T[i] = convert((*S)[i], M);
146     SCRUTE(T[i]);
147   }
148  
149 }
150 }
151
152 #endif