1 #ifndef  color_generic_operation_invert_123
2 #define  color_generic_operation_invert_123
3 
4 // ::color::operation::invert<category_name>( model<category_name> )
5 
6 // ::color::operation::_internal::invert<category_name>::component<>( )
7 // ::color::operation::_internal::invert<category_name>::process( )
8 // ::color::operation::_internal::invert<category_name>::process( )
9 
10 #include "../model.hpp"
11 
12 
13 
14 
15 
16 
17 
18  namespace color
19   {
20    namespace operation
21     {
22      namespace _internal
23       {
24 
25        template< typename category_name>
26         struct invert
27          {
28           public:
29             typedef category_name  category_type;
30 
31             typedef ::color::trait::index<category_type>         index_trait_type;
32             typedef ::color::trait::component< category_type >   component_trait_type;
33             typedef ::color::trait::container< category_type >   container_trait_type;
34             typedef ::color::trait::bound<category_type>         bound_type;
35 
36 
37             typedef ::color::model<category_type>  model_type;
38 
39             typedef model_type &       model_output_type;
40             typedef model_type const&  model_const_input_type;
41 
42             typedef model_type  result_type;
43             typedef model_type  left_type, first_argument_type;
44             typedef model_type  right_type, second_argument_type;
45 
46             typedef typename component_trait_type::model_type component_input_const_type;
47             typedef typename component_trait_type::return_type      component_return_type;
48 
49             typedef typename index_trait_type::instance_type     index_type;
50             typedef typename index_trait_type::model_type  index_input_const_type;
51 
52             typedef ::color::operation::_internal::invert<category_type> this_type;
53 
54 
55             static component_return_type
componentcolor::operation::_internal::invert56             component
57              (
58                component_input_const_type component
59               ,index_input_const_type     index
60              )
61              {
62               return bound_type::range( index ) - component;
63              }
64 
65             template< index_type index_size >
66              static
67              component_return_type
componentcolor::operation::_internal::invert68              component( component_input_const_type component )
69              {
70               return bound_type::template range<index_size>() - component;
71              }
72 
73           public:
operator ()color::operation::_internal::invert74             model_type & operator()( model_type & result ) const
75              {
76               return this_type::accumulate( result );
77              }
78 
operator ()color::operation::_internal::invert79             model_type & operator()( model_type &result, model_type const& right ) const
80              {
81               return this_type::process( result, right );
82              }
83 
84           public:
accumulatecolor::operation::_internal::invert85             static model_type & accumulate( model_type &result )
86              {
87               for( index_type index = 0; index < container_trait_type::size(); index ++ )
88                {
89                 result.set( index, component( result.get( index ), index ) );
90                }
91               return result;
92              }
93 
functioncolor::operation::_internal::invert94             static model_type  function( model_type const& right )
95              {
96               model_type result;
97               for( index_type index = 0; index < container_trait_type::size(); index ++ )
98                {
99                 result.set( index, component( right.get( index ), index ) );
100                }
101               return result;
102              }
103 
processcolor::operation::_internal::invert104             static model_type & process( model_type &result, model_type const& right )
105              {
106               for( index_type index = 0; index < container_trait_type::size(); index ++ )
107                {
108                 result.set( index, component( right.get( index ), index ) );
109                }
110               return result;
111              }
112 
113          };
114       }
115 
116 
117      template< typename category_name >
118       ::color::model<category_name>      &
invert(::color::model<category_name> & result)119       invert
120        (
121          ::color::model<category_name>      & result
122        )
123        {
124         return ::color::operation::_internal::invert<category_name>::accumulate( result );
125        }
126 
127      //template< typename category_name >
128      // ::color::model<category_name>
129      // invert
130      //  (
131      //    ::color::model<category_name>      const& input
132      //  )
133      //  { // rejected as confusing during the reading of code
134      //   ::color::model<category_name>      result;
135      //   return ::color::operation::_internal::invert<category_name>::process( result, input );
136      //  }
137 
138      template< typename category_name >
139       ::color::model<category_name>      &
invert(::color::model<category_name> & result,::color::model<category_name> const & right)140       invert
141        (
142          ::color::model<category_name>      & result
143         ,::color::model<category_name> const& right
144        )
145        {
146         return ::color::operation::_internal::invert<category_name>::process( result, right );
147        }
148 
149 
150     }
151   }
152 
153 #endif
154