mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 14:53:52 +00:00
Normalize line endings
This commit contains only the result of `git add --renormalize .` `git show --ignore-space-change` can verify that this commit only changes whitespace.
This commit is contained in:
@@ -1,25 +1,25 @@
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := PortabilityLayer
|
||||
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/../GpCommon \
|
||||
$(LOCAL_PATH)/../Common \
|
||||
$(LOCAL_PATH)/../rapidjson/include \
|
||||
$(LOCAL_PATH)/../MacRomanConversion \
|
||||
$(LOCAL_PATH)/../stb
|
||||
|
||||
LOCAL_CFLAGS := -DGP_DEBUG_CONFIG=0 -DGP_ZLIB_BUILTIN=1
|
||||
|
||||
LOCAL_EXPORT_LDLIBS := -lz
|
||||
|
||||
# Add your application source files here...
|
||||
LOCAL_SRC_FILES := \
|
||||
PortabilityLayer_Combined.cpp
|
||||
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := MacRomanConversion stb
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := PortabilityLayer
|
||||
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/../GpCommon \
|
||||
$(LOCAL_PATH)/../Common \
|
||||
$(LOCAL_PATH)/../rapidjson/include \
|
||||
$(LOCAL_PATH)/../MacRomanConversion \
|
||||
$(LOCAL_PATH)/../stb
|
||||
|
||||
LOCAL_CFLAGS := -DGP_DEBUG_CONFIG=0 -DGP_ZLIB_BUILTIN=1
|
||||
|
||||
LOCAL_EXPORT_LDLIBS := -lz
|
||||
|
||||
# Add your application source files here...
|
||||
LOCAL_SRC_FILES := \
|
||||
PortabilityLayer_Combined.cpp
|
||||
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := MacRomanConversion stb
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
@@ -1,37 +1,37 @@
|
||||
#pragma once
|
||||
#ifndef __PL_BINARY_SEARCH_H__
|
||||
#define __PL_BINARY_SEARCH_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<class TIterator, class TItem, class TPredicate>
|
||||
TIterator BinarySearch(const TIterator &startInclusive, const TIterator &endExclusive, const TItem &item, const TPredicate &pred)
|
||||
{
|
||||
TIterator searchStartInclusive = startInclusive;
|
||||
TIterator searchEndExclusive = endExclusive;
|
||||
|
||||
while (searchStartInclusive != searchEndExclusive)
|
||||
{
|
||||
const ptrdiff_t delta = searchEndExclusive - searchStartInclusive;
|
||||
const ptrdiff_t halfDelta = delta / 2;
|
||||
|
||||
const TIterator midPoint = searchStartInclusive + halfDelta;
|
||||
|
||||
const int comparison = pred(item, *midPoint);
|
||||
|
||||
if (comparison < 0)
|
||||
searchEndExclusive = midPoint;
|
||||
else if (comparison > 0)
|
||||
searchStartInclusive = midPoint + 1;
|
||||
else
|
||||
return midPoint;
|
||||
}
|
||||
|
||||
return endExclusive;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
#ifndef __PL_BINARY_SEARCH_H__
|
||||
#define __PL_BINARY_SEARCH_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<class TIterator, class TItem, class TPredicate>
|
||||
TIterator BinarySearch(const TIterator &startInclusive, const TIterator &endExclusive, const TItem &item, const TPredicate &pred)
|
||||
{
|
||||
TIterator searchStartInclusive = startInclusive;
|
||||
TIterator searchEndExclusive = endExclusive;
|
||||
|
||||
while (searchStartInclusive != searchEndExclusive)
|
||||
{
|
||||
const ptrdiff_t delta = searchEndExclusive - searchStartInclusive;
|
||||
const ptrdiff_t halfDelta = delta / 2;
|
||||
|
||||
const TIterator midPoint = searchStartInclusive + halfDelta;
|
||||
|
||||
const int comparison = pred(item, *midPoint);
|
||||
|
||||
if (comparison < 0)
|
||||
searchEndExclusive = midPoint;
|
||||
else if (comparison > 0)
|
||||
searchStartInclusive = midPoint + 1;
|
||||
else
|
||||
return midPoint;
|
||||
}
|
||||
|
||||
return endExclusive;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,100 +1,100 @@
|
||||
#include "ByteSwap.h"
|
||||
#include "CoreDefs.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
namespace ByteSwap
|
||||
{
|
||||
template<class TNumberType, class TUnsignedType>
|
||||
void SwapArbitraryBig(TNumberType &v)
|
||||
{
|
||||
GP_STATIC_ASSERT(sizeof(TNumberType) == sizeof(TUnsignedType));
|
||||
|
||||
uint8_t bytes[sizeof(TNumberType)];
|
||||
for (size_t i = 0; i < sizeof(TNumberType); i++)
|
||||
bytes[i] = reinterpret_cast<const uint8_t*>(&v)[i];
|
||||
|
||||
TUnsignedType result = 0;
|
||||
for (size_t i = 0; i < sizeof(TNumberType); i++)
|
||||
result |= static_cast<TUnsignedType>(bytes[i]) << (sizeof(TUnsignedType) * 8 - 8 - (i * 8));
|
||||
|
||||
v = static_cast<TNumberType>(result);
|
||||
}
|
||||
|
||||
template<class TNumberType, class TUnsignedType>
|
||||
void SwapArbitraryLittle(TNumberType &v)
|
||||
{
|
||||
GP_STATIC_ASSERT(sizeof(TNumberType) == sizeof(TUnsignedType));
|
||||
|
||||
uint8_t bytes[sizeof(TNumberType)];
|
||||
for (size_t i = 0; i < sizeof(TNumberType); i++)
|
||||
bytes[i] = reinterpret_cast<const uint8_t*>(&v)[i];
|
||||
|
||||
TUnsignedType result = 0;
|
||||
for (size_t i = 0; i < sizeof(TNumberType); i++)
|
||||
result |= static_cast<TUnsignedType>(bytes[i]) << (i * 8);
|
||||
|
||||
v = static_cast<TNumberType>(result);
|
||||
}
|
||||
|
||||
void BigInt16(int16_t &v)
|
||||
{
|
||||
SwapArbitraryBig<int16_t, uint16_t>(v);
|
||||
}
|
||||
|
||||
void BigInt32(int32_t &v)
|
||||
{
|
||||
SwapArbitraryBig<int32_t, uint32_t>(v);
|
||||
}
|
||||
|
||||
void BigInt64(int64_t &v)
|
||||
{
|
||||
SwapArbitraryBig<int64_t, uint64_t>(v);
|
||||
}
|
||||
|
||||
void BigUInt16(uint16_t &v)
|
||||
{
|
||||
SwapArbitraryBig<uint16_t, uint16_t>(v);
|
||||
}
|
||||
|
||||
void BigUInt32(uint32_t &v)
|
||||
{
|
||||
SwapArbitraryBig<uint32_t, uint32_t>(v);
|
||||
}
|
||||
|
||||
void BigUInt64(uint64_t &v)
|
||||
{
|
||||
SwapArbitraryBig<uint64_t, uint64_t>(v);
|
||||
}
|
||||
|
||||
void LittleInt16(int16_t &v)
|
||||
{
|
||||
SwapArbitraryLittle<int16_t, uint16_t>(v);
|
||||
}
|
||||
|
||||
void LittleInt32(int32_t &v)
|
||||
{
|
||||
SwapArbitraryLittle<int32_t, uint32_t>(v);
|
||||
}
|
||||
|
||||
void LittleInt64(int64_t &v)
|
||||
{
|
||||
SwapArbitraryLittle<int64_t, uint64_t>(v);
|
||||
}
|
||||
|
||||
void LittleUInt16(uint16_t &v)
|
||||
{
|
||||
SwapArbitraryLittle<uint16_t, uint16_t>(v);
|
||||
}
|
||||
|
||||
void LittleUInt32(uint32_t &v)
|
||||
{
|
||||
SwapArbitraryLittle<uint32_t, uint32_t>(v);
|
||||
}
|
||||
|
||||
void LittleUInt64(uint64_t &v)
|
||||
{
|
||||
SwapArbitraryLittle<uint64_t, uint64_t>(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
#include "ByteSwap.h"
|
||||
#include "CoreDefs.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
namespace ByteSwap
|
||||
{
|
||||
template<class TNumberType, class TUnsignedType>
|
||||
void SwapArbitraryBig(TNumberType &v)
|
||||
{
|
||||
GP_STATIC_ASSERT(sizeof(TNumberType) == sizeof(TUnsignedType));
|
||||
|
||||
uint8_t bytes[sizeof(TNumberType)];
|
||||
for (size_t i = 0; i < sizeof(TNumberType); i++)
|
||||
bytes[i] = reinterpret_cast<const uint8_t*>(&v)[i];
|
||||
|
||||
TUnsignedType result = 0;
|
||||
for (size_t i = 0; i < sizeof(TNumberType); i++)
|
||||
result |= static_cast<TUnsignedType>(bytes[i]) << (sizeof(TUnsignedType) * 8 - 8 - (i * 8));
|
||||
|
||||
v = static_cast<TNumberType>(result);
|
||||
}
|
||||
|
||||
template<class TNumberType, class TUnsignedType>
|
||||
void SwapArbitraryLittle(TNumberType &v)
|
||||
{
|
||||
GP_STATIC_ASSERT(sizeof(TNumberType) == sizeof(TUnsignedType));
|
||||
|
||||
uint8_t bytes[sizeof(TNumberType)];
|
||||
for (size_t i = 0; i < sizeof(TNumberType); i++)
|
||||
bytes[i] = reinterpret_cast<const uint8_t*>(&v)[i];
|
||||
|
||||
TUnsignedType result = 0;
|
||||
for (size_t i = 0; i < sizeof(TNumberType); i++)
|
||||
result |= static_cast<TUnsignedType>(bytes[i]) << (i * 8);
|
||||
|
||||
v = static_cast<TNumberType>(result);
|
||||
}
|
||||
|
||||
void BigInt16(int16_t &v)
|
||||
{
|
||||
SwapArbitraryBig<int16_t, uint16_t>(v);
|
||||
}
|
||||
|
||||
void BigInt32(int32_t &v)
|
||||
{
|
||||
SwapArbitraryBig<int32_t, uint32_t>(v);
|
||||
}
|
||||
|
||||
void BigInt64(int64_t &v)
|
||||
{
|
||||
SwapArbitraryBig<int64_t, uint64_t>(v);
|
||||
}
|
||||
|
||||
void BigUInt16(uint16_t &v)
|
||||
{
|
||||
SwapArbitraryBig<uint16_t, uint16_t>(v);
|
||||
}
|
||||
|
||||
void BigUInt32(uint32_t &v)
|
||||
{
|
||||
SwapArbitraryBig<uint32_t, uint32_t>(v);
|
||||
}
|
||||
|
||||
void BigUInt64(uint64_t &v)
|
||||
{
|
||||
SwapArbitraryBig<uint64_t, uint64_t>(v);
|
||||
}
|
||||
|
||||
void LittleInt16(int16_t &v)
|
||||
{
|
||||
SwapArbitraryLittle<int16_t, uint16_t>(v);
|
||||
}
|
||||
|
||||
void LittleInt32(int32_t &v)
|
||||
{
|
||||
SwapArbitraryLittle<int32_t, uint32_t>(v);
|
||||
}
|
||||
|
||||
void LittleInt64(int64_t &v)
|
||||
{
|
||||
SwapArbitraryLittle<int64_t, uint64_t>(v);
|
||||
}
|
||||
|
||||
void LittleUInt16(uint16_t &v)
|
||||
{
|
||||
SwapArbitraryLittle<uint16_t, uint16_t>(v);
|
||||
}
|
||||
|
||||
void LittleUInt32(uint32_t &v)
|
||||
{
|
||||
SwapArbitraryLittle<uint32_t, uint32_t>(v);
|
||||
}
|
||||
|
||||
void LittleUInt64(uint64_t &v)
|
||||
{
|
||||
SwapArbitraryLittle<uint64_t, uint64_t>(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,78 +1,78 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef __PL_BYTEUNPACK_H__
|
||||
#define __PL_BYTEUNPACK_H__
|
||||
|
||||
#include "DataTypes.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
namespace ByteUnpack
|
||||
{
|
||||
uint64_t BigUInt64(const uint8_t *bytes);
|
||||
uint32_t BigUInt32(const uint8_t *bytes);
|
||||
uint16_t BigUInt16(const uint8_t *bytes);
|
||||
|
||||
int64_t BigInt64(const uint8_t *bytes);
|
||||
int32_t BigInt32(const uint8_t *bytes);
|
||||
int16_t BigInt16(const uint8_t *bytes);
|
||||
}
|
||||
}
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
namespace ByteUnpack
|
||||
{
|
||||
inline uint64_t BigUInt64(const uint8_t *bytes)
|
||||
{
|
||||
return (static_cast<uint64_t>(bytes[0]) << 56)
|
||||
| (static_cast<uint64_t>(bytes[1]) << 48)
|
||||
| (static_cast<uint64_t>(bytes[2]) << 32)
|
||||
| (static_cast<uint64_t>(bytes[3]) << 24)
|
||||
| (static_cast<uint64_t>(bytes[4]) << 16)
|
||||
| (static_cast<uint64_t>(bytes[5]) << 8)
|
||||
| (static_cast<uint64_t>(bytes[6]));
|
||||
}
|
||||
|
||||
inline uint32_t BigUInt32(const uint8_t *bytes)
|
||||
{
|
||||
return (static_cast<uint32_t>(bytes[0]) << 24)
|
||||
| (static_cast<uint32_t>(bytes[1]) << 16)
|
||||
| (static_cast<uint32_t>(bytes[2]) << 8)
|
||||
| (static_cast<uint32_t>(bytes[3]));
|
||||
}
|
||||
|
||||
inline uint16_t BigUInt16(const uint8_t *bytes)
|
||||
{
|
||||
return (static_cast<uint16_t>(bytes[0]) << 8)
|
||||
| (static_cast<uint16_t>(bytes[1]));
|
||||
}
|
||||
|
||||
inline int64_t BigInt64(const uint8_t *bytes)
|
||||
{
|
||||
return (static_cast<int64_t>(bytes[0]) << 56)
|
||||
| (static_cast<int64_t>(bytes[1]) << 48)
|
||||
| (static_cast<int64_t>(bytes[2]) << 32)
|
||||
| (static_cast<int64_t>(bytes[3]) << 24)
|
||||
| (static_cast<int64_t>(bytes[4]) << 16)
|
||||
| (static_cast<int64_t>(bytes[5]) << 8)
|
||||
| (static_cast<int64_t>(bytes[6]));
|
||||
}
|
||||
|
||||
inline int32_t BigInt32(const uint8_t *bytes)
|
||||
{
|
||||
return (static_cast<int32_t>(bytes[0]) << 24)
|
||||
| (static_cast<int32_t>(bytes[1]) << 16)
|
||||
| (static_cast<int32_t>(bytes[2]) << 8)
|
||||
| (static_cast<int32_t>(bytes[3]));
|
||||
}
|
||||
|
||||
inline int16_t BigInt16(const uint8_t *bytes)
|
||||
{
|
||||
return (static_cast<int16_t>(bytes[0]) << 8)
|
||||
| (static_cast<int16_t>(bytes[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
|
||||
#ifndef __PL_BYTEUNPACK_H__
|
||||
#define __PL_BYTEUNPACK_H__
|
||||
|
||||
#include "DataTypes.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
namespace ByteUnpack
|
||||
{
|
||||
uint64_t BigUInt64(const uint8_t *bytes);
|
||||
uint32_t BigUInt32(const uint8_t *bytes);
|
||||
uint16_t BigUInt16(const uint8_t *bytes);
|
||||
|
||||
int64_t BigInt64(const uint8_t *bytes);
|
||||
int32_t BigInt32(const uint8_t *bytes);
|
||||
int16_t BigInt16(const uint8_t *bytes);
|
||||
}
|
||||
}
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
namespace ByteUnpack
|
||||
{
|
||||
inline uint64_t BigUInt64(const uint8_t *bytes)
|
||||
{
|
||||
return (static_cast<uint64_t>(bytes[0]) << 56)
|
||||
| (static_cast<uint64_t>(bytes[1]) << 48)
|
||||
| (static_cast<uint64_t>(bytes[2]) << 32)
|
||||
| (static_cast<uint64_t>(bytes[3]) << 24)
|
||||
| (static_cast<uint64_t>(bytes[4]) << 16)
|
||||
| (static_cast<uint64_t>(bytes[5]) << 8)
|
||||
| (static_cast<uint64_t>(bytes[6]));
|
||||
}
|
||||
|
||||
inline uint32_t BigUInt32(const uint8_t *bytes)
|
||||
{
|
||||
return (static_cast<uint32_t>(bytes[0]) << 24)
|
||||
| (static_cast<uint32_t>(bytes[1]) << 16)
|
||||
| (static_cast<uint32_t>(bytes[2]) << 8)
|
||||
| (static_cast<uint32_t>(bytes[3]));
|
||||
}
|
||||
|
||||
inline uint16_t BigUInt16(const uint8_t *bytes)
|
||||
{
|
||||
return (static_cast<uint16_t>(bytes[0]) << 8)
|
||||
| (static_cast<uint16_t>(bytes[1]));
|
||||
}
|
||||
|
||||
inline int64_t BigInt64(const uint8_t *bytes)
|
||||
{
|
||||
return (static_cast<int64_t>(bytes[0]) << 56)
|
||||
| (static_cast<int64_t>(bytes[1]) << 48)
|
||||
| (static_cast<int64_t>(bytes[2]) << 32)
|
||||
| (static_cast<int64_t>(bytes[3]) << 24)
|
||||
| (static_cast<int64_t>(bytes[4]) << 16)
|
||||
| (static_cast<int64_t>(bytes[5]) << 8)
|
||||
| (static_cast<int64_t>(bytes[6]));
|
||||
}
|
||||
|
||||
inline int32_t BigInt32(const uint8_t *bytes)
|
||||
{
|
||||
return (static_cast<int32_t>(bytes[0]) << 24)
|
||||
| (static_cast<int32_t>(bytes[1]) << 16)
|
||||
| (static_cast<int32_t>(bytes[2]) << 8)
|
||||
| (static_cast<int32_t>(bytes[3]));
|
||||
}
|
||||
|
||||
inline int16_t BigInt16(const uint8_t *bytes)
|
||||
{
|
||||
return (static_cast<int16_t>(bytes[0]) << 8)
|
||||
| (static_cast<int16_t>(bytes[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef __PL_DATATYPES_H__
|
||||
#define __PL_DATATYPES_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
typedef int64_t LargestInt_t;
|
||||
typedef uint64_t LargestUInt_t;
|
||||
}
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
|
||||
#ifndef __PL_DATATYPES_H__
|
||||
#define __PL_DATATYPES_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
typedef int64_t LargestInt_t;
|
||||
typedef uint64_t LargestUInt_t;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,16 +1,16 @@
|
||||
#pragma once
|
||||
#ifndef __PL_FILE_PERMISSION_H__
|
||||
#define __PL_FILE_PERMISSION_H__
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
enum EFilePermission
|
||||
{
|
||||
EFilePermission_Any,
|
||||
EFilePermission_Read,
|
||||
EFilePermission_ReadWrite,
|
||||
EFilePermission_Write,
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
#ifndef __PL_FILE_PERMISSION_H__
|
||||
#define __PL_FILE_PERMISSION_H__
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
enum EFilePermission
|
||||
{
|
||||
EFilePermission_Any,
|
||||
EFilePermission_Read,
|
||||
EFilePermission_ReadWrite,
|
||||
EFilePermission_Write,
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,19 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "HostSuspendCallID.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
union HostSuspendCallArgument
|
||||
{
|
||||
uint32_t m_uint;
|
||||
int32_t m_int;
|
||||
size_t m_size;
|
||||
void *m_pointer;
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "HostSuspendCallID.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
union HostSuspendCallArgument
|
||||
{
|
||||
uint32_t m_uint;
|
||||
int32_t m_int;
|
||||
size_t m_size;
|
||||
void *m_pointer;
|
||||
const void *m_constPointer;
|
||||
void (*m_functionPtr)(void *context);
|
||||
};
|
||||
}
|
||||
void (*m_functionPtr)(void *context);
|
||||
};
|
||||
}
|
||||
|
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "HostSuspendCallID.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
union HostSuspendCallArgument;
|
||||
|
||||
typedef void(*HostSuspendHook_t)(void *context, HostSuspendCallID callID, const HostSuspendCallArgument *args, HostSuspendCallArgument *returnValue);
|
||||
|
||||
void RenderFrames(unsigned int ticks);
|
||||
#pragma once
|
||||
|
||||
#include "HostSuspendCallID.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
union HostSuspendCallArgument;
|
||||
|
||||
typedef void(*HostSuspendHook_t)(void *context, HostSuspendCallID callID, const HostSuspendCallArgument *args, HostSuspendCallArgument *returnValue);
|
||||
|
||||
void RenderFrames(unsigned int ticks);
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "PlotDirection.h"
|
||||
#include "PlotDirection.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct Vec2i;
|
||||
|
||||
|
||||
struct IPlotter
|
||||
{
|
||||
virtual PlotDirection PlotNext() = 0;
|
||||
|
@@ -1,17 +1,17 @@
|
||||
#include "MMHandleBlock.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
MMHandleBlock::MMHandleBlock(void *contents, size_t size)
|
||||
: m_contents(contents)
|
||||
, m_rmSelfRef(nullptr)
|
||||
, m_size(size)
|
||||
{
|
||||
}
|
||||
|
||||
void **MMHandleBlock::AsHandle()
|
||||
{
|
||||
return &m_contents;
|
||||
}
|
||||
|
||||
}
|
||||
#include "MMHandleBlock.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
MMHandleBlock::MMHandleBlock(void *contents, size_t size)
|
||||
: m_contents(contents)
|
||||
, m_rmSelfRef(nullptr)
|
||||
, m_size(size)
|
||||
{
|
||||
}
|
||||
|
||||
void **MMHandleBlock::AsHandle()
|
||||
{
|
||||
return &m_contents;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,37 +1,37 @@
|
||||
#include "MacFileMem.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
#include "MacFileMem.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
MacFileMem::MacFileMem(IGpAllocator *alloc, const MacFileInfo &fileInfo)
|
||||
: m_alloc(alloc)
|
||||
, m_info(fileInfo)
|
||||
, m_data(alloc)
|
||||
{
|
||||
}
|
||||
|
||||
bool MacFileMem::Init(const uint8_t *dataFork, const uint8_t *resourceFork, const char* comment)
|
||||
{
|
||||
const size_t combinedSize = m_info.m_dataForkSize + m_info.m_resourceForkSize + m_info.m_commentSize + 1;
|
||||
}
|
||||
|
||||
bool MacFileMem::Init(const uint8_t *dataFork, const uint8_t *resourceFork, const char* comment)
|
||||
{
|
||||
const size_t combinedSize = m_info.m_dataForkSize + m_info.m_resourceForkSize + m_info.m_commentSize + 1;
|
||||
if (!m_data.Resize(combinedSize))
|
||||
return false;
|
||||
|
||||
uint8_t *buffer = m_data.Buffer();
|
||||
memcpy(buffer, dataFork, m_info.m_dataForkSize);
|
||||
buffer += m_info.m_dataForkSize;
|
||||
|
||||
memcpy(buffer, resourceFork, m_info.m_resourceForkSize);
|
||||
buffer += m_info.m_resourceForkSize;
|
||||
|
||||
memcpy(buffer, comment, m_info.m_commentSize);
|
||||
buffer += m_info.m_commentSize;
|
||||
|
||||
uint8_t *buffer = m_data.Buffer();
|
||||
memcpy(buffer, dataFork, m_info.m_dataForkSize);
|
||||
buffer += m_info.m_dataForkSize;
|
||||
|
||||
memcpy(buffer, resourceFork, m_info.m_resourceForkSize);
|
||||
buffer += m_info.m_resourceForkSize;
|
||||
|
||||
memcpy(buffer, comment, m_info.m_commentSize);
|
||||
buffer += m_info.m_commentSize;
|
||||
|
||||
*buffer = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
MacFileMem::~MacFileMem()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
MacFileMem::~MacFileMem()
|
||||
{
|
||||
}
|
||||
|
||||
MacFileMem *MacFileMem::Create(IGpAllocator *alloc, const uint8_t *dataFork, const uint8_t *resourceFork, const char* comment, const MacFileInfo &fileInfo)
|
||||
@@ -51,9 +51,9 @@ namespace PortabilityLayer
|
||||
}
|
||||
|
||||
void MacFileMem::Destroy()
|
||||
{
|
||||
{
|
||||
IGpAllocator *alloc = m_alloc;
|
||||
this->~MacFileMem();
|
||||
alloc->Release(this);
|
||||
}
|
||||
}
|
||||
alloc->Release(this);
|
||||
}
|
||||
}
|
||||
|
@@ -1,55 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "DataTypes.h"
|
||||
#include "MacFileInfo.h"
|
||||
#pragma once
|
||||
|
||||
#include "DataTypes.h"
|
||||
#include "MacFileInfo.h"
|
||||
#include "GpVector.h"
|
||||
|
||||
struct IGpAllocator;
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class MacFileMem
|
||||
{
|
||||
public:
|
||||
const MacFileInfo &FileInfo() const;
|
||||
const uint8_t *DataFork() const;
|
||||
const uint8_t *ResourceFork() const;
|
||||
struct IGpAllocator;
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class MacFileMem
|
||||
{
|
||||
public:
|
||||
const MacFileInfo &FileInfo() const;
|
||||
const uint8_t *DataFork() const;
|
||||
const uint8_t *ResourceFork() const;
|
||||
const char *Comment() const;
|
||||
|
||||
static MacFileMem *Create(IGpAllocator *alloc, const uint8_t *dataFork, const uint8_t *resourceFork, const char* comment, const MacFileInfo &fileInfo);
|
||||
void Destroy();
|
||||
|
||||
private:
|
||||
MacFileMem(IGpAllocator *alloc, const MacFileInfo &fileInfo);
|
||||
void Destroy();
|
||||
|
||||
private:
|
||||
MacFileMem(IGpAllocator *alloc, const MacFileInfo &fileInfo);
|
||||
~MacFileMem();
|
||||
|
||||
bool Init(const uint8_t *dataFork, const uint8_t *resourceFork, const char* comment);
|
||||
|
||||
GpVector<uint8_t> m_data;
|
||||
|
||||
GpVector<uint8_t> m_data;
|
||||
MacFileInfo m_info;
|
||||
IGpAllocator *m_alloc;
|
||||
};
|
||||
}
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
inline const MacFileInfo &MacFileMem::FileInfo() const
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
inline const uint8_t *MacFileMem::DataFork() const
|
||||
{
|
||||
return m_data.Buffer();
|
||||
}
|
||||
|
||||
inline const uint8_t *MacFileMem::ResourceFork() const
|
||||
{
|
||||
return m_data.Buffer() + m_info.m_dataForkSize;
|
||||
}
|
||||
|
||||
inline const char *MacFileMem::Comment() const
|
||||
{
|
||||
return reinterpret_cast<const char*>(m_data.Buffer() + m_info.m_dataForkSize + m_info.m_resourceForkSize);
|
||||
}
|
||||
}
|
||||
IGpAllocator *m_alloc;
|
||||
};
|
||||
}
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
inline const MacFileInfo &MacFileMem::FileInfo() const
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
inline const uint8_t *MacFileMem::DataFork() const
|
||||
{
|
||||
return m_data.Buffer();
|
||||
}
|
||||
|
||||
inline const uint8_t *MacFileMem::ResourceFork() const
|
||||
{
|
||||
return m_data.Buffer() + m_info.m_dataForkSize;
|
||||
}
|
||||
|
||||
inline const char *MacFileMem::Comment() const
|
||||
{
|
||||
return reinterpret_cast<const char*>(m_data.Buffer() + m_info.m_dataForkSize + m_info.m_resourceForkSize);
|
||||
}
|
||||
}
|
||||
|
@@ -1,21 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef __PL_MACRSRCHEADER_H__
|
||||
#define __PL_MACRSRCHEADER_H__
|
||||
|
||||
#include "DataTypes.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct MacRsrcHeader
|
||||
{
|
||||
uint32_t m_resDataOffset;
|
||||
uint32_t m_resMapOffset;
|
||||
uint32_t m_resDataSize;
|
||||
uint32_t m_resMapSize;
|
||||
|
||||
void Load(const void *data);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
|
||||
#ifndef __PL_MACRSRCHEADER_H__
|
||||
#define __PL_MACRSRCHEADER_H__
|
||||
|
||||
#include "DataTypes.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct MacRsrcHeader
|
||||
{
|
||||
uint32_t m_resDataOffset;
|
||||
uint32_t m_resMapOffset;
|
||||
uint32_t m_resDataSize;
|
||||
uint32_t m_resMapSize;
|
||||
|
||||
void Load(const void *data);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,20 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef __PL_MACRSRCMAP_H__
|
||||
#define __PL_MACRSRCMAP_H__
|
||||
|
||||
#include "DataTypes.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct MacRsrcMap
|
||||
{
|
||||
uint16_t m_resTypeListOffset;
|
||||
uint16_t m_resNameListOffset;
|
||||
uint16_t m_numTypesMinusOne;
|
||||
|
||||
void Load(const void *data);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
|
||||
#ifndef __PL_MACRSRCMAP_H__
|
||||
#define __PL_MACRSRCMAP_H__
|
||||
|
||||
#include "DataTypes.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct MacRsrcMap
|
||||
{
|
||||
uint16_t m_resTypeListOffset;
|
||||
uint16_t m_resNameListOffset;
|
||||
uint16_t m_numTypesMinusOne;
|
||||
|
||||
void Load(const void *data);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -30,6 +30,6 @@ void SysBeep(int duration)
|
||||
}
|
||||
|
||||
void SetBeepFunction(BeepFunction_t beepFunction)
|
||||
{
|
||||
{
|
||||
PortabilityLayer::gs_beepFunction = beepFunction;
|
||||
}
|
||||
|
@@ -1,41 +1,41 @@
|
||||
#pragma once
|
||||
#ifndef __PL_APPLICATION_H__
|
||||
#define __PL_APPLICATION_H__
|
||||
|
||||
#include "PLCore.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<size_t TSize>
|
||||
class PascalStrLiteral;
|
||||
}
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
namespace Utils
|
||||
{
|
||||
void MakePStr(unsigned char *dest, size_t sz, const char *src);
|
||||
}
|
||||
}
|
||||
|
||||
void PasStringCopy(const unsigned char *src, unsigned char *dest);
|
||||
|
||||
template<size_t TSize>
|
||||
void PasStringCopy(const PortabilityLayer::PascalStrLiteral<TSize> &src, unsigned char *dest);
|
||||
|
||||
#pragma once
|
||||
#ifndef __PL_APPLICATION_H__
|
||||
#define __PL_APPLICATION_H__
|
||||
|
||||
#include "PLCore.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<size_t TSize>
|
||||
class PascalStrLiteral;
|
||||
}
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
namespace Utils
|
||||
{
|
||||
void MakePStr(unsigned char *dest, size_t sz, const char *src);
|
||||
}
|
||||
}
|
||||
|
||||
void PasStringCopy(const unsigned char *src, unsigned char *dest);
|
||||
|
||||
template<size_t TSize>
|
||||
void PasStringCopy(const PortabilityLayer::PascalStrLiteral<TSize> &src, unsigned char *dest);
|
||||
|
||||
void SysBeep(int duration);
|
||||
|
||||
typedef void (*BeepFunction_t)(int duration);
|
||||
void SetBeepFunction(BeepFunction_t beepFunction);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#include "PascalStrLiteral.h"
|
||||
|
||||
template<size_t TSize>
|
||||
inline void PasStringCopy(const PortabilityLayer::PascalStrLiteral<TSize> &src, unsigned char *dest)
|
||||
{
|
||||
PortabilityLayer::Utils::MakePStr(dest, TSize - 1, src.GetStr());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#include "PascalStrLiteral.h"
|
||||
|
||||
template<size_t TSize>
|
||||
inline void PasStringCopy(const PortabilityLayer::PascalStrLiteral<TSize> &src, unsigned char *dest)
|
||||
{
|
||||
PortabilityLayer::Utils::MakePStr(dest, TSize - 1, src.GetStr());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,269 +1,269 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
template<class T>
|
||||
struct BEInteger
|
||||
{
|
||||
public:
|
||||
BEInteger();
|
||||
BEInteger(const BEInteger<T> &other);
|
||||
explicit BEInteger(T i);
|
||||
|
||||
operator T() const;
|
||||
BEInteger<T> &operator=(T value);
|
||||
|
||||
template<class TOther>
|
||||
BEInteger<T> &operator+=(TOther value);
|
||||
|
||||
template<class TOther>
|
||||
BEInteger<T> &operator-=(TOther value);
|
||||
|
||||
template<class TOther>
|
||||
BEInteger<T> &operator*=(TOther value);
|
||||
|
||||
template<class TOther>
|
||||
BEInteger<T> &operator/=(TOther value);
|
||||
|
||||
template<class TOther>
|
||||
BEInteger<T> &operator%=(TOther value);
|
||||
|
||||
BEInteger<T>& operator--();
|
||||
BEInteger<T> operator--(int);
|
||||
|
||||
BEInteger<T>& operator++();
|
||||
BEInteger<T> operator++(int);
|
||||
|
||||
private:
|
||||
uint8_t m_beValueBytes[sizeof(T)];
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct BEInteger_SwapHelper
|
||||
{
|
||||
};
|
||||
|
||||
#include "ByteSwap.h"
|
||||
|
||||
template<>
|
||||
struct BEInteger_SwapHelper<int16_t>
|
||||
{
|
||||
inline static void Swap(int16_t &v)
|
||||
{
|
||||
PortabilityLayer::ByteSwap::BigInt16(v);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct BEInteger_SwapHelper<int32_t>
|
||||
{
|
||||
inline static void Swap(int32_t &v)
|
||||
{
|
||||
PortabilityLayer::ByteSwap::BigInt32(v);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct BEInteger_SwapHelper<uint16_t>
|
||||
{
|
||||
inline static void Swap(uint16_t &v)
|
||||
{
|
||||
PortabilityLayer::ByteSwap::BigUInt16(v);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct BEInteger_SwapHelper<uint32_t>
|
||||
{
|
||||
inline static void Swap(uint32_t &v)
|
||||
{
|
||||
PortabilityLayer::ByteSwap::BigUInt32(v);
|
||||
}
|
||||
};
|
||||
|
||||
#include <string.h>
|
||||
|
||||
template<class T>
|
||||
inline BEInteger<T>::BEInteger()
|
||||
{
|
||||
memset(m_beValueBytes, 0, sizeof(T));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline BEInteger<T>::BEInteger(const BEInteger<T> &other)
|
||||
{
|
||||
memcpy(m_beValueBytes, other.m_beValueBytes, sizeof(T));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline BEInteger<T>::BEInteger(T i)
|
||||
{
|
||||
BEInteger_SwapHelper<T>::Swap(i);
|
||||
memcpy(m_beValueBytes, &i, sizeof(T));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline BEInteger<T>::operator T() const
|
||||
{
|
||||
T result;
|
||||
memcpy(&result, m_beValueBytes, sizeof(T));
|
||||
BEInteger_SwapHelper<T>::Swap(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline BEInteger<T> &BEInteger<T>::operator=(T value)
|
||||
{
|
||||
BEInteger_SwapHelper<T>::Swap(value);
|
||||
memcpy(m_beValueBytes, &value, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
BEInteger<T> &BEInteger<T>::operator+=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_beValueBytes, sizeof(T));
|
||||
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue += value;
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_beValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
BEInteger<T> &BEInteger<T>::operator-=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_beValueBytes, sizeof(T));
|
||||
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue -= value;
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_beValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
BEInteger<T> &BEInteger<T>::operator*=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_beValueBytes, sizeof(T));
|
||||
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue *= value;
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_beValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
BEInteger<T> &BEInteger<T>::operator/=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_beValueBytes, sizeof(T));
|
||||
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue /= value;
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_beValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
BEInteger<T> &BEInteger<T>::operator%=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_beValueBytes, sizeof(T));
|
||||
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue %= value;
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_beValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
BEInteger<T>& BEInteger<T>::operator--()
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_beValueBytes, sizeof(T));
|
||||
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue--;
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_beValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
BEInteger<T> BEInteger<T>::operator--(int)
|
||||
{
|
||||
BEInteger<T> orig(*this);
|
||||
--(*this);
|
||||
return orig;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
BEInteger<T>& BEInteger<T>::operator++()
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_beValueBytes, sizeof(T));
|
||||
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue++;
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_beValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
BEInteger<T> BEInteger<T>::operator++(int)
|
||||
{
|
||||
BEInteger<T> orig(*this);
|
||||
++(*this);
|
||||
return orig;
|
||||
}
|
||||
|
||||
|
||||
typedef BEInteger<int16_t> BEInt16_t;
|
||||
typedef BEInteger<int32_t> BEInt32_t;
|
||||
typedef BEInteger<uint16_t> BEUInt16_t;
|
||||
typedef BEInteger<uint32_t> BEUInt32_t;
|
||||
|
||||
struct BESFixed32_t
|
||||
{
|
||||
BEInt16_t m_intPart;
|
||||
BEUInt16_t m_fracPart;
|
||||
};
|
||||
|
||||
struct BEUFixed32_t
|
||||
{
|
||||
BEUInt16_t m_intPart;
|
||||
BEUInt16_t m_fracPart;
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
template<class T>
|
||||
struct BEInteger
|
||||
{
|
||||
public:
|
||||
BEInteger();
|
||||
BEInteger(const BEInteger<T> &other);
|
||||
explicit BEInteger(T i);
|
||||
|
||||
operator T() const;
|
||||
BEInteger<T> &operator=(T value);
|
||||
|
||||
template<class TOther>
|
||||
BEInteger<T> &operator+=(TOther value);
|
||||
|
||||
template<class TOther>
|
||||
BEInteger<T> &operator-=(TOther value);
|
||||
|
||||
template<class TOther>
|
||||
BEInteger<T> &operator*=(TOther value);
|
||||
|
||||
template<class TOther>
|
||||
BEInteger<T> &operator/=(TOther value);
|
||||
|
||||
template<class TOther>
|
||||
BEInteger<T> &operator%=(TOther value);
|
||||
|
||||
BEInteger<T>& operator--();
|
||||
BEInteger<T> operator--(int);
|
||||
|
||||
BEInteger<T>& operator++();
|
||||
BEInteger<T> operator++(int);
|
||||
|
||||
private:
|
||||
uint8_t m_beValueBytes[sizeof(T)];
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct BEInteger_SwapHelper
|
||||
{
|
||||
};
|
||||
|
||||
#include "ByteSwap.h"
|
||||
|
||||
template<>
|
||||
struct BEInteger_SwapHelper<int16_t>
|
||||
{
|
||||
inline static void Swap(int16_t &v)
|
||||
{
|
||||
PortabilityLayer::ByteSwap::BigInt16(v);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct BEInteger_SwapHelper<int32_t>
|
||||
{
|
||||
inline static void Swap(int32_t &v)
|
||||
{
|
||||
PortabilityLayer::ByteSwap::BigInt32(v);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct BEInteger_SwapHelper<uint16_t>
|
||||
{
|
||||
inline static void Swap(uint16_t &v)
|
||||
{
|
||||
PortabilityLayer::ByteSwap::BigUInt16(v);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct BEInteger_SwapHelper<uint32_t>
|
||||
{
|
||||
inline static void Swap(uint32_t &v)
|
||||
{
|
||||
PortabilityLayer::ByteSwap::BigUInt32(v);
|
||||
}
|
||||
};
|
||||
|
||||
#include <string.h>
|
||||
|
||||
template<class T>
|
||||
inline BEInteger<T>::BEInteger()
|
||||
{
|
||||
memset(m_beValueBytes, 0, sizeof(T));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline BEInteger<T>::BEInteger(const BEInteger<T> &other)
|
||||
{
|
||||
memcpy(m_beValueBytes, other.m_beValueBytes, sizeof(T));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline BEInteger<T>::BEInteger(T i)
|
||||
{
|
||||
BEInteger_SwapHelper<T>::Swap(i);
|
||||
memcpy(m_beValueBytes, &i, sizeof(T));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline BEInteger<T>::operator T() const
|
||||
{
|
||||
T result;
|
||||
memcpy(&result, m_beValueBytes, sizeof(T));
|
||||
BEInteger_SwapHelper<T>::Swap(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline BEInteger<T> &BEInteger<T>::operator=(T value)
|
||||
{
|
||||
BEInteger_SwapHelper<T>::Swap(value);
|
||||
memcpy(m_beValueBytes, &value, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
BEInteger<T> &BEInteger<T>::operator+=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_beValueBytes, sizeof(T));
|
||||
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue += value;
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_beValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
BEInteger<T> &BEInteger<T>::operator-=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_beValueBytes, sizeof(T));
|
||||
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue -= value;
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_beValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
BEInteger<T> &BEInteger<T>::operator*=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_beValueBytes, sizeof(T));
|
||||
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue *= value;
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_beValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
BEInteger<T> &BEInteger<T>::operator/=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_beValueBytes, sizeof(T));
|
||||
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue /= value;
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_beValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
BEInteger<T> &BEInteger<T>::operator%=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_beValueBytes, sizeof(T));
|
||||
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue %= value;
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_beValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
BEInteger<T>& BEInteger<T>::operator--()
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_beValueBytes, sizeof(T));
|
||||
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue--;
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_beValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
BEInteger<T> BEInteger<T>::operator--(int)
|
||||
{
|
||||
BEInteger<T> orig(*this);
|
||||
--(*this);
|
||||
return orig;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
BEInteger<T>& BEInteger<T>::operator++()
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_beValueBytes, sizeof(T));
|
||||
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue++;
|
||||
BEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_beValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
BEInteger<T> BEInteger<T>::operator++(int)
|
||||
{
|
||||
BEInteger<T> orig(*this);
|
||||
++(*this);
|
||||
return orig;
|
||||
}
|
||||
|
||||
|
||||
typedef BEInteger<int16_t> BEInt16_t;
|
||||
typedef BEInteger<int32_t> BEInt32_t;
|
||||
typedef BEInteger<uint16_t> BEUInt16_t;
|
||||
typedef BEInteger<uint32_t> BEUInt32_t;
|
||||
|
||||
struct BESFixed32_t
|
||||
{
|
||||
BEInt16_t m_intPart;
|
||||
BEUInt16_t m_fracPart;
|
||||
};
|
||||
|
||||
struct BEUFixed32_t
|
||||
{
|
||||
BEUInt16_t m_intPart;
|
||||
BEUInt16_t m_fracPart;
|
||||
};
|
||||
|
||||
struct BESFixed16_t
|
||||
{
|
||||
int8_t m_intPart;
|
||||
uint8_t m_fracPart;
|
||||
};
|
||||
|
||||
struct BEUFixed16_t
|
||||
{
|
||||
uint8_t m_intPart;
|
||||
uint8_t m_fracPart;
|
||||
};
|
||||
|
||||
struct BESFixed16_t
|
||||
{
|
||||
int8_t m_intPart;
|
||||
uint8_t m_fracPart;
|
||||
};
|
||||
|
||||
struct BEUFixed16_t
|
||||
{
|
||||
uint8_t m_intPart;
|
||||
uint8_t m_fracPart;
|
||||
};
|
||||
|
@@ -1,245 +1,245 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
template<class T>
|
||||
struct LEInteger
|
||||
{
|
||||
public:
|
||||
LEInteger();
|
||||
LEInteger(const LEInteger<T> &other);
|
||||
explicit LEInteger(T i);
|
||||
|
||||
operator T() const;
|
||||
LEInteger<T> &operator=(T value);
|
||||
|
||||
template<class TOther>
|
||||
LEInteger<T> &operator+=(TOther value);
|
||||
|
||||
template<class TOther>
|
||||
LEInteger<T> &operator-=(TOther value);
|
||||
|
||||
template<class TOther>
|
||||
LEInteger<T> &operator*=(TOther value);
|
||||
|
||||
template<class TOther>
|
||||
LEInteger<T> &operator/=(TOther value);
|
||||
|
||||
template<class TOther>
|
||||
LEInteger<T> &operator%=(TOther value);
|
||||
|
||||
LEInteger<T>& operator--();
|
||||
LEInteger<T> operator--(int);
|
||||
|
||||
LEInteger<T>& operator++();
|
||||
LEInteger<T> operator++(int);
|
||||
|
||||
private:
|
||||
uint8_t m_leValueBytes[sizeof(T)];
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct LEInteger_SwapHelper
|
||||
{
|
||||
};
|
||||
|
||||
#include "ByteSwap.h"
|
||||
|
||||
template<>
|
||||
struct LEInteger_SwapHelper<int16_t>
|
||||
{
|
||||
inline static void Swap(int16_t &v)
|
||||
{
|
||||
PortabilityLayer::ByteSwap::LittleInt16(v);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct LEInteger_SwapHelper<int32_t>
|
||||
{
|
||||
inline static void Swap(int32_t &v)
|
||||
{
|
||||
PortabilityLayer::ByteSwap::LittleInt32(v);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct LEInteger_SwapHelper<uint16_t>
|
||||
{
|
||||
inline static void Swap(uint16_t &v)
|
||||
{
|
||||
PortabilityLayer::ByteSwap::LittleUInt16(v);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct LEInteger_SwapHelper<uint32_t>
|
||||
{
|
||||
inline static void Swap(uint32_t &v)
|
||||
{
|
||||
PortabilityLayer::ByteSwap::LittleUInt32(v);
|
||||
}
|
||||
};
|
||||
|
||||
#include <string.h>
|
||||
|
||||
template<class T>
|
||||
inline LEInteger<T>::LEInteger()
|
||||
{
|
||||
memset(m_leValueBytes, 0, sizeof(T));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline LEInteger<T>::LEInteger(const LEInteger<T> &other)
|
||||
{
|
||||
memcpy(m_leValueBytes, other.m_leValueBytes, sizeof(T));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline LEInteger<T>::LEInteger(T i)
|
||||
{
|
||||
LEInteger_SwapHelper<T>::Swap(i);
|
||||
memcpy(m_leValueBytes, &i, sizeof(T));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline LEInteger<T>::operator T() const
|
||||
{
|
||||
T result;
|
||||
memcpy(&result, m_leValueBytes, sizeof(T));
|
||||
LEInteger_SwapHelper<T>::Swap(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline LEInteger<T> &LEInteger<T>::operator=(T value)
|
||||
{
|
||||
LEInteger_SwapHelper<T>::Swap(value);
|
||||
memcpy(m_leValueBytes, &value, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
LEInteger<T> &LEInteger<T>::operator+=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_leValueBytes, sizeof(T));
|
||||
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue += value;
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_leValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
LEInteger<T> &LEInteger<T>::operator-=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_leValueBytes, sizeof(T));
|
||||
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue -= value;
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_leValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
LEInteger<T> &LEInteger<T>::operator*=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_leValueBytes, sizeof(T));
|
||||
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue *= value;
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_leValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
LEInteger<T> &LEInteger<T>::operator/=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_leValueBytes, sizeof(T));
|
||||
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue /= value;
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_leValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
LEInteger<T> &LEInteger<T>::operator%=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_leValueBytes, sizeof(T));
|
||||
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue %= value;
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_leValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
LEInteger<T>& LEInteger<T>::operator--()
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_leValueBytes, sizeof(T));
|
||||
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue--;
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_leValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
LEInteger<T> LEInteger<T>::operator--(int)
|
||||
{
|
||||
LEInteger<T> orig(*this);
|
||||
--(*this);
|
||||
return orig;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
LEInteger<T>& LEInteger<T>::operator++()
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_leValueBytes, sizeof(T));
|
||||
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue++;
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_leValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
LEInteger<T> LEInteger<T>::operator++(int)
|
||||
{
|
||||
LEInteger<T> orig(*this);
|
||||
++(*this);
|
||||
return orig;
|
||||
}
|
||||
|
||||
|
||||
typedef LEInteger<int16_t> LEInt16_t;
|
||||
typedef LEInteger<int32_t> LEInt32_t;
|
||||
typedef LEInteger<uint16_t> LEUInt16_t;
|
||||
typedef LEInteger<uint32_t> LEUInt32_t;
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
template<class T>
|
||||
struct LEInteger
|
||||
{
|
||||
public:
|
||||
LEInteger();
|
||||
LEInteger(const LEInteger<T> &other);
|
||||
explicit LEInteger(T i);
|
||||
|
||||
operator T() const;
|
||||
LEInteger<T> &operator=(T value);
|
||||
|
||||
template<class TOther>
|
||||
LEInteger<T> &operator+=(TOther value);
|
||||
|
||||
template<class TOther>
|
||||
LEInteger<T> &operator-=(TOther value);
|
||||
|
||||
template<class TOther>
|
||||
LEInteger<T> &operator*=(TOther value);
|
||||
|
||||
template<class TOther>
|
||||
LEInteger<T> &operator/=(TOther value);
|
||||
|
||||
template<class TOther>
|
||||
LEInteger<T> &operator%=(TOther value);
|
||||
|
||||
LEInteger<T>& operator--();
|
||||
LEInteger<T> operator--(int);
|
||||
|
||||
LEInteger<T>& operator++();
|
||||
LEInteger<T> operator++(int);
|
||||
|
||||
private:
|
||||
uint8_t m_leValueBytes[sizeof(T)];
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct LEInteger_SwapHelper
|
||||
{
|
||||
};
|
||||
|
||||
#include "ByteSwap.h"
|
||||
|
||||
template<>
|
||||
struct LEInteger_SwapHelper<int16_t>
|
||||
{
|
||||
inline static void Swap(int16_t &v)
|
||||
{
|
||||
PortabilityLayer::ByteSwap::LittleInt16(v);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct LEInteger_SwapHelper<int32_t>
|
||||
{
|
||||
inline static void Swap(int32_t &v)
|
||||
{
|
||||
PortabilityLayer::ByteSwap::LittleInt32(v);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct LEInteger_SwapHelper<uint16_t>
|
||||
{
|
||||
inline static void Swap(uint16_t &v)
|
||||
{
|
||||
PortabilityLayer::ByteSwap::LittleUInt16(v);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct LEInteger_SwapHelper<uint32_t>
|
||||
{
|
||||
inline static void Swap(uint32_t &v)
|
||||
{
|
||||
PortabilityLayer::ByteSwap::LittleUInt32(v);
|
||||
}
|
||||
};
|
||||
|
||||
#include <string.h>
|
||||
|
||||
template<class T>
|
||||
inline LEInteger<T>::LEInteger()
|
||||
{
|
||||
memset(m_leValueBytes, 0, sizeof(T));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline LEInteger<T>::LEInteger(const LEInteger<T> &other)
|
||||
{
|
||||
memcpy(m_leValueBytes, other.m_leValueBytes, sizeof(T));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline LEInteger<T>::LEInteger(T i)
|
||||
{
|
||||
LEInteger_SwapHelper<T>::Swap(i);
|
||||
memcpy(m_leValueBytes, &i, sizeof(T));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline LEInteger<T>::operator T() const
|
||||
{
|
||||
T result;
|
||||
memcpy(&result, m_leValueBytes, sizeof(T));
|
||||
LEInteger_SwapHelper<T>::Swap(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline LEInteger<T> &LEInteger<T>::operator=(T value)
|
||||
{
|
||||
LEInteger_SwapHelper<T>::Swap(value);
|
||||
memcpy(m_leValueBytes, &value, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
LEInteger<T> &LEInteger<T>::operator+=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_leValueBytes, sizeof(T));
|
||||
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue += value;
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_leValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
LEInteger<T> &LEInteger<T>::operator-=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_leValueBytes, sizeof(T));
|
||||
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue -= value;
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_leValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
LEInteger<T> &LEInteger<T>::operator*=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_leValueBytes, sizeof(T));
|
||||
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue *= value;
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_leValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
LEInteger<T> &LEInteger<T>::operator/=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_leValueBytes, sizeof(T));
|
||||
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue /= value;
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_leValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class TOther>
|
||||
LEInteger<T> &LEInteger<T>::operator%=(TOther value)
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_leValueBytes, sizeof(T));
|
||||
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue %= value;
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_leValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
LEInteger<T>& LEInteger<T>::operator--()
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_leValueBytes, sizeof(T));
|
||||
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue--;
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_leValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
LEInteger<T> LEInteger<T>::operator--(int)
|
||||
{
|
||||
LEInteger<T> orig(*this);
|
||||
--(*this);
|
||||
return orig;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
LEInteger<T>& LEInteger<T>::operator++()
|
||||
{
|
||||
T storedValue;
|
||||
memcpy(&storedValue, m_leValueBytes, sizeof(T));
|
||||
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
storedValue++;
|
||||
LEInteger_SwapHelper<T>::Swap(storedValue);
|
||||
|
||||
memcpy(m_leValueBytes, &storedValue, sizeof(T));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
LEInteger<T> LEInteger<T>::operator++(int)
|
||||
{
|
||||
LEInteger<T> orig(*this);
|
||||
++(*this);
|
||||
return orig;
|
||||
}
|
||||
|
||||
|
||||
typedef LEInteger<int16_t> LEInt16_t;
|
||||
typedef LEInteger<int32_t> LEInt32_t;
|
||||
typedef LEInteger<uint16_t> LEUInt16_t;
|
||||
typedef LEInteger<uint32_t> LEUInt32_t;
|
||||
|
@@ -1,79 +1,79 @@
|
||||
#pragma once
|
||||
#ifndef __PL_PASSTR_H__
|
||||
#define __PL_PASSTR_H__
|
||||
|
||||
#include "CoreDefs.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<size_t TSize>
|
||||
class PascalStrLiteral;
|
||||
}
|
||||
|
||||
class PLPasStr
|
||||
{
|
||||
public:
|
||||
PLPasStr();
|
||||
PLPasStr(const unsigned char *str);
|
||||
template<size_t TSize> PLPasStr(const PortabilityLayer::PascalStrLiteral<TSize> &pstrLiteral);
|
||||
PLPasStr(const PLPasStr &other);
|
||||
PLPasStr(unsigned char length, const char *str);
|
||||
|
||||
unsigned char Length() const;
|
||||
const char *Chars() const;
|
||||
const unsigned char *UChars() const;
|
||||
|
||||
private:
|
||||
unsigned char m_length;
|
||||
const char *m_chars;
|
||||
};
|
||||
|
||||
#include "PascalStrLiteral.h"
|
||||
|
||||
inline PLPasStr::PLPasStr()
|
||||
: m_length(0)
|
||||
, m_chars(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
inline PLPasStr::PLPasStr(const unsigned char *str)
|
||||
: m_length(str[0])
|
||||
, m_chars(reinterpret_cast<const char*>(str) + 1)
|
||||
{
|
||||
}
|
||||
|
||||
template<size_t TSize>
|
||||
inline PLPasStr::PLPasStr(const PortabilityLayer::PascalStrLiteral<TSize> &pstrLiteral)
|
||||
: m_length(pstrLiteral.kLength)
|
||||
, m_chars(pstrLiteral.GetStr())
|
||||
{
|
||||
}
|
||||
|
||||
inline PLPasStr::PLPasStr(const PLPasStr &other)
|
||||
: m_length(other.m_length)
|
||||
, m_chars(other.m_chars)
|
||||
{
|
||||
}
|
||||
|
||||
inline PLPasStr::PLPasStr(uint8_t length, const char *str)
|
||||
: m_length(length)
|
||||
, m_chars(str)
|
||||
{
|
||||
}
|
||||
|
||||
inline unsigned char PLPasStr::Length() const
|
||||
{
|
||||
return m_length;
|
||||
}
|
||||
|
||||
inline const char *PLPasStr::Chars() const
|
||||
{
|
||||
return m_chars;
|
||||
}
|
||||
|
||||
inline const unsigned char *PLPasStr::UChars() const
|
||||
{
|
||||
return reinterpret_cast<const unsigned char*>(m_chars);
|
||||
}
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
#ifndef __PL_PASSTR_H__
|
||||
#define __PL_PASSTR_H__
|
||||
|
||||
#include "CoreDefs.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<size_t TSize>
|
||||
class PascalStrLiteral;
|
||||
}
|
||||
|
||||
class PLPasStr
|
||||
{
|
||||
public:
|
||||
PLPasStr();
|
||||
PLPasStr(const unsigned char *str);
|
||||
template<size_t TSize> PLPasStr(const PortabilityLayer::PascalStrLiteral<TSize> &pstrLiteral);
|
||||
PLPasStr(const PLPasStr &other);
|
||||
PLPasStr(unsigned char length, const char *str);
|
||||
|
||||
unsigned char Length() const;
|
||||
const char *Chars() const;
|
||||
const unsigned char *UChars() const;
|
||||
|
||||
private:
|
||||
unsigned char m_length;
|
||||
const char *m_chars;
|
||||
};
|
||||
|
||||
#include "PascalStrLiteral.h"
|
||||
|
||||
inline PLPasStr::PLPasStr()
|
||||
: m_length(0)
|
||||
, m_chars(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
inline PLPasStr::PLPasStr(const unsigned char *str)
|
||||
: m_length(str[0])
|
||||
, m_chars(reinterpret_cast<const char*>(str) + 1)
|
||||
{
|
||||
}
|
||||
|
||||
template<size_t TSize>
|
||||
inline PLPasStr::PLPasStr(const PortabilityLayer::PascalStrLiteral<TSize> &pstrLiteral)
|
||||
: m_length(pstrLiteral.kLength)
|
||||
, m_chars(pstrLiteral.GetStr())
|
||||
{
|
||||
}
|
||||
|
||||
inline PLPasStr::PLPasStr(const PLPasStr &other)
|
||||
: m_length(other.m_length)
|
||||
, m_chars(other.m_chars)
|
||||
{
|
||||
}
|
||||
|
||||
inline PLPasStr::PLPasStr(uint8_t length, const char *str)
|
||||
: m_length(length)
|
||||
, m_chars(str)
|
||||
{
|
||||
}
|
||||
|
||||
inline unsigned char PLPasStr::Length() const
|
||||
{
|
||||
return m_length;
|
||||
}
|
||||
|
||||
inline const char *PLPasStr::Chars() const
|
||||
{
|
||||
return m_chars;
|
||||
}
|
||||
|
||||
inline const unsigned char *PLPasStr::UChars() const
|
||||
{
|
||||
return reinterpret_cast<const unsigned char*>(m_chars);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace RegionIDs
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
{
|
||||
template<class T>
|
||||
class UnalignedPtr
|
||||
{
|
||||
@@ -15,13 +15,13 @@ namespace PortabilityLayer
|
||||
private:
|
||||
const T *m_ref;
|
||||
};
|
||||
|
||||
|
||||
template<class T>
|
||||
UnalignedPtr<T>::UnalignedPtr()
|
||||
: m_ref(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
UnalignedPtr<T>::UnalignedPtr(const T *ref)
|
||||
: m_ref(ref)
|
||||
|
@@ -1,40 +1,40 @@
|
||||
#pragma once
|
||||
#ifndef __PL_PASCAL_STR_LITERAL_H__
|
||||
#define __PL_PASCAL_STR_LITERAL_H__
|
||||
|
||||
#include "DataTypes.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<size_t TSize>
|
||||
class PascalStrLiteral
|
||||
{
|
||||
public:
|
||||
PascalStrLiteral(const char (&literalStr)[TSize]);
|
||||
const char *GetStr() const;
|
||||
|
||||
static const uint8_t kLength = TSize - 1;
|
||||
|
||||
private:
|
||||
const char *m_literal;
|
||||
};
|
||||
}
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<size_t TSize>
|
||||
inline PascalStrLiteral<TSize>::PascalStrLiteral(const char(&literalStr)[TSize])
|
||||
: m_literal(literalStr)
|
||||
{
|
||||
}
|
||||
|
||||
template<size_t TSize>
|
||||
inline const char *PascalStrLiteral<TSize>::GetStr() const
|
||||
{
|
||||
return m_literal;
|
||||
}
|
||||
}
|
||||
|
||||
#define PSTR(n) (::PortabilityLayer::PascalStrLiteral<sizeof(n)>(n))
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
#ifndef __PL_PASCAL_STR_LITERAL_H__
|
||||
#define __PL_PASCAL_STR_LITERAL_H__
|
||||
|
||||
#include "DataTypes.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<size_t TSize>
|
||||
class PascalStrLiteral
|
||||
{
|
||||
public:
|
||||
PascalStrLiteral(const char (&literalStr)[TSize]);
|
||||
const char *GetStr() const;
|
||||
|
||||
static const uint8_t kLength = TSize - 1;
|
||||
|
||||
private:
|
||||
const char *m_literal;
|
||||
};
|
||||
}
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<size_t TSize>
|
||||
inline PascalStrLiteral<TSize>::PascalStrLiteral(const char(&literalStr)[TSize])
|
||||
: m_literal(literalStr)
|
||||
{
|
||||
}
|
||||
|
||||
template<size_t TSize>
|
||||
inline const char *PascalStrLiteral<TSize>::GetStr() const
|
||||
{
|
||||
return m_literal;
|
||||
}
|
||||
}
|
||||
|
||||
#define PSTR(n) (::PortabilityLayer::PascalStrLiteral<sizeof(n)>(n))
|
||||
|
||||
#endif
|
||||
|
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
enum PlotDirection
|
||||
{
|
||||
{
|
||||
PlotDirection_NegX_NegY,
|
||||
PlotDirection_0X_NegY,
|
||||
PlotDirection_PosX_NegY,
|
||||
|
@@ -1,85 +1,85 @@
|
||||
#include "AntiAliasTable.cpp"
|
||||
#include "AppEventHandler.cpp"
|
||||
#include "BinHex4.cpp"
|
||||
#include "BitmapImage.cpp"
|
||||
#include "ByteSwap.cpp"
|
||||
#include "CFileStream.cpp"
|
||||
#include "CompositeRenderedFont.cpp"
|
||||
#include "DeflateCodec.cpp"
|
||||
#include "DialogManager.cpp"
|
||||
#include "DisplayDeviceManager.cpp"
|
||||
#include "EllipsePlotter.cpp"
|
||||
#include "FileBrowserUI.cpp"
|
||||
#include "FileManager.cpp"
|
||||
#include "FileSectionStream.cpp"
|
||||
#include "FontFamily.cpp"
|
||||
#include "FontManager.cpp"
|
||||
#include "FontRenderer.cpp"
|
||||
#include "GPArchive.cpp"
|
||||
#include "HostSuspendHook.cpp"
|
||||
#include "IconLoader.cpp"
|
||||
#include "InflateStream.cpp"
|
||||
#include "InputManager.cpp"
|
||||
#include "LinePlotter.cpp"
|
||||
#include "MacBinary2.cpp"
|
||||
#include "MacFileInfo.cpp"
|
||||
#include "MacFileMem.cpp"
|
||||
#include "MemoryManager.cpp"
|
||||
#include "MemReaderStream.cpp"
|
||||
#include "MenuManager.cpp"
|
||||
#include "MMHandleBlock.cpp"
|
||||
#include "PLApplication.cpp"
|
||||
#include "PLButtonWidget.cpp"
|
||||
#include "PLControlDefinitions.cpp"
|
||||
#include "PLCore.cpp"
|
||||
#include "PLCTabReducer.cpp"
|
||||
#include "PLDialogs.cpp"
|
||||
#include "PLDrivers.cpp"
|
||||
#include "PLEditboxWidget.cpp"
|
||||
#include "PLEventQueue.cpp"
|
||||
#include "PLHacks.cpp"
|
||||
#include "PLHandle.cpp"
|
||||
#include "PLIconWidget.cpp"
|
||||
#include "PLImageWidget.cpp"
|
||||
#include "PLInvisibleWidget.cpp"
|
||||
#include "PLKeyEncoding.cpp"
|
||||
#include "PLLabelWidget.cpp"
|
||||
#include "PLMenus.cpp"
|
||||
#include "PLMovies.cpp"
|
||||
#include "PLNumberFormatting.cpp"
|
||||
#include "PLPopupMenuWidget.cpp"
|
||||
#include "PLQDOffscreen.cpp"
|
||||
#include "PLQDraw.cpp"
|
||||
#include "PLResourceManager.cpp"
|
||||
#include "PLResources.cpp"
|
||||
#include "PLScrollBarWidget.cpp"
|
||||
#include "PLSound.cpp"
|
||||
#include "PLStandardColors.cpp"
|
||||
#include "PLStringCompare.cpp"
|
||||
#include "PLSysCalls.cpp"
|
||||
#include "PLTimeTaggedVOSEvent.cpp"
|
||||
#include "PLWidgets.cpp"
|
||||
#include "QDGraf.cpp"
|
||||
#include "QDManager.cpp"
|
||||
#include "QDPictDecoder.cpp"
|
||||
#include "QDPictEmitContext.cpp"
|
||||
#include "QDPictHeader.cpp"
|
||||
#include "QDPixMap.cpp"
|
||||
#include "QDPort.cpp"
|
||||
#include "QDStandardPalette.cpp"
|
||||
#include "RandomNumberGenerator.cpp"
|
||||
#include "ResolveCachingColor.cpp"
|
||||
#include "ResourceCompiledRef.cpp"
|
||||
#include "ResourceFile.cpp"
|
||||
#include "ScanlineMask.cpp"
|
||||
#include "ScanlineMaskBuilder.cpp"
|
||||
#include "ScanlineMaskConverter.cpp"
|
||||
#include "ScanlineMaskIterator.cpp"
|
||||
#include "SimpleGraphic.cpp"
|
||||
#include "TextPlacer.cpp"
|
||||
#include "UTF8.cpp"
|
||||
#include "WindowDef.cpp"
|
||||
#include "WindowManager.cpp"
|
||||
#include "WorkerThread.cpp"
|
||||
#include "XModemCRC.cpp"
|
||||
#include "ZipFileProxy.cpp"
|
||||
#include "AntiAliasTable.cpp"
|
||||
#include "AppEventHandler.cpp"
|
||||
#include "BinHex4.cpp"
|
||||
#include "BitmapImage.cpp"
|
||||
#include "ByteSwap.cpp"
|
||||
#include "CFileStream.cpp"
|
||||
#include "CompositeRenderedFont.cpp"
|
||||
#include "DeflateCodec.cpp"
|
||||
#include "DialogManager.cpp"
|
||||
#include "DisplayDeviceManager.cpp"
|
||||
#include "EllipsePlotter.cpp"
|
||||
#include "FileBrowserUI.cpp"
|
||||
#include "FileManager.cpp"
|
||||
#include "FileSectionStream.cpp"
|
||||
#include "FontFamily.cpp"
|
||||
#include "FontManager.cpp"
|
||||
#include "FontRenderer.cpp"
|
||||
#include "GPArchive.cpp"
|
||||
#include "HostSuspendHook.cpp"
|
||||
#include "IconLoader.cpp"
|
||||
#include "InflateStream.cpp"
|
||||
#include "InputManager.cpp"
|
||||
#include "LinePlotter.cpp"
|
||||
#include "MacBinary2.cpp"
|
||||
#include "MacFileInfo.cpp"
|
||||
#include "MacFileMem.cpp"
|
||||
#include "MemoryManager.cpp"
|
||||
#include "MemReaderStream.cpp"
|
||||
#include "MenuManager.cpp"
|
||||
#include "MMHandleBlock.cpp"
|
||||
#include "PLApplication.cpp"
|
||||
#include "PLButtonWidget.cpp"
|
||||
#include "PLControlDefinitions.cpp"
|
||||
#include "PLCore.cpp"
|
||||
#include "PLCTabReducer.cpp"
|
||||
#include "PLDialogs.cpp"
|
||||
#include "PLDrivers.cpp"
|
||||
#include "PLEditboxWidget.cpp"
|
||||
#include "PLEventQueue.cpp"
|
||||
#include "PLHacks.cpp"
|
||||
#include "PLHandle.cpp"
|
||||
#include "PLIconWidget.cpp"
|
||||
#include "PLImageWidget.cpp"
|
||||
#include "PLInvisibleWidget.cpp"
|
||||
#include "PLKeyEncoding.cpp"
|
||||
#include "PLLabelWidget.cpp"
|
||||
#include "PLMenus.cpp"
|
||||
#include "PLMovies.cpp"
|
||||
#include "PLNumberFormatting.cpp"
|
||||
#include "PLPopupMenuWidget.cpp"
|
||||
#include "PLQDOffscreen.cpp"
|
||||
#include "PLQDraw.cpp"
|
||||
#include "PLResourceManager.cpp"
|
||||
#include "PLResources.cpp"
|
||||
#include "PLScrollBarWidget.cpp"
|
||||
#include "PLSound.cpp"
|
||||
#include "PLStandardColors.cpp"
|
||||
#include "PLStringCompare.cpp"
|
||||
#include "PLSysCalls.cpp"
|
||||
#include "PLTimeTaggedVOSEvent.cpp"
|
||||
#include "PLWidgets.cpp"
|
||||
#include "QDGraf.cpp"
|
||||
#include "QDManager.cpp"
|
||||
#include "QDPictDecoder.cpp"
|
||||
#include "QDPictEmitContext.cpp"
|
||||
#include "QDPictHeader.cpp"
|
||||
#include "QDPixMap.cpp"
|
||||
#include "QDPort.cpp"
|
||||
#include "QDStandardPalette.cpp"
|
||||
#include "RandomNumberGenerator.cpp"
|
||||
#include "ResolveCachingColor.cpp"
|
||||
#include "ResourceCompiledRef.cpp"
|
||||
#include "ResourceFile.cpp"
|
||||
#include "ScanlineMask.cpp"
|
||||
#include "ScanlineMaskBuilder.cpp"
|
||||
#include "ScanlineMaskConverter.cpp"
|
||||
#include "ScanlineMaskIterator.cpp"
|
||||
#include "SimpleGraphic.cpp"
|
||||
#include "TextPlacer.cpp"
|
||||
#include "UTF8.cpp"
|
||||
#include "WindowDef.cpp"
|
||||
#include "WindowManager.cpp"
|
||||
#include "WorkerThread.cpp"
|
||||
#include "XModemCRC.cpp"
|
||||
#include "ZipFileProxy.cpp"
|
||||
|
@@ -1,18 +1,18 @@
|
||||
#include "QDPictEmitContext.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
bool QDPictBlitSourceType_IsIndexed(QDPictBlitSourceType sourceType)
|
||||
{
|
||||
switch (sourceType)
|
||||
{
|
||||
case QDPictBlitSourceType_Indexed1Bit:
|
||||
case QDPictBlitSourceType_Indexed2Bit:
|
||||
case QDPictBlitSourceType_Indexed4Bit:
|
||||
case QDPictBlitSourceType_Indexed8Bit:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#include "QDPictEmitContext.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
bool QDPictBlitSourceType_IsIndexed(QDPictBlitSourceType sourceType)
|
||||
{
|
||||
switch (sourceType)
|
||||
{
|
||||
case QDPictBlitSourceType_Indexed1Bit:
|
||||
case QDPictBlitSourceType_Indexed2Bit:
|
||||
case QDPictBlitSourceType_Indexed4Bit:
|
||||
case QDPictBlitSourceType_Indexed8Bit:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,20 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct RGBAColor;
|
||||
|
||||
struct QDPictEmitScanlineParameters
|
||||
{
|
||||
const RGBAColor *m_colors;
|
||||
size_t m_numColors;
|
||||
size_t m_planarSeparation;
|
||||
|
||||
int32_t m_scanlineOriginX;
|
||||
int32_t m_firstY;
|
||||
int32_t m_constrainedRegionLeft;
|
||||
int32_t m_constrainedRegionRight;
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct RGBAColor;
|
||||
|
||||
struct QDPictEmitScanlineParameters
|
||||
{
|
||||
const RGBAColor *m_colors;
|
||||
size_t m_numColors;
|
||||
size_t m_planarSeparation;
|
||||
|
||||
int32_t m_scanlineOriginX;
|
||||
int32_t m_firstY;
|
||||
int32_t m_constrainedRegionLeft;
|
||||
int32_t m_constrainedRegionRight;
|
||||
};
|
||||
}
|
||||
|
@@ -1,24 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "SharedTypes.h"
|
||||
|
||||
class GpIOStream;
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class QDPictHeader
|
||||
{
|
||||
public:
|
||||
QDPictHeader();
|
||||
bool Load(GpIOStream *stream);
|
||||
|
||||
int GetVersion() const;
|
||||
const Rect &GetFrame() const;
|
||||
|
||||
private:
|
||||
Rect m_frame;
|
||||
|
||||
int m_pictVersion;
|
||||
};
|
||||
}
|
||||
|
||||
class GpIOStream;
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class QDPictHeader
|
||||
{
|
||||
public:
|
||||
QDPictHeader();
|
||||
bool Load(GpIOStream *stream);
|
||||
|
||||
int GetVersion() const;
|
||||
const Rect &GetFrame() const;
|
||||
|
||||
private:
|
||||
Rect m_frame;
|
||||
|
||||
int m_pictVersion;
|
||||
};
|
||||
}
|
||||
|
@@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
namespace QDOpcodes
|
||||
{
|
||||
enum Value
|
||||
{
|
||||
#define PL_PICTOP(number, opcode, sizeRule) opcode = number,
|
||||
#include "QDPictOpcodeDefs.h"
|
||||
#undef PL_PICTOP
|
||||
};
|
||||
}
|
||||
}
|
||||
#pragma once
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
namespace QDOpcodes
|
||||
{
|
||||
enum Value
|
||||
{
|
||||
#define PL_PICTOP(number, opcode, sizeRule) opcode = number,
|
||||
#include "QDPictOpcodeDefs.h"
|
||||
#undef PL_PICTOP
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "ByteSwap.h"
|
||||
#include "SharedTypes.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ByteSwap.h"
|
||||
#include "SharedTypes.h"
|
||||
|
||||
|
@@ -1,121 +1,121 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreDefs.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class RefCountedBase;
|
||||
|
||||
template<class T>
|
||||
class RCPtr
|
||||
{
|
||||
public:
|
||||
RCPtr();
|
||||
RCPtr(T *other);
|
||||
RCPtr(const RCPtr<T> &other);
|
||||
#if IS_CPP11
|
||||
RCPtr(RCPtr<T> &&other);
|
||||
#endif
|
||||
~RCPtr();
|
||||
|
||||
operator T*() const;
|
||||
T* operator ->() const;
|
||||
|
||||
RCPtr<T> &operator=(T *other);
|
||||
#if IS_CPP11
|
||||
RCPtr<T> &operator=(RCPtr<T> &&other);
|
||||
#endif
|
||||
|
||||
T *Get() const;
|
||||
|
||||
private:
|
||||
RefCountedBase *m_target;
|
||||
};
|
||||
}
|
||||
|
||||
#include "RefCounted.h"
|
||||
|
||||
template<class T>
|
||||
inline PortabilityLayer::RCPtr<T>::RCPtr()
|
||||
: m_target(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline PortabilityLayer::RCPtr<T>::RCPtr(const RCPtr<T> &other)
|
||||
: m_target(other.m_target)
|
||||
{
|
||||
if (m_target)
|
||||
m_target->IncRef();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline PortabilityLayer::RCPtr<T>::RCPtr(T *other)
|
||||
: m_target(other)
|
||||
{
|
||||
if (other)
|
||||
other->IncRef();
|
||||
}
|
||||
|
||||
#if IS_CPP11
|
||||
template<class T>
|
||||
inline PortabilityLayer::RCPtr<T>::RCPtr(RCPtr<T> &&other)
|
||||
: m_target(other.m_target)
|
||||
{
|
||||
other.m_target = nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class T>
|
||||
inline PortabilityLayer::RCPtr<T>::~RCPtr()
|
||||
{
|
||||
if (m_target)
|
||||
m_target->DecRef();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T *PortabilityLayer::RCPtr<T>::operator T*() const
|
||||
{
|
||||
return m_target;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T *PortabilityLayer::RCPtr<T>::operator->() const
|
||||
{
|
||||
return m_target;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline PortabilityLayer::RCPtr<T>::RCPtr<T> &PortabilityLayer::RCPtr<T>::operator=(T *other)
|
||||
{
|
||||
RefCountedBase *old = m_target;
|
||||
|
||||
m_target = other;
|
||||
if (other)
|
||||
other->IncRef();
|
||||
|
||||
if (old)
|
||||
old->DecRef();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if IS_CPP11
|
||||
template<class T>
|
||||
inline PortabilityLayer::RCPtr<T>& PortabilityLayer::RCPtr<T>::RCPtr<T> &operator=(RCPtr<TOther> &&other)
|
||||
{
|
||||
RefCountedBase *old = m_target;
|
||||
RefCountedBase *newRC = other.m_target;
|
||||
|
||||
other.m_target = nullptr;
|
||||
|
||||
m_target = newRC;
|
||||
if (newRC)
|
||||
newRC->IncRef();
|
||||
|
||||
if (old)
|
||||
old->DecRef();
|
||||
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
#pragma once
|
||||
|
||||
#include "CoreDefs.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class RefCountedBase;
|
||||
|
||||
template<class T>
|
||||
class RCPtr
|
||||
{
|
||||
public:
|
||||
RCPtr();
|
||||
RCPtr(T *other);
|
||||
RCPtr(const RCPtr<T> &other);
|
||||
#if IS_CPP11
|
||||
RCPtr(RCPtr<T> &&other);
|
||||
#endif
|
||||
~RCPtr();
|
||||
|
||||
operator T*() const;
|
||||
T* operator ->() const;
|
||||
|
||||
RCPtr<T> &operator=(T *other);
|
||||
#if IS_CPP11
|
||||
RCPtr<T> &operator=(RCPtr<T> &&other);
|
||||
#endif
|
||||
|
||||
T *Get() const;
|
||||
|
||||
private:
|
||||
RefCountedBase *m_target;
|
||||
};
|
||||
}
|
||||
|
||||
#include "RefCounted.h"
|
||||
|
||||
template<class T>
|
||||
inline PortabilityLayer::RCPtr<T>::RCPtr()
|
||||
: m_target(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline PortabilityLayer::RCPtr<T>::RCPtr(const RCPtr<T> &other)
|
||||
: m_target(other.m_target)
|
||||
{
|
||||
if (m_target)
|
||||
m_target->IncRef();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline PortabilityLayer::RCPtr<T>::RCPtr(T *other)
|
||||
: m_target(other)
|
||||
{
|
||||
if (other)
|
||||
other->IncRef();
|
||||
}
|
||||
|
||||
#if IS_CPP11
|
||||
template<class T>
|
||||
inline PortabilityLayer::RCPtr<T>::RCPtr(RCPtr<T> &&other)
|
||||
: m_target(other.m_target)
|
||||
{
|
||||
other.m_target = nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class T>
|
||||
inline PortabilityLayer::RCPtr<T>::~RCPtr()
|
||||
{
|
||||
if (m_target)
|
||||
m_target->DecRef();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T *PortabilityLayer::RCPtr<T>::operator T*() const
|
||||
{
|
||||
return m_target;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T *PortabilityLayer::RCPtr<T>::operator->() const
|
||||
{
|
||||
return m_target;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline PortabilityLayer::RCPtr<T>::RCPtr<T> &PortabilityLayer::RCPtr<T>::operator=(T *other)
|
||||
{
|
||||
RefCountedBase *old = m_target;
|
||||
|
||||
m_target = other;
|
||||
if (other)
|
||||
other->IncRef();
|
||||
|
||||
if (old)
|
||||
old->DecRef();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if IS_CPP11
|
||||
template<class T>
|
||||
inline PortabilityLayer::RCPtr<T>& PortabilityLayer::RCPtr<T>::RCPtr<T> &operator=(RCPtr<TOther> &&other)
|
||||
{
|
||||
RefCountedBase *old = m_target;
|
||||
RefCountedBase *newRC = other.m_target;
|
||||
|
||||
other.m_target = nullptr;
|
||||
|
||||
m_target = newRC;
|
||||
if (newRC)
|
||||
newRC->IncRef();
|
||||
|
||||
if (old)
|
||||
old->DecRef();
|
||||
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
@@ -1,85 +1,85 @@
|
||||
#include "RandomNumberGenerator.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class RandomNumberGeneratorMT19937 final : public RandomNumberGenerator
|
||||
{
|
||||
public:
|
||||
RandomNumberGeneratorMT19937();
|
||||
|
||||
void Seed(uint32_t seed) override;
|
||||
uint32_t GetNextAndAdvance() override;
|
||||
|
||||
static RandomNumberGeneratorMT19937 *GetInstance();
|
||||
|
||||
private:
|
||||
static const uint32_t kA = 0x9908b0df;
|
||||
static const int kW = 32;
|
||||
static const int kN = 624;
|
||||
static const int kM = 397;
|
||||
static const int kR = 31;
|
||||
static const uint32_t kLowMask = (static_cast<uint32_t>(1) << kR) - 1;
|
||||
static const uint32_t kHighMask = ~kLowMask;
|
||||
|
||||
void Twist();
|
||||
|
||||
uint32_t m_state[kN];
|
||||
int m_index;
|
||||
|
||||
static RandomNumberGeneratorMT19937 ms_instance;
|
||||
};
|
||||
|
||||
RandomNumberGeneratorMT19937::RandomNumberGeneratorMT19937()
|
||||
{
|
||||
Seed(0x243F6A88); // First 8 hex digits of pi
|
||||
}
|
||||
|
||||
void RandomNumberGeneratorMT19937::Seed(uint32_t seed)
|
||||
{
|
||||
m_index = kN;
|
||||
|
||||
m_state[0] = seed;
|
||||
for (unsigned int i = 1; i < kN; i++)
|
||||
{
|
||||
const uint32_t prev = m_state[i - 1];
|
||||
m_state[i] = static_cast<uint32_t>((static_cast<uint64_t>(1812433253) * static_cast<uint64_t>(prev ^ (prev >> 30)) + i) & 0xffffffff);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t RandomNumberGeneratorMT19937::GetNextAndAdvance()
|
||||
{
|
||||
if (m_index == kN)
|
||||
Twist();
|
||||
|
||||
uint32_t x = m_state[m_index++];
|
||||
x ^= (x >> 11);
|
||||
x ^= (x >> 7) & 0x9d2c5680;
|
||||
x ^= (x << 15) & 0xefc60000;
|
||||
return x ^ (x >> 18);
|
||||
}
|
||||
|
||||
void RandomNumberGeneratorMT19937::Twist()
|
||||
{
|
||||
for (unsigned int i = 0; i < kN; i++)
|
||||
{
|
||||
uint32_t x = (m_state[i] & kHighMask) + (m_state[(i + 1) % kN] & kLowMask);
|
||||
uint32_t xA = x >> 1;
|
||||
if ((x & 1) == 1)
|
||||
xA ^= kA;
|
||||
m_state[i] = m_state[(i + kM) % kN] ^ kA;
|
||||
}
|
||||
m_index = 0;
|
||||
}
|
||||
|
||||
RandomNumberGeneratorMT19937 *RandomNumberGeneratorMT19937::GetInstance()
|
||||
{
|
||||
return &ms_instance;
|
||||
}
|
||||
|
||||
RandomNumberGeneratorMT19937 RandomNumberGeneratorMT19937::ms_instance;
|
||||
|
||||
RandomNumberGenerator* RandomNumberGenerator::GetInstance()
|
||||
{
|
||||
return RandomNumberGeneratorMT19937::GetInstance();
|
||||
}
|
||||
}
|
||||
#include "RandomNumberGenerator.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class RandomNumberGeneratorMT19937 final : public RandomNumberGenerator
|
||||
{
|
||||
public:
|
||||
RandomNumberGeneratorMT19937();
|
||||
|
||||
void Seed(uint32_t seed) override;
|
||||
uint32_t GetNextAndAdvance() override;
|
||||
|
||||
static RandomNumberGeneratorMT19937 *GetInstance();
|
||||
|
||||
private:
|
||||
static const uint32_t kA = 0x9908b0df;
|
||||
static const int kW = 32;
|
||||
static const int kN = 624;
|
||||
static const int kM = 397;
|
||||
static const int kR = 31;
|
||||
static const uint32_t kLowMask = (static_cast<uint32_t>(1) << kR) - 1;
|
||||
static const uint32_t kHighMask = ~kLowMask;
|
||||
|
||||
void Twist();
|
||||
|
||||
uint32_t m_state[kN];
|
||||
int m_index;
|
||||
|
||||
static RandomNumberGeneratorMT19937 ms_instance;
|
||||
};
|
||||
|
||||
RandomNumberGeneratorMT19937::RandomNumberGeneratorMT19937()
|
||||
{
|
||||
Seed(0x243F6A88); // First 8 hex digits of pi
|
||||
}
|
||||
|
||||
void RandomNumberGeneratorMT19937::Seed(uint32_t seed)
|
||||
{
|
||||
m_index = kN;
|
||||
|
||||
m_state[0] = seed;
|
||||
for (unsigned int i = 1; i < kN; i++)
|
||||
{
|
||||
const uint32_t prev = m_state[i - 1];
|
||||
m_state[i] = static_cast<uint32_t>((static_cast<uint64_t>(1812433253) * static_cast<uint64_t>(prev ^ (prev >> 30)) + i) & 0xffffffff);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t RandomNumberGeneratorMT19937::GetNextAndAdvance()
|
||||
{
|
||||
if (m_index == kN)
|
||||
Twist();
|
||||
|
||||
uint32_t x = m_state[m_index++];
|
||||
x ^= (x >> 11);
|
||||
x ^= (x >> 7) & 0x9d2c5680;
|
||||
x ^= (x << 15) & 0xefc60000;
|
||||
return x ^ (x >> 18);
|
||||
}
|
||||
|
||||
void RandomNumberGeneratorMT19937::Twist()
|
||||
{
|
||||
for (unsigned int i = 0; i < kN; i++)
|
||||
{
|
||||
uint32_t x = (m_state[i] & kHighMask) + (m_state[(i + 1) % kN] & kLowMask);
|
||||
uint32_t xA = x >> 1;
|
||||
if ((x & 1) == 1)
|
||||
xA ^= kA;
|
||||
m_state[i] = m_state[(i + kM) % kN] ^ kA;
|
||||
}
|
||||
m_index = 0;
|
||||
}
|
||||
|
||||
RandomNumberGeneratorMT19937 *RandomNumberGeneratorMT19937::GetInstance()
|
||||
{
|
||||
return &ms_instance;
|
||||
}
|
||||
|
||||
RandomNumberGeneratorMT19937 RandomNumberGeneratorMT19937::ms_instance;
|
||||
|
||||
RandomNumberGenerator* RandomNumberGenerator::GetInstance()
|
||||
{
|
||||
return RandomNumberGeneratorMT19937::GetInstance();
|
||||
}
|
||||
}
|
||||
|
@@ -1,19 +1,19 @@
|
||||
#pragma once
|
||||
#ifndef __PL_RANDOM_NUMBER_GENERATOR_H__
|
||||
#define __PL_RANDOM_NUMBER_GENERATOR_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class RandomNumberGenerator
|
||||
{
|
||||
public:
|
||||
virtual void Seed(uint32_t seed) = 0;
|
||||
virtual uint32_t GetNextAndAdvance() = 0;
|
||||
|
||||
static RandomNumberGenerator *GetInstance();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
#ifndef __PL_RANDOM_NUMBER_GENERATOR_H__
|
||||
#define __PL_RANDOM_NUMBER_GENERATOR_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class RandomNumberGenerator
|
||||
{
|
||||
public:
|
||||
virtual void Seed(uint32_t seed) = 0;
|
||||
virtual uint32_t GetNextAndAdvance() = 0;
|
||||
|
||||
static RandomNumberGenerator *GetInstance();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,171 +1,171 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Vec2i.h"
|
||||
|
||||
struct Rect;
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct Vec2i;
|
||||
|
||||
struct Rect2i
|
||||
{
|
||||
Vec2i m_topLeft;
|
||||
Vec2i m_bottomRight;
|
||||
|
||||
Rect2i();
|
||||
Rect2i(const Rect2i &other);
|
||||
explicit Rect2i(const Rect &other);
|
||||
Rect2i(const Vec2i &topLeft, const Vec2i &bottomRight);
|
||||
Rect2i(int32_t top, int32_t left, int32_t bottom, int32_t right);
|
||||
|
||||
Rect2i operator+(const Vec2i &other) const;
|
||||
Rect2i operator-(const Vec2i &other) const;
|
||||
|
||||
Rect2i &operator+=(const Vec2i &other);
|
||||
Rect2i &operator-=(const Vec2i &other);
|
||||
|
||||
int32_t Top() const;
|
||||
void SetTop(int32_t i);
|
||||
|
||||
int32_t Left() const;
|
||||
void SetLeft(int32_t i);
|
||||
|
||||
int32_t Bottom() const;
|
||||
void SetBottom(int32_t i);
|
||||
|
||||
int32_t Right() const;
|
||||
void SetRight(int32_t i);
|
||||
|
||||
bool IsValid() const;
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Vec2i.h"
|
||||
|
||||
struct Rect;
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct Vec2i;
|
||||
|
||||
struct Rect2i
|
||||
{
|
||||
Vec2i m_topLeft;
|
||||
Vec2i m_bottomRight;
|
||||
|
||||
Rect2i();
|
||||
Rect2i(const Rect2i &other);
|
||||
explicit Rect2i(const Rect &other);
|
||||
Rect2i(const Vec2i &topLeft, const Vec2i &bottomRight);
|
||||
Rect2i(int32_t top, int32_t left, int32_t bottom, int32_t right);
|
||||
|
||||
Rect2i operator+(const Vec2i &other) const;
|
||||
Rect2i operator-(const Vec2i &other) const;
|
||||
|
||||
Rect2i &operator+=(const Vec2i &other);
|
||||
Rect2i &operator-=(const Vec2i &other);
|
||||
|
||||
int32_t Top() const;
|
||||
void SetTop(int32_t i);
|
||||
|
||||
int32_t Left() const;
|
||||
void SetLeft(int32_t i);
|
||||
|
||||
int32_t Bottom() const;
|
||||
void SetBottom(int32_t i);
|
||||
|
||||
int32_t Right() const;
|
||||
void SetRight(int32_t i);
|
||||
|
||||
bool IsValid() const;
|
||||
Rect2i Intersect(const Rect2i &other) const;
|
||||
bool Contains(const Vec2i &pt) const;
|
||||
|
||||
Rect ToShortRect() const;
|
||||
};
|
||||
}
|
||||
|
||||
#include "SharedTypes.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
inline Rect2i::Rect2i()
|
||||
{
|
||||
}
|
||||
|
||||
inline Rect2i::Rect2i(const Rect2i &other)
|
||||
: m_topLeft(other.m_topLeft)
|
||||
, m_bottomRight(other.m_bottomRight)
|
||||
{
|
||||
}
|
||||
|
||||
inline Rect2i::Rect2i(const Rect &other)
|
||||
: m_topLeft(other.left, other.top)
|
||||
, m_bottomRight(other.right, other.bottom)
|
||||
{
|
||||
}
|
||||
|
||||
inline Rect2i::Rect2i(int32_t top, int32_t left, int32_t bottom, int32_t right)
|
||||
: m_topLeft(left, top)
|
||||
, m_bottomRight(right, bottom)
|
||||
{
|
||||
}
|
||||
|
||||
inline Rect2i::Rect2i(const Vec2i &topLeft, const Vec2i &bottomRight)
|
||||
: m_topLeft(topLeft)
|
||||
, m_bottomRight(bottomRight)
|
||||
{
|
||||
}
|
||||
|
||||
inline Rect2i Rect2i::operator+(const Vec2i &other) const
|
||||
{
|
||||
return Rect2i(m_topLeft + other, m_bottomRight + other);
|
||||
}
|
||||
|
||||
inline Rect2i Rect2i::operator-(const Vec2i &other) const
|
||||
{
|
||||
return Rect2i(m_topLeft - other, m_bottomRight - other);
|
||||
}
|
||||
|
||||
inline Rect2i &Rect2i::operator+=(const Vec2i &other)
|
||||
{
|
||||
m_topLeft += other;
|
||||
m_bottomRight += other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Rect2i &Rect2i::operator-=(const Vec2i &other)
|
||||
{
|
||||
m_topLeft -= other;
|
||||
m_bottomRight -= other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline int32_t Rect2i::Top() const
|
||||
{
|
||||
return m_topLeft.m_y;
|
||||
}
|
||||
|
||||
inline void Rect2i::SetTop(int32_t i)
|
||||
{
|
||||
m_topLeft.m_y = i;
|
||||
}
|
||||
|
||||
inline int32_t Rect2i::Left() const
|
||||
{
|
||||
return m_topLeft.m_x;
|
||||
}
|
||||
|
||||
inline void Rect2i::SetLeft(int32_t i)
|
||||
{
|
||||
m_topLeft.m_x = i;
|
||||
}
|
||||
|
||||
inline int32_t Rect2i::Bottom() const
|
||||
{
|
||||
return m_bottomRight.m_y;
|
||||
}
|
||||
|
||||
inline void Rect2i::SetBottom(int32_t i)
|
||||
{
|
||||
m_bottomRight.m_y = i;
|
||||
}
|
||||
|
||||
inline int32_t Rect2i::Right() const
|
||||
{
|
||||
return m_bottomRight.m_x;
|
||||
}
|
||||
|
||||
inline void Rect2i::SetRight(int32_t i)
|
||||
{
|
||||
m_bottomRight.m_x = i;
|
||||
}
|
||||
|
||||
inline bool Rect2i::IsValid() const
|
||||
{
|
||||
return m_bottomRight.m_x >= m_topLeft.m_x && m_bottomRight.m_y >= m_topLeft.m_y;
|
||||
}
|
||||
|
||||
inline Rect2i Rect2i::Intersect(const Rect2i &other) const
|
||||
{
|
||||
const int32_t top = std::max(m_topLeft.m_y, other.m_topLeft.m_y);
|
||||
const int32_t left = std::max(m_topLeft.m_x, other.m_topLeft.m_x);
|
||||
const int32_t bottom = std::min(m_bottomRight.m_y, other.m_bottomRight.m_y);
|
||||
const int32_t right = std::min(m_bottomRight.m_x, other.m_bottomRight.m_x);
|
||||
|
||||
return Rect2i(top, left, bottom, right);
|
||||
bool Contains(const Vec2i &pt) const;
|
||||
|
||||
Rect ToShortRect() const;
|
||||
};
|
||||
}
|
||||
|
||||
#include "SharedTypes.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
inline Rect2i::Rect2i()
|
||||
{
|
||||
}
|
||||
|
||||
inline Rect2i::Rect2i(const Rect2i &other)
|
||||
: m_topLeft(other.m_topLeft)
|
||||
, m_bottomRight(other.m_bottomRight)
|
||||
{
|
||||
}
|
||||
|
||||
inline Rect2i::Rect2i(const Rect &other)
|
||||
: m_topLeft(other.left, other.top)
|
||||
, m_bottomRight(other.right, other.bottom)
|
||||
{
|
||||
}
|
||||
|
||||
inline Rect2i::Rect2i(int32_t top, int32_t left, int32_t bottom, int32_t right)
|
||||
: m_topLeft(left, top)
|
||||
, m_bottomRight(right, bottom)
|
||||
{
|
||||
}
|
||||
|
||||
inline Rect2i::Rect2i(const Vec2i &topLeft, const Vec2i &bottomRight)
|
||||
: m_topLeft(topLeft)
|
||||
, m_bottomRight(bottomRight)
|
||||
{
|
||||
}
|
||||
|
||||
inline Rect2i Rect2i::operator+(const Vec2i &other) const
|
||||
{
|
||||
return Rect2i(m_topLeft + other, m_bottomRight + other);
|
||||
}
|
||||
|
||||
inline Rect2i Rect2i::operator-(const Vec2i &other) const
|
||||
{
|
||||
return Rect2i(m_topLeft - other, m_bottomRight - other);
|
||||
}
|
||||
|
||||
inline Rect2i &Rect2i::operator+=(const Vec2i &other)
|
||||
{
|
||||
m_topLeft += other;
|
||||
m_bottomRight += other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Rect2i &Rect2i::operator-=(const Vec2i &other)
|
||||
{
|
||||
m_topLeft -= other;
|
||||
m_bottomRight -= other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline int32_t Rect2i::Top() const
|
||||
{
|
||||
return m_topLeft.m_y;
|
||||
}
|
||||
|
||||
inline void Rect2i::SetTop(int32_t i)
|
||||
{
|
||||
m_topLeft.m_y = i;
|
||||
}
|
||||
|
||||
inline int32_t Rect2i::Left() const
|
||||
{
|
||||
return m_topLeft.m_x;
|
||||
}
|
||||
|
||||
inline void Rect2i::SetLeft(int32_t i)
|
||||
{
|
||||
m_topLeft.m_x = i;
|
||||
}
|
||||
|
||||
inline int32_t Rect2i::Bottom() const
|
||||
{
|
||||
return m_bottomRight.m_y;
|
||||
}
|
||||
|
||||
inline void Rect2i::SetBottom(int32_t i)
|
||||
{
|
||||
m_bottomRight.m_y = i;
|
||||
}
|
||||
|
||||
inline int32_t Rect2i::Right() const
|
||||
{
|
||||
return m_bottomRight.m_x;
|
||||
}
|
||||
|
||||
inline void Rect2i::SetRight(int32_t i)
|
||||
{
|
||||
m_bottomRight.m_x = i;
|
||||
}
|
||||
|
||||
inline bool Rect2i::IsValid() const
|
||||
{
|
||||
return m_bottomRight.m_x >= m_topLeft.m_x && m_bottomRight.m_y >= m_topLeft.m_y;
|
||||
}
|
||||
|
||||
inline Rect2i Rect2i::Intersect(const Rect2i &other) const
|
||||
{
|
||||
const int32_t top = std::max(m_topLeft.m_y, other.m_topLeft.m_y);
|
||||
const int32_t left = std::max(m_topLeft.m_x, other.m_topLeft.m_x);
|
||||
const int32_t bottom = std::min(m_bottomRight.m_y, other.m_bottomRight.m_y);
|
||||
const int32_t right = std::min(m_bottomRight.m_x, other.m_bottomRight.m_x);
|
||||
|
||||
return Rect2i(top, left, bottom, right);
|
||||
}
|
||||
|
||||
inline bool Rect2i::Contains(const Vec2i &pt) const
|
||||
{
|
||||
return pt.m_x >= m_topLeft.m_x && pt.m_x < m_bottomRight.m_x && pt.m_y >= m_topLeft.m_y && pt.m_y < m_bottomRight.m_y;
|
||||
}
|
||||
|
||||
inline Rect Rect2i::ToShortRect() const
|
||||
{
|
||||
return Rect::Create(static_cast<int16_t>(m_topLeft.m_y), static_cast<int16_t>(m_topLeft.m_x), static_cast<int16_t>(m_bottomRight.m_y), static_cast<int16_t>(m_bottomRight.m_x));
|
||||
}
|
||||
}
|
||||
return pt.m_x >= m_topLeft.m_x && pt.m_x < m_bottomRight.m_x && pt.m_y >= m_topLeft.m_y && pt.m_y < m_bottomRight.m_y;
|
||||
}
|
||||
|
||||
inline Rect Rect2i::ToShortRect() const
|
||||
{
|
||||
return Rect::Create(static_cast<int16_t>(m_topLeft.m_y), static_cast<int16_t>(m_topLeft.m_x), static_cast<int16_t>(m_bottomRight.m_y), static_cast<int16_t>(m_bottomRight.m_x));
|
||||
}
|
||||
}
|
||||
|
@@ -1,38 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class RefCountedBase
|
||||
{
|
||||
public:
|
||||
RefCountedBase();
|
||||
virtual ~RefCountedBase();
|
||||
virtual void Release() = 0;
|
||||
|
||||
void IncRef();
|
||||
void DecRef();
|
||||
|
||||
private:
|
||||
unsigned int m_refCount;
|
||||
};
|
||||
}
|
||||
|
||||
inline PortabilityLayer::RefCountedBase::RefCountedBase()
|
||||
: m_refCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline PortabilityLayer::RefCountedBase::~RefCountedBase()
|
||||
{
|
||||
}
|
||||
|
||||
inline void PortabilityLayer::RefCountedBase::IncRef()
|
||||
{
|
||||
m_refCount++;
|
||||
}
|
||||
|
||||
inline void PortabilityLayer::RefCountedBase::DecRef()
|
||||
{
|
||||
if (--m_refCount == 0)
|
||||
this->Release();
|
||||
}
|
||||
#pragma once
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class RefCountedBase
|
||||
{
|
||||
public:
|
||||
RefCountedBase();
|
||||
virtual ~RefCountedBase();
|
||||
virtual void Release() = 0;
|
||||
|
||||
void IncRef();
|
||||
void DecRef();
|
||||
|
||||
private:
|
||||
unsigned int m_refCount;
|
||||
};
|
||||
}
|
||||
|
||||
inline PortabilityLayer::RefCountedBase::RefCountedBase()
|
||||
: m_refCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline PortabilityLayer::RefCountedBase::~RefCountedBase()
|
||||
{
|
||||
}
|
||||
|
||||
inline void PortabilityLayer::RefCountedBase::IncRef()
|
||||
{
|
||||
m_refCount++;
|
||||
}
|
||||
|
||||
inline void PortabilityLayer::RefCountedBase::DecRef()
|
||||
{
|
||||
if (--m_refCount == 0)
|
||||
this->Release();
|
||||
}
|
||||
|
@@ -1,70 +1,70 @@
|
||||
#pragma once
|
||||
#ifndef __PL_RES_TYPE_ID_CODEC_H__
|
||||
#define __PL_RES_TYPE_ID_CODEC_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<int32_t T>
|
||||
class ResTypeIDCodecResolver
|
||||
{
|
||||
};
|
||||
|
||||
template<>
|
||||
class ResTypeIDCodecResolver<0x64636261>
|
||||
{
|
||||
public:
|
||||
static void Encode(int32_t id, char *chars);
|
||||
static int32_t Decode(const char *chars);
|
||||
};
|
||||
|
||||
template<>
|
||||
class ResTypeIDCodecResolver<0x61626364>
|
||||
{
|
||||
public:
|
||||
static void Encode(int32_t id, char *chars);
|
||||
static int32_t Decode(const char *chars);
|
||||
};
|
||||
|
||||
typedef ResTypeIDCodecResolver<'abcd'> ResTypeIDCodec;
|
||||
}
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
inline void ResTypeIDCodecResolver<0x64636261>::Encode(int32_t id, char *chars)
|
||||
{
|
||||
chars[0] = static_cast<char>((id >> 0) & 0xff);
|
||||
chars[1] = static_cast<char>((id >> 8) & 0xff);
|
||||
chars[2] = static_cast<char>((id >> 16) & 0xff);
|
||||
chars[3] = static_cast<char>((id >> 24) & 0xff);
|
||||
}
|
||||
|
||||
inline int32_t ResTypeIDCodecResolver<0x64636261>::Decode(const char *chars)
|
||||
{
|
||||
return static_cast<int32_t>(
|
||||
((chars[0] & 0xff) << 0)
|
||||
| ((chars[1] & 0xff) << 8)
|
||||
| ((chars[2] & 0xff) << 16)
|
||||
| ((chars[3] & 0xff) << 24));
|
||||
}
|
||||
|
||||
inline void ResTypeIDCodecResolver<0x61626364>::Encode(int32_t id, char *chars)
|
||||
{
|
||||
chars[0] = static_cast<char>((id >> 24) & 0xff);
|
||||
chars[1] = static_cast<char>((id >> 16) & 0xff);
|
||||
chars[2] = static_cast<char>((id >> 8) & 0xff);
|
||||
chars[3] = static_cast<char>((id >> 0) & 0xff);
|
||||
}
|
||||
|
||||
inline int32_t ResTypeIDCodecResolver<0x61626364>::Decode(const char *chars)
|
||||
{
|
||||
return static_cast<int32_t>(
|
||||
((chars[0] & 0xff) << 24)
|
||||
| ((chars[1] & 0xff) << 16)
|
||||
| ((chars[2] & 0xff) << 8)
|
||||
| ((chars[3] & 0xff) << 0));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
#ifndef __PL_RES_TYPE_ID_CODEC_H__
|
||||
#define __PL_RES_TYPE_ID_CODEC_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<int32_t T>
|
||||
class ResTypeIDCodecResolver
|
||||
{
|
||||
};
|
||||
|
||||
template<>
|
||||
class ResTypeIDCodecResolver<0x64636261>
|
||||
{
|
||||
public:
|
||||
static void Encode(int32_t id, char *chars);
|
||||
static int32_t Decode(const char *chars);
|
||||
};
|
||||
|
||||
template<>
|
||||
class ResTypeIDCodecResolver<0x61626364>
|
||||
{
|
||||
public:
|
||||
static void Encode(int32_t id, char *chars);
|
||||
static int32_t Decode(const char *chars);
|
||||
};
|
||||
|
||||
typedef ResTypeIDCodecResolver<'abcd'> ResTypeIDCodec;
|
||||
}
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
inline void ResTypeIDCodecResolver<0x64636261>::Encode(int32_t id, char *chars)
|
||||
{
|
||||
chars[0] = static_cast<char>((id >> 0) & 0xff);
|
||||
chars[1] = static_cast<char>((id >> 8) & 0xff);
|
||||
chars[2] = static_cast<char>((id >> 16) & 0xff);
|
||||
chars[3] = static_cast<char>((id >> 24) & 0xff);
|
||||
}
|
||||
|
||||
inline int32_t ResTypeIDCodecResolver<0x64636261>::Decode(const char *chars)
|
||||
{
|
||||
return static_cast<int32_t>(
|
||||
((chars[0] & 0xff) << 0)
|
||||
| ((chars[1] & 0xff) << 8)
|
||||
| ((chars[2] & 0xff) << 16)
|
||||
| ((chars[3] & 0xff) << 24));
|
||||
}
|
||||
|
||||
inline void ResTypeIDCodecResolver<0x61626364>::Encode(int32_t id, char *chars)
|
||||
{
|
||||
chars[0] = static_cast<char>((id >> 24) & 0xff);
|
||||
chars[1] = static_cast<char>((id >> 16) & 0xff);
|
||||
chars[2] = static_cast<char>((id >> 8) & 0xff);
|
||||
chars[3] = static_cast<char>((id >> 0) & 0xff);
|
||||
}
|
||||
|
||||
inline int32_t ResTypeIDCodecResolver<0x61626364>::Decode(const char *chars)
|
||||
{
|
||||
return static_cast<int32_t>(
|
||||
((chars[0] & 0xff) << 24)
|
||||
| ((chars[1] & 0xff) << 16)
|
||||
| ((chars[2] & 0xff) << 8)
|
||||
| ((chars[3] & 0xff) << 0));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -5,5 +5,5 @@
|
||||
union ResolvedColor
|
||||
{
|
||||
uint8_t m_indexed;
|
||||
PortabilityLayer::RGBAColor m_rgba;
|
||||
PortabilityLayer::RGBAColor m_rgba;
|
||||
};
|
||||
|
@@ -1,17 +1,17 @@
|
||||
#include "ResourceCompiledRef.h"
|
||||
#include "ByteSwap.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
uint32_t ResourceCompiledRef::GetSize() const
|
||||
{
|
||||
uint32_t resSize;
|
||||
memcpy(&resSize, m_resData - 4, 4);
|
||||
|
||||
ByteSwap::BigUInt32(resSize);
|
||||
|
||||
return resSize;
|
||||
}
|
||||
#include "ResourceCompiledRef.h"
|
||||
#include "ByteSwap.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
uint32_t ResourceCompiledRef::GetSize() const
|
||||
{
|
||||
uint32_t resSize;
|
||||
memcpy(&resSize, m_resData - 4, 4);
|
||||
|
||||
ByteSwap::BigUInt32(resSize);
|
||||
|
||||
return resSize;
|
||||
}
|
||||
}
|
@@ -1,18 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct MMHandleBlock;
|
||||
|
||||
struct ResourceCompiledRef
|
||||
{
|
||||
const uint8_t *m_resData;
|
||||
int16_t m_resID;
|
||||
int16_t m_resNameOffset;
|
||||
uint8_t m_attributes;
|
||||
|
||||
uint32_t GetSize() const;
|
||||
};
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct MMHandleBlock;
|
||||
|
||||
struct ResourceCompiledRef
|
||||
{
|
||||
const uint8_t *m_resData;
|
||||
int16_t m_resID;
|
||||
int16_t m_resNameOffset;
|
||||
uint8_t m_attributes;
|
||||
|
||||
uint32_t GetSize() const;
|
||||
};
|
||||
}
|
||||
|
@@ -1,16 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "ResTypeID.h"
|
||||
#include "ResourceCompiledRef.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct ResourceCompiledTypeList
|
||||
{
|
||||
ResTypeID m_resType;
|
||||
ResourceCompiledRef *m_firstRef;
|
||||
size_t m_numRefs;
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include "ResTypeID.h"
|
||||
#include "ResourceCompiledRef.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct ResourceCompiledTypeList
|
||||
{
|
||||
ResTypeID m_resType;
|
||||
ResourceCompiledRef *m_firstRef;
|
||||
size_t m_numRefs;
|
||||
};
|
||||
}
|
@@ -1,92 +1,92 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreDefs.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<class T>
|
||||
class ScopedPtr
|
||||
{
|
||||
public:
|
||||
ScopedPtr();
|
||||
ScopedPtr(T *ref);
|
||||
~ScopedPtr();
|
||||
|
||||
void Swap(ScopedPtr<T> &other);
|
||||
|
||||
operator T*();
|
||||
operator const T*() const;
|
||||
T *operator->();
|
||||
const T *operator->() const;
|
||||
|
||||
void Set(T *ref);
|
||||
|
||||
private:
|
||||
ScopedPtr(const ScopedPtr<T> &other) GP_DELETED;
|
||||
void operator=(const ScopedPtr<T> &other) GP_DELETED;
|
||||
T *m_ref;
|
||||
};
|
||||
}
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<class T>
|
||||
inline ScopedPtr<T>::ScopedPtr()
|
||||
: m_ref(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline ScopedPtr<T>::ScopedPtr(T *ref)
|
||||
: m_ref(ref)
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline ScopedPtr<T>::~ScopedPtr()
|
||||
{
|
||||
if (m_ref)
|
||||
m_ref->Destroy();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void ScopedPtr<T>::Swap(ScopedPtr<T> &other)
|
||||
{
|
||||
T *temp = m_ref;
|
||||
m_ref = other.m_ref;
|
||||
other.m_ref = temp;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline ScopedPtr<T>::operator T*()
|
||||
{
|
||||
return m_ref;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline ScopedPtr<T>::operator const T*() const
|
||||
{
|
||||
return m_ref;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T *ScopedPtr<T>::operator->()
|
||||
{
|
||||
return m_ref;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline const T *ScopedPtr<T>::operator->() const
|
||||
{
|
||||
return m_ref;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void ScopedPtr<T>::Set(T *ref)
|
||||
{
|
||||
#pragma once
|
||||
|
||||
#include "CoreDefs.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<class T>
|
||||
class ScopedPtr
|
||||
{
|
||||
public:
|
||||
ScopedPtr();
|
||||
ScopedPtr(T *ref);
|
||||
~ScopedPtr();
|
||||
|
||||
void Swap(ScopedPtr<T> &other);
|
||||
|
||||
operator T*();
|
||||
operator const T*() const;
|
||||
T *operator->();
|
||||
const T *operator->() const;
|
||||
|
||||
void Set(T *ref);
|
||||
|
||||
private:
|
||||
ScopedPtr(const ScopedPtr<T> &other) GP_DELETED;
|
||||
void operator=(const ScopedPtr<T> &other) GP_DELETED;
|
||||
T *m_ref;
|
||||
};
|
||||
}
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<class T>
|
||||
inline ScopedPtr<T>::ScopedPtr()
|
||||
: m_ref(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline ScopedPtr<T>::ScopedPtr(T *ref)
|
||||
: m_ref(ref)
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline ScopedPtr<T>::~ScopedPtr()
|
||||
{
|
||||
if (m_ref)
|
||||
m_ref->Destroy();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void ScopedPtr<T>::Swap(ScopedPtr<T> &other)
|
||||
{
|
||||
T *temp = m_ref;
|
||||
m_ref = other.m_ref;
|
||||
other.m_ref = temp;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline ScopedPtr<T>::operator T*()
|
||||
{
|
||||
return m_ref;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline ScopedPtr<T>::operator const T*() const
|
||||
{
|
||||
return m_ref;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T *ScopedPtr<T>::operator->()
|
||||
{
|
||||
return m_ref;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline const T *ScopedPtr<T>::operator->() const
|
||||
{
|
||||
return m_ref;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void ScopedPtr<T>::Set(T *ref)
|
||||
{
|
||||
if (m_ref && m_ref != ref)
|
||||
m_ref->Destroy();
|
||||
|
||||
m_ref = ref;
|
||||
}
|
||||
}
|
||||
m_ref->Destroy();
|
||||
|
||||
m_ref = ref;
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
{
|
||||
class SimpleImage final
|
||||
{
|
||||
public:
|
||||
|
@@ -1,100 +1,100 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef __PL_SMALLESTINT_H__
|
||||
#define __PL_SMALLESTINT_H__
|
||||
|
||||
#include "DataTypes.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
namespace Internal_SmallestInt
|
||||
{
|
||||
template<bool TFits8, bool TFits16, bool TFits32, bool TFits64>
|
||||
class SmallestIntSignedResolver
|
||||
{
|
||||
};
|
||||
|
||||
template<bool TFits8, bool TFits16, bool TFits32, bool TFits64>
|
||||
class SmallestIntUnsignedResolver
|
||||
{
|
||||
};
|
||||
|
||||
template<>
|
||||
class SmallestIntSignedResolver<1, 1, 1, 1>
|
||||
{
|
||||
public:
|
||||
typedef int8_t ValueType_t;
|
||||
};
|
||||
|
||||
template<>
|
||||
class SmallestIntSignedResolver<0, 1, 1, 1>
|
||||
{
|
||||
public:
|
||||
typedef int16_t ValueType_t;
|
||||
};
|
||||
|
||||
template<>
|
||||
class SmallestIntSignedResolver<0, 0, 1, 1>
|
||||
{
|
||||
public:
|
||||
typedef int32_t ValueType_t;
|
||||
};
|
||||
|
||||
template<>
|
||||
class SmallestIntSignedResolver<0, 0, 0, 1>
|
||||
{
|
||||
public:
|
||||
typedef int64_t ValueType_t;
|
||||
};
|
||||
|
||||
template<>
|
||||
class SmallestIntUnsignedResolver<1, 1, 1, 1>
|
||||
{
|
||||
public:
|
||||
typedef uint8_t ValueType_t;
|
||||
};
|
||||
|
||||
template<>
|
||||
class SmallestIntUnsignedResolver<0, 1, 1, 1>
|
||||
{
|
||||
public:
|
||||
typedef uint16_t ValueType_t;
|
||||
};
|
||||
|
||||
template<>
|
||||
class SmallestIntUnsignedResolver<0, 0, 1, 1>
|
||||
{
|
||||
public:
|
||||
typedef uint32_t ValueType_t;
|
||||
};
|
||||
|
||||
template<>
|
||||
class SmallestIntUnsignedResolver<0, 0, 0, 1>
|
||||
{
|
||||
public:
|
||||
typedef uint64_t ValueType_t;
|
||||
};
|
||||
}
|
||||
|
||||
template<LargestInt_t TValue>
|
||||
struct SmallestInt
|
||||
{
|
||||
typedef typename Internal_SmallestInt::SmallestIntSignedResolver<
|
||||
TValue >= -128 && TValue <= 127,
|
||||
TValue >= -32768 && TValue <= 32767,
|
||||
TValue >= -2147483648LL && TValue <= 2147483647LL,
|
||||
1>::ValueType_t ValueType_t;
|
||||
};
|
||||
|
||||
template<LargestUInt_t TValue>
|
||||
struct SmallestUInt
|
||||
{
|
||||
typedef typename Internal_SmallestInt::SmallestIntUnsignedResolver<
|
||||
TValue <= 256,
|
||||
TValue <= 65536,
|
||||
TValue <= 4294967295,
|
||||
1>::ValueType_t ValueType_t;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
|
||||
#ifndef __PL_SMALLESTINT_H__
|
||||
#define __PL_SMALLESTINT_H__
|
||||
|
||||
#include "DataTypes.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
namespace Internal_SmallestInt
|
||||
{
|
||||
template<bool TFits8, bool TFits16, bool TFits32, bool TFits64>
|
||||
class SmallestIntSignedResolver
|
||||
{
|
||||
};
|
||||
|
||||
template<bool TFits8, bool TFits16, bool TFits32, bool TFits64>
|
||||
class SmallestIntUnsignedResolver
|
||||
{
|
||||
};
|
||||
|
||||
template<>
|
||||
class SmallestIntSignedResolver<1, 1, 1, 1>
|
||||
{
|
||||
public:
|
||||
typedef int8_t ValueType_t;
|
||||
};
|
||||
|
||||
template<>
|
||||
class SmallestIntSignedResolver<0, 1, 1, 1>
|
||||
{
|
||||
public:
|
||||
typedef int16_t ValueType_t;
|
||||
};
|
||||
|
||||
template<>
|
||||
class SmallestIntSignedResolver<0, 0, 1, 1>
|
||||
{
|
||||
public:
|
||||
typedef int32_t ValueType_t;
|
||||
};
|
||||
|
||||
template<>
|
||||
class SmallestIntSignedResolver<0, 0, 0, 1>
|
||||
{
|
||||
public:
|
||||
typedef int64_t ValueType_t;
|
||||
};
|
||||
|
||||
template<>
|
||||
class SmallestIntUnsignedResolver<1, 1, 1, 1>
|
||||
{
|
||||
public:
|
||||
typedef uint8_t ValueType_t;
|
||||
};
|
||||
|
||||
template<>
|
||||
class SmallestIntUnsignedResolver<0, 1, 1, 1>
|
||||
{
|
||||
public:
|
||||
typedef uint16_t ValueType_t;
|
||||
};
|
||||
|
||||
template<>
|
||||
class SmallestIntUnsignedResolver<0, 0, 1, 1>
|
||||
{
|
||||
public:
|
||||
typedef uint32_t ValueType_t;
|
||||
};
|
||||
|
||||
template<>
|
||||
class SmallestIntUnsignedResolver<0, 0, 0, 1>
|
||||
{
|
||||
public:
|
||||
typedef uint64_t ValueType_t;
|
||||
};
|
||||
}
|
||||
|
||||
template<LargestInt_t TValue>
|
||||
struct SmallestInt
|
||||
{
|
||||
typedef typename Internal_SmallestInt::SmallestIntSignedResolver<
|
||||
TValue >= -128 && TValue <= 127,
|
||||
TValue >= -32768 && TValue <= 32767,
|
||||
TValue >= -2147483648LL && TValue <= 2147483647LL,
|
||||
1>::ValueType_t ValueType_t;
|
||||
};
|
||||
|
||||
template<LargestUInt_t TValue>
|
||||
struct SmallestUInt
|
||||
{
|
||||
typedef typename Internal_SmallestInt::SmallestIntUnsignedResolver<
|
||||
TValue <= 256,
|
||||
TValue <= 65536,
|
||||
TValue <= 4294967295,
|
||||
1>::ValueType_t ValueType_t;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,114 +1,114 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef __PL_UNSAFEPASCALSTR_H__
|
||||
#define __PL_UNSAFEPASCALSTR_H__
|
||||
|
||||
#include "DataTypes.h"
|
||||
#include "SmallestInt.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#pragma once
|
||||
|
||||
#ifndef __PL_UNSAFEPASCALSTR_H__
|
||||
#define __PL_UNSAFEPASCALSTR_H__
|
||||
|
||||
#include "DataTypes.h"
|
||||
#include "SmallestInt.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
class PLPasStr;
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<size_t TSize, bool TCStr>
|
||||
class UnsafePascalStr
|
||||
{
|
||||
public:
|
||||
UnsafePascalStr();
|
||||
UnsafePascalStr(size_t size, const char *str);
|
||||
|
||||
char &operator[](size_t index);
|
||||
const char &operator[](size_t index) const;
|
||||
void Set(size_t size, const char *str);
|
||||
void SetLength(size_t size);
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<size_t TSize, bool TCStr>
|
||||
class UnsafePascalStr
|
||||
{
|
||||
public:
|
||||
UnsafePascalStr();
|
||||
UnsafePascalStr(size_t size, const char *str);
|
||||
|
||||
char &operator[](size_t index);
|
||||
const char &operator[](size_t index) const;
|
||||
void Set(size_t size, const char *str);
|
||||
void SetLength(size_t size);
|
||||
size_t Length() const;
|
||||
|
||||
const char *UnsafeCharPtr() const;
|
||||
PLPasStr ToShortStr() const;
|
||||
|
||||
private:
|
||||
char m_chars[TSize + (TCStr ? 1 : 0)];
|
||||
typename SmallestUInt<TSize>::ValueType_t m_size;
|
||||
};
|
||||
}
|
||||
|
||||
#include <string.h>
|
||||
PLPasStr ToShortStr() const;
|
||||
|
||||
private:
|
||||
char m_chars[TSize + (TCStr ? 1 : 0)];
|
||||
typename SmallestUInt<TSize>::ValueType_t m_size;
|
||||
};
|
||||
}
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "PLPasStr.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<size_t TSize, bool TCStr>
|
||||
inline UnsafePascalStr<TSize, TCStr>::UnsafePascalStr(size_t size, const char *str)
|
||||
: m_size(static_cast<typename SmallestUInt<TSize>::ValueType_t>(size))
|
||||
{
|
||||
assert(size <= TSize);
|
||||
|
||||
if (size)
|
||||
memcpy(m_chars, str, size);
|
||||
|
||||
if (TCStr)
|
||||
m_chars[size] = '\0';
|
||||
}
|
||||
|
||||
template<size_t TSize, bool TCStr>
|
||||
inline char &UnsafePascalStr<TSize, TCStr>::operator[](size_t index)
|
||||
{
|
||||
assert(index < m_size);
|
||||
return m_chars[index];
|
||||
}
|
||||
|
||||
template<size_t TSize, bool TCStr>
|
||||
inline const char &UnsafePascalStr<TSize, TCStr>::operator[](size_t index) const
|
||||
{
|
||||
assert(index < m_size);
|
||||
return m_chars[index];
|
||||
}
|
||||
|
||||
template<size_t TSize, bool TCStr>
|
||||
inline void UnsafePascalStr<TSize, TCStr>::Set(size_t size, const char *str)
|
||||
{
|
||||
assert(size <= TSize);
|
||||
|
||||
memcpy(m_chars, str, size);
|
||||
m_size = static_cast<typename SmallestUInt<TSize>::ValueType_t>(size);
|
||||
|
||||
if (TCStr)
|
||||
m_chars[size] = '\0';
|
||||
}
|
||||
|
||||
template<size_t TSize, bool TCStr>
|
||||
inline void UnsafePascalStr<TSize, TCStr>::SetLength(size_t size)
|
||||
{
|
||||
assert(size <= TSize);
|
||||
|
||||
if (TCStr)
|
||||
m_chars[size] = '\0';
|
||||
}
|
||||
|
||||
template<size_t TSize, bool TCStr>
|
||||
inline size_t UnsafePascalStr<TSize, TCStr>::Length() const
|
||||
{
|
||||
return m_size;
|
||||
#include "PLPasStr.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<size_t TSize, bool TCStr>
|
||||
inline UnsafePascalStr<TSize, TCStr>::UnsafePascalStr(size_t size, const char *str)
|
||||
: m_size(static_cast<typename SmallestUInt<TSize>::ValueType_t>(size))
|
||||
{
|
||||
assert(size <= TSize);
|
||||
|
||||
if (size)
|
||||
memcpy(m_chars, str, size);
|
||||
|
||||
if (TCStr)
|
||||
m_chars[size] = '\0';
|
||||
}
|
||||
|
||||
template<size_t TSize, bool TCStr>
|
||||
inline const char *UnsafePascalStr<TSize, TCStr>::UnsafeCharPtr() const
|
||||
{
|
||||
return m_chars;
|
||||
}
|
||||
template<size_t TSize, bool TCStr>
|
||||
inline char &UnsafePascalStr<TSize, TCStr>::operator[](size_t index)
|
||||
{
|
||||
assert(index < m_size);
|
||||
return m_chars[index];
|
||||
}
|
||||
|
||||
template<size_t TSize, bool TCStr>
|
||||
template<size_t TSize, bool TCStr>
|
||||
inline const char &UnsafePascalStr<TSize, TCStr>::operator[](size_t index) const
|
||||
{
|
||||
assert(index < m_size);
|
||||
return m_chars[index];
|
||||
}
|
||||
|
||||
template<size_t TSize, bool TCStr>
|
||||
inline void UnsafePascalStr<TSize, TCStr>::Set(size_t size, const char *str)
|
||||
{
|
||||
assert(size <= TSize);
|
||||
|
||||
memcpy(m_chars, str, size);
|
||||
m_size = static_cast<typename SmallestUInt<TSize>::ValueType_t>(size);
|
||||
|
||||
if (TCStr)
|
||||
m_chars[size] = '\0';
|
||||
}
|
||||
|
||||
template<size_t TSize, bool TCStr>
|
||||
inline void UnsafePascalStr<TSize, TCStr>::SetLength(size_t size)
|
||||
{
|
||||
assert(size <= TSize);
|
||||
|
||||
if (TCStr)
|
||||
m_chars[size] = '\0';
|
||||
}
|
||||
|
||||
template<size_t TSize, bool TCStr>
|
||||
inline size_t UnsafePascalStr<TSize, TCStr>::Length() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
template<size_t TSize, bool TCStr>
|
||||
inline const char *UnsafePascalStr<TSize, TCStr>::UnsafeCharPtr() const
|
||||
{
|
||||
return m_chars;
|
||||
}
|
||||
|
||||
template<size_t TSize, bool TCStr>
|
||||
PLPasStr UnsafePascalStr<TSize, TCStr>::ToShortStr() const
|
||||
{
|
||||
if (m_size > 255)
|
||||
return PLPasStr(255, m_chars);
|
||||
else
|
||||
return PLPasStr(static_cast<uint8_t>(m_size), m_chars);
|
||||
return PLPasStr(static_cast<uint8_t>(m_size), m_chars);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,54 +1,54 @@
|
||||
#include "XModemCRC.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
static const uint16_t gs_crcTable[256] =
|
||||
{
|
||||
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
|
||||
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
|
||||
0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
|
||||
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
|
||||
0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
|
||||
0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
|
||||
0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
|
||||
0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
|
||||
0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
|
||||
0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
|
||||
0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
|
||||
0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
|
||||
0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
|
||||
0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
|
||||
0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
|
||||
0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
|
||||
0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
|
||||
0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
|
||||
0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
|
||||
0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
|
||||
0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
|
||||
0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
|
||||
0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
|
||||
0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
|
||||
0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
|
||||
0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
|
||||
0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
|
||||
0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
|
||||
0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
|
||||
0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
|
||||
0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
|
||||
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
|
||||
};
|
||||
}
|
||||
|
||||
uint16_t PortabilityLayer::XModemCRC(const void *bytes, size_t size, uint16_t initialValue)
|
||||
{
|
||||
const uint8_t *bytesU8 = static_cast<const uint8_t*>(bytes);
|
||||
int crc = initialValue;
|
||||
|
||||
for (size_t i = 0; i < size; i++)
|
||||
{
|
||||
crc ^= (bytesU8[i] << 8);
|
||||
crc = static_cast<uint16_t>(((crc << 8) ^ gs_crcTable[crc >> 8]) & 0xffff);
|
||||
}
|
||||
|
||||
return static_cast<uint16_t>(crc);
|
||||
}
|
||||
#include "XModemCRC.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
static const uint16_t gs_crcTable[256] =
|
||||
{
|
||||
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
|
||||
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
|
||||
0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
|
||||
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
|
||||
0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
|
||||
0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
|
||||
0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
|
||||
0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
|
||||
0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
|
||||
0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
|
||||
0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
|
||||
0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
|
||||
0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
|
||||
0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
|
||||
0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
|
||||
0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
|
||||
0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
|
||||
0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
|
||||
0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
|
||||
0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
|
||||
0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
|
||||
0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
|
||||
0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
|
||||
0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
|
||||
0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
|
||||
0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
|
||||
0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
|
||||
0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
|
||||
0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
|
||||
0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
|
||||
0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
|
||||
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
|
||||
};
|
||||
}
|
||||
|
||||
uint16_t PortabilityLayer::XModemCRC(const void *bytes, size_t size, uint16_t initialValue)
|
||||
{
|
||||
const uint8_t *bytesU8 = static_cast<const uint8_t*>(bytes);
|
||||
int crc = initialValue;
|
||||
|
||||
for (size_t i = 0; i < size; i++)
|
||||
{
|
||||
crc ^= (bytesU8[i] << 8);
|
||||
crc = static_cast<uint16_t>(((crc << 8) ^ gs_crcTable[crc >> 8]) & 0xffff);
|
||||
}
|
||||
|
||||
return static_cast<uint16_t>(crc);
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "DataTypes.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
uint16_t XModemCRC(const void *bytes, size_t size, uint16_t initialValue);
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "DataTypes.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
uint16_t XModemCRC(const void *bytes, size_t size, uint16_t initialValue);
|
||||
}
|
||||
|
Reference in New Issue
Block a user