13#include <mdds/multi_type_vector/types.hpp>
17template<
typename SizeT,
typename Ret =
bool>
20 Ret
operator() (mdds::mtv::element_t, SizeT, SizeT)
const
26template<
typename FuncElem,
typename Elem>
33 return !
func(s, elem);
41template<
typename StoreT,
typename Func>
42typename StoreT::const_iterator
44 const typename StoreT::const_iterator& itPos,
const StoreT& rStore, Func& rFunc,
45 typename StoreT::size_type nStart,
typename StoreT::size_type nEnd)
47 typedef std::pair<typename StoreT::const_iterator, typename StoreT::size_type> PositionType;
49 PositionType aPos = rStore.position(itPos, nStart);
50 typename StoreT::const_iterator it = aPos.first;
51 typename StoreT::size_type nOffset = aPos.second;
52 typename StoreT::size_type nDataSize = 0;
53 typename StoreT::size_type nTopRow = nStart;
55 for (; it != rStore.end() && nTopRow <= nEnd; ++it, nOffset = 0, nTopRow += nDataSize)
57 bool bLastBlock =
false;
58 nDataSize = it->size - nOffset;
59 if (nTopRow + nDataSize - 1 > nEnd)
62 nDataSize = nEnd - nTopRow + 1;
66 rFunc(*it, nOffset, nDataSize);
79template<
typename StoreT,
typename Func>
80typename StoreT::iterator
81ProcessBlock(
const typename StoreT::iterator& itPos, StoreT& rStore, Func& rFunc,
typename StoreT::size_type nStart,
typename StoreT::size_type nEnd)
83 typedef std::pair<typename StoreT::iterator, typename StoreT::size_type> PositionType;
85 PositionType aPos = rStore.position(itPos, nStart);
86 typename StoreT::iterator it = aPos.first;
87 typename StoreT::size_type nOffset = aPos.second;
88 typename StoreT::size_type nDataSize = 0;
89 typename StoreT::size_type nCurRow = nStart;
91 for (; it != rStore.end() && nCurRow <= nEnd; ++it, nOffset = 0, nCurRow += nDataSize)
93 bool bLastBlock =
false;
94 nDataSize = it->size - nOffset;
95 if (nCurRow + nDataSize - 1 > nEnd)
98 nDataSize = nEnd - nCurRow + 1;
102 rFunc(*it, nOffset, nDataSize);
111template<
typename BlkT,
typename ItrT,
typename NodeT,
typename FuncElem>
112void EachElem(NodeT& rNode,
size_t nOffset,
size_t nDataSize, FuncElem& rFuncElem)
114 ItrT it = BlkT::begin(*rNode.data);
115 std::advance(it, nOffset);
117 std::advance(itEnd, nDataSize);
118 size_t nRow = rNode.position + nOffset;
119 for (; it != itEnd; ++it, ++nRow)
120 rFuncElem(nRow, *it);
123template<
typename BlkT,
typename ItrT,
typename NodeT,
typename FuncElem>
126 auto it = BlkT::begin(*rNode.data);
127 auto itEnd = BlkT::end(*rNode.data);
128 size_t nRow = rNode.position;
129 for (; it != itEnd; ++it, ++nRow)
130 rFuncElem(nRow, *it);
133template<
typename BlkT,
typename ItrT,
typename NodeT,
typename FuncElem>
136 auto it = BlkT::rbegin(*rNode.data);
137 auto itEnd = BlkT::rend(*rNode.data);
138 size_t nRow = rNode.position;
139 for (; it != itEnd; ++it, ++nRow)
140 rFuncElem(nRow, *it);
143template<
typename BlkT,
typename StoreT,
typename FuncElem>
144std::pair<typename StoreT::const_iterator, size_t>
146 const StoreT& rStore,
const typename StoreT::const_iterator& it,
size_t nOffset,
size_t nDataSize,
149 typedef std::pair<typename StoreT::const_iterator, size_t> PositionType;
151 typename BlkT::const_iterator itData = BlkT::begin(*it->data);
152 std::advance(itData, nOffset);
153 typename BlkT::const_iterator itDataEnd = itData;
154 std::advance(itDataEnd, nDataSize);
155 size_t nTopRow = it->position + nOffset;
156 size_t nRow = nTopRow;
157 for (; itData != itDataEnd; ++itData, ++nRow)
159 if (rFuncElem(nRow, *itData))
160 return PositionType(it, nRow - it->position);
163 return PositionType(rStore.end(), 0);
166template<
typename StoreT,
typename BlkT,
typename FuncElem,
typename FuncElse>
167void ParseElements1(
const StoreT& rStore, FuncElem& rFuncElem, FuncElse& rFuncElse)
169 typename StoreT::size_type nTopRow = 0, nDataSize = 0;
170 typename StoreT::const_iterator it = rStore.begin(), itEnd = rStore.end();
171 for (; it != itEnd; ++it, nTopRow += nDataSize)
173 nDataSize = it->size;
174 if (it->type != BlkT::block_type)
176 rFuncElse(it->type, nTopRow, nDataSize);
180 EachElem<BlkT, typename BlkT::const_iterator>(*it, rFuncElem);
184template<
typename StoreT,
typename BlkT,
typename FuncElem,
typename FuncElse>
185typename StoreT::const_iterator
187 const typename StoreT::const_iterator& itPos,
const StoreT& rStore,
188 typename StoreT::size_type nStart,
typename StoreT::size_type nEnd,
189 FuncElem& rFuncElem, FuncElse& rFuncElse)
191 typedef std::pair<typename StoreT::const_iterator, typename StoreT::size_type> PositionType;
193 PositionType aPos = rStore.position(itPos, nStart);
194 typename StoreT::const_iterator it = aPos.first;
195 typename StoreT::size_type nOffset = aPos.second;
196 typename StoreT::size_type nDataSize = 0;
197 typename StoreT::size_type nTopRow = nStart;
199 for (; it != rStore.end() && nTopRow <= nEnd; ++it, nOffset = 0, nTopRow += nDataSize)
201 bool bLastBlock =
false;
202 nDataSize = it->size - nOffset;
203 if (nTopRow + nDataSize - 1 > nEnd)
206 nDataSize = nEnd - nTopRow + 1;
210 if (it->type == BlkT::block_type)
211 EachElem<BlkT, typename BlkT::const_iterator>(*it, nOffset, nDataSize, rFuncElem);
213 rFuncElse(it->type, nTopRow, nDataSize);
222template<
typename StoreT,
typename Blk1,
typename Blk2,
typename FuncElem,
typename FuncElse>
223typename StoreT::const_iterator
225 const typename StoreT::const_iterator& itPos,
const StoreT& rStore,
typename StoreT::size_type nStart,
typename StoreT::size_type nEnd,
226 FuncElem& rFuncElem, FuncElse& rFuncElse)
228 typedef std::pair<typename StoreT::const_iterator, typename StoreT::size_type> PositionType;
230 PositionType aPos = rStore.position(itPos, nStart);
231 typename StoreT::const_iterator it = aPos.first;
232 typename StoreT::size_type nOffset = aPos.second;
233 typename StoreT::size_type nDataSize = 0;
234 typename StoreT::size_type nTopRow = nStart;
236 for (; it != rStore.end() && nTopRow <= nEnd; ++it, nOffset = 0, nTopRow += nDataSize)
238 bool bLastBlock =
false;
239 nDataSize = it->size - nOffset;
240 if (nTopRow + nDataSize - 1 > nEnd)
243 nDataSize = nEnd - nTopRow + 1;
249 case Blk1::block_type:
250 EachElem<Blk1, typename Blk1::const_iterator>(*it, nOffset, nDataSize, rFuncElem);
252 case Blk2::block_type:
253 EachElem<Blk2, typename Blk2::const_iterator>(*it, nOffset, nDataSize, rFuncElem);
256 rFuncElse(it->type, nTopRow, nDataSize);
266template<
typename StoreT,
typename Blk1,
typename Blk2,
typename Blk3,
typename Blk4,
typename FuncElem,
typename FuncElse>
267typename StoreT::const_iterator
269 const typename StoreT::const_iterator& itPos,
const StoreT& rStore,
typename StoreT::size_type nStart,
typename StoreT::size_type nEnd,
270 FuncElem& rFuncElem, FuncElse& rFuncElse)
272 typedef std::pair<typename StoreT::const_iterator, typename StoreT::size_type> PositionType;
274 PositionType aPos = rStore.position(itPos, nStart);
275 typename StoreT::const_iterator it = aPos.first;
276 typename StoreT::size_type nOffset = aPos.second;
277 typename StoreT::size_type nDataSize = 0;
278 typename StoreT::size_type nTopRow = nStart;
280 for (; it != rStore.end() && nTopRow <= nEnd; ++it, nOffset = 0, nTopRow += nDataSize)
282 bool bLastBlock =
false;
283 nDataSize = it->size - nOffset;
284 if (nTopRow + nDataSize - 1 > nEnd)
287 nDataSize = nEnd - nTopRow + 1;
293 case Blk1::block_type:
294 EachElem<Blk1, typename Blk1::const_iterator>(*it, nOffset, nDataSize, rFuncElem);
296 case Blk2::block_type:
297 EachElem<Blk2, typename Blk2::const_iterator>(*it, nOffset, nDataSize, rFuncElem);
299 case Blk3::block_type:
300 EachElem<Blk3, typename Blk3::const_iterator>(*it, nOffset, nDataSize, rFuncElem);
302 case Blk4::block_type:
303 EachElem<Blk4, typename Blk4::const_iterator>(*it, nOffset, nDataSize, rFuncElem);
306 rFuncElse(it->type, nTopRow, nDataSize);
316template<
typename StoreT,
typename BlkT,
typename FuncElem,
typename FuncElse>
319 typename StoreT::size_type nTopRow = 0, nDataSize = 0;
320 typename StoreT::iterator it = rStore.begin(), itEnd = rStore.end();
321 for (; it != itEnd; ++it, nTopRow += nDataSize)
323 nDataSize = it->size;
324 if (it->type != BlkT::block_type)
326 rFuncElse(it->type, nTopRow, nDataSize);
330 EachElem<BlkT, typename BlkT::iterator>(*it, rFuncElem);
337template<
typename StoreT,
typename BlkT,
typename FuncElem,
typename FuncElse>
338typename StoreT::iterator
340 const typename StoreT::iterator& itPos, StoreT& rStore,
341 typename StoreT::size_type nStart,
typename StoreT::size_type nEnd,
342 FuncElem& rFuncElem, FuncElse& rFuncElse)
344 typedef std::pair<typename StoreT::iterator, typename StoreT::size_type> PositionType;
346 PositionType aPos = rStore.position(itPos, nStart);
347 typename StoreT::iterator it = aPos.first;
348 typename StoreT::size_type nOffset = aPos.second;
349 typename StoreT::size_type nDataSize = 0;
350 typename StoreT::size_type nTopRow = nStart;
352 for (; it != rStore.end() && nTopRow <= nEnd; ++it, nOffset = 0, nTopRow += nDataSize)
354 bool bLastBlock =
false;
355 nDataSize = it->size - nOffset;
356 if (nTopRow + nDataSize - 1 > nEnd)
359 nDataSize = nEnd - nTopRow + 1;
363 if (it->type == BlkT::block_type)
364 EachElem<BlkT, typename BlkT::iterator>(*it, nOffset, nDataSize, rFuncElem);
366 rFuncElse(it->type, nTopRow, nDataSize);
375template<
typename StoreT,
typename Blk1,
typename Blk2,
typename FuncElem,
typename FuncElse>
378 typename StoreT::size_type nTopRow = 0, nDataSize = 0;
379 typename StoreT::iterator it = rStore.begin(), itEnd = rStore.end();
380 for (; it != itEnd; ++it, nTopRow += nDataSize)
382 nDataSize = it->size;
385 case Blk1::block_type:
386 EachElem<Blk1, typename Blk1::iterator>(*it, rFuncElem);
388 case Blk2::block_type:
389 EachElem<Blk2, typename Blk2::iterator>(*it, rFuncElem);
392 rFuncElse(it->type, nTopRow, nDataSize);
397template<
typename StoreT,
typename Blk1,
typename Blk2,
typename FuncElem,
typename FuncElse>
400 typename StoreT::size_type nTopRow = 0, nDataSize = 0;
401 typename StoreT::iterator it = rStore.begin(), itEnd = rStore.end();
402 for (; it != itEnd; ++it, nTopRow += nDataSize)
404 nDataSize = it->size;
407 case Blk1::block_type:
408 EachElemReverse<Blk1, typename Blk1::iterator>(*it, rFuncElem);
410 case Blk2::block_type:
411 EachElemReverse<Blk2, typename Blk2::iterator>(*it, rFuncElem);
414 rFuncElse(it->type, nTopRow, nDataSize);
419template<
typename StoreT,
typename Blk1,
typename FuncElem,
typename FuncElse>
420std::pair<typename StoreT::const_iterator, typename StoreT::size_type>
422 const StoreT& rStore,
typename StoreT::size_type nStart,
typename StoreT::size_type nEnd,
423 FuncElem& rFuncElem, FuncElse& rFuncElse)
425 typedef std::pair<typename StoreT::const_iterator, typename StoreT::size_type> PositionType;
426 typedef std::pair<typename StoreT::size_type, bool> ElseRetType;
428 PositionType aPos = rStore.position(nStart);
429 typename StoreT::const_iterator it = aPos.first;
430 typename StoreT::size_type nOffset = aPos.second;
431 typename StoreT::size_type nDataSize = 0;
432 typename StoreT::size_type nTopRow = nStart;
434 for (; it != rStore.end() && nTopRow <= nEnd; ++it, nOffset = 0, nTopRow += nDataSize)
436 bool bLastBlock =
false;
437 nDataSize = it->size - nOffset;
438 if (nTopRow + nDataSize - 1 > nEnd)
441 nDataSize = nEnd - nTopRow + 1;
447 case Blk1::block_type:
449 PositionType aRet = CheckElem<Blk1>(rStore, it, nOffset, nDataSize, rFuncElem);
450 if (aRet.first != rStore.end())
456 ElseRetType aRet = rFuncElse(it->type, nTopRow, nDataSize);
458 return PositionType(it, aRet.first);
466 return PositionType(rStore.end(), 0);
469template<
typename StoreT,
typename Blk1,
typename Blk2,
typename FuncElem,
typename FuncElse>
470std::pair<typename StoreT::const_iterator, typename StoreT::size_type>
472 const StoreT& rStore,
typename StoreT::size_type nStart,
typename StoreT::size_type nEnd,
473 FuncElem& rFuncElem, FuncElse& rFuncElse)
475 typedef std::pair<typename StoreT::const_iterator, typename StoreT::size_type> PositionType;
476 typedef std::pair<typename StoreT::size_type, bool> ElseRetType;
478 PositionType aPos = rStore.position(nStart);
479 typename StoreT::const_iterator it = aPos.first;
480 typename StoreT::size_type nOffset = aPos.second;
481 typename StoreT::size_type nDataSize = 0;
482 typename StoreT::size_type nTopRow = nStart;
484 for (; it != rStore.end() && nTopRow <= nEnd; ++it, nOffset = 0, nTopRow += nDataSize)
486 bool bLastBlock =
false;
487 nDataSize = it->size - nOffset;
488 if (nTopRow + nDataSize - 1 > nEnd)
491 nDataSize = nEnd - nTopRow + 1;
497 case Blk1::block_type:
499 PositionType aRet = CheckElem<Blk1>(rStore, it, nOffset, nDataSize, rFuncElem);
500 if (aRet.first != rStore.end())
504 case Blk2::block_type:
506 PositionType aRet = CheckElem<Blk2>(rStore, it, nOffset, nDataSize, rFuncElem);
507 if (aRet.first != rStore.end())
513 ElseRetType aRet = rFuncElse(*it, nOffset, nDataSize);
515 return PositionType(it, aRet.first);
523 return PositionType(rStore.end(), 0);
527template<
typename Blk1,
typename StoreT,
typename FuncElem>
529 StoreT& rStore, FuncElem& rFuncElem)
531 typedef std::pair<typename StoreT::const_iterator, typename StoreT::size_type> PositionType;
533 for (
typename StoreT::iterator it = rStore.begin(); it != rStore.end(); ++it)
535 if (it->type == Blk1::block_type)
537 PositionType firstToEmpty = CheckElem<Blk1>(rStore, it, 0, it->size, rFuncElem);
538 if (firstToEmpty.first != rStore.end())
540 typename StoreT::size_type nFirstOffset = firstToEmpty.second;
541 typename StoreT::size_type nRemainingDataSize = it->size - nFirstOffset;
543 PositionType lastToEmpty = CheckElem<Blk1>(rStore, it, nFirstOffset, nRemainingDataSize,
545 typename StoreT::size_type nLastOffset = lastToEmpty.first != rStore.end()
546 ? lastToEmpty.second - 1 : it->size - 1;
547 it = rStore.set_empty(it, it->position + nFirstOffset, it->position + nLastOffset);
CAUTION! The following defines must be in the same namespace as the respective type.
std::pair< typename StoreT::const_iterator, size_t > CheckElem(const StoreT &rStore, const typename StoreT::const_iterator &it, size_t nOffset, size_t nDataSize, FuncElem &rFuncElem)
void ProcessElements2(StoreT &rStore, FuncElem &rFuncElem, FuncElse &rFuncElse)
StoreT::const_iterator ParseBlock(const typename StoreT::const_iterator &itPos, const StoreT &rStore, Func &rFunc, typename StoreT::size_type nStart, typename StoreT::size_type nEnd)
Generic algorithm to parse blocks of multi_type_vector either partially or fully.
std::pair< typename StoreT::const_iterator, typename StoreT::size_type > FindElement1(const StoreT &rStore, typename StoreT::size_type nStart, typename StoreT::size_type nEnd, FuncElem &rFuncElem, FuncElse &rFuncElse)
StoreT::iterator ProcessBlock(const typename StoreT::iterator &itPos, StoreT &rStore, Func &rFunc, typename StoreT::size_type nStart, typename StoreT::size_type nEnd)
Non-const variant of the above function.
void EachElem(NodeT &rNode, size_t nOffset, size_t nDataSize, FuncElem &rFuncElem)
void ParseElements1(const StoreT &rStore, FuncElem &rFuncElem, FuncElse &rFuncElse)
StoreT::const_iterator ParseElements4(const typename StoreT::const_iterator &itPos, const StoreT &rStore, typename StoreT::size_type nStart, typename StoreT::size_type nEnd, FuncElem &rFuncElem, FuncElse &rFuncElse)
void ProcessElements2Reverse(StoreT &rStore, FuncElem &rFuncElem, FuncElse &rFuncElse)
void ProcessElements1(StoreT &rStore, FuncElem &rFuncElem, FuncElse &rFuncElse)
void EachElemReverse(NodeT &rNode, FuncElem &rFuncElem)
void SetElementsToEmpty1(StoreT &rStore, FuncElem &rFuncElem)
const mdds::mtv::element_t element_type_empty
StoreT::const_iterator ParseElements2(const typename StoreT::const_iterator &itPos, const StoreT &rStore, typename StoreT::size_type nStart, typename StoreT::size_type nEnd, FuncElem &rFuncElem, FuncElse &rFuncElse)
std::pair< typename StoreT::const_iterator, typename StoreT::size_type > FindElement2(const StoreT &rStore, typename StoreT::size_type nStart, typename StoreT::size_type nEnd, FuncElem &rFuncElem, FuncElse &rFuncElse)
Ret operator()(mdds::mtv::element_t, SizeT, SizeT) const
bool operator()(size_t s, Elem elem) const