29 #define ARRAYLENGTH( aa ) \
30 ( sizeof( aa ) / sizeof( ( aa )[ 0 ] ) )
41 #define STDCALL __stdcall
54 #if defined( __GNUC__ )
55 #define ALIGN( aa ) __attribute__(( aligned( aa ) ))
56 #elif defined( _WIN32 )
57 #define ALIGN( aa ) __declspec( align( aa ) )
58 #endif // __GNUC__, _WIN32
69 template<
typename t_Type >
70 inline t_Type
Square( t_Type
const& value ) {
72 return( value * value );
84 template<
typename t_Type >
85 inline t_Type
Cube( t_Type
const& value ) {
87 return( value * value * value );
117 std::string::const_iterator ii = source.begin();
118 std::string::const_iterator iiEnd = source.end();
121 for ( ; ( ii != iiEnd ) && isspace( *ii ); ++ii );
122 while ( ii != iiEnd ) {
124 std::string::const_iterator lower = ii;
125 for ( ; ( ii != iiEnd ) && ( ! isspace( *ii ) ); ++ii );
128 result.append( 1, space );
129 result.append( lower, ii );
132 for ( ; ( ii != iiEnd ) && isspace( *ii ); ++ii );
149 static_assert( (
sizeof( number ) == 1 ),
"uint8_t should be one byte long" );
150 number = ( number & 0x55 ) + ( ( number >> 1 ) & 0x55 );
151 number = ( number & 0x33 ) + ( ( number >> 2 ) & 0x33 );
152 number = ( number & 0x0f ) + ( number >> 4 );
160 static_assert( (
sizeof( number ) == 2 ),
"uint16_t should be two bytes long" );
161 number = ( number & 0x5555 ) + ( ( number >> 1 ) & 0x5555 );
162 number = ( number & 0x3333 ) + ( ( number >> 2 ) & 0x3333 );
163 number = ( number & 0x0f0f ) + ( ( number >> 4 ) & 0x0f0f );
164 number = ( number & 0x00ff ) + ( number >> 8 );
172 static_assert( (
sizeof( number ) == 4 ),
"uint32_t should be four bytes long" );
173 number = ( number & 0x55555555 ) + ( ( number >> 1 ) & 0x55555555 );
174 number = ( number & 0x33333333 ) + ( ( number >> 2 ) & 0x33333333 );
175 number = ( number & 0x0f0f0f0f ) + ( ( number >> 4 ) & 0x0f0f0f0f );
176 number = ( number & 0x00ff00ff ) + ( ( number >> 8 ) & 0x00ff00ff );
177 number = ( number & 0x0000ffff ) + ( number >> 16 );
185 static_assert( (
sizeof( number ) == 8 ),
"uint64_t should be eight bytes long" );
186 number = ( number & 0x5555555555555555ull ) + ( ( number >> 1 ) & 0x5555555555555555ull );
187 number = ( number & 0x3333333333333333ull ) + ( ( number >> 2 ) & 0x3333333333333333ull );
188 number = ( number & 0x0f0f0f0f0f0f0f0full ) + ( ( number >> 4 ) & 0x0f0f0f0f0f0f0f0full );
189 number = ( number & 0x00ff00ff00ff00ffull ) + ( ( number >> 8 ) & 0x00ff00ff00ff00ffull );
190 number = ( number & 0x0000ffff0000ffffull ) + ( ( number >> 16 ) & 0x0000ffff0000ffffull );
191 number = ( number & 0x00000000ffffffffull ) + ( number >> 32 );
206 static_assert( (
sizeof( number ) == 1 ),
"uint8_t should be one byte long" );
208 unsigned int bits = 0;
210 if ( number & 0xf0 ) {
216 if ( number & 0x0c ) {
224 else if ( number & 0x01 )
234 static_assert( (
sizeof( number ) == 2 ),
"uint16_t should be two bytes long" );
236 unsigned int bits = 0;
238 if ( number & 0xff00 ) {
244 if ( number & 0x00f0 ) {
250 if ( number & 0x000c ) {
256 if ( number & 0x0002 )
258 else if ( number & 0x0001 )
268 static_assert( (
sizeof( number ) == 4 ),
"uint32_t should be four bytes long" );
270 unsigned int bits = 0;
272 if ( number & 0xffff0000 ) {
278 if ( number & 0x0000ff00 ) {
284 if ( number & 0x000000f0 ) {
290 if ( number & 0x0000000c ) {
296 if ( number & 0x00000002 )
298 else if ( number & 0x00000001 )
308 static_assert( (
sizeof( number ) == 8 ),
"uint64_t should be eight bytes long" );
310 unsigned int bits = 0;
312 if ( number & 0xffffffff00000000ull ) {
318 if ( number & 0x00000000ffff0000ull ) {
324 if ( number & 0x000000000000ff00ull ) {
330 if ( number & 0x00000000000000f0ull ) {
336 if ( number & 0x000000000000000cull ) {
342 if ( number & 0x0000000000000002ull )
344 else if ( number & 0x0000000000000001ull )