FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
circular_iterator.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** FougTools
3 ** Copyright Fougue (1 Mar. 2011)
4 ** contact@fougue.pro
5 **
6 ** This software is a computer program whose purpose is to provide utility
7 ** tools for the C++ language and the Qt toolkit.
8 **
9 ** This software is governed by the CeCILL-C license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-C
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info".
14 ****************************************************************************/
15 
16 #pragma once
17 
18 namespace cpp {
19 
27 template<typename BI_ITERATOR>
28 BI_ITERATOR circularNext(BI_ITERATOR iBegin, BI_ITERATOR iEnd, BI_ITERATOR iCurr)
29 {
30  if (iCurr == --iEnd)
31  return iBegin;
32  return ++iCurr;
33 }
34 
42 template<typename BI_ITERATOR>
43 BI_ITERATOR circularPrior(BI_ITERATOR iBegin, BI_ITERATOR iEnd, BI_ITERATOR iCurr)
44 {
45  if (iCurr == iBegin)
46  return --iEnd;
47  return --iCurr;
48 }
49 
56 template<typename BI_ITERATOR, typename DISTANCE>
57 BI_ITERATOR circularAdvance(BI_ITERATOR iBegin, BI_ITERATOR iEnd,
58  BI_ITERATOR iCurr, DISTANCE d)
59 {
60  const DISTANCE absD = d < 0 ? -d : d;
61  for (DISTANCE i = 0; i < absD; ++i) {
62  iCurr = d < 0 ? circularPrior(iBegin, iEnd, iCurr) :
63  circularNext(iBegin, iEnd, iCurr);
64  }
65  return iCurr;
66 }
67 
68 } // namespace cpp
Definition: basic_shared_pointer.h:20
BI_ITERATOR circularNext(BI_ITERATOR iBegin, BI_ITERATOR iEnd, BI_ITERATOR iCurr)
Iterator next to iCurr bounded between iBegin and iEnd.
Definition: circular_iterator.h:28
BI_ITERATOR circularPrior(BI_ITERATOR iBegin, BI_ITERATOR iEnd, BI_ITERATOR iCurr)
Iterator prior to iCurr bounded between iBegin and iEnd.
Definition: circular_iterator.h:43
BI_ITERATOR circularAdvance(BI_ITERATOR iBegin, BI_ITERATOR iEnd, BI_ITERATOR iCurr, DISTANCE d)
Iterator advanced by d bounded between iBegin and iEnd.
Definition: circular_iterator.h:57