Salome HOME
Updated copyright comment
[modules/kernel.git] / src / DSC / DSC_User / Datastream / Palm / PalmCouplingPolicy.hxx
1 // Copyright (C) 2007-2024  CEA, EDF, 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, or (at your option) any later version.
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
23 //  File   : PalmCouplingPolicy.hxx
24 //  Author : Eric Fayolle (EDF)
25 //  Module : KERNEL
26 // Modified by : $LastChangedBy$
27 // Date        : $LastChangedDate: 2007-01-29 16:12:41 +0100 (lun, 29 jan 2007) $
28 // Id          : $Id$
29 //
30 #ifndef _PALM_COUPLING_POLICIES_HXX_
31 #define _PALM_COUPLING_POLICIES_HXX_
32
33 #include <SALOMEconfig.h>
34
35 #include <omniORB4/CORBA.h>
36 #include <vector>
37 #include "DataIdFilter.hxx"
38 #include "DisplayPair.hxx"
39 #include "CouplingPolicy.hxx"
40
41 class PalmCouplingPolicy: public CouplingPolicy {
42
43   // Objet de filtrage et conversion d'un TIME
44   filtre_conversion filtre_convert_TIME ;
45   // Objet de filtrage et conversion d'un TAG
46   filtre_conversion filtre_convert_TAG ;
47
48 public:
49
50   template <typename T_TIME, typename T_TAG >        class InternalDataIdContainer;
51   template <typename T_TIME, typename T_TAG > friend class InternalDataIdContainer;
52
53   filtre_conversion * get_filtre_convert_TIME() { return &filtre_convert_TIME; }
54   filtre_conversion * get_filtre_convert_TAG()  { return &filtre_convert_TAG;  }
55  
56   // Classe DataId rassemblant les paramètres de la méthode PORT::put 
57   // qui identifient l'instance d'une donnée pour Palm
58   // Rem : Le DataId doit pouvoir être une key dans une map stl
59   typedef CORBA::Long TimeType;
60   typedef CORBA::Long TagType;
61   typedef std::pair               < TimeType , TagType > DataId;
62   typedef InternalDataIdContainer < TimeType , TagType > DataIdContainer;
63
64   TimeType getTime(const DataId &dataId) const { return dataId.first;}
65   TagType  getTag (const DataId &dataId) const { return dataId.second;}
66
67   // Container qui permet d'itérer sur l'ensemble des DataId générés par les
68   // eventuelles conversions
69   template <typename T_TIME, typename T_TAG > class InternalDataIdContainer {
70
71     std::vector<T_TIME>  _lTime;
72     std::vector<T_TAG>   _lTag;
73     
74     // Interdit la construction d'un container vide car
75     // aucune méthode d'ajout d'élément n'a été implémentée
76     InternalDataIdContainer() {}
77  
78   public:
79     typedef DataId                                   value_type;
80     template <typename TTIME, typename TTAG>   class DataIdIterator;
81     typedef  DataIdIterator<T_TIME, T_TAG>           iterator;                  
82     typedef value_type &                             reference;
83     typedef value_type const &                       const_reference;
84  
85     // Remplit le container d'identificateurs après avoir appliqué
86     // les filtres/convertions  des paramètres "TIMEs" et des "TAGs"
87     InternalDataIdContainer(const DataId & dataId, const PalmCouplingPolicy & policy ) {
88       std::cout << "----Cst ----  InternalDataIdContainer(const DataId & dataId..) " << dataId <<std::endl;
89       policy.filtre_convert_TIME.applique_filtre_conversion(dataId.first, _lTime);
90       int c=0;
91       for(std::vector<CORBA::Long>::iterator i=_lTime.begin();i!=_lTime.end();++i)
92         std::cout << "_lTime["<< c++ << "] : " << *i << std::endl;
93       policy.filtre_convert_TAG.applique_filtre_conversion(dataId.second, _lTag);
94       c=0;
95       for(std::vector<CORBA::Long>::iterator i=_lTag.begin();i!=_lTag.end();++i)
96         std::cout << "_lTag["<< c++ << "] : " << *i << std::endl;
97     }
98
99     // Pas encore testé
100     InternalDataIdContainer(std::vector<T_TIME> const & lTime, std::vector<T_TAG> const & lTag):
101       _lTime(lTime),_lTag(lTag) {}
102   
103
104     // Pas encore testé
105     InternalDataIdContainer( InternalDataIdContainer const & pc):
106       _lTime(pc._lTime), _lTag(pc._lTag) {}
107
108
109     // Pas encore testé
110     InternalDataIdContainer & operator=(const InternalDataIdContainer & pc) {
111       if (this != &pc) { _lTime=pc._lTime; _lTag=pc._lTag; }
112       return *this;
113     }
114     
115     virtual ~InternalDataIdContainer() {}
116
117     iterator begin() { return iterator(*this);  }
118     iterator end()   { return iterator(*this,_lTime.end(),_lTag.end()); }
119     // En Palm les deux paramètres du couple (temps,tag) doivent
120     // exister (un seul paramètre n'est pas recevable) 
121     bool     empty() const { return _lTime.empty() || _lTag.empty(); }
122
123     // Définition de l'itérateur du container
124     template <typename TTIME, typename TTAG> class DataIdIterator {
125
126     public:
127
128       typedef typename std::vector<TTIME>::const_iterator ItTime;
129       typedef typename std::vector<TTAG >::const_iterator ItTag;
130
131     private:
132       ItTime _itTime;
133       ItTag  _itTag;
134       const InternalDataIdContainer<TTIME,TTAG> & _pc;
135       DataIdIterator() {}
136
137     public:
138  
139  
140       // Pas encore testé
141       DataIdIterator(const InternalDataIdContainer<TTIME,TTAG> & pc):
142         _itTime(pc._lTime.begin()),_itTag(pc._lTag.begin()),_pc(pc){}
143       DataIdIterator(const InternalDataIdContainer<TTIME,TTAG> & pc, ItTime itTime, ItTag itTag):
144         _itTime(itTime),_itTag(itTag),_pc(pc) {}
145       // Pas encore testé
146       DataIdIterator(const DataIdIterator & dIt):
147         _itTime(dIt._itTime),_itTag(dIt._itTag), _pc(dIt._pc) {}
148       ~DataIdIterator() {}
149       
150
151       // Pas encore testé
152       DataIdIterator & operator=(const DataIdIterator & dIt) {
153         if (this != &dIt) {
154           _pc=dIt._pc;_itTime=dIt._itTime;_itTag=dIt._itTag;
155         }
156         return *this;
157       }
158
159       DataId operator*() const {
160         std::cout << "-------- operator*(),  *_itTime : " << *_itTime << " *_itTag " <<  *_itTag <<std::endl;
161         return DataId(*_itTime,*_itTag); }
162    
163       bool operator==( const DataIdIterator  & dIt) const {
164         return (_itTime == dIt._itTime) && (_itTag == dIt._itTag) && (&_pc == &dIt._pc);
165       }
166
167       bool operator!=( const DataIdIterator  & dIt) const { 
168         return (_itTime != dIt._itTime) || (_itTag != dIt._itTag) || (&_pc != &dIt._pc);
169       }
170
171       // Notation préfixé
172       DataIdIterator & operator++() {
173         if ( _itTag != _pc._lTag.end() ) { 
174           ++_itTag;
175           if (_itTag != _pc._lTag.end() ) return *this;
176         }
177         if ( _itTime != _pc._lTime.end() )  { 
178           ++_itTime;
179           if (_itTime != _pc._lTime.end() ) _itTag=_pc._lTag.begin();
180         }
181         return *this;
182       }
183
184       // Notation postfixé
185       DataIdIterator operator++(int fake) { 
186         DataIdIterator tmpIt=*this; ++*this; return tmpIt; 
187       }
188       
189     }; //Fin de la classe de l'itérateur
190   };   //Fin de la classe du container
191
192
193
194 };
195
196 #endif