/*	swap.h
 *
 *		Byte swap of integers
 */

/*  RCompile - UNIX Resource compiler for YAAF Library
 *  Copyright (C) 1998 William Edward Woody
 *  
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 *  02111-1307, USA.
 *  
 *  To contact the author, either e-mail me at woody@pandawave.com, 
 *	or write to
 *  
 *          William Edward Woody
 *          In Phase Consulting
 *          1545 Ard Eevin Avenue
 *          Glendale, CA 91202
 *
 *	Or visit us on the web at http://www.pandawave.com
 */

#ifndef PandaWave_SWAP
#define PandaWave_SWAP

/************************************************************************/
/*																		*/
/*	Macros																*/
/*																		*/
/************************************************************************/

/*
 *	Depending on my compiler environment, set the OPT_NATIVEORDER flag.
 *	This won't set it on Unix; that has to be done in the makefile
 */

#if defined(__MWERKS__)						// using Metrowerks?

	#if defined(macintosh)
		#define OPT_NATIVEORDER		1
	#endif // defined(macintosh)
	
	#if defined(__INTEL__)
		#define OPT_NATIVEORDER		0
	#endif // defined(__INTEL__)

#else // !defined(__MWERKS__)

	#if defined(WIN32)
		#define OPT_NATIVEORDER		0
	#endif

#endif // define(__MWERKS__)

/************************************************************************/
/*																		*/
/*	Verification														*/
/*																		*/
/************************************************************************/

#ifndef OPT_NATIVEORDER
#error OPT_NATIVEORDER is not defined in swap.h
#endif

/************************************************************************/
/*																		*/
/*	Macros																*/
/*																		*/
/************************************************************************/

/*
 *	Byte order swap
 */

extern unsigned short	SwapWord(unsigned short);
extern unsigned long	SwapLong(unsigned long);

/*
 *	Conversion to/from network order
 */

#if OPT_NATIVEORDER == 1

#define	ESwapWord(x)	SwapWord(x)
#define	ESwapLong(x)	SwapLong(x)
#define	NSwapWord(x)	(x)
#define	NSwapLong(x)	(x)

#else

#define	ESwapWord(x)	(x)
#define	ESwapLong(x)	(x)
#define	NSwapWord(x)	SwapWord(x)
#define	NSwapLong(x)	SwapLong(x)

#endif


/*
 *	MKLinux Kludge
 */

#if OPT_XWIN && defined(__cplusplus) && (OPT_NATIVEORDER == 1)
	// Kludge to make this work with MkLinux's compiler under DR2.1r6.
	// You may wish to comment the following out with DR3
	#include <g++/std/typeinfo.h>			// 'cause I hate including this
#endif

#endif // PandaWave_SWAP
