wendian.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (c) 1996-2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED, AS TO THE CORRECTNESS
00008 //  OF THIS CODE OR ANY DERIVATIVE WORKS WHICH INCORPORATE IT. AUTODESK
00009 //  PROVIDES THE CODE ON AN "AS-IS" BASIS AND EXPLICITLY DISCLAIMS ANY
00010 //  LIABILITY, INCLUDING CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00011 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00012 //
00013 //  Use, duplication, or disclosure by the U.S. Government is subject to
00014 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00015 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00016 //  Data and Computer Software), as applicable.
00017 //
00018 
00019 #if !defined ENDIAN_HEADER
00020 #define ENDIAN_HEADER
00021 
00025 
00026 #include "whiptk/whipcore.h"
00027 
00028 
00029 // We could handle the endian flipping by using a "union" structure
00030 // of a word and a character array, and then use direct subscripts rather
00031 // than all the bitwise and shift operations.
00032 
00034 
00035 class WHIPTK_API WT_Endian
00036 {
00037 public:
00038 
00040     static WT_Integer16 adjust(WT_Integer16 value)
00041     {
00042 #if WD_BIGENDIAN
00043         return (   ( (value << 8) & 0xFF00) |
00044                    ( (value >> 8) & 0x00FF)    );
00045 #else
00046         return value;
00047 #endif
00048     }
00049 
00051     static WT_Unsigned_Integer16 adjust(WT_Unsigned_Integer16 value)
00052     {
00053 #if WD_BIGENDIAN
00054         return (   ( (value << 8) & 0xFF00) |
00055                    ( (value >> 8) & 0x00FF)    );
00056 #else
00057         return value;
00058 #endif
00059     }
00060 
00062     static WT_Integer32 adjust(WT_Integer32 value)
00063     {
00064 #if WD_BIGENDIAN
00065         return (   ( (value << 24) & 0xFF000000)  |
00066                    ( (value <<  8) & 0x00FF0000)  |
00067                    ( (value >>  8) & 0x0000FF00)  |
00068                    ( (value >> 24) & 0x000000FF)    );
00069 #else
00070         return value;
00071 #endif
00072     }
00073 
00075     static WT_Unsigned_Integer32 adjust(WT_Unsigned_Integer32 value)
00076     {
00077 #if WD_BIGENDIAN
00078         return (   ( (value << 24) & 0xFF000000)  |
00079                    ( (value <<  8) & 0x00FF0000)  |
00080                    ( (value >>  8) & 0x0000FF00)  |
00081                    ( (value >> 24) & 0x000000FF)    );
00082 #else
00083         return value;
00084 #endif
00085     }
00086 
00087 };
00088 
00089 #endif // ENDIAN_HEADER

Generated on Tue Jan 6 22:41:13 2009 for Autodesk DWF Whip 2D Toolkit by  doxygen 1.4.5