fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / include / basebmp / stridedarrayiterator.hxx
blob6f5772e527c64cf1e04525a2ab8945bd6d222ba6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_BASEBMP_STRIDEDARRAYITERATOR_HXX
21 #define INCLUDED_BASEBMP_STRIDEDARRAYITERATOR_HXX
23 #include <basebmp/metafunctions.hxx>
25 namespace basebmp
28 /** Like vigra::StridedArrayIterator
30 Changed semantics re. DirectionSelector<StridedArrayTag>: stride
31 now counts in <em>raw</em> bytes
33 Adapts given ptr, in a way that iterator increments move forward
34 in strided steps. Stride can, by the way, also be negative
36 template< typename T > class StridedArrayIterator
38 public:
39 typedef typename clone_const<T, unsigned char>::type internal_type;
41 /** Create iterator
43 @param stride
45 Stride in bytes. Given value should better match memory layout
46 of T, as memory gets reinterpret-casted.
48 explicit StridedArrayIterator(int stride, T* ptr = 0) :
49 stride_(stride),
50 current_(reinterpret_cast<internal_type*>(ptr))
53 /** Copy from other StridedArrayIterator, plus given offset
55 @param offset
56 Offset in bytes
58 StridedArrayIterator( StridedArrayIterator const& rSrc,
59 int offset ) :
60 stride_(rSrc.stride_),
61 current_(reinterpret_cast<internal_type*>(
62 reinterpret_cast<T*>(rSrc.current_)+offset))
65 void operator++() {current_ += stride_; }
66 void operator++(int) {current_ += stride_; }
67 void operator--() {current_ -= stride_; }
68 void operator--(int) {current_ -= stride_; }
69 void operator+=(int dy) {current_ += dy*stride_; }
70 void operator-=(int dy) {current_ -= dy*stride_; }
72 int operator-(StridedArrayIterator const & rhs) const
73 { return (current_ - rhs.current_) / stride_; }
75 bool operator==(StridedArrayIterator const & rhs) const
76 { return current_ == rhs.current_; }
78 bool operator!=(StridedArrayIterator const & rhs) const
79 { return current_ != rhs.current_; }
81 bool operator<(StridedArrayIterator const & rhs) const
82 { return *this - rhs < 0; }
84 bool operator<=(StridedArrayIterator const & rhs) const
85 { return *this - rhs <= 0; }
87 bool operator>(StridedArrayIterator const & rhs) const
88 { return *this - rhs > 0; }
90 bool operator>=(StridedArrayIterator const & rhs) const
91 { return *this - rhs >= 0; }
93 T* operator()() const
94 { return reinterpret_cast<T*>(current_); }
96 T* operator()(int d) const
97 { return reinterpret_cast<T*>(current_ + d*stride_); }
99 private:
100 int stride_;
101 internal_type* current_;
104 } // namespace basebmp
106 #endif /* INCLUDED_BASEBMP_STRIDEDARRAYITERATOR_HXX */
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */