From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- indexlib/bitio.tcc | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 indexlib/bitio.tcc (limited to 'indexlib/bitio.tcc') diff --git a/indexlib/bitio.tcc b/indexlib/bitio.tcc new file mode 100644 index 00000000..2779cfed --- /dev/null +++ b/indexlib/bitio.tcc @@ -0,0 +1,91 @@ +#include "boost-compat/static_assert.hpp" +#include "boost-compat/remove_cv.hpp" +#ifdef HAVE_BOOST +#include +#endif + + +namespace byte_io { + + template + inline T no_const( const volatile T v ) { + return v; + } + + template + inline + void write( unsigned char* out, const volatile T d ) { + write( out, no_const( d ) ); + } + + + template + inline + T read( const unsigned char* out ) { + //BOOST_STATIC_ASSERT( !( ::boost::is_same::type>::value ) ); + return read::type>( out ); + } + + template<> + inline + void write( unsigned char* out, uint8_t d ) { + *out = d; + } + + template<> + inline + uint8_t read( const unsigned char* in ) { + return *in; + } + + template<> + struct byte_lenght_struct { + static const int value = 1; + }; + + template<> + inline + void write( unsigned char* out, uint16_t d ) { + *out++ = ( ( d >> 0 ) & 0xff ); + *out++ = ( ( d >> 8 ) & 0xff ); + } + + template<> + inline + uint16_t read( const unsigned char* in ) { + uint16_t res = 0; + res |= ( ( *in++ & 0xff ) << 0 ); + res |= ( ( *in++ & 0xff ) << 8 ); + return res; + } + + template<> + struct byte_lenght_struct { + static const int value = 2; + }; + + template<> + inline + void write( unsigned char* out, uint32_t d ) { + *out++ = ( ( d >> 0 ) & 0xff ); + *out++ = ( ( d >> 8 ) & 0xff ); + *out++ = ( ( d >> 16 ) & 0xff ); + *out++ = ( ( d >> 24 ) & 0xff ); + } + + template<> + inline + uint32_t read( const unsigned char* in ) { + uint32_t res = 0; + res |= ( ( *in++ & 0xff ) << 0 ); + res |= ( ( *in++ & 0xff ) << 8 ); + res |= ( ( *in++ & 0xff ) << 16 ); + res |= ( ( *in++ & 0xff ) << 24 ); + return res; + } + template<> + struct byte_lenght_struct { + static const int value = 4; + }; +} + -- cgit v1.2.3