Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Endian.h

Go to the documentation of this file.
00001 /****************** <SNX heading BEGIN do not edit this line> *****************
00002  *
00003  * sonix
00004  *
00005  * Original Authors:
00006  *   Kevin Meinert, Carolina Cruz-Neira
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile: Endian.h,v $
00010  * Date modified: $Date: 2003/12/01 22:25:22 $
00011  * Version:       $Revision: 1.11 $
00012  * -----------------------------------------------------------------
00013  *
00014  ****************** <SNX heading END do not edit this line> ******************/
00015 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00016  *
00017  * VR Juggler is (C) Copyright 1998-2003 by Iowa State University
00018  *
00019  * Original Authors:
00020  *   Allen Bierbaum, Christopher Just,
00021  *   Patrick Hartling, Kevin Meinert,
00022  *   Carolina Cruz-Neira, Albert Baker
00023  *
00024  * This library is free software; you can redistribute it and/or
00025  * modify it under the terms of the GNU Library General Public
00026  * License as published by the Free Software Foundation; either
00027  * version 2 of the License, or (at your option) any later version.
00028  *
00029  * This library is distributed in the hope that it will be useful,
00030  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00031  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00032  * Library General Public License for more details.
00033  *
00034  * You should have received a copy of the GNU Library General Public
00035  * License along with this library; if not, write to the
00036  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00037  * Boston, MA 02111-1307, USA.
00038  *
00039  *************** <auto-copyright.pl END do not edit this line> ***************/
00040 
00041 #ifndef _SNX_ENDIAN_FUNCS_
00042 #define _SNX_ENDIAN_FUNCS_
00043 
00044 #include <vpr/vpr.h>
00045 #include <vpr/System.h>
00046 
00047 
00048 namespace snxEndian
00049 {
00050    //: Swap the bytes in any data type.
00051    // Motorola and Intel store their bytes in reversed formats <BR>
00052    // ex: An SGI image is native to the SGI system,            <BR>
00053    // to be read on an intel machine, it's bytes need to be reversed <BR>
00054    // NOTE: chars aren't affected by this since it only        <BR>
00055    // affects the order of bytes, not bits.
00056    template< class Type >
00057    inline void  byteReverse(Type& bytes)
00058    {     
00059       const int size = sizeof(Type);
00060       Type buf = 0;
00061       int x, y;
00062 
00063       //we want to index the bytes in the buffer
00064       unsigned char* buffer = (unsigned char*) &buf;
00065 
00066       for ( x = 0, y = size-1; 
00067          x < size;
00068          ++x, --y )
00069       {
00070          buffer[x] |= ((unsigned char*)&bytes)[y];
00071       }
00072       bytes = buf;
00073    }
00074 
00075    enum Endianness
00076    {
00077       BIG, LITTLE
00078    };   
00079 
00080    template< class Type >
00081    inline void  byteReverse( Endianness& e, Type& bytes )
00082    {
00083       if (e == BIG && vpr::System::isLittleEndian())
00084       {
00085          byteReverse( bytes );
00086       }
00087       if (e == LITTLE && vpr::System::isBigEndian())
00088       {
00089          byteReverse( bytes );
00090       }
00091    }
00092 
00093 } // end namespace.
00094 
00095 #endif

Generated on Sun May 2 14:39:26 2004 for Juggler Sonix by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002