Back to index

salome-kernel  6.5.0
Copy2CorbaSpace.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 //  File   : Copy2CorbaSpace.hxx
00024 //  Author : Eric Fayolle (EDF)
00025 //  Module : KERNEL
00026 // Modified by : $LastChangedBy$
00027 // Date        : $LastChangedDate: 2007-02-07 18:26:44 +0100 (mer, 07 fév 2007) $
00028 // Id          : $Id: Copy2CorbaSpace.hxx,v 1.3.2.3.10.2.12.1 2012-04-12 14:05:07 vsr Exp $
00029 //
00030 #ifndef _COPY_TO_CORBA_SPACE_HXX_
00031 #define _COPY_TO_CORBA_SPACE_HXX_
00032 
00033 
00034 #include <string>
00035 #include <iostream>
00036 #include "CalciumPortTraits.hxx"
00037 
00038 //#define MYDEBUG
00039 
00040 template <bool zerocopy, typename DataManipulator> 
00041 struct Copy2CorbaSpace  {
00042 
00043   template <class T1, class T2>
00044   static void apply( T1 * & corbaData, T2 const & data, size_t nRead){
00045 
00046     typedef typename ProvidesPortTraits<T2>::PortType  PortType;
00047     //typedef typename UsesPortTraits<T2>::PortType      PortType;
00048     //ESSAI:     typedef typename PortType::DataManipulator         DataManipulator;
00049     typedef typename DataManipulator::InnerType        InnerType;
00050 
00051 #ifdef MYDEBUG
00052     std::cerr << "-------- Copy2CorbaSpace<true> MARK 1 ------------------" << std::endl;
00053 #endif
00054     // Crée le type corba à partir du data sans lui en donner la propriété.
00055     // Le const_cast supprime le caractère const du type T2 const & de data car 
00056     // DataManipulator::create n'a pas le caractère const sur son paramètre data pour le
00057     // cas de figure où  la propriété de la donnée lui est donnée.
00058     corbaData = DataManipulator::create(nRead,const_cast<T2 * > (&data),false);
00059 #ifdef MYDEBUG
00060     std::cerr << "-------- Copy2CorbaSpace<true> MARK 2 --(dataPtr : " 
00061               << DataManipulator::getPointer(corbaData,false)<<")----------------" << std::endl;
00062 #endif
00063 
00064   }
00065 };
00066 
00067 // Cas ou il faut effectuer une recopie
00068 template <typename DataManipulator> struct
00069 Copy2CorbaSpace<false, DataManipulator>  {
00070   
00071   template <class T1, class T2>
00072   static void apply( T1 * & corbaData,  T2 const & data, size_t nRead){
00073 
00074     typedef typename ProvidesPortTraits<T2>::PortType  PortType;
00075     // typedef typename UsesPortTraits<T2>::PortType     PortType;
00076 //ESSAI:    typedef typename PortType::DataManipulator        DataManipulator;
00077     typedef typename DataManipulator::InnerType       InnerType;
00078 
00079     corbaData = DataManipulator::create(nRead);
00080     InnerType * dataPtr  = DataManipulator::getPointer(corbaData,false);
00081 
00082 #ifdef MYDEBUG
00083     std::cerr << "-------- Copy2CorbaSpace<false> MARK 1 --(dataPtr : " <<
00084       dataPtr<<")----------------" << std::endl;
00085 #endif
00086     // Attention : Pour les chaines ou tout autre object complexe il faut utiliser une recopie profonde !   
00087     std::copy(&data,&data+nRead,dataPtr);
00088  
00089 #ifdef MYDEBUG
00090     std::cerr << "-------- Copy2CorbaSpace<false> MARK 2 --(nRead: "<<nRead<<")-------------" << std::endl;
00091  
00092     std::cerr << "-------- Copy2CorbaSpace<false> MARK 3 : " ;
00093     std::copy(dataPtr,dataPtr+nRead,std::ostream_iterator<InnerType>(std::cout," "));
00094     std::cout << std::endl;
00095     std::cerr << "-------- Copy2CorbaSpace<false> MARK 4 --(data : " <<data<<") :" ;
00096     for (int i=0; i<nRead; ++i)
00097       std::cerr << (*corbaData)[i] << " ";
00098     std::cout << std::endl;
00099 #endif
00100     
00101   }
00102 };
00103 
00104 #endif