~ubuntu-branches/ubuntu/oneiric/bombono-dvd/oneiric

« back to all changes in this revision

Viewing changes to src/mlib/range/my_adaptors.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-11-04 11:46:25 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20101104114625-2tfaxma74eqggp5r
Tags: 0.8.0-0ubuntu1
* New upstream release (LP: #670193).
* Refresh 02_sparc.diff patch.
* Replace 05-boost_filesystem-link.patch with 05-fix_boost.patch, it fixes
  build failure with Boost <= 1.44.
* Bump Standards.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// mlib/range/my_adaptors.h
 
3
// This file is part of Bombono DVD project.
 
4
//
 
5
// Copyright (c) 2010 Ilya Murav'jov
 
6
//
 
7
// This program is free software; you can redistribute it and/or modify
 
8
// it under the terms of the GNU General Public License as published by
 
9
// the Free Software Foundation; either version 2 of the License, or
 
10
// (at your option) any later version.
 
11
//
 
12
// This program is distributed in the hope that it will be useful,
 
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
// GNU General Public License for more details.
 
16
//
 
17
// You should have received a copy of the GNU General Public License
 
18
// along with this program; if not, write to the Free Software
 
19
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
20
// 
 
21
 
 
22
#ifndef __MLIB_RANGE_MY_ADAPTORS_H__
 
23
#define __MLIB_RANGE_MY_ADAPTORS_H__
 
24
 
 
25
#include <boost/range/iterator_range.hpp>
 
26
#include <boost/iterator/transform_iterator.hpp>
 
27
#include <boost/iterator/filter_iterator.hpp>
 
28
 
 
29
namespace RangeAdaptor {
 
30
 
 
31
// 
 
32
// transform
 
33
// 
 
34
 
 
35
// :TODO: рефакторинг range_transform & range_filter
 
36
template <class Range, class UnaryFunc> 
 
37
struct range_transform
 
38
{
 
39
    typedef typename boost::range_iterator<Range>::type iterator;
 
40
    typedef boost::transform_iterator<UnaryFunc, iterator> op_iterator;
 
41
    typedef boost::iterator_range<op_iterator> type;
 
42
};
 
43
 
 
44
template <class Range, class UnaryFunc>
 
45
typename range_transform<Range, UnaryFunc>::type
 
46
_transform(Range& r, const UnaryFunc& f)
 
47
{
 
48
    typedef typename boost::range_iterator<Range>::type iterator;
 
49
    iterator beg = boost::begin(r), end = boost::end(r);
 
50
 
 
51
    typedef boost::transform_iterator<UnaryFunc, iterator> op_iterator;
 
52
    return boost::iterator_range<op_iterator>(op_iterator(beg, f), op_iterator(end, f));
 
53
}
 
54
 
 
55
template <class Range, class UnaryFunc>
 
56
typename range_transform<Range, UnaryFunc>::type
 
57
transform(Range& r, const UnaryFunc& f)
 
58
{
 
59
    return _transform(r, f);
 
60
}
 
61
 
 
62
template <class Range, class UnaryFunc>
 
63
typename range_transform<const Range, UnaryFunc>::type
 
64
transform(const Range& r, const UnaryFunc& f)
 
65
{
 
66
    return _transform(r, f);
 
67
}
 
68
 
 
69
//
 
70
// filter
 
71
// 
 
72
 
 
73
template <class Range, class Predicate>
 
74
struct range_filter
 
75
{
 
76
    typedef typename boost::range_iterator<Range>::type iterator;
 
77
    typedef boost::filter_iterator<Predicate, iterator> op_iterator;
 
78
    typedef boost::iterator_range<op_iterator> type;
 
79
};
 
80
 
 
81
template <class Range, class Predicate>
 
82
typename range_filter<Range, Predicate>::type 
 
83
_filter(Range& r, const Predicate& f)
 
84
{
 
85
    typedef typename boost::range_iterator<Range>::type iterator;
 
86
    iterator beg = boost::begin(r), end = boost::end(r);
 
87
 
 
88
    typedef boost::filter_iterator<Predicate, iterator> op_iterator;
 
89
    return boost::iterator_range<op_iterator>(op_iterator(f, beg, end), op_iterator(f, end, end));
 
90
}
 
91
 
 
92
template <class Range, class Predicate>
 
93
typename range_filter<Range, Predicate>::type 
 
94
filter(Range& r, const Predicate& f)
 
95
{
 
96
    return _filter(r, f);
 
97
}
 
98
 
 
99
template <class Range, class Predicate>
 
100
typename range_filter<const Range, Predicate>::type 
 
101
filter(const Range& r, const Predicate& f)
 
102
{
 
103
    return _filter(r, f);
 
104
}
 
105
 
 
106
} // namespace RangeAdaptor
 
107
 
 
108
#endif // #ifndef __MLIB_RANGE_MY_ADAPTORS_H__
 
109