Back to index

salome-med  6.5.0
MEDMEM_FieldTemplate_i.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #ifndef __MED_FIELDTEMPLATE_I_HXX__
00024 #define __MED_FIELDTEMPLATE_I_HXX__
00025 
00026 #include <SALOMEconfig.h> 
00027 #include  CORBA_SERVER_HEADER(MED)
00028 #include "MEDMEM_Field_i.hxx"
00029 #include "MEDMEM_Field.hxx"
00030 #include "SenderFactory.hxx"
00031 #include "MultiCommException.hxx"
00032 #include "MEDMEM_ArrayConvert.hxx"
00033 #include "MEDMEM_TraitsForFields.hxx"
00034 #include "utilities.h"
00035 
00036 namespace MEDMEM
00037 {
00038   template < class T, class INTERLACING_TAG=FullInterlace >
00039   class FIELDTEMPLATE_I : public FIELDI_TRAITS<T,INTERLACING_TAG>::InterfaceForServant,
00040                           public FIELD_i,
00041                           public SALOMEMultiComm
00042   {
00043   public:
00044     FIELDTEMPLATE_I();
00045     ~FIELDTEMPLATE_I();
00046     FIELDTEMPLATE_I(MEDMEM::FIELD<T, INTERLACING_TAG> *f, bool ownCppPtr=false);
00047     FIELDTEMPLATE_I(FIELDTEMPLATE_I & f);
00048     typename FIELDI_TRAITS<T,INTERLACING_TAG>::SeqType* getValue (SALOME_MED::medModeSwitch mode ) 
00049       throw (SALOME::SALOME_Exception);
00050     typename FIELDI_TRAITS<T,INTERLACING_TAG>::SenderPtrType getSenderForValue(SALOME_MED::medModeSwitch mode)
00051       throw (SALOME::SALOME_Exception);
00052   };
00053 
00054   //=============================================================================
00058   //=============================================================================
00059   template < class T, class INTERLACING_TAG >
00060   FIELDTEMPLATE_I<T,INTERLACING_TAG>::FIELDTEMPLATE_I(): FIELD_i()
00061   {
00062   }
00063   //=============================================================================
00067   //=============================================================================
00068   template < class T, class INTERLACING_TAG >
00069   FIELDTEMPLATE_I<T,INTERLACING_TAG>::~FIELDTEMPLATE_I()
00070   {
00071   }
00072   //=============================================================================
00076   //=============================================================================
00077   template < class T, class INTERLACING_TAG >
00078   FIELDTEMPLATE_I<T,INTERLACING_TAG>::FIELDTEMPLATE_I(FIELDTEMPLATE_I<T, INTERLACING_TAG>& fd):
00079     FIELD_i(fd)
00080   {
00081   }
00082   //=============================================================================
00086   //=============================================================================
00087   template < class T, class INTERLACING_TAG >
00088   FIELDTEMPLATE_I<T,INTERLACING_TAG>::FIELDTEMPLATE_I(MEDMEM::FIELD<T, INTERLACING_TAG> *f, bool ownCppPtr):FIELD_i(f,ownCppPtr)
00089   {
00090   }
00091 
00092   //=============================================================================
00096   //=============================================================================
00097   template < class T, class INTERLACING_TAG >
00098   typename FIELDI_TRAITS<T,INTERLACING_TAG>::SeqType *FIELDTEMPLATE_I<T,INTERLACING_TAG>::getValue( SALOME_MED::medModeSwitch mode ) 
00099     throw (SALOME::SALOME_Exception)
00100   {
00101     if (_fieldTptr==NULL)
00102       THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00103                                    SALOME::INTERNAL_ERROR);
00104     typename FIELDI_TRAITS<T,INTERLACING_TAG>::SeqVarType myseq = new typename FIELDI_TRAITS<T,INTERLACING_TAG>::SeqType;
00105     try
00106       {
00107         medModeSwitch modemed=convertIdlModeToMedMode(mode);
00108         //              ::FIELD<T> *ptrD=dynamic_cast< ::FIELD<T>* >(_fieldTptr);
00109         // the alternative is not safe but the dynamic_cast fails using the python API
00110         MEDMEM::FIELD<T, INTERLACING_TAG> *ptrD = static_cast<MEDMEM::FIELD<T, INTERLACING_TAG>* >(_fieldTptr);
00111         int nbval=ptrD->getValueLength();
00112         if(ptrD->getInterlacingType()==modemed)
00113           {
00114             const T* values =ptrD->getValue();
00115             myseq->length(nbval);
00116             for (int i=0; i<nbval; i++)
00117               {
00118                 myseq[i]=values[i];
00119               }
00120           }
00121         else
00122           {
00123             T *values;
00124             if  ( ptrD->getGaussPresence() ) 
00125               {
00126                 typename MEDMEM_ArrayInterface<T,INTERLACING_TAG,Gauss>::Array * myArray = ptrD->getArrayGauss();
00127                 int size=myArray->getArraySize();
00128                 values=new T[size];
00129                 delete ArrayConvert(*myArray,values);
00130               }
00131             else 
00132               {
00133                 typename MEDMEM_ArrayInterface<T,INTERLACING_TAG,NoGauss>::Array * myArray = ptrD->getArrayNoGauss();
00134                 int size=myArray->getArraySize();
00135                 values=new T[size];
00136                 delete ArrayConvert(*myArray,values);
00137               }
00138             for (int i=0; i<nbval; i++)
00139               {
00140                 myseq[i]=values[i];
00141               }
00142           }
00143       }
00144     catch (MEDEXCEPTION &ex)
00145       {
00146         MESSAGE("Unable to acces Field ");
00147         THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00148       }
00149     return myseq._retn();
00150   }
00151   //=============================================================================
00155   //=============================================================================
00156   template < class T, class INTERLACING_TAG >
00157   typename FIELDI_TRAITS<T,INTERLACING_TAG>::SenderPtrType FIELDTEMPLATE_I<T,INTERLACING_TAG>::getSenderForValue( SALOME_MED::medModeSwitch mode ) 
00158     throw (SALOME::SALOME_Exception)
00159   {
00160     if (_fieldTptr==NULL)
00161       THROW_SALOME_CORBA_EXCEPTION("No associated Field", \
00162                                    SALOME::INTERNAL_ERROR);
00163     typename FIELDI_TRAITS<T,INTERLACING_TAG>::SenderPtrType ret;
00164     try
00165       {
00166         medModeSwitch modemed=convertIdlModeToMedMode(mode);
00167         // ::FIELD<T> *ptrD=dynamic_cast< ::FIELD<T>* >(_fieldTptr);
00168         // the alternative is not safe but the dynamic_cast fails using the python API
00169         MEDMEM::FIELD<T, INTERLACING_TAG> *ptrD=static_cast< MEDMEM::FIELD<T, INTERLACING_TAG>* >(_fieldTptr);
00170         int nbval=ptrD->getValueLength();
00171         if(ptrD->getInterlacingType()==modemed)
00172           {
00173             const T* values =ptrD->getValue();
00174             ret=SenderFactory::buildSender(*this,values,nbval);
00175           }
00176         else
00177           {
00178             T *values;
00179             if  ( ptrD->getGaussPresence() ) 
00180               {
00181                 typename MEDMEM_ArrayInterface<T,INTERLACING_TAG,Gauss>::Array * myArray = ptrD->getArrayGauss();
00182                 int size=myArray->getArraySize();
00183                 values=new T[size];
00184                 delete ArrayConvert(*myArray,values);
00185                 
00186               }
00187             else 
00188               {
00189                 typename MEDMEM_ArrayInterface<T,INTERLACING_TAG,NoGauss>::Array * myArray = ptrD->getArrayNoGauss();
00190                 int size=myArray->getArraySize();
00191                 values=new T[size];
00192                 delete ArrayConvert(*myArray,values);
00193               }
00194             ret=SenderFactory::buildSender(*this,values,nbval);
00195           }
00196       }
00197     catch (MEDEXCEPTION &ex)
00198       {
00199         MESSAGE("Unable to acces Field ");
00200         THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00201       }
00202     return ret;
00203   }
00204 
00205 }
00206 
00207 #endif