LeechCraft  0.6.70-6645-gcd10d7e
Modular cross-platform feature rich live environment.
views.h
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Boost Software License - Version 1.0 - August 17th, 2003
6  *
7  * Permission is hereby granted, free of charge, to any person or organization
8  * obtaining a copy of the software and accompanying documentation covered by
9  * this license (the "Software") to use, reproduce, display, distribute,
10  * execute, and transmit the Software, and to prepare derivative works of the
11  * Software, and to permit third-parties to whom the Software is furnished to
12  * do so, all subject to the following:
13  *
14  * The copyright notices in the Software and this entire statement, including
15  * the above license grant, this restriction and the following disclaimer,
16  * must be included in all copies of the Software, in whole or in part, and
17  * all derivative works of the Software, unless such copies or derivative
18  * works are solely in the form of machine-executable object code generated by
19  * a source language processor.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
24  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
25  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  **********************************************************************/
29 
30 #pragma once
31 
32 #include <iterator>
33 #include <boost/iterator/zip_iterator.hpp>
34 #include <boost/range.hpp>
35 #include "oldcppkludges.h"
36 
37 namespace LeechCraft
38 {
39 namespace Util
40 {
41 namespace Views
42 {
43  namespace detail
44  {
45  template<template<typename, typename> class PairType, typename FirstIt, typename SecondIt>
46  using ValueType_t = PairType<typename std::iterator_traits<FirstIt>::value_type, typename std::iterator_traits<SecondIt>::value_type>;
47 
48  template<template<typename, typename> class PairType, typename FirstIt, typename SecondIt>
49  class PairIterator : public std::iterator<std::forward_iterator_tag, ValueType_t<PairType, FirstIt, SecondIt>>
50  {
51  bool IsSentinel_;
52 
53  FirstIt First_;
54  FirstIt FirstEnd_;
55  SecondIt Second_;
56  SecondIt SecondEnd_;
57  public:
59  : IsSentinel_ { true }
60  {
61  }
62 
63  PairIterator (const FirstIt& first, const FirstIt& firstEnd,
64  const SecondIt& second, const SecondIt& secondEnd)
65  : IsSentinel_ { false }
66  , First_ { first }
67  , FirstEnd_ { firstEnd }
68  , Second_ { second }
69  , SecondEnd_ { secondEnd }
70  {
71  }
72 
73  bool operator== (const PairIterator& other) const
74  {
75  return (IsSentinel () && other.IsSentinel ()) ||
76  (First_ == other.First_ && Second_ == other.Second_);
77  }
78 
79  bool operator!= (const PairIterator& other) const
80  {
81  return !(*this == other);
82  }
83 
84  bool IsSentinel () const
85  {
86  return IsSentinel_ || First_ == FirstEnd_ || Second_ == SecondEnd_;
87  }
88 
90  {
91  ++First_;
92  ++Second_;
93  return *this;
94  }
95 
97  {
98  auto it = *this;
99 
100  ++First_;
101  ++Second_;
102 
103  return it;
104  }
105 
106  PairType<typename std::iterator_traits<FirstIt>::value_type, typename std::iterator_traits<SecondIt>::value_type> operator* () const
107  {
108  return { *First_, *Second_ };
109  }
110  };
111 
112  template<typename I1, typename I2, template<typename, typename> class PairType>
113  class ZipRange : public boost::iterator_range<PairIterator<PairType, I1, I2>>
114  {
116  public:
117  template<typename C1, typename C2>
118  ZipRange (C1&& c1, C2&& c2)
119  : boost::iterator_range<IteratorType_t>
120  {
121  IteratorType_t { c1.begin (), c1.end (), c2.begin (), c2.end () },
122  IteratorType_t {}
123  }
124  {
125  }
126  };
127  }
128 
129  template<template<typename, typename> class PairType = QPair, typename C1, typename C2>
131  {
132  return { c1, c2 };
133  }
134 }
135 }
136 }
bool operator!=(const PairIterator &other) const
Definition: views.h:79
bool operator==(const PairIterator &other) const
Definition: views.h:73
PairType< typename std::iterator_traits< FirstIt >::value_type, typename std::iterator_traits< SecondIt >::value_type > operator*() const
Definition: views.h:106
PairIterator(const FirstIt &first, const FirstIt &firstEnd, const SecondIt &second, const SecondIt &secondEnd)
Definition: views.h:63
PairType< typename std::iterator_traits< FirstIt >::value_type, typename std::iterator_traits< SecondIt >::value_type > ValueType_t
Definition: views.h:46
detail::ZipRange< typename C1::const_iterator, typename C2::const_iterator, PairType > Zip(const C1 &c1, const C2 &c2)
Definition: views.h:130