1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : PalmCouplingPolicy.hxx
24 // Author : Eric Fayolle (EDF)
26 // Modified by : $LastChangedBy$
27 // Date : $LastChangedDate: 2007-01-29 16:12:41 +0100 (lun, 29 jan 2007) $
30 #ifndef _PALM_COUPLING_POLICIES_HXX_
31 #define _PALM_COUPLING_POLICIES_HXX_
33 #include <SALOMEconfig.h>
37 #include "DataIdFilter.hxx"
38 #include "DisplayPair.hxx"
39 #include "CouplingPolicy.hxx"
41 class PalmCouplingPolicy: public CouplingPolicy {
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 ;
50 template <typename T_TIME, typename T_TAG > class InternalDataIdContainer;
51 template <typename T_TIME, typename T_TAG > friend class InternalDataIdContainer;
53 filtre_conversion * get_filtre_convert_TIME() { return &filtre_convert_TIME; }
54 filtre_conversion * get_filtre_convert_TAG() { return &filtre_convert_TAG; }
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;
64 TimeType getTime(const DataId &dataId) const { return dataId.first;}
65 TagType getTag (const DataId &dataId) const { return dataId.second;}
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 {
71 std::vector<T_TIME> _lTime;
72 std::vector<T_TAG> _lTag;
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() {}
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;
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);
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);
95 for(std::vector<CORBA::Long>::iterator i=_lTag.begin();i!=_lTag.end();++i)
96 std::cout << "_lTag["<< c++ << "] : " << *i << std::endl;
100 InternalDataIdContainer(std::vector<T_TIME> const & lTime, std::vector<T_TAG> const & lTag):
101 _lTime(lTime),_lTag(lTag) {}
105 InternalDataIdContainer( InternalDataIdContainer const & pc):
106 _lTime(pc._lTime), _lTag(pc._lTag) {}
110 InternalDataIdContainer & operator=(const InternalDataIdContainer & pc) {
111 if (this != &pc) { _lTime=pc._lTime; _lTag=pc._lTag; }
115 virtual ~InternalDataIdContainer() {}
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(); }
123 // Définition de l'itérateur du container
124 template <typename TTIME, typename TTAG> class DataIdIterator {
128 typedef typename std::vector<TTIME>::const_iterator ItTime;
129 typedef typename std::vector<TTAG >::const_iterator ItTag;
134 const InternalDataIdContainer<TTIME,TTAG> & _pc;
141 DataIdIterator(const InternalDataIdContainer<TTIME,TTAG> & pc):
142 _pc(pc),_itTime(pc._lTime.begin()),_itTag(pc._lTag.begin()) {}
143 DataIdIterator(const InternalDataIdContainer<TTIME,TTAG> & pc, ItTime itTime, ItTag itTag):
144 _pc(pc),_itTime(itTime),_itTag(itTag) {}
146 DataIdIterator(const DataIdIterator & dIt):
147 _pc(dIt._pc),_itTime(dIt._itTime),_itTag(dIt._itTag) {}
152 DataIdIterator & operator=(const DataIdIterator & dIt) {
154 _pc=dIt._pc;_itTime=dIt._itTime;_itTag=dIt._itTag;
159 DataId operator*() const {
160 std::cout << "-------- operator*(), *_itTime : " << *_itTime << " *_itTag " << *_itTag <<std::endl;
161 return DataId(*_itTime,*_itTag); }
163 bool operator==( const DataIdIterator & dIt) const {
164 return (_itTime == dIt._itTime) && (_itTag == dIt._itTag) && (&_pc == &dIt._pc);
167 bool operator!=( const DataIdIterator & dIt) const {
168 return (_itTime != dIt._itTime) || (_itTag != dIt._itTag) || (&_pc != &dIt._pc);
172 DataIdIterator & operator++() {
173 if ( _itTag != _pc._lTag.end() ) {
175 if (_itTag != _pc._lTag.end() ) return *this;
177 if ( _itTime != _pc._lTime.end() ) {
179 if (_itTime != _pc._lTime.end() ) _itTag=_pc._lTag.begin();
185 DataIdIterator operator++(int fake) {
186 DataIdIterator tmpIt=*this; ++*this; return tmpIt;
189 }; //Fin de la classe de l'itérateur
190 }; //Fin de la classe du container