00001 /* 00002 libglim: a C++ Free library render images using OpenGL 00003 Copyright (C) 2002 Nestal Wan 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU General Public License 00007 as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 */ 00026 #ifndef __PICINFO_BYTE_ORDER_HEADER_INCLUDED__ 00027 #define __PICINFO_BYTE_ORDER_HEADER_INCLUDED__ 00028 00029 #ifdef WIN32 00030 // win32 doesn't have these lovely values telling us the endianness 00031 // luckily windows is unportable enough to run on intel (which is 00032 // little-endian) only 00033 #define LITTLE_ENDIAN 1234 00034 #define BIG_ENDIAN 4321 00035 #define BYTE_ORDER LITTLE_ENDIAN 00036 #else 00037 // assume sys/param.h contain the endian symbols 00038 #include <sys/param.h> 00039 #endif 00040 00041 namespace picinfo { 00042 00051 template <typename T> 00052 T SwapBytes( int new_order, T value ) ; 00053 00057 template <typename T> 00058 void SetByteOrder( int new_order, T& value ) 00059 { 00060 value = SwapBytes( new_order, value ) ; 00061 } 00062 00066 template <typename FwdIt> 00067 void SetByteOrder( int new_order, FwdIt first, FwdIt last ) 00068 { 00069 while ( first != last ) 00070 { 00071 SetByteOrder( new_order, *first ) ; 00072 ++first ; 00073 } 00074 } 00075 00076 } // end of namespace 00077 00078 #endif