~ubuntu-branches/ubuntu/wily/bombono-dvd/wily

« back to all changes in this revision

Viewing changes to src/mlib/adobe/algorithm/copy.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-11-04 11:46:25 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20101104114625-8xfdhvhpsm51i0nu
Tags: upstream-0.8.0
ImportĀ upstreamĀ versionĀ 0.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright 2005-2007 Adobe Systems Incorporated
 
3
    Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
 
4
    or a copy at http://stlab.adobe.com/licenses.html)
 
5
*/
 
6
 
 
7
/*************************************************************************************************/
 
8
 
 
9
#ifndef ADOBE_ALGORITHM_COPY_HPP
 
10
#define ADOBE_ALGORITHM_COPY_HPP
 
11
 
 
12
#include <mlib/adobe/config.hpp>
 
13
 
 
14
#include <boost/range/begin.hpp>
 
15
#include <boost/range/end.hpp>
 
16
#include <boost/range/size.hpp>
 
17
 
 
18
#include <algorithm>
 
19
#include <iterator>
 
20
 
 
21
/*************************************************************************************************/
 
22
 
 
23
namespace adobe {
 
24
 
 
25
/*************************************************************************************************/
 
26
/*!
 
27
\defgroup copy copy
 
28
\ingroup mutating_algorithm
 
29
 
 
30
\see
 
31
    - STL documentation for \ref stldoc_copy
 
32
    - STL documentation for \ref stldoc_copy_n
 
33
    - STL documentation for \ref stldoc_copy_backward
 
34
*/
 
35
/*************************************************************************************************/
 
36
 
 
37
/*!
 
38
    \ingroup copy
 
39
 
 
40
    \brief copy implementation
 
41
*/
 
42
template <class InputRange, class OutputIterator>
 
43
inline OutputIterator copy(const InputRange& range, OutputIterator result)
 
44
{
 
45
    return std::copy(boost::begin(range), boost::end(range), result);
 
46
}
 
47
 
 
48
/*!
 
49
    \ingroup copy
 
50
 
 
51
    \brief copy implementation
 
52
*/
 
53
template <class BidirectionalRange1, class BidirectionalIterator2>
 
54
inline BidirectionalIterator2 copy_backward(BidirectionalRange1& range1, BidirectionalIterator2 result)
 
55
{
 
56
    return std::copy_backward(boost::begin(range1), boost::end(range1), result);
 
57
}
 
58
 
 
59
/*!
 
60
    \ingroup copy
 
61
 
 
62
    \brief copy implementation
 
63
*/
 
64
template <class BidirectionalRange1, class BidirectionalIterator2>
 
65
inline BidirectionalIterator2 copy_backward(const BidirectionalRange1& range1, BidirectionalIterator2 result)
 
66
{
 
67
    return std::copy_backward(boost::begin(range1), boost::end(range1), result);
 
68
}
 
69
 
 
70
/*************************************************************************************************/
 
71
#ifndef ADOBE_NO_DOCUMENTATION
 
72
namespace implementation {
 
73
 
 
74
/*************************************************************************************************/
 
75
/*!
 
76
    \ingroup copy
 
77
    \brief taken from SGI STL.
 
78
*/
 
79
template <class InputIter, class Size, class OutputIter>
 
80
std::pair<InputIter, OutputIter> copy_n(InputIter first, Size count,
 
81
                                        OutputIter result,
 
82
                                        std::input_iterator_tag) 
 
83
{
 
84
   for ( ; count > 0; --count) {
 
85
      *result = *first;
 
86
      ++first;
 
87
      ++result;
 
88
   }
 
89
   return std::pair<InputIter, OutputIter>(first, result);
 
90
}
 
91
 
 
92
/*!
 
93
    \ingroup copy
 
94
 
 
95
    \brief copy implementation
 
96
*/
 
97
template <class RAIter, class Size, class OutputIter>
 
98
inline std::pair<RAIter, OutputIter>
 
99
copy_n(RAIter first, Size count, OutputIter result, std::random_access_iterator_tag) 
 
100
{
 
101
   RAIter last = first + count;
 
102
   return std::pair<RAIter, OutputIter>(last, std::copy(first, last, result));
 
103
}
 
104
 
 
105
/*************************************************************************************************/
 
106
 
 
107
} // namespace implementation
 
108
#endif
 
109
/*************************************************************************************************/
 
110
 
 
111
/*!
 
112
    \ingroup copy
 
113
 
 
114
    \brief copy implementation
 
115
*/
 
116
template <class InputIter, class Size, class OutputIter>
 
117
inline std::pair<InputIter, OutputIter> copy_n(InputIter first, Size count, OutputIter result) 
 
118
{
 
119
    return implementation::copy_n(first, count, result,
 
120
        typename std::iterator_traits<InputIter>::iterator_category());
 
121
}
 
122
 
 
123
/*************************************************************************************************/
 
124
 
 
125
#ifndef ADOBE_NO_DOCUMENTATION
 
126
namespace implementation {
 
127
 
 
128
/*************************************************************************************************/
 
129
/*!
 
130
    \ingroup copy
 
131
 
 
132
    REVIST (sparent) : There is an assumption here that the difference types of the two ranges are
 
133
    the same.  We need a way to promote the smaller integral type to the larger.
 
134
*/
 
135
template <typename I, // I models RandomAccessIterator
 
136
          typename F> // F models RandomAccessIterator
 
137
inline std::pair<I, F> copy_bounded(I first, I last,
 
138
                                  F result_first, F result_last,
 
139
                                  std::random_access_iterator_tag, std::random_access_iterator_tag)
 
140
{
 
141
    return adobe::copy_n(first, std::min(last - first, result_last - result_first), result_first);
 
142
}
 
143
 
 
144
/*!
 
145
    \ingroup copy
 
146
 
 
147
    \brief copy implementation
 
148
*/
 
149
template <typename I, // I models InputIterator
 
150
          typename F> // F models ForwardIterator
 
151
inline std::pair<I, F> copy_bounded(I first, I last,
 
152
                                    F result_first, F result_last,
 
153
                                    std::input_iterator_tag, std::forward_iterator_tag)
 
154
{
 
155
    while (first != last && result_first != result_last)
 
156
    {
 
157
        *result_first = *first;
 
158
        ++first; ++result_first;
 
159
    }
 
160
    
 
161
    return std::make_pair(first, result_first);
 
162
}
 
163
 
 
164
/*************************************************************************************************/
 
165
 
 
166
} // namespace implementation
 
167
#endif
 
168
 
 
169
/*************************************************************************************************/
 
170
/*!
 
171
    \ingroup copy
 
172
 
 
173
    \brief copy implementation
 
174
*/
 
175
template <typename I, // I models InputIterator
 
176
          typename F> // F models ForwardIterator
 
177
inline std::pair<I, F> copy_bounded(I first, I last, F result_first, F result_last)
 
178
{
 
179
    return implementation::copy_bounded(first, last, result_first, result_last,
 
180
        typename std::iterator_traits<I>::iterator_category(),
 
181
        typename std::iterator_traits<F>::iterator_category());
 
182
}
 
183
 
 
184
/*************************************************************************************************/
 
185
 
 
186
/*!
 
187
    \ingroup copy
 
188
    
 
189
    \brief copy implementation
 
190
*/
 
191
template <typename I, // I models InputIterator
 
192
          typename O, // O models OutputIterator
 
193
          typename T> // T == value_type(I)
 
194
inline std::pair<I, O> copy_sentinal(I f, O o, const T& x)
 
195
{
 
196
    while (*f != x) {
 
197
        *o = *f;
 
198
        ++f, ++o;
 
199
    }
 
200
    return std::make_pair(f, o);
 
201
}
 
202
 
 
203
/*************************************************************************************************/
 
204
 
 
205
/*!
 
206
    \ingroup copy
 
207
    
 
208
    \brief copy implementation
 
209
*/
 
210
template <typename I, // I models InputIterator
 
211
          typename O> // O models OutputIterator
 
212
inline std::pair<I, O> copy_sentinal(I f, O o)
 
213
{
 
214
    return copy_sentinal(f, o, typename std::iterator_traits<I>::value_type());
 
215
}
 
216
 
 
217
/*************************************************************************************************/
 
218
 
 
219
} // namespace adobe
 
220
 
 
221
/*************************************************************************************************/
 
222
 
 
223
#endif
 
224
 
 
225
/*************************************************************************************************/