summaryrefslogtreecommitdiffstats
path: root/indexlib/bitio.tcc
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /indexlib/bitio.tcc
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
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
Diffstat (limited to 'indexlib/bitio.tcc')
-rw-r--r--indexlib/bitio.tcc91
1 files changed, 91 insertions, 0 deletions
diff --git a/indexlib/bitio.tcc b/indexlib/bitio.tcc
new file mode 100644
index 000000000..2779cfedb
--- /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 <boost/type_traits/is_same.hpp>
+#endif
+
+
+namespace byte_io {
+
+ template <typename T>
+ inline T no_const( const volatile T v ) {
+ return v;
+ }
+
+ template<typename T>
+ inline
+ void write( unsigned char* out, const volatile T d ) {
+ write( out, no_const( d ) );
+ }
+
+
+ template <typename T>
+ inline
+ T read( const unsigned char* out ) {
+ //BOOST_STATIC_ASSERT( !( ::boost::is_same<T,typename ::boost::remove_cv<T>::type>::value ) );
+ return read<typename ::boost::remove_cv<T>::type>( out );
+ }
+
+ template<>
+ inline
+ void write<uint8_t>( unsigned char* out, uint8_t d ) {
+ *out = d;
+ }
+
+ template<>
+ inline
+ uint8_t read<uint8_t>( const unsigned char* in ) {
+ return *in;
+ }
+
+ template<>
+ struct byte_lenght_struct<uint8_t> {
+ static const int value = 1;
+ };
+
+ template<>
+ inline
+ void write<uint16_t>( unsigned char* out, uint16_t d ) {
+ *out++ = ( ( d >> 0 ) & 0xff );
+ *out++ = ( ( d >> 8 ) & 0xff );
+ }
+
+ template<>
+ inline
+ uint16_t read<uint16_t>( const unsigned char* in ) {
+ uint16_t res = 0;
+ res |= ( ( *in++ & 0xff ) << 0 );
+ res |= ( ( *in++ & 0xff ) << 8 );
+ return res;
+ }
+
+ template<>
+ struct byte_lenght_struct<uint16_t> {
+ static const int value = 2;
+ };
+
+ template<>
+ inline
+ void write<uint32_t>( 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<uint32_t>( 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<uint32_t> {
+ static const int value = 4;
+ };
+}
+