1 #ifndef color__internal_utility_container_unsigned
2 #define color__internal_utility_container_unsigned
3 
4 // ::color::_internal::utility::container::Unsigned< unsigned_name,  index_name,  length, width>
5 
6 #include "../type/index.hpp"
7 #include "../type/size.hpp"
8 #include "../type/traitp.hpp"
9 
10 
11 
12 namespace color
13  {
14   namespace _internal
15    {
16     namespace utility
17      {
18       namespace container
19        {
20 
21         template< typename unsigned_name, typename value_name, typename index_name, unsigned length, unsigned width >
22          struct Unsigned
23           {
24            public:
25              typedef unsigned_name  unsigned_type;
26              typedef value_name     value_type;
27              typedef index_name     index_type;
28              typedef unsigned_name  instance_type;
29 
30              typedef ::color::_internal::utility::container::Unsigned<unsigned_name,value_name,index_name,length,width> this_type;
31 
32              typedef instance_type const      const_type;
33              typedef instance_type const&     return_image_type;
34              typedef instance_type      &     return_type;
35              typedef instance_type      &     return_original_type;
36              typedef instance_type const&     model_type;
37              typedef instance_type      &     input_type;
38              typedef instance_type      &     output_type;
39 
40              typedef ::color::_internal::utility::type::index< index_type >   index_trait_type;
41 
42              typedef typename index_trait_type::instance_type     index_instance_type;
43              typedef typename index_trait_type::model_type  index_input_const_type;
44 
45              typedef typename index_trait_type::return_image_type index_return_image_type;
46 
47              typedef ::color::_internal::utility::type::traitP< value_name >         component_trait_type;
48 
49              typedef typename component_trait_type::instance_type        component_type;
50              typedef typename component_trait_type::const_type           component_const_type;
51              typedef typename component_trait_type::return_image_type    component_return_const_type;
52              typedef typename component_trait_type::model_type     component_input_const_type;
53 
54              typedef ::color::_internal::utility::type::size< std::size_t >   size_trait_type;
55 
56              typedef typename size_trait_type::return_image_type        size_return_image_type;
57              typedef typename size_trait_type::instance_type            size_instance_type;
58 
59              typedef void set_return_type;
60 
61              enum { size_entity = length };
62 
63 
initcolor::_internal::utility::container::Unsigned64              static set_return_type init( input_type container, index_input_const_type index, component_input_const_type value )
65               {
66                this_type::set( container, index, value );
67               }
68 
69              template< index_instance_type index >
initcolor::_internal::utility::container::Unsigned70               static set_return_type init( input_type container, component_input_const_type value )
71                {
72                 this_type:: template set<index>( container, value );
73                }
74 
getcolor::_internal::utility::container::Unsigned75              static component_return_const_type get( model_type container, index_input_const_type index )
76               {
77                return (component_type)(  ( container >> (  index *  width  ) ) & mask() );
78               }
79 
80              template< index_instance_type index >
getcolor::_internal::utility::container::Unsigned81               static component_return_const_type get( model_type container )
82                {
83                 //TODO C++14 static_assert( index <  length, "Index is out of range." );
84                 return (component_type)(  ( container >> (  index * width  ) ) & mask() );
85                }
86 
setcolor::_internal::utility::container::Unsigned87              static set_return_type set( input_type container, index_input_const_type index, component_input_const_type value )
88               {
89                container = ( container & ~(  this_type::mask() << ( index * width ) ) )  |  ( ( instance_type(value) << ( index * width ) ) );
90               }
91 
92              template< index_instance_type index >
setcolor::_internal::utility::container::Unsigned93               static set_return_type set( input_type container, component_input_const_type value )
94                {
95                 //TODO C++14 static_assert( index <  length, "Index out of range." );
96                 container = ( container & ~(  this_type::mask() << ( index * width ) ) )  |  ( ( instance_type(value) ) << ( index * width ) );
97                }
98 
sizecolor::_internal::utility::container::Unsigned99              static /*constexpr*/ size_return_image_type size()
100               {
101                static const size_instance_type local_length = size_entity;
102                return local_length;
103               }
104             private:
maskcolor::_internal::utility::container::Unsigned105               static /*constexpr*/ return_image_type mask()
106                {
107                 static const instance_type local_mask = ((( instance_type(1) << (width-1)) - instance_type(1) )<< 1) + instance_type(1);
108                 return local_mask;
109                }
110           };
111 
112 
113        }
114      }
115    }
116  }
117 
118 #endif
119