1*48cdb363SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*48cdb363SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*48cdb363SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*48cdb363SAndrew Rist * distributed with this work for additional information 6*48cdb363SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*48cdb363SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*48cdb363SAndrew Rist * "License"); you may not use this file except in compliance 9*48cdb363SAndrew Rist * with the License. You may obtain a copy of the License at 10*48cdb363SAndrew Rist * 11*48cdb363SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*48cdb363SAndrew Rist * 13*48cdb363SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*48cdb363SAndrew Rist * software distributed under the License is distributed on an 15*48cdb363SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*48cdb363SAndrew Rist * KIND, either express or implied. See the License for the 17*48cdb363SAndrew Rist * specific language governing permissions and limitations 18*48cdb363SAndrew Rist * under the License. 19*48cdb363SAndrew Rist * 20*48cdb363SAndrew Rist *************************************************************/ 21*48cdb363SAndrew Rist 22*48cdb363SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef INCLUDED_BASEBMP_ACCESSOR_HXX 25cdf0e10cSrcweir #define INCLUDED_BASEBMP_ACCESSOR_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <vigra/numerictraits.hxx> 28cdf0e10cSrcweir 29cdf0e10cSrcweir namespace basebmp 30cdf0e10cSrcweir { 31cdf0e10cSrcweir 32cdf0e10cSrcweir /** Standard accessor type 33cdf0e10cSrcweir 34cdf0e10cSrcweir Accesses the iterator values the standard way (i.e. via 35cdf0e10cSrcweir *operator()/operator[]) 36cdf0e10cSrcweir */ 37cdf0e10cSrcweir template<typename ValueType> class StandardAccessor 38cdf0e10cSrcweir { 39cdf0e10cSrcweir public: 40cdf0e10cSrcweir typedef ValueType value_type; 41cdf0e10cSrcweir 42cdf0e10cSrcweir // ------------------------------------------------------- 43cdf0e10cSrcweir 44cdf0e10cSrcweir template< class Iterator > operator ()(Iterator const & i) const45cdf0e10cSrcweir value_type operator()(Iterator const& i) const 46cdf0e10cSrcweir { 47cdf0e10cSrcweir return *i; 48cdf0e10cSrcweir } 49cdf0e10cSrcweir 50cdf0e10cSrcweir template< class Iterator, class Difference > operator ()(Iterator const & i,Difference const & diff) const51cdf0e10cSrcweir value_type operator()(Iterator const& i, Difference const& diff) const 52cdf0e10cSrcweir { 53cdf0e10cSrcweir return i[diff]; 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56cdf0e10cSrcweir // ------------------------------------------------------- 57cdf0e10cSrcweir 58cdf0e10cSrcweir template< typename V, class Iterator > set(V const & value,Iterator const & i) const59cdf0e10cSrcweir void set(V const& value, Iterator const& i) const 60cdf0e10cSrcweir { 61cdf0e10cSrcweir *i = vigra::detail::RequiresExplicitCast<value_type>::cast(value); 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir template< typename V, class Iterator, class Difference > set(V const & value,Iterator const & i,Difference const & diff) const65cdf0e10cSrcweir void set(V const& value, Iterator const& i, Difference const& diff) const 66cdf0e10cSrcweir { 67cdf0e10cSrcweir i[diff] = vigra::detail::RequiresExplicitCast<value_type>::cast(value); 68cdf0e10cSrcweir } 69cdf0e10cSrcweir }; 70cdf0e10cSrcweir 71cdf0e10cSrcweir //----------------------------------------------------------------------------- 72cdf0e10cSrcweir 73cdf0e10cSrcweir /** Non-standard accessor type 74cdf0e10cSrcweir 75cdf0e10cSrcweir Uses getter/setter methods at the given iterator type, to access 76cdf0e10cSrcweir the underlying values. 77cdf0e10cSrcweir */ 78cdf0e10cSrcweir template<typename ValueType> class NonStandardAccessor 79cdf0e10cSrcweir { 80cdf0e10cSrcweir public: 81cdf0e10cSrcweir typedef ValueType value_type; 82cdf0e10cSrcweir 83cdf0e10cSrcweir // ------------------------------------------------------- 84cdf0e10cSrcweir 85cdf0e10cSrcweir template< class Iterator > operator ()(Iterator const & i) const86cdf0e10cSrcweir value_type operator()(Iterator const& i) const 87cdf0e10cSrcweir { 88cdf0e10cSrcweir return i.get(); 89cdf0e10cSrcweir } 90cdf0e10cSrcweir 91cdf0e10cSrcweir template< class Iterator, class Difference > operator ()(Iterator const & i,Difference const & diff) const92cdf0e10cSrcweir value_type operator()(Iterator const& i, Difference const& diff) const 93cdf0e10cSrcweir { 94cdf0e10cSrcweir return i.get(diff); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir // ------------------------------------------------------- 98cdf0e10cSrcweir 99cdf0e10cSrcweir template< typename V, class Iterator > set(V const & value,Iterator const & i) const100cdf0e10cSrcweir void set(V const& value, Iterator const& i) const 101cdf0e10cSrcweir { 102cdf0e10cSrcweir i.set( vigra::detail::RequiresExplicitCast<value_type>::cast(value) ); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir template< typename V, class Iterator, class Difference > set(V const & value,Iterator const & i,Difference const & diff) const106cdf0e10cSrcweir void set(V const& value, Iterator const& i, Difference const& diff) const 107cdf0e10cSrcweir { 108cdf0e10cSrcweir i.set( vigra::detail::RequiresExplicitCast<value_type>::cast(value), 109cdf0e10cSrcweir diff ); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir }; 112cdf0e10cSrcweir 113cdf0e10cSrcweir } // namespace basebmp 114cdf0e10cSrcweir 115cdf0e10cSrcweir #endif /* INCLUDED_BASEBMP_ACCESSOR_HXX */ 116