flatten 20260225

This commit is contained in:
Timothy Prepscius
2026-02-25 12:39:24 -05:00
commit fa54be052a
315 changed files with 49791 additions and 0 deletions

16
tjp/core/endian/Endian.cpp Executable file
View File

@@ -0,0 +1,16 @@
// TJP COPYRIGHT HEADER
#include "Endian.h"
using namespace tjp::core;
void endian::swap (char *buffer, int size)
{
int i, j;
for (i = 0, j = size-1 ; i < size/2; ++i, --j)
{
char switcheroo = buffer[i];
buffer[i] = buffer[j];
buffer[j] = switcheroo;
}
}

72
tjp/core/endian/Endian.h Executable file
View File

@@ -0,0 +1,72 @@
// TJP COPYRIGHT HEADER
#ifndef __Utilities_Endian_h__
#define __Utilities_Endian_h__
namespace tjp {
namespace core {
namespace endian {
/**
* Swaps a buffer that represents one variable
*/
void swap (char *, int size);
/**
* Swaps the specified buffer if the processor is big endian.
*/
inline void toLittleEndian (char *buffer, int size)
{
#ifdef __BIG_ENDIAN__
swap(buffer, size);
#endif
}
template<typename T>
inline void toLittleEndian (T &t)
{
#ifdef __BIG_ENDIAN__
swap((char*)&t, sizeof(T));
#endif
return t;
}
/**
* Swaps the specified buffer if the processor is little endian.
*/
inline void toBigEndian (char *buffer, int size)
{
#ifndef __BIG_ENDIAN__
swap(buffer, size);
#endif
}
template<typename T>
inline void toBigEndian (T &t)
{
#ifndef __BIG_ENDIAN__
swap((char*)&t, sizeof(T));
#endif
return t;
}
/**
* Swaps a single variable.
*/
template<typename T>
inline T &swap (T &t)
{
#ifdef __BIG_ENDIAN__
swap((char*)&t, sizeof(T));
#endif
return t;
}
} // namespace endian
} // namespace core
} // namespace
#endif