first commit
This commit is contained in:
52
include/platform/memory/endian.h
Normal file
52
include/platform/memory/endian.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
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__
|
||||
Reference in New Issue
Block a user