15 void setmem(
void* mem,
const void* value,
unsigned value_size,
size_t num_elem )
17 if( !num_elem )
return;
19 char* array =
reinterpret_cast< char*
>( mem );
20 memcpy( array, value, value_size );
22 for( count = 1; count * 2 < num_elem; count *= 2 )
23 memcpy( array + count * value_size, array, count * value_size );
24 memcpy( array + count * value_size, array, ( num_elem - count ) * value_size );
29 long curr_pos = ftell( filp );
30 if( fseek( filp, 0, SEEK_END ) )
return -1;
32 long length = ftell( filp );
33 if( fseek( filp, curr_pos, SEEK_SET ) )
44 std::istream::pos_type curr_pos = str.tellg();
45 if( !str.seekg( 0, std::ios_base::end ) )
return -1;
47 long length =
static_cast< long >( str.tellg() );
48 if( !str.seekg( curr_pos, std::ios_base::beg ) )
57 void byteswap(
void* data,
unsigned value_size,
size_t num_elem )
59 char* mem =
reinterpret_cast< char*
>( data );
60 char*
const end = mem + value_size * num_elem;
61 for( ; mem < end; mem += value_size )
63 unsigned i = 0, j = value_size - 1;
65 std::swap( mem[i++], mem[j--] );
71 return ( value >> 8 ) | ( value << 8 );
76 return ( ( value ) >> 24 ) | ( ( value & (uint32_t)0x00FF0000 ) >> 8 ) |
77 ( ( value & (uint32_t)0x0000FF00 ) << 8 ) | ( ( value ) << 24 );
91 return ( ( value ) >> 56 ) | ( ( value &
m64b7 ) >> 40 ) | ( ( value &
m64b6 ) >> 24 ) |
92 ( ( value &
m64b5 ) >> 8 ) | ( ( value &
m64b4 ) << 8 ) | ( ( value &
m64b3 ) << 24 ) |
93 ( ( value &
m64b2 ) << 40 ) | ( ( value ) << 56 );
130 uint16_t* mem =
reinterpret_cast< uint16_t*
>( data );
131 uint16_t* end = mem + num_elem;
132 for( ; mem < end; ++mem )
138 uint32_t* mem =
reinterpret_cast< uint32_t*
>( data );
139 uint32_t* end = mem + num_elem;
140 for( ; mem < end; ++mem )
146 if(
sizeof(
void* ) >= 8 )
148 uint64_t* mem =
reinterpret_cast< uint64_t*
>( data );
149 uint64_t* end = mem + num_elem;
150 for( ; mem < end; ++mem )
155 uint32_t* mem =
reinterpret_cast< uint32_t*
>( data );
156 uint32_t* end = mem + 2 * num_elem;
157 for( ; mem < end; mem += 2 )