1 #ifndef color__internal_utility_container_pack4 2 #define color__internal_utility_container_pack4 3 4 // ::color::_internal::utility::container::pack4< 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, unsigned fourth_size 27 > 28 struct pack4 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::pack4< container_name, component_name, index_name, first_size, second_size, third_size, fourth_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 = 4 }; 68 enum 69 { 70 first_position = 0, 71 second_position = first_size, 72 third_position = first_size + second_size, 73 fourth_position = first_size + second_size + third_size 74 }; 75 76 enum 77 { 78 first_mask = ( 1 << first_size )-1 , 79 second_mask = ( 1 << second_size )-1 , 80 third_mask = ( 1 << third_size )-1 , 81 fourth_mask = ( 1 << fourth_size )-1 82 }; 83 84 initcolor::_internal::utility::container::pack485 static set_return_type init( input_type container, index_input_const_type index, component_input_const_type value ) 86 { 87 this_type::set( container, index, value ); 88 } 89 90 template< index_instance_type index > initcolor::_internal::utility::container::pack491 static set_return_type init( input_type container, component_input_const_type value ) 92 { 93 this_type:: template set<index>( container, value ); 94 } 95 getcolor::_internal::utility::container::pack496 static component_return_const_type get( model_type container, index_input_const_type index ) 97 { 98 switch( index ) 99 { 100 default: 101 case( 0 ): return ( ( container >> ( first_position ) ) & first_mask ); 102 case( 1 ): return ( ( container >> ( second_position ) ) & second_mask ); 103 case( 2 ): return ( ( container >> ( third_position ) ) & third_mask ); 104 case( 3 ): return ( ( container >> ( fourth_position ) ) & fourth_mask ); 105 } 106 return 0; 107 } 108 109 template< index_instance_type index > getcolor::_internal::utility::container::pack4110 static component_return_const_type get( model_type container ) 111 { 112 //TODO C++14 static_assert( index < size_entity, "Index is out of range." ); 113 switch( index ) 114 { 115 case( 0 ): return ( ( container >> ( first_position ) ) & first_mask ); 116 case( 1 ): return ( ( container >> ( second_position ) ) & second_mask ); 117 case( 2 ): return ( ( container >> ( third_position ) ) & third_mask ); 118 case( 3 ): return ( ( container >> ( fourth_position ) ) & fourth_mask ); 119 } 120 return 0; 121 } 122 setcolor::_internal::utility::container::pack4123 static set_return_type set( input_type container, index_input_const_type index, component_input_const_type value ) 124 { 125 switch( index ) 126 { 127 default: 128 case( 0 ) : container = ( container & ~( first_mask << ( first_position ) ) ) | ( ((instance_type)value) << ( first_position ) ); break; 129 case( 1 ) : container = ( container & ~( second_mask << ( second_position ) ) ) | ( ((instance_type)value) << ( second_position ) ); break; 130 case( 2 ) : container = ( container & ~( third_mask << ( third_position ) ) ) | ( ((instance_type)value) << ( third_position ) ); break; 131 case( 3 ) : container = ( container & ~( fourth_mask << ( fourth_position ) ) ) | ( ((instance_type)value) << ( fourth_position ) ); break; 132 } 133 } 134 135 template< index_instance_type index > setcolor::_internal::utility::container::pack4136 static set_return_type set( input_type container, component_input_const_type value ) 137 { 138 //TODO C++14 static_assert( index < size_entity, "Index is out of range." ); 139 switch( index ) 140 { 141 case( 0 ) : container = ( container & ~( first_mask << ( first_position ) ) ) | ( ((instance_type)value) << ( first_position ) ); break; 142 case( 1 ) : container = ( container & ~( second_mask << ( second_position ) ) ) | ( ((instance_type)value) << ( second_position ) ); break; 143 case( 2 ) : container = ( container & ~( third_mask << ( third_position ) ) ) | ( ((instance_type)value) << ( third_position ) ); break; 144 case( 3 ) : container = ( container & ~( fourth_mask << ( fourth_position ) ) ) | ( ((instance_type)value) << ( fourth_position ) ); break; 145 } 146 } 147 sizecolor::_internal::utility::container::pack4148 static /*constexpr*/ size_return_image_type size() 149 { 150 static const size_instance_type local_length = size_entity; 151 return local_length; 152 } 153 }; 154 155 template< typename container_name, typename component_name, unsigned first_size, unsigned second_size, unsigned third_size, unsigned fourth_size > 156 using pack4_N_N_t = ::color::_internal::utility::container::pack4< container_name, component_name, unsigned, first_size, second_size, third_size, fourth_size >; 157 158 template< unsigned first_size, unsigned second_size, unsigned third_size, unsigned fourth_size > 159 using pack4_8_8_t = ::color::_internal::utility::container::pack4_N_N_t< std::uint8_t, std::uint8_t, first_size, second_size, third_size, fourth_size >; 160 161 template< unsigned first_size, unsigned second_size, unsigned third_size, unsigned fourth_size > 162 using pack4_16_8_t = ::color::_internal::utility::container::pack4_N_N_t< std::uint16_t, std::uint8_t, first_size, second_size, third_size, fourth_size >; 163 164 template< unsigned first_size, unsigned second_size, unsigned third_size, unsigned fourth_size > 165 using pack4_32_8_t = ::color::_internal::utility::container::pack4_N_N_t< std::uint32_t, std::uint8_t, first_size, second_size, third_size, fourth_size >; 166 167 template< unsigned first_size, unsigned second_size, unsigned third_size, unsigned fourth_size > 168 using pack4_32_16_t = ::color::_internal::utility::container::pack4_N_N_t< std::uint32_t, std::uint16_t, first_size, second_size, third_size, fourth_size >; 169 170 template< unsigned first_size, unsigned second_size, unsigned third_size, unsigned fourth_size > 171 using pack4_64_16_t = ::color::_internal::utility::container::pack4_N_N_t< std::uint64_t, std::uint16_t, first_size, second_size, third_size, fourth_size >; 172 173 template< unsigned first_size, unsigned second_size, unsigned third_size, unsigned fourth_size > 174 using pack4_64_32_t = ::color::_internal::utility::container::pack4_N_N_t< std::uint64_t, std::uint32_t, first_size, second_size, third_size, fourth_size >; 175 176 using split2222_t = ::color::_internal::utility::container::pack4_8_8_t< 2, 2, 2, 2 >; 177 using split4444_t = ::color::_internal::utility::container::pack4_16_8_t< 4, 4, 4, 4 >; 178 179 using split1555_t = ::color::_internal::utility::container::pack4_16_8_t< 1, 5, 5, 5 >; 180 using split5551_t = ::color::_internal::utility::container::pack4_16_8_t< 5, 5, 5, 1 >; 181 182 using split8888_t = ::color::_internal::utility::container::pack4_32_8_t< 8, 8, 8, 8 >; 183 184 using split2AAA_t = ::color::_internal::utility::container::pack4_32_16_t< 2, 10, 10, 10 >; 185 using splitAAA2_t = ::color::_internal::utility::container::pack4_32_16_t< 10, 10, 10 , 2 >; 186 187 using splitGGGG_t = ::color::_internal::utility::container::pack4_64_16_t< 16, 16, 16, 16 >; 188 using splitIIIA_t = ::color::_internal::utility::container::pack4_64_16_t< 18, 18, 18, 10 >; 189 using splitKKK6_t = ::color::_internal::utility::container::pack4_64_16_t< 20, 20, 20, 6 >; 190 191 using splitAIII_t = ::color::_internal::utility::container::pack4_64_16_t< 10, 18, 18, 18 >; 192 using split6KKK_t = ::color::_internal::utility::container::pack4_64_16_t< 6, 20, 20, 20 >; 193 194 } 195 } 196 } 197 } 198 199 #endif 200