Salome HOME
Updated copyright comment
[modules/kernel.git] / src / DSC / DSC_User / Datastream / CouplingPolicy.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   : CouplingPolicy.hxx
24 //  Author : Eric Fayolle (EDF)
25 //  Module : KERNEL
26 // Modified by : $LastChangedBy$
27 // Date        : $LastChangedDate: 2007-02-28 15:26:32 +0100 (mer, 28 fév 2007) $
28 // Id          : $Id$
29 //
30 #ifndef _COUPLING_POLICY_HXX_
31 #define _COUPLING_POLICY_HXX_
32
33 #include "IteratorTraits.hxx"
34 #include "FindKeyPredicate.hxx"
35 #include <algorithm>
36 #include <functional>
37 #include <iterator>
38
39 // La politique de couplage doit définir
40 // 1) le type DataId qui identifie une instance de données 
41 // 2) Un container de DataId appelé DataIdContainer et son itérateur
42 // 3) Un constructeur de DataIdContainer qui  initialise le container à partir d'un DataId
43
44 //////////  Le DataId //////////////
45 //   COUPLING_POLICY::DataId 
46 //   est construit par  DataId(T1 time,T2 tag)
47 //
48 //   COUPLING_POLICY::DataIdContainer
49 //   qui défini  
50 //   les types    : DataIdContainer::iterator 
51 //   les méthodes : begin(), end(), empty()
52 //   COUPLING_POLICY::DataIdContainer::iterator 
53 //   qui défini 
54 //   les méthodes : != , == , ++() , ()++, *(), =
55
56 //   COUPLING_POLICY::DataTable
57 //    std::map< DataId, DataType>      DataTable;
58
59 //   Définir void COUPLING_POLICY::DataIdContainer(const DataId &, CouplingPolicy & )
60 //   qui initialise le container à partir d'un DataId
61
62 //   Opérateur d'affichage d'un dataId (les types doivent être affichables)
63
64   
65 class CouplingPolicy {
66
67 public:
68
69   // Renvoie isEqual si le dataId attendu est trouvé dans storedDataIds :
70   //   - l'itérateur wDataIt1 pointe alors sur ce dataId
71   // Cette méthode doit être redéfini dans le mode de couplage s'il veut gérer
72   // le cas d'un  dataId damandé non trouvé mais encadrable 
73   // par deux autres dataIds. La méthode renvoie alors isBounded== true et : 
74   //   - l'itérateur wDataIt1 doit  être tel que :
75   //     wDataIt1->first < wdataId < (wDataIt1+1)->first
76   template < typename Container >
77   bool isDataIdConveniant(Container & storedDatas, 
78                           const typename Container::key_type & expectedDataId,
79                           bool & isEqual ,  bool & isBounded, 
80                           typename Container::iterator & wDataIt1 ) const {
81     typedef typename Container::key_type   key_type;
82     typedef typename Container::value_type value_type;
83     typedef typename Container::iterator iterator;
84     isBounded = false;
85     FindKeyPredicate<value_type> fkp(expectedDataId);
86     wDataIt1  = std::find_if(storedDatas.begin(),storedDatas.end(),fkp);
87     isEqual   = (wDataIt1 != storedDatas.end());
88     std::cout << "-------- Generic isDataIdConvenient : isEqual : " << isEqual << " , isBounded " << isBounded << std::endl;
89     return isEqual || isBounded;
90   }
91
92   
93   // Méthode Vide déclarée ici pour définir son nom dans GenericPort
94   // Elle profite à tous les modes de couplages n'implémentant pas
95   // de comportement particulier dans la méthode get pour 
96   // le cas d'une demande de dataId inexistant mais encadré par deux autres
97   template <typename DataManipulator, class EnableIf = void >
98   struct BoundedDataIdProcessor{
99     BoundedDataIdProcessor(const CouplingPolicy & couplingPolicy) {};
100     template < typename Iterator, typename DataId > 
101     void inline apply(typename iterator_t<Iterator>::value_type & data,
102                       const DataId & dataId,
103                       const Iterator  & it1) const {
104       typedef typename iterator_t<Iterator>::value_type value_type;
105       std::cout << "-------- Generic BoundedDataIdProcessor.apply() called " << std::endl;
106
107     }
108   };
109
110   // Supprime un DataId et ses données associées
111   // du container
112   // Cette méthode utilisée dans GenericPort::Get 
113   // peut être surchargée pour par exemple
114   // conserver un historique.
115   template <typename DataManipulator>
116   struct EraseDataIdProcessor {
117
118     EraseDataIdProcessor(CouplingPolicy couplingPolicy) {};
119
120     template < typename Container >
121     void apply(Container & storedDatas, 
122                typename Container::iterator & wDataIt1 ) const {
123       typedef typename Container::key_type   key_type;
124       typedef typename Container::value_type value_type;
125       typedef typename Container::iterator iterator;
126
127       std::cout << "-------- Generic eraseDataId called " << std::endl;
128     }
129   };
130
131   // Lorsque cette méthode est appelée l'expectedDataId n'a pas été trouvé
132   // et n'est pas non plus encadrée (en mode temporel)
133   // Si l'on effectue pas de traitement particulier la méthode renvoie false
134   // Si le port a reçu une directive STOP une exception est levée
135   // Si le port a reçu une directive CONTINUE, on localise l'expected
136   template < typename DataManipulator > 
137   struct DisconnectProcessor {
138
139     DisconnectProcessor(const CouplingPolicy & couplingPolicy) {};
140
141     template < typename Container, typename DataId >
142     bool apply(Container & storedDatas,
143                const DataId & expectedDataId,
144                typename Container::iterator & wDataIt1 ) const {
145       typedef typename Container::key_type   key_type;
146       typedef typename Container::value_type value_type;
147       typedef typename Container::iterator   iterator;
148
149       std::cout << "-------- Generic DisconnectProcessor called " << std::endl;
150       return true;
151     }
152   };
153
154   // Remove all DataId from a container before a given time or tag
155   template <typename DataManipulator>
156   struct EraseDataIdBeforeOrAfterTagProcessor {
157
158     EraseDataIdBeforeOrAfterTagProcessor(CouplingPolicy couplingPolicy) {};
159
160     template < typename Container , typename TimeType , typename TagType >
161     void apply(Container & storedDatas, TimeType time, TagType tag, bool before ) const {
162       typedef typename Container::key_type   key_type;
163       typedef typename Container::value_type value_type;
164       typedef typename Container::iterator iterator;
165     }
166   };
167
168   // Permet de réveiller les méthodes d'un GenericPort en attente
169   // depuis une CouplingPolicy
170   virtual void wakeupWaiting(){};
171
172   virtual ~CouplingPolicy() {}
173
174 };
175
176 #endif