1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_BASEBMP_ACCESSORTRAITS_HXX
25 #define INCLUDED_BASEBMP_ACCESSORTRAITS_HXX
26 
27 #include <basebmp/accessorfunctors.hxx>
28 #include <basebmp/accessoradapters.hxx>
29 #include <basebmp/metafunctions.hxx>
30 
31 #include <functional>
32 
33 namespace basebmp
34 {
35 
36 struct FastMask;
37 struct NoFastMask;
38 
39 /// Metafunction to select output mask functor from iterator and mask value type
40 template< typename T, typename M, bool polarity, typename DUMMY > struct outputMaskFunctorSelector : public
41     ifBothScalarIntegral< T, M,
42                           IntegerOutputMaskFunctor< T, M, polarity >,
43                           GenericOutputMaskFunctor< T, M, polarity > >
44 {
45 };
46 template< typename T, typename M, bool polarity > struct outputMaskFunctorSelector< T, M, polarity, FastMask > : public
47     ifBothScalarIntegral< T, M,
48                           FastIntegerOutputMaskFunctor< T, M, polarity >,
49                           GenericOutputMaskFunctor< T, M, polarity > >
50 {
51 };
52 
53 /** Metafunction providing a point of configuration for iterators
54     capable of employing the fast output mask functor.
55 
56     Specialize this metafunction for your case, and pass FastMask to
57     the outputMaskFunctorSelector.
58  */
59 template< class Accessor,
60           class MaskAccessor,
61           class Iterator,
62           class MaskIterator,
63           bool  polarity > struct maskedAccessorSelector
64 {
65     typedef TernarySetterFunctionAccessorAdapter<
66         Accessor,
67         MaskAccessor,
68         typename outputMaskFunctorSelector<
69             typename Accessor::value_type,
70             typename MaskAccessor::value_type,
71             polarity,
72             NoFastMask > ::type >
73         type;
74 };
75 
76 //-----------------------------------------------------------------------------
77 
78 /** Traits template for Accessor
79 
80     Provides wrapped types for color lookup, raw pixel access, xor and
81     mask accessors.
82  */
83 template< class Accessor > struct AccessorTraits
84 {
85     /// value type of described accessor
86     typedef typename Accessor::value_type           value_type;
87 
88     /// Retrieve stand-alone color lookup function for given Accessor type
89     typedef std::project2nd< Accessor, value_type > color_lookup;
90 
91     /// Retrieve raw pixel data accessor for given Accessor type
92     typedef Accessor                                raw_accessor;
93 
94     /// Retrieve wrapped accessor for XOR setter access
95     typedef BinarySetterFunctionAccessorAdapter<
96         Accessor,
97         XorFunctor< value_type > >                  xor_accessor;
98 
99     /** Retrieve masked accessor for given types
100 
101         A masked accessor works like a filter, where the mask gates
102         the accessor's setter methods (if the mask contains a 0 at a
103         given iterator position, the original value is
104         preserved. Otherwise, the new value gets set).
105 
106         @attention be careful when retrieving a masked accessor for a
107         set of types, and using it for a different one - there are
108         partial specializations that take an optimized functor for
109         certain mask accessors.
110      */
111     template< class MaskAccessor,
112               class Iterator,
113               class MaskIterator,
114               bool  polarity > struct               masked_accessor :
115         public maskedAccessorSelector< Accessor,
116                                        MaskAccessor,
117                                        Iterator,
118                                        MaskIterator,
119                                        polarity >
120     {};
121 
122 };
123 
124 } // namespace basebmp
125 
126 #endif /* INCLUDED_BASEBMP_ACCESSORTRAITS_HXX */
127