/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */


#ifndef	__NENDIAN__
#define	__NENDIAN__


		#include "ntypes.h"


namespace GS {
	namespace Endian {

enum Config
{
	Undefined       =   0,

	Big,
	Little,

	Motorola		= Big,
	Intel			= Little
};

/// Swap bytes in memory.
void		SwapBytes(void *, size_t);

/// Return the current host memory configuration.
Config		GetHostConfiguration();

/// Convert a memory block to the host configuration.
void		*ToHost(void *, size_t, Config = Big);

/// Convert a value to the host configuration.
template <class T> T ToHost(const T &v, Config cfg = Big)
{
	if	(GetHostConfiguration() == cfg)
		return v;

	T host_value = v;
	SwapBytes(&host_value, sizeof(T));
	return host_value;	
}

	} // Endian
} // GS


#endif	//__NENDIAN__
