]> SALOME platform Git repositories - modules/kernel.git/blob - src/DSC/DSC_User/Datastream/Calcium/Copy2CorbaSpace.hxx
Salome HOME
merge from branch BR_V5_DEV
[modules/kernel.git] / src / DSC / DSC_User / Datastream / Calcium / Copy2CorbaSpace.hxx
1 //  Copyright (C) 2007-2008  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 //  File   : Copy2CorbaSpace.hxx
23 //  Author : Eric Fayolle (EDF)
24 //  Module : KERNEL
25 // Modified by : $LastChangedBy$
26 // Date        : $LastChangedDate: 2007-02-07 18:26:44 +0100 (mer, 07 fév 2007) $
27 // Id          : $Id$
28 //
29 #ifndef _COPY_TO_CORBA_SPACE_HXX_
30 #define _COPY_TO_CORBA_SPACE_HXX_
31
32 #include <string>
33 #include <iostream>
34 #include "CalciumPortTraits.hxx"
35
36 template <bool zerocopy, typename DataManipulator> 
37 struct Copy2CorbaSpace  {
38
39   template <class T1, class T2>
40   static void apply( T1 * & corbaData, T2 const & data, size_t nRead){
41
42     typedef typename ProvidesPortTraits<T2>::PortType  PortType;
43     //typedef typename UsesPortTraits<T2>::PortType      PortType;
44     //ESSAI:     typedef typename PortType::DataManipulator         DataManipulator;
45     typedef typename DataManipulator::InnerType        InnerType;
46
47 #ifdef _DEBUG_
48     std::cerr << "-------- Copy2CorbaSpace<true> MARK 1 ------------------" << std::endl;
49 #endif
50     // Crée le type corba à partir du data sans lui en donner la propriété.
51     // Le const_cast supprime le caractère const du type T2 const & de data car 
52     // DataManipulator::create n'a pas le caractère const sur son paramètre data pour le
53     // cas de figure où  la propriété de la donnée lui est donnée.
54     corbaData = DataManipulator::create(nRead,const_cast<T2 * > (&data),false);
55 #ifdef _DEBUG_
56     std::cerr << "-------- Copy2CorbaSpace<true> MARK 2 --(dataPtr : " 
57               << DataManipulator::getPointer(corbaData,false)<<")----------------" << std::endl;
58 #endif
59
60   }
61 };
62
63 // Cas ou il faut effectuer une recopie
64 template <typename DataManipulator> struct
65 Copy2CorbaSpace<false, DataManipulator>  {
66   
67   template <class T1, class T2>
68   static void apply( T1 * & corbaData,  T2 const & data, size_t nRead){
69
70     typedef typename ProvidesPortTraits<T2>::PortType  PortType;
71     // typedef typename UsesPortTraits<T2>::PortType     PortType;
72 //ESSAI:    typedef typename PortType::DataManipulator        DataManipulator;
73     typedef typename DataManipulator::InnerType       InnerType;
74
75     corbaData = DataManipulator::create(nRead);
76     InnerType * dataPtr  = DataManipulator::getPointer(corbaData,false);
77
78 #ifdef _DEBUG_
79     std::cerr << "-------- Copy2CorbaSpace<false> MARK 1 --(dataPtr : " <<
80       dataPtr<<")----------------" << std::endl;
81 #endif
82     // Attention : Pour les chaines ou tout autre object complexe il faut utiliser une recopie profonde !   
83     std::copy(&data,&data+nRead,dataPtr);
84  
85 #ifdef _DEBUG_
86     std::cerr << "-------- Copy2CorbaSpace<false> MARK 2 --(nRead: "<<nRead<<")-------------" << std::endl;
87  
88     std::cerr << "-------- Copy2CorbaSpace<false> MARK 3 : " ;
89     std::copy(dataPtr,dataPtr+nRead,std::ostream_iterator<InnerType>(std::cout," "));
90     std::cout << std::endl;
91     std::cerr << "-------- Copy2CorbaSpace<false> MARK 4 --(data : " <<data<<") :" ;
92     for (int i=0; i<nRead; ++i)
93       std::cerr << (*corbaData)[i] << " ";
94     std::cout << std::endl;
95 #endif
96     
97   }
98 };
99
100 #endif