src/MedClient/src/UtilClient.hxx

Go to the documentation of this file.
00001 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00002 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00003 // 
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either 
00007 // version 2.1 of the License.
00008 // 
00009 // This library is distributed in the hope that it will be useful 
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00012 // Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public  
00015 // License along with this library; if not, write to the Free Software 
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00017 //
00018 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00019 //
00020 #ifndef UTILCLIENT_HXX_
00021 #define UTILCLIENT_HXX_
00022 
00023 #include <vector>
00024 #include <utilities.h>
00025 #include "MEDMEM_PointerOf.hxx"
00026 
00027 namespace MEDMEM {
00028 template <typename TLocal, 
00029        typename TCorbaSeq,
00030        typename Tint>
00031 inline void convertCorbaArray (TLocal * & T, Tint &nT, const TCorbaSeq & S)
00032 {
00033   Tint i, n = S->length();
00034 
00035   nT = n;
00036   T = n > 0 ? new TLocal[n] : NULL;
00037 
00038   for (i=0; i<n; i++) {
00039     T[i] = (*S)[i];
00040   }
00041 }
00042 
00043 template <typename TLocal, 
00044        typename TCorbaSeq,
00045        typename Tint>
00046 inline void convertCorbaArray2 (TLocal& tab, Tint &nT, const TCorbaSeq s)
00047 {
00048   Tint i, n = s.length();
00049 
00050   nT = n;
00051   tab.set(n);
00052   for (i=0; i<n; i++) {
00053     tab[i] = s[i];
00054   }
00055 }
00056 
00057 template <typename TCorba,
00058        typename TLocal,
00059        typename TCorbaSeq>
00060 inline void convertCorbaArray (TLocal * & T, long &nT, const TCorbaSeq & S,
00061                       void *f)
00062 {
00063   int i, n = S->length();
00064   SCRUTE(n);
00065 
00066   nT = n;
00067   T = n > 0 ? new TLocal[n] : NULL;
00068 
00069   typedef TLocal (*pfn) (const TCorba &T);
00070 
00071   pfn convert = pfn(f);
00072   for (i=0; i<n; i++) {
00073     SCRUTE((*S)[i]);
00074     T[i] = convert((*S)[i]);
00075     SCRUTE(T[i]);
00076   }
00077 }
00078 
00079 template <typename TLocal,
00080        typename TCorbaSeq>
00081 inline void convertCorbaArray (std::vector<TLocal> & T, int &nT, 
00082                       const TCorbaSeq & S)
00083 {
00084   int i, n = S->length();
00085   SCRUTE(n);
00086 
00087   nT = n;
00088   T.resize(nT);
00089 
00090   for (i=0; i<nT; i++) {
00091     SCRUTE((*S)[i]);
00092     T[i] = convert((*S)[i]);
00093     SCRUTE(T[i]);
00094   }
00095 }
00096 
00097 
00098 template <typename TCorba,
00099        typename TLocal,
00100        typename TCorbaSeq>
00101 inline void convertCorbaArray (std::vector<TLocal> & T, int &nT, 
00102                       const TCorbaSeq & S,
00103                       void *f)
00104 {
00105   int i, n = S->length();
00106   SCRUTE(n);
00107 
00108   nT = n;
00109   T.resize(nT);
00110 
00111   typedef TLocal (*pfn) (const TCorba &T);
00112 
00113   pfn convert = pfn(f);
00114   for (i=0; i<nT; i++) {
00115     SCRUTE((*S)[i]);
00116     T[i] = convert((*S)[i]);
00117     SCRUTE(T[i]);
00118   }
00119  
00120 }
00121 
00122 
00123 template <typename TCorba,
00124        typename TLocal,
00125        typename TCorbaSeq,
00126        typename TInfo>
00127 inline void convertCorbaArray (std::vector<TLocal> & T, 
00128                       const TCorbaSeq & S,
00129                       void *f, TInfo M)
00130 {
00131   int i, n = S->length();
00132   SCRUTE(n);
00133 
00134   int nT = n;
00135   T.resize(nT);
00136 
00137   typedef TLocal (*pfn) (const TCorba & , TInfo);
00138 
00139   pfn convert = pfn(f);
00140   for (i=0; i<nT; i++) {
00141     SCRUTE((*S)[i]);
00142     T[i] = convert((*S)[i], M);
00143     SCRUTE(T[i]);
00144   }
00145  
00146 }
00147 }
00148 
00149 #endif