1 #ifndef color__internal_utility_container_pack3 2 #define color__internal_utility_container_pack3 3 4 // ::color::_internal::utility::container::pack3< index_name > 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 22 < 23 typename container_name, 24 typename component_name, 25 typename index_name 26 ,unsigned first_size, unsigned second_size, unsigned third_size 27 > 28 struct pack3 29 { 30 public: 31 typedef container_name instance_type; 32 typedef component_name value_type; 33 typedef index_name index_type; 34 35 typedef ::color::_internal::utility::container::pack3< container_name, component_name, index_name, first_size, second_size, third_size > this_type; 36 37 38 typedef instance_type const const_type; 39 typedef instance_type const& return_image_type; 40 typedef instance_type & return_type; 41 typedef instance_type & return_original_type; 42 typedef instance_type const& model_type; 43 typedef instance_type & input_type; 44 typedef instance_type & output_type; 45 46 typedef ::color::_internal::utility::type::index< index_type > index_trait_type; 47 48 typedef typename index_trait_type::instance_type index_instance_type; 49 50 typedef typename index_trait_type::model_type index_input_const_type; 51 typedef typename index_trait_type::return_image_type index_return_image_type; 52 53 typedef ::color::_internal::utility::type::traitP< value_type > component_trait_type; 54 55 typedef typename component_trait_type::instance_type component_type; 56 typedef typename component_trait_type::const_type component_const_type; 57 typedef typename component_trait_type::return_image_type component_return_const_type; 58 typedef typename component_trait_type::model_type component_input_const_type; 59 60 typedef ::color::_internal::utility::type::size< std::size_t > size_trait_type; 61 62 typedef typename size_trait_type::return_image_type size_return_image_type; 63 typedef typename size_trait_type::instance_type size_instance_type; 64 65 typedef void set_return_type; 66 67 enum { size_entity = 3 }; 68 enum 69 { 70 first_position = 0, 71 second_position = first_size, 72 third_position = first_size + second_size 73 }; 74 75 enum 76 { 77 first_mask = ( 1 << first_size )-1 , 78 second_mask = ( 1 << second_size )-1 , 79 third_mask = ( 1 << third_size )-1 80 }; 81 82 initcolor::_internal::utility::container::pack383 static set_return_type init( input_type container, index_input_const_type index, component_input_const_type value ) 84 { 85 this_type::set( container, index, value ); 86 } 87 88 template< index_instance_type index > initcolor::_internal::utility::container::pack389 static set_return_type init( input_type container, component_input_const_type value ) 90 { 91 this_type:: template set<index>( container, value ); 92 } 93 94 getcolor::_internal::utility::container::pack395 static component_return_const_type get( model_type container, index_input_const_type index ) 96 { 97 switch( index ) 98 { 99 default: 100 case( 0 ): return ( ( container >> ( first_position ) ) & first_mask ); 101 case( 1 ): return ( ( container >> ( second_position ) ) & second_mask ); 102 case( 2 ): return ( ( container >> ( third_position ) ) & third_mask ); 103 } 104 return 0; 105 } 106 107 template< index_instance_type index > getcolor::_internal::utility::container::pack3108 static component_return_const_type get( model_type container ) 109 { 110 //TODO C++14 static_assert( index < size_entity, "Index is out of range." ); 111 switch( index ) 112 { 113 case( 0 ): return ( ( container >> ( first_position ) ) & first_mask ); 114 case( 1 ): return ( ( container >> ( second_position ) ) & second_mask ); 115 case( 2 ): return ( ( container >> ( third_position ) ) & third_mask ); 116 } 117 return 0; 118 } 119 setcolor::_internal::utility::container::pack3120 static set_return_type set( input_type container, index_input_const_type index, component_input_const_type value ) 121 { 122 switch( index ) 123 { 124 default: 125 case( 0 ) : container = ( container & ~( first_mask << ( first_position ) ) ) | ( ((instance_type)value) << ( first_position ) ); break; 126 case( 1 ) : container = ( container & ~( second_mask << ( second_position ) ) ) | ( ((instance_type)value) << ( second_position ) ); break; 127 case( 2 ) : container = ( container & ~( third_mask << ( third_position ) ) ) | ( ((instance_type)value) << ( third_position ) ); break; 128 } 129 } 130 131 template< index_instance_type index > setcolor::_internal::utility::container::pack3132 static set_return_type set( input_type container, component_input_const_type value ) 133 { 134 //TODO C++14 static_assert( index < size_entity, "Index is out of range." ); 135 switch( index ) 136 { 137 case( 0 ) : container = ( container & ~( first_mask << ( first_position ) ) ) | ( ((instance_type)value) << ( first_position ) ); break; 138 case( 1 ) : container = ( container & ~( second_mask << ( second_position ) ) ) | ( ((instance_type)value) << ( second_position ) ); break; 139 case( 2 ) : container = ( container & ~( third_mask << ( third_position ) ) ) | ( ((instance_type)value) << ( third_position ) ); break; 140 } 141 } 142 sizecolor::_internal::utility::container::pack3143 static /*constexpr*/ size_return_image_type size() 144 { 145 static const size_instance_type local_length = size_entity; 146 return local_length; 147 } 148 }; 149 150 template< typename container_name, typename component_name, unsigned first_size, unsigned second_size, unsigned third_size > 151 using pack3_N_N_t = ::color::_internal::utility::container::pack3< container_name, component_name, unsigned, first_size, second_size, third_size >; 152 153 template< unsigned first_size, unsigned second_size, unsigned third_size > 154 using pack3_8_8_t = ::color::_internal::utility::container::pack3_N_N_t< std::uint8_t, std::uint8_t, first_size, second_size, third_size >; 155 156 template< unsigned first_size, unsigned second_size, unsigned third_size > 157 using pack3_16_8_t = ::color::_internal::utility::container::pack3_N_N_t< std::uint16_t, std::uint8_t, first_size, second_size, third_size >; 158 159 template< unsigned first_size, unsigned second_size, unsigned third_size > 160 using pack3_32_16_t = ::color::_internal::utility::container::pack3_N_N_t< std::uint32_t, std::uint16_t, first_size, second_size, third_size >; 161 162 template< unsigned first_size, unsigned second_size, unsigned third_size > 163 using pack3_64_16_t = ::color::_internal::utility::container::pack3_N_N_t< std::uint64_t, std::uint16_t, first_size, second_size, third_size >; 164 165 template< unsigned first_size, unsigned second_size, unsigned third_size > 166 using pack3_64_32_t = ::color::_internal::utility::container::pack3_N_N_t< std::uint64_t, std::uint32_t, first_size, second_size, third_size >; 167 168 using split233_t = ::color::_internal::utility::container::pack3_8_8_t< 2, 3, 3 >; 169 using split323_t = ::color::_internal::utility::container::pack3_8_8_t< 3, 2, 3 >; 170 using split332_t = ::color::_internal::utility::container::pack3_8_8_t< 3, 3, 2 >; 171 172 using split422_t = ::color::_internal::utility::container::pack3_8_8_t< 4, 2, 2 >; 173 using split242_t = ::color::_internal::utility::container::pack3_8_8_t< 2, 4, 2 >; 174 using split224_t = ::color::_internal::utility::container::pack3_8_8_t< 2, 2, 4 >; 175 176 using split655_t = ::color::_internal::utility::container::pack3_16_8_t< 6, 5, 5 >; 177 using split565_t = ::color::_internal::utility::container::pack3_16_8_t< 5, 6, 5 >; 178 using split556_t = ::color::_internal::utility::container::pack3_16_8_t< 5, 5, 6 >; 179 180 } 181 } 182 } 183 } 184 185 #endif 186