LeechCraft  0.6.70-13729-g7046a9d2a7
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 
36 namespace LC
37 {
38 namespace Util
39 {
40 namespace Views
41 {
42  namespace detail
43  {
44  template<template<typename, typename> class PairType, typename FirstIt, typename SecondIt>
45  using ValueType_t = PairType<typename std::iterator_traits<FirstIt>::value_type, typename std::iterator_traits<SecondIt>::value_type>;
46 
47  template<template<typename, typename> class PairType, typename FirstIt, typename SecondIt>
48  class PairIterator : public std::iterator<std::forward_iterator_tag, ValueType_t<PairType, FirstIt, SecondIt>>
49  {
50  bool IsSentinel_;
51 
52  FirstIt First_;
53  FirstIt FirstEnd_;
54  SecondIt Second_;
55  SecondIt SecondEnd_;
56  public:
58  : IsSentinel_ { true }
59  {
60  }
61 
62  PairIterator (const FirstIt& first, const FirstIt& firstEnd,
63  const SecondIt& second, const SecondIt& secondEnd)
64  : IsSentinel_ { false }
65  , First_ { first }
66  , FirstEnd_ { firstEnd }
67  , Second_ { second }
68  , SecondEnd_ { secondEnd }
69  {
70  }
71 
72  bool operator== (const PairIterator& other) const
73  {
74  return (IsSentinel () && other.IsSentinel ()) ||
75  (First_ == other.First_ && Second_ == other.Second_);
76  }
77 
78  bool operator!= (const PairIterator& other) const
79  {
80  return !(*this == other);
81  }
82 
83  bool IsSentinel () const
84  {
85  return IsSentinel_ || First_ == FirstEnd_ || Second_ == SecondEnd_;
86  }
87 
89  {
90  ++First_;
91  ++Second_;
92  return *this;
93  }
94 
96  {
97  auto it = *this;
98 
99  ++First_;
100  ++Second_;
101 
102  return it;
103  }
104 
105  PairType<typename std::iterator_traits<FirstIt>::value_type, typename std::iterator_traits<SecondIt>::value_type> operator* () const
106  {
107  return { *First_, *Second_ };
108  }
109  };
110 
111  template<typename I1, typename I2, template<typename, typename> class PairType>
112  class ZipRange : public boost::iterator_range<PairIterator<PairType, I1, I2>>
113  {
115  public:
116  template<typename C1, typename C2>
117  ZipRange (C1&& c1, C2&& c2)
118  : boost::iterator_range<IteratorType_t>
119  {
120  IteratorType_t { c1.begin (), c1.end (), c2.begin (), c2.end () },
121  IteratorType_t {}
122  }
123  {
124  }
125  };
126  }
127 
128  template<template<typename, typename> class PairType = QPair, typename C1, typename C2>
130  {
131  return { c1, c2 };
132  }
133 }
134 }
135 }
PairType< typename std::iterator_traits< FirstIt >::value_type, typename std::iterator_traits< SecondIt >::value_type > operator*() const
Definition: views.h:105
Definition: prelude.h:38
PairType< typename std::iterator_traits< FirstIt >::value_type, typename std::iterator_traits< SecondIt >::value_type > ValueType_t
Definition: views.h:45
bool operator!=(const PairIterator &other) const
Definition: views.h:78
detail::ZipRange< typename C1::const_iterator, typename C2::const_iterator, PairType > Zip(const C1 &c1, const C2 &c2)
Definition: views.h:129
ZipRange(C1 &&c1, C2 &&c2)
Definition: views.h:117
bool operator==(const PairIterator &other) const
Definition: views.h:72
PairIterator(const FirstIt &first, const FirstIt &firstEnd, const SecondIt &second, const SecondIt &secondEnd)
Definition: views.h:62
Definition: constants.h:35