SALOME documentation central

src/DSC/DSC_User/Datastream/Calcium/Copy2CorbaSpace.hxx

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