28 #ifndef __CALCIUM_COUPLING_POLICY__
29 #define __CALCIUM_COUPLING_POLICY__
37 #include <boost/lambda/lambda.hpp>
38 #include <boost/utility/enable_if.hpp>
39 #include <boost/type_traits/is_arithmetic.hpp>
52 template <
typename DataManipulator,
103 typedef std::pair< TimeType , TagType >
DataId;
107 template <
typename T_TIME,
typename T_TAG >
113 template <
typename DataManipulator,
126 template <
typename AssocContainer >
128 const typename AssocContainer::key_type & expectedDataId,
129 bool & isEqual,
bool & isBounded,
130 typename AssocContainer::iterator & wDataIt1)
const;
146 template <
typename T_TIME,
typename T_TAG >
152 ):std::vector< std::pair< T_TIME,T_TAG> >() {
156 this->push_back(
DataId(dataId.first,0));
159 this->push_back(
DataId(0,dataId.second));
169 template <
typename DataManipulator,
class EnableIf >
172 template <
typename Iterator,
typename DataId >
175 const Iterator & it1)
const {
178 std::cout <<
"-------- Calcium Generic BoundedDataIdProcessor.apply() called " << std::endl;
185 template <
typename DataManipulator >
188 typename boost::enable_if< boost::is_float< typename DataManipulator::InnerType> >::type > {
193 _couplingPolicy(couplingPolicy) {};
196 template <
typename MapIterator >
198 const DataId & dataId,
const MapIterator & it1)
const {
201 typedef typename DataManipulator::InnerType InnerType;
202 typedef typename DataManipulator::Type Type;
204 MapIterator it2=it1; ++it2;
205 size_t dataSize1 = DataManipulator::size(it1->second);
207 std::cout <<
"-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Taille de donnée dataId1 : " << dataSize1 << std::endl;
212 size_t dataSize2 = DataManipulator::size(it2->second);
214 std::cout <<
"-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Taille de donnée dataId2 : " << dataSize2 << std::endl;
217 size_t dataSize = std::min< size_t >( dataSize1, dataSize2 );
218 DataId dataId2 = it2->first;
219 DataId dataId1 = it1->first;
223 std::cout <<
"-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Valeur de t1 : " << t1 << std::endl;
224 std::cout <<
"-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Valeur de t2 : " << t2 << std::endl;
228 std::cout <<
"-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Valeur de t : " << t << std::endl;
232 std::cout <<
"-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Valeur de timeDiff : " << timeDiff << std::endl;
236 std::cout <<
"-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Valeur de coeff : " << coeff << std::endl;
239 InnerType
const *
const InIt1 = DataManipulator::getPointer(it1->second);
241 std::cout <<
"-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Données à t1 : " << std::endl;
242 std::copy(InIt1,InIt1+dataSize1,std::ostream_iterator<InnerType>(std::cout,
" "));
243 std::cout << std::endl;
245 InnerType
const *
const InIt2 = DataManipulator::getPointer(it2->second);
247 std::cout <<
"-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Données à t2 : " << std::endl;
248 std::copy(InIt2,InIt2+dataSize2,std::ostream_iterator<InnerType>(std::cout,
" "));
249 std::cout << std::endl;
251 Type dataOut = DataManipulator::create(dataSize);
252 InnerType *
const OutIt = DataManipulator::getPointer(dataOut);
255 std::cerr <<
"-------- CalciumCouplingPolicy::BoundedDataIdProcessor : interpolationSchem : " << _couplingPolicy._interpolationSchem << std::endl;
256 std::cerr <<
"-------- CalciumCouplingPolicy::BoundedDataIdProcessor : alpha : " << _couplingPolicy._alpha << std::endl;
257 std::cerr <<
"-------- CalciumCouplingPolicy::BoundedDataIdProcessor : datecalschem : " << _couplingPolicy._dateCalSchem << std::endl;
258 std::cerr <<
"-------- CalciumCouplingPolicy::BoundedDataIdProcessor : storageLevel : " << _couplingPolicy._storageLevel << std::endl;
261 std::copy(InIt1,InIt1+dataSize,OutIt);
264 boost::lambda::placeholder1_type _1;
265 boost::lambda::placeholder2_type _2;
268 std::transform(InIt1,InIt1+dataSize,InIt2,OutIt,
269 ( _1 - _2 ) * coeff + _2 );
276 std::cout <<
"-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Données calculées à t : " << std::endl;
277 std::copy(OutIt,OutIt+dataSize,std::ostream_iterator<InnerType>(std::cout,
" "));
278 std::cout << std::endl;
291 template <
typename AssocContainer >
293 bool & isEqual,
bool & isBounded,
typename AssocContainer::iterator & wDataIt1)
const {
296 typedef typename AssocContainer::key_type key_type;
301 std::cout <<
"-------- time expected : " << expectedDataId.first << std::endl;
302 std::cout <<
"-------- time expected corrected : " << expectedDataId.first*(1.0-
_deltaT) << std::endl;
323 typename AssocContainer::iterator prev = storedDatas.begin();
324 typename AssocContainer::iterator current = prev;
325 while ( (current != storedDatas.end()) && !af(current->first) )
328 std::cerr <<
"------- stored time : " << current->first << std::endl;
340 if ( isEqual ) wDataIt1 = current;
342 if (isBounded) wDataIt1 = prev;
344 wDataIt1 = storedDatas.end();
347 std::cout <<
"-------- isDataIdConvenient : isEqual : " << isEqual <<
" , isBounded " << isBounded << std::endl;
350 return isEqual || isBounded;
354 template <
typename DataManipulator >
362 template <
typename Container,
typename TimeType,
typename TagType >
365 typedef typename Container::iterator
iterator;
366 typedef typename Container::reverse_iterator riterator;
372 iterator it=storedDatas.begin();
373 while(it != storedDatas.end() && it->first.first <= time)
375 DataManipulator::delete_data(it->second);
376 storedDatas.erase(it);
377 it=storedDatas.begin();
382 riterator it=storedDatas.rbegin();
383 while(it != storedDatas.rend() && it->first.first >= time)
385 DataManipulator::delete_data(it->second);
386 storedDatas.erase(it->first);
387 it=storedDatas.rbegin();
395 iterator it=storedDatas.begin();
396 while(it != storedDatas.end() && it->first.second <= tag)
398 DataManipulator::delete_data(it->second);
399 storedDatas.erase(it);
400 it=storedDatas.begin();
405 riterator it=storedDatas.rbegin();
406 while(it != storedDatas.rend() && it->first.second >= tag)
408 DataManipulator::delete_data(it->second);
409 storedDatas.erase(it->first);
410 it=storedDatas.rbegin();
424 template <
typename DataManipulator >
432 template <
typename Container >
434 typename Container::iterator & wDataIt1 )
const {
436 typedef typename Container::key_type key_type;
437 typedef typename Container::value_type value_type;
438 typedef typename Container::iterator
iterator;
441 std::cout <<
"-------- CalciumCouplingPolicy::eraseDataId, storedDatasSize : " << storedDatas.size() << std::endl;
446 size_t storedDatasSize = storedDatas.size();
449 size_t dist=distance(storedDatas.begin(),wDataIt1);
450 for (
int i=0; i<s; ++i) {
452 DataManipulator::delete_data((*storedDatas.begin()).second);
453 storedDatas.erase(storedDatas.begin());
459 " has just removed the data to send")));
463 std::cout <<
"-------- CalciumCouplingPolicy::eraseDataId, new storedDatasSize : " << storedDatas.size() << std::endl;
478 template <
typename DataManipulator >
486 template <
typename Container,
typename DataId >
488 const DataId & expectedDataId,
489 typename Container::iterator & wDataIt1 )
const {
491 typedef typename Container::key_type key_type;
492 typedef typename Container::value_type value_type;
493 typedef typename Container::iterator
iterator;
502 std::cout <<
"-------- CalciumCouplingPolicy::DisconnectProcessor MARK2 --------" << std::endl;
508 <<
" interrupts all further data reading")));
510 std::cout <<
"-------- CalciumCouplingPolicy::DisconnectProcessor MARK3 --------" << std::endl;
516 if ( storedDatas.empty() )
518 <<
" is active but no data is available.")));
525 std::cout <<
"-------- CalciumCouplingPolicy::DisconnectProcessor MARK4 " << expectedDataId <<
" --------" << std::endl;
529 iterator it1 = storedDatas.lower_bound(expectedDataId);
531 std::cout <<
"-------- CalciumCouplingPolicy::DisconnectProcessor MARK5 " << std::endl;
532 for (iterator it=storedDatas.begin();it!=storedDatas.end();++it)
533 std::cout <<
" "<<(*it).first ;
534 std::cout <<std::endl;
538 if (it1 == storedDatas.end())
540 <<
" is active but the requested dataId is less or equal to the last one received.")));
543 std::cout <<
"-------- CalciumCouplingPolicy::DisconnectProcessor MARK6 " << std::endl;
546 wDataIt1 = storedDatas.end();
549 std::cout <<
"-------- CalciumCouplingPolicy::DisconnectProcessor, CP_CONT : " << (*wDataIt1).first << std::endl;