Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_BASEBMP_STRIDEDARRAYITERATOR_HXX
21 : #define INCLUDED_BASEBMP_STRIDEDARRAYITERATOR_HXX
22 :
23 : #include <basebmp/metafunctions.hxx>
24 :
25 : namespace basebmp
26 : {
27 :
28 : /** Like vigra::StridedArrayIterator
29 :
30 : Changed semantics re. DirectionSelector<StridedArrayTag>: stride
31 : now counts in <em>raw</em> bytes
32 :
33 : Adapts given ptr, in a way that iterator increments move forward
34 : in strided steps. Stride can, by the way, also be negative
35 : */
36 : template< typename T > class StridedArrayIterator
37 : {
38 : public:
39 : typedef typename clone_const<T, unsigned char>::type internal_type;
40 :
41 : /** Create iterator
42 :
43 : @param stride
44 :
45 : Stride in bytes. Given value should better match memory layout
46 : of T, as memory gets reinterpret-casted.
47 : */
48 1830472 : explicit StridedArrayIterator(int stride, T* ptr = 0) :
49 : stride_(stride),
50 1830472 : current_(reinterpret_cast<internal_type*>(ptr))
51 1830472 : {}
52 :
53 : /** Copy from other StridedArrayIterator, plus given offset
54 :
55 : @param offset
56 : Offset in bytes
57 : */
58 2097783 : StridedArrayIterator( StridedArrayIterator const& rSrc,
59 : int offset ) :
60 : stride_(rSrc.stride_),
61 : current_(reinterpret_cast<internal_type*>(
62 2097783 : reinterpret_cast<T*>(rSrc.current_)+offset))
63 2097783 : {}
64 :
65 200244191 : void operator++() {current_ += stride_; }
66 : void operator++(int) {current_ += stride_; }
67 : void operator--() {current_ -= stride_; }
68 : void operator--(int) {current_ -= stride_; }
69 250273381 : void operator+=(int dy) {current_ += dy*stride_; }
70 : void operator-=(int dy) {current_ -= dy*stride_; }
71 :
72 21827633 : int operator-(StridedArrayIterator const & rhs) const
73 21827633 : { return (current_ - rhs.current_) / stride_; }
74 :
75 2732 : bool operator==(StridedArrayIterator const & rhs) const
76 2732 : { return current_ == rhs.current_; }
77 :
78 : bool operator!=(StridedArrayIterator const & rhs) const
79 : { return current_ != rhs.current_; }
80 :
81 21769283 : bool operator<(StridedArrayIterator const & rhs) const
82 21769283 : { return *this - rhs < 0; }
83 :
84 : bool operator<=(StridedArrayIterator const & rhs) const
85 : { return *this - rhs <= 0; }
86 :
87 : bool operator>(StridedArrayIterator const & rhs) const
88 : { return *this - rhs > 0; }
89 :
90 : bool operator>=(StridedArrayIterator const & rhs) const
91 : { return *this - rhs >= 0; }
92 :
93 486808633 : T* operator()() const
94 486808633 : { return reinterpret_cast<T*>(current_); }
95 :
96 : T* operator()(int d) const
97 : { return reinterpret_cast<T*>(current_ + d*stride_); }
98 :
99 : private:
100 : int stride_;
101 : internal_type* current_;
102 : };
103 :
104 : } // namespace basebmp
105 :
106 : #endif /* INCLUDED_BASEBMP_STRIDEDARRAYITERATOR_HXX */
107 :
108 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|