endian.h

Go to the documentation of this file.
00001 
00010 /*
00011  *  Copyright (c) 2001 BBC R&D and 2003 Matt Beard
00012  *
00013  *  This software is provided 'as-is', without any express or implied warranty.
00014  *  In no event will the authors be held liable for any damages arising from
00015  *  the use of this software.
00016  *
00017  *  Permission is granted to anyone to use this software for any purpose,
00018  *  including commercial applications, and to alter it and redistribute it
00019  *  freely, subject to the following restrictions:
00020  *
00021  *    1. The origin of this software must not be misrepresented; you must
00022  *       not claim that you wrote the original software. If you use this
00023  *       software in a product, an acknowledgment in the product
00024  *       documentation would be appreciated but is not required.
00025  *  
00026  *    2. Altered source versions must be plainly marked as such, and must
00027  *       not be misrepresented as being the original software.
00028  *  
00029  *    3. This notice may not be removed or altered from any source
00030  *       distribution.
00031  */
00032 
00033 #include <mxflib/system.h>
00034 
00035 namespace mxflib
00036 {
00037     /*
00038     ** PutUxx() - Put unsigned xx-bit integer
00039     */
00040     inline void PutU8(UInt8 x, unsigned char *dest) { *dest=(x); }
00041     inline void PutU16(UInt16 Data, unsigned char *Dest) { PutU8(Data >> 8, Dest); PutU8(Data & 0xff, &Dest[1]); }
00042     inline void PutU32(UInt32 Data, unsigned char *Dest) { PutU16(Data >> 16, Dest); PutU16(Data & 0xffff, &Dest[2]); }
00043     inline void PutU64(UInt64 Data, unsigned char *Dest) { PutU32((UInt32)(Data >> 32), Dest); 
00044                                                            PutU32((UInt32)Data & 0xffffffff, &Dest[4]); }
00045 
00046     /*
00047     ** PutIxx() - Signed versions of PutUxx()
00048     */
00049     inline void PutI8(Int8 x, unsigned char *dest) { PutU8((UInt8)x,dest); }
00050     inline void PutI16(Int16 x, unsigned char *dest) { PutU16((UInt16)x,dest); }
00051     inline void PutI32(Int32 x, unsigned char *dest) { PutU32((UInt32)x,dest); }
00052     inline void PutI64(Int64 x, unsigned char *dest) { PutU64((UInt64)x,dest); }
00053 
00054     /*
00055     ** GetUxx() - Get unsigned xx-bit integer
00056     */
00057     inline UInt8 GetU8(const unsigned char *src) { return (UInt8) *src; }
00058     inline UInt16 GetU16(const unsigned char *src) { return (GetU8(src) << 8) | GetU8(&src[1]); }
00059     inline UInt32 GetU32(const unsigned char *src) { return (GetU16(src) << 16) | GetU16(&src[2]); }
00060     inline UInt64 GetU64(const unsigned char *src) { return (((UInt64)GetU32(src)) << 32) | (GetU32(&src[4])); }
00061 
00062     /*
00063     ** GetIxx() - Signed versions of GetUxx()
00064     */
00065     inline Int8 GetI8(const unsigned char *src) { return (Int8)GetU8(src); }
00066     inline Int16 GetI16(const unsigned char *src) { return (Int16)GetU16(src); }
00067     inline Int32 GetI32(const unsigned char *src) { return (Int32)GetU32(src); }
00068     inline Int64 GetI64(const unsigned char *src) { return (Int64)GetU64(src); }
00069 
00070     /*
00071     ** PutUxx_LE() - Put LITTLE ENDIAN unsigned xx-bit integer
00072     */
00073     inline void PutU8_LE(UInt8 x, unsigned char *dest) { *dest=(x); }
00074     inline void PutU16_LE(UInt16 Data, unsigned char *Dest) { PutU8_LE(Data & 0xff, Dest); PutU8_LE(Data >> 8, &Dest[1]); }
00075     inline void PutU32_LE(UInt32 Data, unsigned char *Dest) { PutU16_LE(Data & 0xffff, Dest); PutU16_LE(Data >> 16, &Dest[2]); }
00076     inline void PutU64_LE(UInt64 Data, unsigned char *Dest) { PutU32_LE((UInt32)(Data & 0xffffffff), Dest); 
00077                                                               PutU32_LE((UInt32)(Data >> 32), &Dest[4]); }
00078 
00079     /*
00080     ** PutIxx_LE() - Signed versions of PutUxx_LE()
00081     */
00082     inline void PutI8_LE(Int8 x, unsigned char *dest) { PutU8_LE((UInt8)x,dest); }
00083     inline void PutI16_LE(Int16 x, unsigned char *dest) { PutU16_LE((UInt16)x,dest); }
00084     inline void PutI32_LE(Int32 x, unsigned char *dest) { PutU32_LE((UInt32)x,dest); }
00085     inline void PutI64_LE(Int64 x, unsigned char *dest) { PutU64_LE((UInt64)x,dest); }
00086 
00087     /*
00088     ** GetUxx_LE() - Get LITTLE ENDIAN unsigned xx-bit integer
00089     */
00090     inline UInt8 GetU8_LE(const unsigned char *src) { return (UInt8) *src; }
00091     inline UInt16 GetU16_LE(const unsigned char *src) { return GetU8_LE(src) | (GetU8_LE(&src[1]) << 8); }
00092     inline UInt32 GetU32_LE(const unsigned char *src) { return GetU16_LE(src) | (GetU16_LE(&src[2]) << 16); }
00093     inline UInt64 GetU64_LE(const unsigned char *src) { return GetU32_LE(src) | ((UInt64)(GetU32_LE(&src[4])) << 32); }
00094 
00095     /*
00096     ** GetIxx_LE() - Signed versions of GetUxx_LE()
00097     */
00098     inline Int8 GetI8_LE(const unsigned char *src) { return (Int8)GetU8_LE(src); }
00099     inline Int16 GetI16_LE(const unsigned char *src) { return (Int16)GetU16_LE(src); }
00100     inline Int32 GetI32_LE(const unsigned char *src) { return (Int32)GetU32_LE(src); }
00101     inline Int64 GetI64_LE(const unsigned char *src) { return (Int64)GetU64_LE(src); }
00102 }
00103 
00104 

Generated on Mon Apr 2 15:20:53 2007 for MXFLib by  doxygen 1.5.1-p1