mirror of https://github.com/libAthena/athena.git
Huge non-virtual template-based refactor for DNA
This commit is contained in:
parent
42b97e0306
commit
13d13f935b
|
@ -234,4 +234,9 @@ macro(atdna out)
|
|||
endif()
|
||||
endmacro()
|
||||
|
||||
# Test target
|
||||
atdna(atdna_test.cpp test.hpp)
|
||||
add_executable(atdna-test test.cpp atdna_test.cpp test.hpp)
|
||||
target_link_libraries(atdna-test athena-core athena-libyaml)
|
||||
|
||||
endif()
|
||||
|
|
2173
atdna/main.cpp
2173
atdna/main.cpp
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,24 @@
|
|||
#include "test.hpp"
|
||||
#include "athena/MemoryWriter.hpp"
|
||||
|
||||
#define EXPECTED_BYTES 265
|
||||
|
||||
int main(int argc, const char** argv)
|
||||
{
|
||||
TESTFile file = {};
|
||||
file.arrCount[0] = 2;
|
||||
file.array.push_back(42);
|
||||
file.array.push_back(64);
|
||||
size_t binSize = 0;
|
||||
file.binarySize(binSize);
|
||||
athena::io::MemoryCopyWriter w(nullptr, binSize);
|
||||
atInt64 pos = w.position();
|
||||
file.write(w);
|
||||
bool pass = !w.hasError() && w.position() - pos == binSize && binSize == EXPECTED_BYTES;
|
||||
if (pass)
|
||||
printf("[PASS] %" PRISize " bytes written\n", size_t(w.position() - pos));
|
||||
else
|
||||
printf("[FAIL] %" PRISize " bytes written; %" PRISize " bytes sized; %d bytes expected\n",
|
||||
size_t(w.position() - pos), binSize, EXPECTED_BYTES);
|
||||
return pass ? 0 : 1;
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
#include <athena/DNAYaml.hpp>
|
||||
|
||||
using namespace athena;
|
||||
typedef io::DNAYaml<BigEndian> BigDNA;
|
||||
typedef io::DNA<Big> BigDNA;
|
||||
|
||||
struct TESTSubFile : public BigDNA
|
||||
{
|
||||
DECL_YAML
|
||||
AT_DECL_DNA
|
||||
enum ETest : atUint8
|
||||
{
|
||||
ZERO,
|
||||
|
@ -20,30 +20,30 @@ struct TESTSubFile : public BigDNA
|
|||
|
||||
struct TESTSubClassFile : public TESTSubFile
|
||||
{
|
||||
DECL_YAML
|
||||
AT_DECL_DNA
|
||||
Value<atUint32> sub3;
|
||||
Value<atUint32> sub4;
|
||||
};
|
||||
|
||||
struct TESTSubSubClassFile : public TESTSubClassFile
|
||||
{
|
||||
DECL_YAML
|
||||
AT_DECL_DNA
|
||||
Value<atUint32> sub5;
|
||||
Value<atUint32> sub6;
|
||||
};
|
||||
|
||||
struct TESTFile : public BigDNA
|
||||
{
|
||||
DECL_YAML
|
||||
AT_DECL_DNA
|
||||
Value<bool> varBool;
|
||||
Value<atUint32> var32;
|
||||
Value<atUint16> var16;
|
||||
AT_OVERRIDE_RCRC32(12345678) Value<atUint32> x4_var32;
|
||||
AT_OVERRIDE_RCRC32(deadbabe) Value<atUint16> x8_var16;
|
||||
Value<atVec3f> vec3;
|
||||
Value<atVec4f> vec4;
|
||||
|
||||
struct TESTNestedSubFile : public BigDNA
|
||||
{
|
||||
DECL_YAML
|
||||
AT_DECL_DNA
|
||||
Value<atUint32> nestSub1;
|
||||
Value<atUint32> nestSub2;
|
||||
} nestedSubFile;
|
||||
|
@ -55,12 +55,12 @@ struct TESTFile : public BigDNA
|
|||
|
||||
struct TESTExplicitSubFile : public BigDNA
|
||||
{
|
||||
DECL_YAML
|
||||
AT_DECL_DNA
|
||||
Value<atUint32> explSub1;
|
||||
Value<atUint32> explSub2;
|
||||
} explSubFile;
|
||||
|
||||
Value<atUint32, LittleEndian> arrCount[2];
|
||||
Value<atUint32, Little> arrCount[2];
|
||||
Vector<atUint32, DNA_COUNT(arrCount[0])> array;
|
||||
|
||||
Seek<21, Current> seek;
|
||||
|
@ -73,6 +73,5 @@ struct TESTFile : public BigDNA
|
|||
|
||||
String<32> str;
|
||||
WString<64> wstr;
|
||||
WStringAsString<> utf8str[5];
|
||||
};
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "athena/Global.hpp"
|
||||
|
||||
namespace athena::Checksums
|
||||
namespace athena::checksums
|
||||
{
|
||||
atUint32 crc32(const atUint8* data, atUint64 length, atUint32 mask = 0xFFFFFFFF, atUint32 seed = 0xFFFFFFFF);
|
||||
atUint16 crc16CCITT(const atUint8* data, atUint64 length, atUint16 seed = 0xFFFF, atUint16 final = 0);
|
||||
|
|
|
@ -0,0 +1,199 @@
|
|||
#ifndef AT_CHECKSUMSLITERALS_HPP
|
||||
#define AT_CHECKSUMSLITERALS_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace athena::checksums::literals
|
||||
{
|
||||
|
||||
constexpr uint32_t crc32_table[] =
|
||||
{
|
||||
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
|
||||
0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
|
||||
0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
|
||||
0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
|
||||
0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
|
||||
0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
|
||||
0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
|
||||
0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
|
||||
0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
|
||||
0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
|
||||
0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
|
||||
0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
|
||||
0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
|
||||
0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
|
||||
0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
|
||||
0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
|
||||
0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
|
||||
0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
|
||||
0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
|
||||
0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
|
||||
0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
|
||||
0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
|
||||
0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
|
||||
0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
|
||||
0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
|
||||
0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
|
||||
0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
|
||||
0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
|
||||
0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
|
||||
0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
|
||||
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
|
||||
0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
|
||||
};
|
||||
|
||||
template<uint32_t CRC, char ...Chars> struct Crc32Impl {
|
||||
};
|
||||
|
||||
template<uint32_t CRC, char Head, char ...Tail> struct Crc32Impl<CRC, Head, Tail...> {
|
||||
static constexpr uint32_t value = Crc32Impl<
|
||||
crc32_table[static_cast<unsigned char>(CRC) ^ static_cast<unsigned char>(Head)]
|
||||
^ (CRC >> 8), Tail...>::value;
|
||||
};
|
||||
|
||||
template<uint32_t CRC> struct Crc32Impl<CRC> {
|
||||
static constexpr uint32_t value = CRC ^ 0xFFFFFFFF;
|
||||
};
|
||||
|
||||
|
||||
template<char ...Chars> using Crc32 = Crc32Impl<0xFFFFFFFF, Chars...>;
|
||||
|
||||
constexpr uint32_t crc32_rec(uint32_t crc, const char *s) {
|
||||
return *s == 0 ? crc ^ 0xFFFFFFFF :
|
||||
crc32_rec(crc32_table[static_cast<unsigned char>(crc) ^
|
||||
static_cast<unsigned char>(*s)]
|
||||
^ (crc >> 8), s + 1);
|
||||
}
|
||||
|
||||
constexpr uint32_t operator "" _crc32(const char *s, size_t len) {
|
||||
return crc32_rec(0xFFFFFFFF, s);
|
||||
}
|
||||
|
||||
static_assert("Hello"_crc32 == Crc32<'H', 'e', 'l', 'l', 'o'>::value,
|
||||
"CRC32 values don't match");
|
||||
static_assert("0"_crc32 == Crc32<'0'>::value,
|
||||
"CRC32 values don't match");
|
||||
|
||||
|
||||
constexpr uint32_t rcrc32_rec(uint32_t crc, const char *s) {
|
||||
return *s == 0 ? crc :
|
||||
crc32_rec(crc32_table[static_cast<unsigned char>(crc) ^
|
||||
static_cast<unsigned char>(*s)]
|
||||
^ (crc >> 8), s + 1);
|
||||
}
|
||||
|
||||
constexpr uint32_t operator "" _rcrc32(const char *s, size_t len) {
|
||||
return rcrc32_rec(0xFFFFFFFF, s);
|
||||
}
|
||||
|
||||
static_assert("Hello"_rcrc32 == Crc32<'H', 'e', 'l', 'l', 'o'>::value,
|
||||
"CRC32 values don't match");
|
||||
static_assert("0"_rcrc32 == Crc32<'0'>::value,
|
||||
"CRC32 values don't match");
|
||||
|
||||
|
||||
|
||||
constexpr uint64_t crc64_table[] =
|
||||
{
|
||||
0x0000000000000000, 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26, 0xC711223CFA3E5BB5,
|
||||
0x493366450E42ECDF, 0x0BC387AEA7A8DA4C, 0xCCD2A5925D9681F9, 0x8E224479F47CB76A,
|
||||
0x9266CC8A1C85D9BE, 0xD0962D61B56FEF2D, 0x17870F5D4F51B498, 0x5577EEB6E6BB820B,
|
||||
0xDB55AACF12C73561, 0x99A54B24BB2D03F2, 0x5EB4691841135847, 0x1C4488F3E8F96ED4,
|
||||
0x663D78FF90E185EF, 0x24CD9914390BB37C, 0xE3DCBB28C335E8C9, 0xA12C5AC36ADFDE5A,
|
||||
0x2F0E1EBA9EA36930, 0x6DFEFF5137495FA3, 0xAAEFDD6DCD770416, 0xE81F3C86649D3285,
|
||||
0xF45BB4758C645C51, 0xB6AB559E258E6AC2, 0x71BA77A2DFB03177, 0x334A9649765A07E4,
|
||||
0xBD68D2308226B08E, 0xFF9833DB2BCC861D, 0x388911E7D1F2DDA8, 0x7A79F00C7818EB3B,
|
||||
0xCC7AF1FF21C30BDE, 0x8E8A101488293D4D, 0x499B3228721766F8, 0x0B6BD3C3DBFD506B,
|
||||
0x854997BA2F81E701, 0xC7B97651866BD192, 0x00A8546D7C558A27, 0x4258B586D5BFBCB4,
|
||||
0x5E1C3D753D46D260, 0x1CECDC9E94ACE4F3, 0xDBFDFEA26E92BF46, 0x990D1F49C77889D5,
|
||||
0x172F5B3033043EBF, 0x55DFBADB9AEE082C, 0x92CE98E760D05399, 0xD03E790CC93A650A,
|
||||
0xAA478900B1228E31, 0xE8B768EB18C8B8A2, 0x2FA64AD7E2F6E317, 0x6D56AB3C4B1CD584,
|
||||
0xE374EF45BF6062EE, 0xA1840EAE168A547D, 0x66952C92ECB40FC8, 0x2465CD79455E395B,
|
||||
0x3821458AADA7578F, 0x7AD1A461044D611C, 0xBDC0865DFE733AA9, 0xFF3067B657990C3A,
|
||||
0x711223CFA3E5BB50, 0x33E2C2240A0F8DC3, 0xF4F3E018F031D676, 0xB60301F359DBE0E5,
|
||||
0xDA050215EA6C212F, 0x98F5E3FE438617BC, 0x5FE4C1C2B9B84C09, 0x1D14202910527A9A,
|
||||
0x93366450E42ECDF0, 0xD1C685BB4DC4FB63, 0x16D7A787B7FAA0D6, 0x5427466C1E109645,
|
||||
0x4863CE9FF6E9F891, 0x0A932F745F03CE02, 0xCD820D48A53D95B7, 0x8F72ECA30CD7A324,
|
||||
0x0150A8DAF8AB144E, 0x43A04931514122DD, 0x84B16B0DAB7F7968, 0xC6418AE602954FFB,
|
||||
0xBC387AEA7A8DA4C0, 0xFEC89B01D3679253, 0x39D9B93D2959C9E6, 0x7B2958D680B3FF75,
|
||||
0xF50B1CAF74CF481F, 0xB7FBFD44DD257E8C, 0x70EADF78271B2539, 0x321A3E938EF113AA,
|
||||
0x2E5EB66066087D7E, 0x6CAE578BCFE24BED, 0xABBF75B735DC1058, 0xE94F945C9C3626CB,
|
||||
0x676DD025684A91A1, 0x259D31CEC1A0A732, 0xE28C13F23B9EFC87, 0xA07CF2199274CA14,
|
||||
0x167FF3EACBAF2AF1, 0x548F120162451C62, 0x939E303D987B47D7, 0xD16ED1D631917144,
|
||||
0x5F4C95AFC5EDC62E, 0x1DBC74446C07F0BD, 0xDAAD56789639AB08, 0x985DB7933FD39D9B,
|
||||
0x84193F60D72AF34F, 0xC6E9DE8B7EC0C5DC, 0x01F8FCB784FE9E69, 0x43081D5C2D14A8FA,
|
||||
0xCD2A5925D9681F90, 0x8FDAB8CE70822903, 0x48CB9AF28ABC72B6, 0x0A3B7B1923564425,
|
||||
0x70428B155B4EAF1E, 0x32B26AFEF2A4998D, 0xF5A348C2089AC238, 0xB753A929A170F4AB,
|
||||
0x3971ED50550C43C1, 0x7B810CBBFCE67552, 0xBC902E8706D82EE7, 0xFE60CF6CAF321874,
|
||||
0xE224479F47CB76A0, 0xA0D4A674EE214033, 0x67C58448141F1B86, 0x253565A3BDF52D15,
|
||||
0xAB1721DA49899A7F, 0xE9E7C031E063ACEC, 0x2EF6E20D1A5DF759, 0x6C0603E6B3B7C1CA,
|
||||
0xF6FAE5C07D3274CD, 0xB40A042BD4D8425E, 0x731B26172EE619EB, 0x31EBC7FC870C2F78,
|
||||
0xBFC9838573709812, 0xFD39626EDA9AAE81, 0x3A28405220A4F534, 0x78D8A1B9894EC3A7,
|
||||
0x649C294A61B7AD73, 0x266CC8A1C85D9BE0, 0xE17DEA9D3263C055, 0xA38D0B769B89F6C6,
|
||||
0x2DAF4F0F6FF541AC, 0x6F5FAEE4C61F773F, 0xA84E8CD83C212C8A, 0xEABE6D3395CB1A19,
|
||||
0x90C79D3FEDD3F122, 0xD2377CD44439C7B1, 0x15265EE8BE079C04, 0x57D6BF0317EDAA97,
|
||||
0xD9F4FB7AE3911DFD, 0x9B041A914A7B2B6E, 0x5C1538ADB04570DB, 0x1EE5D94619AF4648,
|
||||
0x02A151B5F156289C, 0x4051B05E58BC1E0F, 0x87409262A28245BA, 0xC5B073890B687329,
|
||||
0x4B9237F0FF14C443, 0x0962D61B56FEF2D0, 0xCE73F427ACC0A965, 0x8C8315CC052A9FF6,
|
||||
0x3A80143F5CF17F13, 0x7870F5D4F51B4980, 0xBF61D7E80F251235, 0xFD913603A6CF24A6,
|
||||
0x73B3727A52B393CC, 0x31439391FB59A55F, 0xF652B1AD0167FEEA, 0xB4A25046A88DC879,
|
||||
0xA8E6D8B54074A6AD, 0xEA16395EE99E903E, 0x2D071B6213A0CB8B, 0x6FF7FA89BA4AFD18,
|
||||
0xE1D5BEF04E364A72, 0xA3255F1BE7DC7CE1, 0x64347D271DE22754, 0x26C49CCCB40811C7,
|
||||
0x5CBD6CC0CC10FAFC, 0x1E4D8D2B65FACC6F, 0xD95CAF179FC497DA, 0x9BAC4EFC362EA149,
|
||||
0x158E0A85C2521623, 0x577EEB6E6BB820B0, 0x906FC95291867B05, 0xD29F28B9386C4D96,
|
||||
0xCEDBA04AD0952342, 0x8C2B41A1797F15D1, 0x4B3A639D83414E64, 0x09CA82762AAB78F7,
|
||||
0x87E8C60FDED7CF9D, 0xC51827E4773DF90E, 0x020905D88D03A2BB, 0x40F9E43324E99428,
|
||||
0x2CFFE7D5975E55E2, 0x6E0F063E3EB46371, 0xA91E2402C48A38C4, 0xEBEEC5E96D600E57,
|
||||
0x65CC8190991CB93D, 0x273C607B30F68FAE, 0xE02D4247CAC8D41B, 0xA2DDA3AC6322E288,
|
||||
0xBE992B5F8BDB8C5C, 0xFC69CAB42231BACF, 0x3B78E888D80FE17A, 0x7988096371E5D7E9,
|
||||
0xF7AA4D1A85996083, 0xB55AACF12C735610, 0x724B8ECDD64D0DA5, 0x30BB6F267FA73B36,
|
||||
0x4AC29F2A07BFD00D, 0x08327EC1AE55E69E, 0xCF235CFD546BBD2B, 0x8DD3BD16FD818BB8,
|
||||
0x03F1F96F09FD3CD2, 0x41011884A0170A41, 0x86103AB85A2951F4, 0xC4E0DB53F3C36767,
|
||||
0xD8A453A01B3A09B3, 0x9A54B24BB2D03F20, 0x5D45907748EE6495, 0x1FB5719CE1045206,
|
||||
0x919735E51578E56C, 0xD367D40EBC92D3FF, 0x1476F63246AC884A, 0x568617D9EF46BED9,
|
||||
0xE085162AB69D5E3C, 0xA275F7C11F7768AF, 0x6564D5FDE549331A, 0x279434164CA30589,
|
||||
0xA9B6706FB8DFB2E3, 0xEB46918411358470, 0x2C57B3B8EB0BDFC5, 0x6EA7525342E1E956,
|
||||
0x72E3DAA0AA188782, 0x30133B4B03F2B111, 0xF7021977F9CCEAA4, 0xB5F2F89C5026DC37,
|
||||
0x3BD0BCE5A45A6B5D, 0x79205D0E0DB05DCE, 0xBE317F32F78E067B, 0xFCC19ED95E6430E8,
|
||||
0x86B86ED5267CDBD3, 0xC4488F3E8F96ED40, 0x0359AD0275A8B6F5, 0x41A94CE9DC428066,
|
||||
0xCF8B0890283E370C, 0x8D7BE97B81D4019F, 0x4A6ACB477BEA5A2A, 0x089A2AACD2006CB9,
|
||||
0x14DEA25F3AF9026D, 0x562E43B4931334FE, 0x913F6188692D6F4B, 0xD3CF8063C0C759D8,
|
||||
0x5DEDC41A34BBEEB2, 0x1F1D25F19D51D821, 0xD80C07CD676F8394, 0x9AFCE626CE85B507
|
||||
};
|
||||
|
||||
template<uint64_t CRC, char ...Chars> struct Crc64Impl {
|
||||
};
|
||||
|
||||
template<uint64_t CRC, char Head, char ...Tail> struct Crc64Impl<CRC, Head, Tail...> {
|
||||
static constexpr uint64_t value = Crc64Impl<
|
||||
crc64_table[static_cast<unsigned char>(CRC >> 56) ^ static_cast<unsigned char>(Head)]
|
||||
^ (CRC << 8), Tail...>::value;
|
||||
};
|
||||
|
||||
template<uint64_t CRC> struct Crc64Impl<CRC> {
|
||||
static constexpr uint64_t value = CRC ^ 0xFFFFFFFFFFFFFFFF;
|
||||
};
|
||||
|
||||
|
||||
template<char ...Chars> using Crc64 = Crc64Impl<0xFFFFFFFFFFFFFFFF, Chars...>;
|
||||
|
||||
constexpr uint64_t crc64_rec(uint64_t crc, const char *s) {
|
||||
return *s == 0 ? crc ^ 0xFFFFFFFFFFFFFFFF :
|
||||
crc64_rec(crc64_table[static_cast<unsigned char>(crc >> 56) ^
|
||||
static_cast<unsigned char>(*s)]
|
||||
^ (crc << 8), s + 1);
|
||||
}
|
||||
|
||||
constexpr uint64_t operator "" _crc64(const char *s, size_t len) {
|
||||
return crc64_rec(0xFFFFFFFFFFFFFFFF, s);
|
||||
}
|
||||
|
||||
static_assert("Hello"_crc64 == Crc64<'H', 'e', 'l', 'l', 'o'>::value,
|
||||
"CRC64 values don't match");
|
||||
static_assert("0"_crc64 == Crc64<'0'>::value,
|
||||
"CRC64 values don't match");
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // AT_CHECKSUMSLITERALS_HPP
|
|
@ -10,26 +10,13 @@
|
|||
#include "Global.hpp"
|
||||
#include "IStreamReader.hpp"
|
||||
#include "IStreamWriter.hpp"
|
||||
#include "DNAOp.hpp"
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace athena::io
|
||||
{
|
||||
|
||||
/* forward-declaration dance for recursively-derived types */
|
||||
|
||||
template <size_t sizeVar, Endian VE>
|
||||
struct Buffer;
|
||||
|
||||
template <atInt32 sizeVar, Endian VE>
|
||||
struct String;
|
||||
|
||||
template <atInt32 sizeVar, Endian VE>
|
||||
struct WString;
|
||||
|
||||
template <atInt32 sizeVar, Endian VE>
|
||||
struct WStringAsString;
|
||||
|
||||
/**
|
||||
* @brief Base DNA class used against 'atdna'
|
||||
* @tparam DNAE Default-endianness for contained DNA values
|
||||
|
@ -42,22 +29,10 @@ struct WStringAsString;
|
|||
template <Endian DNAE>
|
||||
struct DNA
|
||||
{
|
||||
virtual ~DNA() = default;
|
||||
|
||||
/**
|
||||
* @brief Common virtual read function for all DNA types
|
||||
* @brief Designated byte-order used for serializing fields
|
||||
*/
|
||||
virtual void read(IStreamReader&)=0;
|
||||
/**
|
||||
* @brief Common virtual write function for all DNA types
|
||||
*/
|
||||
virtual void write(IStreamWriter&) const=0;
|
||||
/**
|
||||
* @brief Common virtual binary size computation for all DNA types
|
||||
* @param __isz initial cumulative value to add result to
|
||||
* @return Cumulative size
|
||||
*/
|
||||
virtual size_t binarySize(size_t __isz) const=0;
|
||||
static constexpr Endian DNAEndian = DNAE;
|
||||
|
||||
/**
|
||||
* @brief Template type signaling atdna to capture the value where it's used
|
||||
|
@ -82,7 +57,7 @@ struct DNA
|
|||
* @tparam sizeVar C++ expression wrapped in DNA_COUNT macro to determine number of bytes for buffer
|
||||
*/
|
||||
template <size_t sizeVar>
|
||||
using Buffer = struct athena::io::Buffer<sizeVar, DNAE>;
|
||||
using Buffer = std::unique_ptr<atUint8[]>;
|
||||
|
||||
/**
|
||||
* @brief Template type wrapping std::string and signaling atdna to read string data where it's used
|
||||
|
@ -90,7 +65,7 @@ struct DNA
|
|||
* -1 literal indicates null-terminated string
|
||||
*/
|
||||
template <atInt32 sizeVar = -1>
|
||||
using String = struct athena::io::String<sizeVar, DNAE>;
|
||||
using String = std::string;
|
||||
|
||||
/**
|
||||
* @brief Template type wrapping std::wstring and signaling atdna to read wstring data where it's used
|
||||
|
@ -98,15 +73,7 @@ struct DNA
|
|||
* -1 literal indicates null-terminated wstring
|
||||
*/
|
||||
template <atInt32 sizeVar = -1, Endian VE = DNAE>
|
||||
using WString = struct athena::io::WString<sizeVar, VE>;
|
||||
|
||||
/**
|
||||
* @brief Template type wrapping std::string and signaling atdna to read wstring data where it's used
|
||||
* @tparam sizeVar C++ expression wrapped in DNA_COUNT macro to determine number of characters for string
|
||||
* -1 literal indicates null-terminated string
|
||||
*/
|
||||
template <atInt32 sizeVar = -1>
|
||||
using WStringAsString = struct athena::io::WStringAsString<sizeVar, DNAE>;
|
||||
using WString = std::wstring;
|
||||
|
||||
/**
|
||||
* @brief Meta Template signaling atdna to insert a stream seek where it's used
|
||||
|
@ -127,120 +94,8 @@ struct DNA
|
|||
* @brief Meta Template preventing atdna from emitting read/write implementations
|
||||
*/
|
||||
struct Delete {};
|
||||
|
||||
/**
|
||||
* @brief Internal DNA helper for accumulating binarySize
|
||||
* @param __isz initial size value
|
||||
* @param v Vector to enumerate
|
||||
* @return Cumulative total
|
||||
*/
|
||||
template <typename T>
|
||||
static size_t __EnumerateSize(size_t __isz, const T& v)
|
||||
{
|
||||
for (const auto& val : v)
|
||||
__isz = val.binarySize(__isz);
|
||||
return __isz;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Concrete buffer type used by DNA::Buffer
|
||||
*/
|
||||
template <size_t sizeVar, Endian VE>
|
||||
struct Buffer : public DNA<VE>, public std::unique_ptr<atUint8[]>
|
||||
{
|
||||
typename DNA<VE>::Delete expl;
|
||||
void read(IStreamReader& reader)
|
||||
{
|
||||
reset(new atUint8[sizeVar]);
|
||||
reader.readUBytesToBuf(get(), sizeVar);
|
||||
}
|
||||
void write(IStreamWriter& writer) const
|
||||
{
|
||||
writer.writeUBytes(get(), sizeVar);
|
||||
}
|
||||
size_t binarySize(size_t __isz) const
|
||||
{
|
||||
return __isz + sizeVar;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Concrete string type used by DNA::String
|
||||
*/
|
||||
template <atInt32 sizeVar, Endian VE>
|
||||
struct String : public DNA<VE>, public std::string
|
||||
{
|
||||
typename DNA<VE>::Delete expl;
|
||||
void read(IStreamReader& reader)
|
||||
{this->assign(std::move(reader.readString(sizeVar)));}
|
||||
void write(IStreamWriter& writer) const
|
||||
{writer.writeString(*this, sizeVar);}
|
||||
size_t binarySize(size_t __isz) const
|
||||
{return __isz + ((sizeVar<0)?(this->size()+1):sizeVar);}
|
||||
std::string& operator=(std::string_view __str)
|
||||
{return this->assign(__str);}
|
||||
std::string& operator=(std::string&& __str)
|
||||
{this->swap(__str); return *this;}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Concrete wstring type used by DNA::WString
|
||||
*/
|
||||
template <atInt32 sizeVar, Endian VE>
|
||||
struct WString : public DNA<VE>, public std::wstring
|
||||
{
|
||||
typename DNA<VE>::Delete expl;
|
||||
void read(IStreamReader& reader)
|
||||
{
|
||||
reader.setEndian(VE);
|
||||
this->assign(std::move(reader.readWString(sizeVar)));
|
||||
}
|
||||
void write(IStreamWriter& writer) const
|
||||
{
|
||||
writer.setEndian(VE);
|
||||
writer.writeWString(*this, sizeVar);
|
||||
}
|
||||
size_t binarySize(size_t __isz) const
|
||||
{return __isz + (((sizeVar<0)?(this->size()+1):sizeVar)*2);}
|
||||
std::wstring& operator=(std::wstring_view __str)
|
||||
{return this->assign(__str);}
|
||||
std::wstring& operator=(std::wstring&& __str)
|
||||
{this->swap(__str); return *this;}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Concrete converting-wstring type used by DNA::WStringAsString
|
||||
*/
|
||||
template <atInt32 sizeVar, Endian VE>
|
||||
struct WStringAsString : public DNA<VE>, public std::string
|
||||
{
|
||||
typename DNA<VE>::Delete expl;
|
||||
void read(IStreamReader& reader)
|
||||
{*this = reader.readWStringAsString(sizeVar);}
|
||||
void write(IStreamWriter& writer) const
|
||||
{writer.writeStringAsWString(*this, sizeVar);}
|
||||
size_t binarySize(size_t __isz) const
|
||||
{return __isz + (((sizeVar<0)?(this->size()+1):sizeVar)*2);}
|
||||
std::string& operator=(std::string_view __str)
|
||||
{return this->assign(__str);}
|
||||
std::string& operator=(std::string&& __str)
|
||||
{this->swap(__str); return *this;}
|
||||
};
|
||||
|
||||
/** Macro to automatically declare read/write methods in subclasses */
|
||||
#define DECL_DNA \
|
||||
void read(athena::io::IStreamReader&); \
|
||||
void write(athena::io::IStreamWriter&) const; \
|
||||
size_t binarySize(size_t __isz) const;
|
||||
|
||||
/** Macro to automatically declare read/write methods and prevent outputting implementation */
|
||||
#define DECL_EXPLICIT_DNA \
|
||||
void read(athena::io::IStreamReader&); \
|
||||
void write(athena::io::IStreamWriter&) const; \
|
||||
size_t binarySize(size_t __isz) const; \
|
||||
Delete __dna_delete;
|
||||
|
||||
/** Macro to supply count variable to atdna and mute it for other compilers */
|
||||
#ifdef __clang__
|
||||
#define DNA_COUNT(cnt) sizeof(cnt)
|
||||
|
|
|
@ -0,0 +1,908 @@
|
|||
#ifndef AT_OP_HPP
|
||||
#define AT_OP_HPP
|
||||
|
||||
#include "IStreamReader.hpp"
|
||||
#include "IStreamWriter.hpp"
|
||||
#include "DNAYaml.hpp"
|
||||
#include "ChecksumsLiterals.hpp"
|
||||
|
||||
namespace athena::io
|
||||
{
|
||||
|
||||
struct PropId
|
||||
{
|
||||
const char* name = nullptr;
|
||||
uint32_t rcrc32 = 0xffffffff;
|
||||
uint64_t crc64 = 0x0;
|
||||
template <class T> constexpr T opget() const;
|
||||
constexpr PropId() = default;
|
||||
constexpr PropId(const char* name, uint32_t rcrc32, uint64_t crc64)
|
||||
: name(name), rcrc32(rcrc32), crc64(crc64) {}
|
||||
constexpr PropId(const char* name)
|
||||
: name(name),
|
||||
rcrc32(athena::checksums::literals::rcrc32_rec(0xFFFFFFFF, name)),
|
||||
crc64(athena::checksums::literals::crc64_rec(0xFFFFFFFFFFFFFFFF, name)) {}
|
||||
constexpr PropId(const char* name, uint32_t rcrc32)
|
||||
: name(name),
|
||||
rcrc32(rcrc32),
|
||||
crc64(athena::checksums::literals::crc64_rec(0xFFFFFFFFFFFFFFFF, name)) {}
|
||||
};
|
||||
|
||||
template <>
|
||||
constexpr uint32_t PropId::opget<uint32_t>() const { return rcrc32; }
|
||||
|
||||
template <>
|
||||
constexpr uint64_t PropId::opget<uint64_t>() const { return crc64; }
|
||||
|
||||
namespace literals
|
||||
{
|
||||
constexpr PropId operator "" _propid(const char* s, size_t len)
|
||||
{
|
||||
return {s};
|
||||
}
|
||||
}
|
||||
|
||||
#define AT_PROP_CASE(...) case athena::io::PropId(__VA_ARGS__).opget<typename Op::PropT>()
|
||||
|
||||
#if defined(__atdna__)
|
||||
# define AT_OVERRIDE_RCRC32(rcrc32) __attribute__((annotate("rcrc32=" #rcrc32)))
|
||||
#else
|
||||
# define AT_OVERRIDE_RCRC32(rcrc32)
|
||||
#endif
|
||||
|
||||
enum class PropType
|
||||
{
|
||||
None,
|
||||
CRC32,
|
||||
CRC64
|
||||
};
|
||||
|
||||
template <class T>
|
||||
static inline constexpr bool __IsPODType()
|
||||
{
|
||||
return std::is_arithmetic<T>::value ||
|
||||
std::is_same<T, atVec2f>::value ||
|
||||
std::is_same<T, atVec3f>::value ||
|
||||
std::is_same<T, atVec4f>::value ||
|
||||
std::is_same<T, atVec2d>::value ||
|
||||
std::is_same<T, atVec3d>::value ||
|
||||
std::is_same<T, atVec4d>::value;
|
||||
}
|
||||
|
||||
template <PropType PropOp>
|
||||
struct BinarySize
|
||||
{
|
||||
using PropT = std::conditional_t<PropOp == PropType::CRC64, uint64_t, uint32_t>;
|
||||
using StreamT = size_t;
|
||||
template <class T, Endian DNAE>
|
||||
static typename std::enable_if_t<std::is_enum_v<T>>
|
||||
Do(const PropId& id, T& var, StreamT& s)
|
||||
{
|
||||
if (PropOp != PropType::None)
|
||||
{
|
||||
/* Accessed via Enumerate, header */
|
||||
s += 6;
|
||||
}
|
||||
using PODType = std::underlying_type_t<T>;
|
||||
BinarySize<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), s);
|
||||
}
|
||||
template <class T, Endian DNAE>
|
||||
static typename std::enable_if_t<__IsPODType<T>()>
|
||||
Do(const PropId& id, T& var, StreamT& s)
|
||||
{
|
||||
if (PropOp != PropType::None)
|
||||
{
|
||||
/* Accessed via Enumerate, header */
|
||||
s += 6;
|
||||
}
|
||||
BinarySize<PropType::None>::Do<T, DNAE>(id, var, s);
|
||||
}
|
||||
template <class T, Endian DNAE>
|
||||
static typename std::enable_if_t<!std::is_enum_v<T> && !__IsPODType<T>()>
|
||||
Do(const PropId& id, T& var, StreamT& s)
|
||||
{
|
||||
if (PropOp != PropType::None)
|
||||
{
|
||||
/* Accessed via Enumerate, header */
|
||||
s += 6;
|
||||
var.template Enumerate<BinarySize<PropOp>>(s);
|
||||
}
|
||||
else
|
||||
var.template Enumerate<BinarySize>(s);
|
||||
}
|
||||
template <class T, Endian DNAE>
|
||||
static void Do(const PropId& id, std::vector<T>& vector, size_t count, StreamT& s)
|
||||
{
|
||||
for (T& v : vector)
|
||||
BinarySize<PropOp>::Do<T, DNAE>(id, v, s);
|
||||
}
|
||||
static void Do(const PropId& id, std::unique_ptr<atUint8[]>& buf, size_t count, StreamT& s)
|
||||
{
|
||||
if (buf)
|
||||
s += count;
|
||||
}
|
||||
static void Do(const PropId& id, std::string& str, StreamT& s)
|
||||
{
|
||||
s += str.size() + 1;
|
||||
}
|
||||
static void Do(const PropId& id, std::string& str, size_t count, StreamT& s)
|
||||
{
|
||||
s += count;
|
||||
}
|
||||
template <Endian DNAE>
|
||||
static void Do(const PropId& id, std::wstring& str, StreamT& s)
|
||||
{
|
||||
s += str.size() * 2 + 2;
|
||||
}
|
||||
template <Endian DNAE>
|
||||
static void Do(const PropId& id, std::wstring& str, size_t count, StreamT& s)
|
||||
{
|
||||
s += count * 2;
|
||||
}
|
||||
static void DoSeek(atInt64 amount, SeekOrigin whence, StreamT& s)
|
||||
{
|
||||
switch (whence)
|
||||
{
|
||||
case SeekOrigin::Begin:
|
||||
s = amount;
|
||||
break;
|
||||
case SeekOrigin::Current:
|
||||
s += amount;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
static void DoAlign(atInt64 amount, StreamT& s)
|
||||
{
|
||||
s = (s + amount-1) / amount * amount;
|
||||
}
|
||||
};
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<bool, Endian::Big>(const PropId& id, bool& var, BinarySize::StreamT& s) { s += 1; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atInt8, Endian::Big>(const PropId& id, atInt8& var, BinarySize::StreamT& s) { s += 1; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atUint8, Endian::Big>(const PropId& id, atUint8& var, BinarySize::StreamT& s) { s += 1; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atInt16, Endian::Big>(const PropId& id, atInt16& var, BinarySize::StreamT& s) { s += 2; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atUint16, Endian::Big>(const PropId& id, atUint16& var, BinarySize::StreamT& s) { s += 2; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atInt32, Endian::Big>(const PropId& id, atInt32& var, BinarySize::StreamT& s) { s += 4; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atUint32, Endian::Big>(const PropId& id, atUint32& var, BinarySize::StreamT& s) { s += 4; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atInt64, Endian::Big>(const PropId& id, atInt64& var, BinarySize::StreamT& s) { s += 8; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atUint64, Endian::Big>(const PropId& id, atUint64& var, BinarySize::StreamT& s) { s += 8; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<float, Endian::Big>(const PropId& id, float& var, BinarySize::StreamT& s) { s += 4; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<double, Endian::Big>(const PropId& id, double& var, BinarySize::StreamT& s) { s += 8; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atVec2f, Endian::Big>(const PropId& id, atVec2f& var, BinarySize::StreamT& s) { s += 8; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atVec2d, Endian::Big>(const PropId& id, atVec2d& var, BinarySize::StreamT& s) { s += 16; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atVec3f, Endian::Big>(const PropId& id, atVec3f& var, BinarySize::StreamT& s) { s += 12; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atVec3d, Endian::Big>(const PropId& id, atVec3d& var, BinarySize::StreamT& s) { s += 24; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atVec4f, Endian::Big>(const PropId& id, atVec4f& var, BinarySize::StreamT& s) { s += 16; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atVec4d, Endian::Big>(const PropId& id, atVec4d& var, BinarySize::StreamT& s) { s += 32; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<bool, Endian::Little>(const PropId& id, bool& var, BinarySize::StreamT& s) { s += 1; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atInt8, Endian::Little>(const PropId& id, atInt8& var, BinarySize::StreamT& s) { s += 1; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atUint8, Endian::Little>(const PropId& id, atUint8& var, BinarySize::StreamT& s) { s += 1; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atInt16, Endian::Little>(const PropId& id, atInt16& var, BinarySize::StreamT& s) { s += 2; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atUint16, Endian::Little>(const PropId& id, atUint16& var, BinarySize::StreamT& s) { s += 2; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atInt32, Endian::Little>(const PropId& id, atInt32& var, BinarySize::StreamT& s) { s += 4; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atUint32, Endian::Little>(const PropId& id, atUint32& var, BinarySize::StreamT& s) { s += 4; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atInt64, Endian::Little>(const PropId& id, atInt64& var, BinarySize::StreamT& s) { s += 8; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atUint64, Endian::Little>(const PropId& id, atUint64& var, BinarySize::StreamT& s) { s += 8; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<float, Endian::Little>(const PropId& id, float& var, BinarySize::StreamT& s) { s += 4; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<double, Endian::Little>(const PropId& id, double& var, BinarySize::StreamT& s) { s += 8; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atVec2f, Endian::Little>(const PropId& id, atVec2f& var, BinarySize::StreamT& s) { s += 8; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atVec2d, Endian::Little>(const PropId& id, atVec2d& var, BinarySize::StreamT& s) { s += 16; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atVec3f, Endian::Little>(const PropId& id, atVec3f& var, BinarySize::StreamT& s) { s += 12; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atVec3d, Endian::Little>(const PropId& id, atVec3d& var, BinarySize::StreamT& s) { s += 24; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atVec4f, Endian::Little>(const PropId& id, atVec4f& var, BinarySize::StreamT& s) { s += 16; }
|
||||
template <> template <> inline void BinarySize<PropType::None>::Do<atVec4d, Endian::Little>(const PropId& id, atVec4d& var, BinarySize::StreamT& s) { s += 32; }
|
||||
|
||||
template <PropType PropOp>
|
||||
struct PropCount
|
||||
{
|
||||
using PropT = std::conditional_t<PropOp == PropType::CRC64, uint64_t, uint32_t>;
|
||||
using StreamT = size_t;
|
||||
template <class T, Endian DNAE>
|
||||
static void Do(const PropId& id, T& var, StreamT& s)
|
||||
{
|
||||
/* Only reports one level of properties */
|
||||
s += 1;
|
||||
}
|
||||
template <class T, Endian DNAE>
|
||||
static void Do(const PropId& id, std::vector<T>& vector, size_t count, StreamT& s)
|
||||
{
|
||||
/* Only reports one level of properties */
|
||||
s += 1;
|
||||
}
|
||||
static void Do(const PropId& id, std::unique_ptr<atUint8[]>& buf, size_t count, StreamT& s)
|
||||
{
|
||||
/* Only reports one level of properties */
|
||||
s += 1;
|
||||
}
|
||||
static void Do(const PropId& id, std::string& str, StreamT& s)
|
||||
{
|
||||
/* Only reports one level of properties */
|
||||
s += 1;
|
||||
}
|
||||
static void Do(const PropId& id, std::string& str, size_t count, StreamT& s)
|
||||
{
|
||||
/* Only reports one level of properties */
|
||||
s += 1;
|
||||
}
|
||||
template <Endian DNAE>
|
||||
static void Do(const PropId& id, std::wstring& str, StreamT& s)
|
||||
{
|
||||
/* Only reports one level of properties */
|
||||
s += 1;
|
||||
}
|
||||
template <Endian DNAE>
|
||||
static void Do(const PropId& id, std::wstring& str, size_t count, StreamT& s)
|
||||
{
|
||||
/* Only reports one level of properties */
|
||||
s += 1;
|
||||
}
|
||||
static void DoSeek(atInt64 amount, SeekOrigin whence, StreamT& s) {}
|
||||
static void DoAlign(atInt64 amount, StreamT& s) {}
|
||||
};
|
||||
|
||||
template <PropType PropOp>
|
||||
struct Read
|
||||
{
|
||||
using PropT = std::conditional_t<PropOp == PropType::CRC64, uint64_t, uint32_t>;
|
||||
using StreamT = IStreamReader;
|
||||
template <class T, Endian DNAE>
|
||||
static typename std::enable_if_t<std::is_enum_v<T>>
|
||||
Do(const PropId& id, T& var, StreamT& r)
|
||||
{
|
||||
using PODType = std::underlying_type_t<T>;
|
||||
Read<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), r);
|
||||
}
|
||||
template <class T, Endian DNAE>
|
||||
static typename std::enable_if_t<__IsPODType<T>()>
|
||||
Do(const PropId& id, T& var, StreamT& r)
|
||||
{
|
||||
Read<PropType::None>::Do<T, DNAE>(id, var, r);
|
||||
}
|
||||
template <class T, Endian DNAE>
|
||||
static typename std::enable_if_t<!std::is_enum_v<T> && !__IsPODType<T>()>
|
||||
Do(const PropId& id, T& var, StreamT& r)
|
||||
{
|
||||
if (PropOp != PropType::None)
|
||||
{
|
||||
/* Accessed via Lookup, no header */
|
||||
atUint16 propCount = T::DNAEndian == Endian::Big ? r.readUint16Big() : r.readUint16Little();
|
||||
for (atUint32 i = 0; i < propCount; ++i)
|
||||
{
|
||||
atUint64 hash;
|
||||
if (PropOp == PropType::CRC64)
|
||||
hash = T::DNAEndian == Endian::Big ? r.readUint64Big() : r.readUint64Little();
|
||||
else
|
||||
hash = T::DNAEndian == Endian::Big ? r.readUint32Big() : r.readUint32Little();
|
||||
atInt64 size = T::DNAEndian == Endian::Big ? r.readUint16Big() : r.readUint16Little();
|
||||
atInt64 start = r.position();
|
||||
var.template Lookup<Read<PropOp>>(hash, r);
|
||||
atInt64 actualRead = r.position() - start;
|
||||
if (actualRead != size)
|
||||
r.seek(size - actualRead);
|
||||
}
|
||||
}
|
||||
else
|
||||
var.template Enumerate<Read<PropOp>>(r);
|
||||
}
|
||||
template <class T, Endian DNAE>
|
||||
static void Do(const PropId& id, std::vector<T>& vector, size_t count, StreamT& r)
|
||||
{
|
||||
vector.clear();
|
||||
vector.reserve(count);
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
vector.emplace_back();
|
||||
Read<PropOp>::Do<T, DNAE>(id, vector.back(), r);
|
||||
}
|
||||
}
|
||||
static void Do(const PropId& id, std::unique_ptr<atUint8[]>& buf, size_t count, StreamT& r)
|
||||
{
|
||||
buf.reset(new atUint8[count]);
|
||||
r.readUBytesToBuf(buf.get(), count);
|
||||
}
|
||||
static void Do(const PropId& id, std::string& str, StreamT& r)
|
||||
{
|
||||
str = r.readString();
|
||||
}
|
||||
static void Do(const PropId& id, std::string& str, size_t count, StreamT& r)
|
||||
{
|
||||
str = r.readString(count);
|
||||
}
|
||||
template <Endian DNAE>
|
||||
static void Do(const PropId& id, std::wstring& str, StreamT& r)
|
||||
{
|
||||
Read<PropType::None>::Do<DNAE>(id, str, r);
|
||||
}
|
||||
template <Endian DNAE>
|
||||
static void Do(const PropId& id, std::wstring& str, size_t count, StreamT& r)
|
||||
{
|
||||
Read<PropType::None>::Do<DNAE>(id, str, count, r);
|
||||
}
|
||||
static void DoSeek(atInt64 amount, SeekOrigin whence, StreamT& r)
|
||||
{
|
||||
r.seek(amount, whence);
|
||||
}
|
||||
static void DoAlign(atInt64 amount, StreamT& r)
|
||||
{
|
||||
r.seek((r.position() + amount-1) / amount * amount, athena::Begin);
|
||||
}
|
||||
};
|
||||
template <> template <> inline void Read<PropType::None>::Do<bool, Endian::Big>(const PropId& id, bool& var, Read::StreamT& r) { var = r.readBool(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atInt8, Endian::Big>(const PropId& id, atInt8& var, Read::StreamT& r) { var = r.readByte(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atUint8, Endian::Big>(const PropId& id, atUint8& var, Read::StreamT& r) { var = r.readUByte(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atInt16, Endian::Big>(const PropId& id, atInt16& var, Read::StreamT& r) { var = r.readInt16Big(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atUint16, Endian::Big>(const PropId& id, atUint16& var, Read::StreamT& r) { var = r.readUint16Big(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atInt32, Endian::Big>(const PropId& id, atInt32& var, Read::StreamT& r) { var = r.readInt32Big(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atUint32, Endian::Big>(const PropId& id, atUint32& var, Read::StreamT& r) { var = r.readUint32Big(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atInt64, Endian::Big>(const PropId& id, atInt64& var, Read::StreamT& r) { var = r.readInt64Big(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atUint64, Endian::Big>(const PropId& id, atUint64& var, Read::StreamT& r) { var = r.readUint64Big(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<float, Endian::Big>(const PropId& id, float& var, Read::StreamT& r) { var = r.readFloatBig(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<double, Endian::Big>(const PropId& id, double& var, Read::StreamT& r) { var = r.readDoubleBig(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atVec2f, Endian::Big>(const PropId& id, atVec2f& var, Read::StreamT& r) { var = r.readVec2fBig(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atVec2d, Endian::Big>(const PropId& id, atVec2d& var, Read::StreamT& r) { var = r.readVec2dBig(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atVec3f, Endian::Big>(const PropId& id, atVec3f& var, Read::StreamT& r) { var = r.readVec3fBig(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atVec3d, Endian::Big>(const PropId& id, atVec3d& var, Read::StreamT& r) { var = r.readVec3dBig(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atVec4f, Endian::Big>(const PropId& id, atVec4f& var, Read::StreamT& r) { var = r.readVec4fBig(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atVec4d, Endian::Big>(const PropId& id, atVec4d& var, Read::StreamT& r) { var = r.readVec4dBig(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<Endian::Big>(const PropId& id, std::wstring& str, StreamT& r) { str = r.readWStringBig(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<Endian::Big>(const PropId& id, std::wstring& str, size_t count, StreamT& r) { str = r.readWStringBig(count); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<bool, Endian::Little>(const PropId& id, bool& var, Read::StreamT& r) { var = r.readBool(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atInt8, Endian::Little>(const PropId& id, atInt8& var, Read::StreamT& r) { var = r.readByte(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atUint8, Endian::Little>(const PropId& id, atUint8& var, Read::StreamT& r) { var = r.readUByte(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atInt16, Endian::Little>(const PropId& id, atInt16& var, Read::StreamT& r) { var = r.readInt16Little(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atUint16, Endian::Little>(const PropId& id, atUint16& var, Read::StreamT& r) { var = r.readUint16Little(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atInt32, Endian::Little>(const PropId& id, atInt32& var, Read::StreamT& r) { var = r.readInt32Little(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atUint32, Endian::Little>(const PropId& id, atUint32& var, Read::StreamT& r) { var = r.readUint32Little(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atInt64, Endian::Little>(const PropId& id, atInt64& var, Read::StreamT& r) { var = r.readInt64Little(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atUint64, Endian::Little>(const PropId& id, atUint64& var, Read::StreamT& r) { var = r.readUint64Little(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<float, Endian::Little>(const PropId& id, float& var, Read::StreamT& r) { var = r.readFloatLittle(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<double, Endian::Little>(const PropId& id, double& var, Read::StreamT& r) { var = r.readDoubleLittle(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atVec2f, Endian::Little>(const PropId& id, atVec2f& var, Read::StreamT& r) { var = r.readVec2fLittle(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atVec2d, Endian::Little>(const PropId& id, atVec2d& var, Read::StreamT& r) { var = r.readVec2dLittle(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atVec3f, Endian::Little>(const PropId& id, atVec3f& var, Read::StreamT& r) { var = r.readVec3fLittle(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atVec3d, Endian::Little>(const PropId& id, atVec3d& var, Read::StreamT& r) { var = r.readVec3dLittle(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atVec4f, Endian::Little>(const PropId& id, atVec4f& var, Read::StreamT& r) { var = r.readVec4fLittle(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<atVec4d, Endian::Little>(const PropId& id, atVec4d& var, Read::StreamT& r) { var = r.readVec4dLittle(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<Endian::Little>(const PropId& id, std::wstring& str, StreamT& r) { str = r.readWStringLittle(); }
|
||||
template <> template <> inline void Read<PropType::None>::Do<Endian::Little>(const PropId& id, std::wstring& str, size_t count, StreamT& r) { str = r.readWStringLittle(count); }
|
||||
|
||||
template <PropType PropOp>
|
||||
struct Write
|
||||
{
|
||||
using PropT = std::conditional_t<PropOp == PropType::CRC64, uint64_t, uint32_t>;
|
||||
using StreamT = IStreamWriter;
|
||||
template <class T, Endian DNAE>
|
||||
static typename std::enable_if_t<std::is_enum_v<T>>
|
||||
Do(const PropId& id, T& var, StreamT& w)
|
||||
{
|
||||
if (PropOp != PropType::None)
|
||||
{
|
||||
/* Accessed via Enumerate, header */
|
||||
if (PropOp == PropType::CRC64)
|
||||
DNAE == Endian::Big ? w.writeUint64Big(id.crc64) : w.writeUint64Little(id.crc64);
|
||||
else
|
||||
DNAE == Endian::Big ? w.writeUint32Big(id.rcrc32) : w.writeUint32Little(id.rcrc32);
|
||||
size_t binarySize = 0;
|
||||
BinarySize<PropType::None>::Do<T, DNAE>(id, var, binarySize);
|
||||
DNAE == Endian::Big ? w.writeUint16Big(atUint16(binarySize)) : w.writeUint16Little(atUint16(binarySize));
|
||||
}
|
||||
using PODType = std::underlying_type_t<T>;
|
||||
Write<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), w);
|
||||
}
|
||||
template <class T, Endian DNAE>
|
||||
static typename std::enable_if_t<__IsPODType<T>()>
|
||||
Do(const PropId& id, T& var, StreamT& w)
|
||||
{
|
||||
if (PropOp != PropType::None)
|
||||
{
|
||||
/* Accessed via Enumerate, header */
|
||||
if (PropOp == PropType::CRC64)
|
||||
DNAE == Endian::Big ? w.writeUint64Big(id.crc64) : w.writeUint64Little(id.crc64);
|
||||
else
|
||||
DNAE == Endian::Big ? w.writeUint32Big(id.rcrc32) : w.writeUint32Little(id.rcrc32);
|
||||
size_t binarySize = 0;
|
||||
BinarySize<PropType::None>::Do<T, DNAE>(id, var, binarySize);
|
||||
DNAE == Endian::Big ? w.writeUint16Big(atUint16(binarySize)) : w.writeUint16Little(atUint16(binarySize));
|
||||
}
|
||||
Write<PropType::None>::Do<T, DNAE>(id, var, w);
|
||||
}
|
||||
template <class T, Endian DNAE>
|
||||
static typename std::enable_if_t<!std::is_enum_v<T> && !__IsPODType<T>()>
|
||||
Do(const PropId& id, T& var, StreamT& w)
|
||||
{
|
||||
if (PropOp != PropType::None)
|
||||
{
|
||||
/* Accessed via Enumerate, header */
|
||||
if (PropOp == PropType::CRC64)
|
||||
T::DNAEndian == Endian::Big ? w.writeUint64Big(id.crc64) : w.writeUint64Little(id.crc64);
|
||||
else
|
||||
T::DNAEndian == Endian::Big ? w.writeUint32Big(id.rcrc32) : w.writeUint32Little(id.rcrc32);
|
||||
size_t binarySize = 0;
|
||||
var.template Enumerate<BinarySize<PropOp>>(binarySize);
|
||||
T::DNAEndian == Endian::Big ? w.writeUint16Big(atUint16(binarySize)) : w.writeUint16Little(atUint16(binarySize));
|
||||
|
||||
size_t propCount = 0;
|
||||
var.template Enumerate<PropCount<PropOp>>(propCount);
|
||||
T::DNAEndian == Endian::Big ? w.writeUint16Big(atUint16(propCount)) : w.writeUint16Little(atUint16(propCount));
|
||||
var.template Enumerate<Write<PropOp>>(w);
|
||||
}
|
||||
else
|
||||
var.template Enumerate<Write<PropOp>>(w);
|
||||
}
|
||||
template <class T, Endian DNAE>
|
||||
static void Do(const PropId& id, std::vector<T>& vector, size_t count, StreamT& w)
|
||||
{
|
||||
for (T& v : vector)
|
||||
Write<PropOp>::Do<T, DNAE>(id, v, w);
|
||||
}
|
||||
static void Do(const PropId& id, std::unique_ptr<atUint8[]>& buf, size_t count, StreamT& w)
|
||||
{
|
||||
if (buf)
|
||||
w.writeUBytes(buf.get(), count);
|
||||
}
|
||||
static void Do(const PropId& id, std::string& str, StreamT& w)
|
||||
{
|
||||
w.writeString(str);
|
||||
}
|
||||
static void Do(const PropId& id, std::string& str, size_t count, StreamT& w)
|
||||
{
|
||||
w.writeString(str, count);
|
||||
}
|
||||
template <Endian DNAE>
|
||||
static void Do(const PropId& id, std::wstring& str, StreamT& w)
|
||||
{
|
||||
Write<PropType::None>::Do<DNAE>(id, str, w);
|
||||
}
|
||||
template <Endian DNAE>
|
||||
static void Do(const PropId& id, std::wstring& str, size_t count, StreamT& w)
|
||||
{
|
||||
Write<PropType::None>::Do<DNAE>(id, str, count, w);
|
||||
}
|
||||
static void DoSeek(atInt64 amount, SeekOrigin whence, StreamT& w)
|
||||
{
|
||||
w.seek(amount, whence);
|
||||
}
|
||||
static void DoAlign(atInt64 amount, StreamT& w)
|
||||
{
|
||||
w.writeZeroTo((w.position() + amount-1) / amount * amount);
|
||||
}
|
||||
};
|
||||
template <> template <> inline void Write<PropType::None>::Do<bool, Endian::Big>(const PropId& id, bool& var, Write::StreamT& w) { w.writeBool(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atInt8, Endian::Big>(const PropId& id, atInt8& var, Write::StreamT& w) { w.writeByte(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atUint8, Endian::Big>(const PropId& id, atUint8& var, Write::StreamT& w) { w.writeUByte(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atInt16, Endian::Big>(const PropId& id, atInt16& var, Write::StreamT& w) { w.writeInt16Big(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atUint16, Endian::Big>(const PropId& id, atUint16& var, Write::StreamT& w) { w.writeUint16Big(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atInt32, Endian::Big>(const PropId& id, atInt32& var, Write::StreamT& w) { w.writeInt32Big(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atUint32, Endian::Big>(const PropId& id, atUint32& var, Write::StreamT& w) { w.writeUint32Big(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atInt64, Endian::Big>(const PropId& id, atInt64& var, Write::StreamT& w) { w.writeInt64Big(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atUint64, Endian::Big>(const PropId& id, atUint64& var, Write::StreamT& w) { w.writeUint64Big(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<float, Endian::Big>(const PropId& id, float& var, Write::StreamT& w) { w.writeFloatBig(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<double, Endian::Big>(const PropId& id, double& var, Write::StreamT& w) { w.writeDoubleBig(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atVec2f, Endian::Big>(const PropId& id, atVec2f& var, Write::StreamT& w) { w.writeVec2fBig(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atVec2d, Endian::Big>(const PropId& id, atVec2d& var, Write::StreamT& w) { w.writeVec2dBig(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atVec3f, Endian::Big>(const PropId& id, atVec3f& var, Write::StreamT& w) { w.writeVec3fBig(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atVec3d, Endian::Big>(const PropId& id, atVec3d& var, Write::StreamT& w) { w.writeVec3dBig(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atVec4f, Endian::Big>(const PropId& id, atVec4f& var, Write::StreamT& w) { w.writeVec4fBig(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atVec4d, Endian::Big>(const PropId& id, atVec4d& var, Write::StreamT& w) { w.writeVec4dBig(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<Endian::Big>(const PropId& id, std::wstring& str, StreamT& w) { w.writeWStringBig(str); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<Endian::Big>(const PropId& id, std::wstring& str, size_t count, StreamT& w) { w.writeWStringBig(str, count); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<bool, Endian::Little>(const PropId& id, bool& var, Write::StreamT& w) { w.writeBool(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atInt8, Endian::Little>(const PropId& id, atInt8& var, Write::StreamT& w) { w.writeByte(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atUint8, Endian::Little>(const PropId& id, atUint8& var, Write::StreamT& w) { w.writeUByte(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atInt16, Endian::Little>(const PropId& id, atInt16& var, Write::StreamT& w) { w.writeInt16Little(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atUint16, Endian::Little>(const PropId& id, atUint16& var, Write::StreamT& w) { w.writeUint16Little(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atInt32, Endian::Little>(const PropId& id, atInt32& var, Write::StreamT& w) { w.writeInt32Little(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atUint32, Endian::Little>(const PropId& id, atUint32& var, Write::StreamT& w) { w.writeUint32Little(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atInt64, Endian::Little>(const PropId& id, atInt64& var, Write::StreamT& w) { w.writeInt64Little(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atUint64, Endian::Little>(const PropId& id, atUint64& var, Write::StreamT& w) { w.writeUint64Little(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<float, Endian::Little>(const PropId& id, float& var, Write::StreamT& w) { w.writeFloatLittle(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<double, Endian::Little>(const PropId& id, double& var, Write::StreamT& w) { w.writeDoubleLittle(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atVec2f, Endian::Little>(const PropId& id, atVec2f& var, Write::StreamT& w) { w.writeVec2fLittle(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atVec2d, Endian::Little>(const PropId& id, atVec2d& var, Write::StreamT& w) { w.writeVec2dLittle(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atVec3f, Endian::Little>(const PropId& id, atVec3f& var, Write::StreamT& w) { w.writeVec3fLittle(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atVec3d, Endian::Little>(const PropId& id, atVec3d& var, Write::StreamT& w) { w.writeVec3dLittle(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atVec4f, Endian::Little>(const PropId& id, atVec4f& var, Write::StreamT& w) { w.writeVec4fLittle(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<atVec4d, Endian::Little>(const PropId& id, atVec4d& var, Write::StreamT& w) { w.writeVec4dLittle(var); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<Endian::Little>(const PropId& id, std::wstring& str, StreamT& w) { w.writeWStringLittle(str); }
|
||||
template <> template <> inline void Write<PropType::None>::Do<Endian::Little>(const PropId& id, std::wstring& str, size_t count, StreamT& w) { w.writeWStringLittle(str, count); }
|
||||
|
||||
template <PropType PropOp>
|
||||
struct ReadYaml
|
||||
{
|
||||
using PropT = std::conditional_t<PropOp == PropType::CRC64, uint64_t, uint32_t>;
|
||||
using StreamT = YAMLDocReader;
|
||||
template <class T, Endian DNAE>
|
||||
static typename std::enable_if_t<std::is_enum_v<T>>
|
||||
Do(const PropId& id, T& var, StreamT& r)
|
||||
{
|
||||
using PODType = std::underlying_type_t<T>;
|
||||
ReadYaml<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), r);
|
||||
}
|
||||
template <class T, Endian DNAE>
|
||||
static typename std::enable_if_t<__IsPODType<T>()>
|
||||
Do(const PropId& id, T& var, StreamT& r)
|
||||
{
|
||||
ReadYaml<PropType::None>::Do<T, DNAE>(id, var, r);
|
||||
}
|
||||
template <class T, Endian DNAE>
|
||||
static typename std::enable_if_t<!std::is_enum_v<T> && !__IsPODType<T>()>
|
||||
Do(const PropId& id, T& var, StreamT& r)
|
||||
{
|
||||
if (auto rec = r.enterSubRecord(id.name))
|
||||
var.template Enumerate<ReadYaml<PropOp>>(r);
|
||||
}
|
||||
template <class T, Endian DNAE>
|
||||
static void Do(const PropId& id, std::vector<T>& vector, size_t count, StreamT& r)
|
||||
{
|
||||
vector.clear();
|
||||
vector.reserve(count);
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
vector.emplace_back();
|
||||
ReadYaml<PropOp>::Do<T, DNAE>(id, vector.back(), r);
|
||||
}
|
||||
}
|
||||
static void Do(const PropId& id, std::unique_ptr<atUint8[]>& buf, size_t count, StreamT& r)
|
||||
{
|
||||
buf = r.readUBytes(id.name);
|
||||
}
|
||||
static void Do(const PropId& id, std::string& str, StreamT& r)
|
||||
{
|
||||
str = r.readString(id.name);
|
||||
}
|
||||
static void Do(const PropId& id, std::string& str, size_t count, StreamT& r)
|
||||
{
|
||||
str = r.readString(id.name);
|
||||
}
|
||||
template <Endian DNAE>
|
||||
static void Do(const PropId& id, std::wstring& str, StreamT& r)
|
||||
{
|
||||
str = r.readWString(id.name);
|
||||
}
|
||||
template <Endian DNAE>
|
||||
static void Do(const PropId& id, std::wstring& str, size_t count, StreamT& r)
|
||||
{
|
||||
str = r.readWString(id.name);
|
||||
}
|
||||
static void DoSeek(atInt64 amount, SeekOrigin whence, StreamT& r) {}
|
||||
static void DoAlign(atInt64 amount, StreamT& r) {}
|
||||
};
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<bool, Endian::Big>(const PropId& id, bool& var, ReadYaml::StreamT& r) { var = r.readBool(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atInt8, Endian::Big>(const PropId& id, atInt8& var, ReadYaml::StreamT& r) { var = r.readByte(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atUint8, Endian::Big>(const PropId& id, atUint8& var, ReadYaml::StreamT& r) { var = r.readUByte(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atInt16, Endian::Big>(const PropId& id, atInt16& var, ReadYaml::StreamT& r) { var = r.readInt16(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atUint16, Endian::Big>(const PropId& id, atUint16& var, ReadYaml::StreamT& r) { var = r.readUint16(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atInt32, Endian::Big>(const PropId& id, atInt32& var, ReadYaml::StreamT& r) { var = r.readInt32(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atUint32, Endian::Big>(const PropId& id, atUint32& var, ReadYaml::StreamT& r) { var = r.readUint32(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atInt64, Endian::Big>(const PropId& id, atInt64& var, ReadYaml::StreamT& r) { var = r.readInt64(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atUint64, Endian::Big>(const PropId& id, atUint64& var, ReadYaml::StreamT& r) { var = r.readUint64(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<float, Endian::Big>(const PropId& id, float& var, ReadYaml::StreamT& r) { var = r.readFloat(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<double, Endian::Big>(const PropId& id, double& var, ReadYaml::StreamT& r) { var = r.readDouble(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atVec2f, Endian::Big>(const PropId& id, atVec2f& var, ReadYaml::StreamT& r) { var = r.readVec2f(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atVec2d, Endian::Big>(const PropId& id, atVec2d& var, ReadYaml::StreamT& r) { var = r.readVec2d(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atVec3f, Endian::Big>(const PropId& id, atVec3f& var, ReadYaml::StreamT& r) { var = r.readVec3f(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atVec3d, Endian::Big>(const PropId& id, atVec3d& var, ReadYaml::StreamT& r) { var = r.readVec3d(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atVec4f, Endian::Big>(const PropId& id, atVec4f& var, ReadYaml::StreamT& r) { var = r.readVec4f(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atVec4d, Endian::Big>(const PropId& id, atVec4d& var, ReadYaml::StreamT& r) { var = r.readVec4d(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<bool, Endian::Little>(const PropId& id, bool& var, ReadYaml::StreamT& r) { var = r.readBool(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atInt8, Endian::Little>(const PropId& id, atInt8& var, ReadYaml::StreamT& r) { var = r.readByte(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atUint8, Endian::Little>(const PropId& id, atUint8& var, ReadYaml::StreamT& r) { var = r.readUByte(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atInt16, Endian::Little>(const PropId& id, atInt16& var, ReadYaml::StreamT& r) { var = r.readInt16(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atUint16, Endian::Little>(const PropId& id, atUint16& var, ReadYaml::StreamT& r) { var = r.readUint16(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atInt32, Endian::Little>(const PropId& id, atInt32& var, ReadYaml::StreamT& r) { var = r.readInt32(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atUint32, Endian::Little>(const PropId& id, atUint32& var, ReadYaml::StreamT& r) { var = r.readUint32(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atInt64, Endian::Little>(const PropId& id, atInt64& var, ReadYaml::StreamT& r) { var = r.readInt64(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atUint64, Endian::Little>(const PropId& id, atUint64& var, ReadYaml::StreamT& r) { var = r.readUint64(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<float, Endian::Little>(const PropId& id, float& var, ReadYaml::StreamT& r) { var = r.readFloat(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<double, Endian::Little>(const PropId& id, double& var, ReadYaml::StreamT& r) { var = r.readDouble(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atVec2f, Endian::Little>(const PropId& id, atVec2f& var, ReadYaml::StreamT& r) { var = r.readVec2f(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atVec2d, Endian::Little>(const PropId& id, atVec2d& var, ReadYaml::StreamT& r) { var = r.readVec2d(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atVec3f, Endian::Little>(const PropId& id, atVec3f& var, ReadYaml::StreamT& r) { var = r.readVec3f(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atVec3d, Endian::Little>(const PropId& id, atVec3d& var, ReadYaml::StreamT& r) { var = r.readVec3d(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atVec4f, Endian::Little>(const PropId& id, atVec4f& var, ReadYaml::StreamT& r) { var = r.readVec4f(id.name); }
|
||||
template <> template <> inline void ReadYaml<PropType::None>::Do<atVec4d, Endian::Little>(const PropId& id, atVec4d& var, ReadYaml::StreamT& r) { var = r.readVec4d(id.name); }
|
||||
|
||||
template <PropType PropOp>
|
||||
struct WriteYaml
|
||||
{
|
||||
using PropT = std::conditional_t<PropOp == PropType::CRC64, uint64_t, uint32_t>;
|
||||
using StreamT = YAMLDocWriter;
|
||||
template <class T, Endian DNAE>
|
||||
static typename std::enable_if_t<std::is_enum_v<T>>
|
||||
Do(const PropId& id, T& var, StreamT& w)
|
||||
{
|
||||
using PODType = std::underlying_type_t<T>;
|
||||
WriteYaml<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), w);
|
||||
}
|
||||
template <class T, Endian DNAE>
|
||||
static typename std::enable_if_t<__IsPODType<T>()>
|
||||
Do(const PropId& id, T& var, StreamT& w)
|
||||
{
|
||||
WriteYaml<PropType::None>::Do<T, DNAE>(id, var, w);
|
||||
}
|
||||
template <class T, Endian DNAE>
|
||||
static typename std::enable_if_t<!std::is_enum_v<T> && !__IsPODType<T>()>
|
||||
Do(const PropId& id, T& var, StreamT& w)
|
||||
{
|
||||
if (auto rec = w.enterSubRecord(id.name))
|
||||
var.template Enumerate<WriteYaml<PropOp>>(w);
|
||||
}
|
||||
template <class T, Endian DNAE>
|
||||
static void Do(const PropId& id, std::vector<T>& vector, size_t count, StreamT& w)
|
||||
{
|
||||
for (T& v : vector)
|
||||
WriteYaml<PropOp>::Do<T, DNAE>(id, v, w);
|
||||
}
|
||||
static void Do(const PropId& id, std::unique_ptr<atUint8[]>& buf, size_t count, StreamT& w)
|
||||
{
|
||||
w.writeUBytes(id.name, buf, count);
|
||||
}
|
||||
static void Do(const PropId& id, std::string& str, StreamT& w)
|
||||
{
|
||||
w.writeString(id.name, str);
|
||||
}
|
||||
static void Do(const PropId& id, std::string& str, size_t count, StreamT& w)
|
||||
{
|
||||
w.writeString(id.name, str);
|
||||
}
|
||||
template <Endian DNAE>
|
||||
static void Do(const PropId& id, std::wstring& str, StreamT& w)
|
||||
{
|
||||
w.writeWString(id.name, str);
|
||||
}
|
||||
template <Endian DNAE>
|
||||
static void Do(const PropId& id, std::wstring& str, size_t count, StreamT& w)
|
||||
{
|
||||
w.writeWString(id.name, str);
|
||||
}
|
||||
static void DoSeek(atInt64 amount, SeekOrigin whence, StreamT& w) {}
|
||||
static void DoAlign(atInt64 amount, StreamT& w) {}
|
||||
};
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<bool, Endian::Big>(const PropId& id, bool& var, WriteYaml::StreamT& w) { w.writeBool(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atInt8, Endian::Big>(const PropId& id, atInt8& var, WriteYaml::StreamT& w) { w.writeByte(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atUint8, Endian::Big>(const PropId& id, atUint8& var, WriteYaml::StreamT& w) { w.writeUByte(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atInt16, Endian::Big>(const PropId& id, atInt16& var, WriteYaml::StreamT& w) { w.writeInt16(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atUint16, Endian::Big>(const PropId& id, atUint16& var, WriteYaml::StreamT& w) { w.writeUint16(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atInt32, Endian::Big>(const PropId& id, atInt32& var, WriteYaml::StreamT& w) { w.writeInt32(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atUint32, Endian::Big>(const PropId& id, atUint32& var, WriteYaml::StreamT& w) { w.writeUint32(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atInt64, Endian::Big>(const PropId& id, atInt64& var, WriteYaml::StreamT& w) { w.writeInt64(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atUint64, Endian::Big>(const PropId& id, atUint64& var, WriteYaml::StreamT& w) { w.writeUint64(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<float, Endian::Big>(const PropId& id, float& var, WriteYaml::StreamT& w) { w.writeFloat(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<double, Endian::Big>(const PropId& id, double& var, WriteYaml::StreamT& w) { w.writeDouble(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atVec2f, Endian::Big>(const PropId& id, atVec2f& var, WriteYaml::StreamT& w) { w.writeVec2f(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atVec2d, Endian::Big>(const PropId& id, atVec2d& var, WriteYaml::StreamT& w) { w.writeVec2d(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atVec3f, Endian::Big>(const PropId& id, atVec3f& var, WriteYaml::StreamT& w) { w.writeVec3f(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atVec3d, Endian::Big>(const PropId& id, atVec3d& var, WriteYaml::StreamT& w) { w.writeVec3d(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atVec4f, Endian::Big>(const PropId& id, atVec4f& var, WriteYaml::StreamT& w) { w.writeVec4f(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atVec4d, Endian::Big>(const PropId& id, atVec4d& var, WriteYaml::StreamT& w) { w.writeVec4d(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<bool, Endian::Little>(const PropId& id, bool& var, WriteYaml::StreamT& w) { w.writeBool(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atInt8, Endian::Little>(const PropId& id, atInt8& var, WriteYaml::StreamT& w) { w.writeByte(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atUint8, Endian::Little>(const PropId& id, atUint8& var, WriteYaml::StreamT& w) { w.writeUByte(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atInt16, Endian::Little>(const PropId& id, atInt16& var, WriteYaml::StreamT& w) { w.writeInt16(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atUint16, Endian::Little>(const PropId& id, atUint16& var, WriteYaml::StreamT& w) { w.writeUint16(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atInt32, Endian::Little>(const PropId& id, atInt32& var, WriteYaml::StreamT& w) { w.writeInt32(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atUint32, Endian::Little>(const PropId& id, atUint32& var, WriteYaml::StreamT& w) { w.writeUint32(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atInt64, Endian::Little>(const PropId& id, atInt64& var, WriteYaml::StreamT& w) { w.writeInt64(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atUint64, Endian::Little>(const PropId& id, atUint64& var, WriteYaml::StreamT& w) { w.writeUint64(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<float, Endian::Little>(const PropId& id, float& var, WriteYaml::StreamT& w) { w.writeFloat(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<double, Endian::Little>(const PropId& id, double& var, WriteYaml::StreamT& w) { w.writeDouble(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atVec2f, Endian::Little>(const PropId& id, atVec2f& var, WriteYaml::StreamT& w) { w.writeVec2f(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atVec2d, Endian::Little>(const PropId& id, atVec2d& var, WriteYaml::StreamT& w) { w.writeVec2d(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atVec3f, Endian::Little>(const PropId& id, atVec3f& var, WriteYaml::StreamT& w) { w.writeVec3f(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atVec3d, Endian::Little>(const PropId& id, atVec3d& var, WriteYaml::StreamT& w) { w.writeVec3d(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atVec4f, Endian::Little>(const PropId& id, atVec4f& var, WriteYaml::StreamT& w) { w.writeVec4f(id.name, var); }
|
||||
template <> template <> inline void WriteYaml<PropType::None>::Do<atVec4d, Endian::Little>(const PropId& id, atVec4d& var, WriteYaml::StreamT& w) { w.writeVec4d(id.name, var); }
|
||||
|
||||
template <class Op, class T, Endian DNAE>
|
||||
static inline void __Do(const PropId& id, T& var, typename Op::StreamT& s)
|
||||
{
|
||||
Op::template Do<T, DNAE>(id, var, s);
|
||||
}
|
||||
|
||||
template <class Op, class T, Endian DNAE>
|
||||
static inline void __Do(const PropId& id, std::vector<T>& vector, size_t count, typename Op::StreamT& s)
|
||||
{
|
||||
Op::template Do<T, DNAE>(id, vector, count, s);
|
||||
}
|
||||
|
||||
template <class Op>
|
||||
static inline void __Do(const PropId& id, std::unique_ptr<atUint8[]>& buf, size_t count, typename Op::StreamT& s)
|
||||
{
|
||||
Op::Do(id, buf, count, s);
|
||||
}
|
||||
|
||||
template <class Op>
|
||||
static inline void __Do(const PropId& id, std::string& str, typename Op::StreamT& s)
|
||||
{
|
||||
Op::Do(id, str, s);
|
||||
}
|
||||
|
||||
template <class Op>
|
||||
static inline void __Do(const PropId& id, std::string& str, size_t count, typename Op::StreamT& s)
|
||||
{
|
||||
Op::Do(id, str, count, s);
|
||||
}
|
||||
|
||||
template <class Op, Endian DNAE>
|
||||
static inline void __Do(const PropId& id, std::wstring& str, typename Op::StreamT& s)
|
||||
{
|
||||
Op::template Do<DNAE>(id, str, s);
|
||||
}
|
||||
|
||||
template <class Op, Endian DNAE>
|
||||
static inline void __Do(const PropId& id, std::wstring& str, size_t count, typename Op::StreamT& s)
|
||||
{
|
||||
Op::template Do<DNAE>(id, str, count, s);
|
||||
}
|
||||
|
||||
template <class Op>
|
||||
static inline void __DoSeek(atInt64 delta, athena::SeekOrigin whence, typename Op::StreamT& s)
|
||||
{
|
||||
Op::DoSeek(delta, whence, s);
|
||||
}
|
||||
|
||||
template <class Op>
|
||||
static inline void __DoAlign(atInt64 amount, typename Op::StreamT& s)
|
||||
{
|
||||
Op::DoAlign(amount, s);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline void __Read(T& obj, athena::io::IStreamReader& r)
|
||||
{
|
||||
__Do<Read<PropType::None>, T, T::DNAEndian>({}, obj, r);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline void __Write(const T& obj, athena::io::IStreamWriter& w)
|
||||
{
|
||||
__Do<Write<PropType::None>, T, T::DNAEndian>({}, const_cast<T&>(obj), w);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline void __BinarySize(const T& obj, size_t& s)
|
||||
{
|
||||
__Do<BinarySize<PropType::None>, T, T::DNAEndian>({}, const_cast<T&>(obj), s);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline void __PropCount(const T& obj, size_t& s)
|
||||
{
|
||||
const_cast<T&>(obj).template Enumerate<PropCount<PropType::None>>(s);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline void __ReadYaml(T& obj, athena::io::YAMLDocReader& r)
|
||||
{
|
||||
obj.template Enumerate<ReadYaml<PropType::None>>(r);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline void __WriteYaml(const T& obj, athena::io::YAMLDocWriter& w)
|
||||
{
|
||||
const_cast<T&>(obj).template Enumerate<WriteYaml<PropType::None>>(w);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline void __ReadProp(T& obj, athena::io::IStreamReader& r)
|
||||
{
|
||||
/* Read root 0xffffffff hash (hashed empty string) */
|
||||
atUint32 hash = T::DNAEndian == Endian::Big ? r.readUint32Big() : r.readUint32Little();
|
||||
atInt64 size = T::DNAEndian == Endian::Big ? r.readUint16Big() : r.readUint16Little();
|
||||
atInt64 start = r.position();
|
||||
__Do<Read<PropType::CRC32>, T, T::DNAEndian>({}, obj, r);
|
||||
atInt64 actualRead = r.position() - start;
|
||||
if (actualRead != size)
|
||||
r.seek(size - actualRead);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline void __WriteProp(const T& obj, athena::io::IStreamWriter& w)
|
||||
{
|
||||
__Do<Write<PropType::CRC32>, T, T::DNAEndian>({}, const_cast<T&>(obj), w);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline void __BinarySizeProp(const T& obj, size_t& s)
|
||||
{
|
||||
__Do<BinarySize<PropType::CRC32>, T, T::DNAEndian>({}, const_cast<T&>(obj), s);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline void __ReadProp64(T& obj, athena::io::IStreamReader& r)
|
||||
{
|
||||
/* Read root 0x0 hash (hashed empty string) */
|
||||
atUint64 hash = T::DNAEndian == Endian::Big ? r.readUint64Big() : r.readUint64Little();
|
||||
atInt64 size = T::DNAEndian == Endian::Big ? r.readUint16Big() : r.readUint16Little();
|
||||
atInt64 start = r.position();
|
||||
__Do<Read<PropType::CRC64>, T, T::DNAEndian>({}, obj, r);
|
||||
atInt64 actualRead = r.position() - start;
|
||||
if (actualRead != size)
|
||||
r.seek(size - actualRead);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline void __WriteProp64(const T& obj, athena::io::IStreamWriter& w)
|
||||
{
|
||||
__Do<Write<PropType::CRC64>, T, T::DNAEndian>({}, const_cast<T&>(obj), w);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline void __BinarySizeProp64(const T& obj, size_t& s)
|
||||
{
|
||||
__Do<BinarySize<PropType::CRC64>, T, T::DNAEndian>({}, const_cast<T&>(obj), s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#define AT_DECL_DNA \
|
||||
template <class Op, athena::Endian DNAE = DNAEndian, class T> \
|
||||
void Do(const athena::io::PropId& id, T& var, typename Op::StreamT& s) { athena::io::__Do<Op, T, DNAE>(id, var, s); } \
|
||||
template <class Op, athena::Endian DNAE = DNAEndian, class T> \
|
||||
void Do(const athena::io::PropId& id, std::vector<T>& var, size_t count, typename Op::StreamT& s) { athena::io::__Do<Op, T, DNAE>(id, var, count, s); } \
|
||||
template <class Op> \
|
||||
void Do(const athena::io::PropId& id, std::unique_ptr<atUint8[]>& buf, size_t count, typename Op::StreamT& s) { athena::io::__Do<Op>(id, buf, count, s); } \
|
||||
template <class Op> \
|
||||
void Do(const athena::io::PropId& id, std::string& str, typename Op::StreamT& s) { athena::io::__Do<Op>(id, str, s); } \
|
||||
template <class Op> \
|
||||
void Do(const athena::io::PropId& id, std::string& str, size_t count, typename Op::StreamT& s) { athena::io::__Do<Op>(id, str, count, s); } \
|
||||
template <class Op, athena::Endian DNAE = DNAEndian> \
|
||||
void Do(const athena::io::PropId& id, std::wstring& str, typename Op::StreamT& s) { athena::io::__Do<Op, DNAE>(id, str, s); } \
|
||||
template <class Op, athena::Endian DNAE = DNAEndian> \
|
||||
void Do(const athena::io::PropId& id, std::wstring& str, size_t count, typename Op::StreamT& s) { athena::io::__Do<Op, DNAE>(id, str, count, s); } \
|
||||
template <class Op> \
|
||||
void DoSeek(atInt64 delta, athena::SeekOrigin whence, typename Op::StreamT& s) { athena::io::__DoSeek<Op>(delta, whence, s); } \
|
||||
template <class Op> \
|
||||
void DoAlign(atInt64 amount, typename Op::StreamT& s) { athena::io::__DoAlign<Op>(amount, s); } \
|
||||
template <class Op> \
|
||||
void Enumerate(typename Op::StreamT& s); \
|
||||
template <class Op> \
|
||||
bool Lookup(uint64_t hash, typename Op::StreamT& s); \
|
||||
void read(athena::io::IStreamReader& r) { athena::io::__Read(*this, r); } \
|
||||
void write(athena::io::IStreamWriter& w) const { athena::io::__Write(*this, w); } \
|
||||
void binarySize(size_t& s) const { athena::io::__BinarySize(*this, s); } \
|
||||
void read(athena::io::YAMLDocReader& r) { athena::io::__ReadYaml(*this, r); } \
|
||||
void write(athena::io::YAMLDocWriter& w) const { athena::io::__WriteYaml(*this, w); } \
|
||||
void readProp(athena::io::IStreamReader& r) { athena::io::__ReadProp(*this, r); } \
|
||||
void writeProp(athena::io::IStreamWriter& w) const { athena::io::__WriteProp(*this, w); } \
|
||||
void binarySizeProp(size_t& s) const { athena::io::__BinarySizeProp(*this, s); } \
|
||||
void propCount(size_t& s) const { athena::io::__PropCount(*this, s); } \
|
||||
void readProp64(athena::io::IStreamReader& r) { athena::io::__ReadProp64(*this, r); } \
|
||||
void writeProp64(athena::io::IStreamWriter& w) const { athena::io::__WriteProp64(*this, w); } \
|
||||
void binarySizeProp64(size_t& s) const { athena::io::__BinarySizeProp64(*this, s); } \
|
||||
|
||||
#define AT_SPECIALIZE_DNA(__Type) \
|
||||
template void __Type::Enumerate<athena::io::Read<athena::io::PropType::None>>(athena::io::Read<athena::io::PropType::None>::StreamT& s); \
|
||||
template void __Type::Enumerate<athena::io::Write<athena::io::PropType::None>>(athena::io::Write<athena::io::PropType::None>::StreamT& s); \
|
||||
template void __Type::Enumerate<athena::io::BinarySize<athena::io::PropType::None>>(athena::io::BinarySize<athena::io::PropType::None>::StreamT& s); \
|
||||
template void __Type::Enumerate<athena::io::ReadYaml<athena::io::PropType::None>>(athena::io::ReadYaml<athena::io::PropType::None>::StreamT& s); \
|
||||
template void __Type::Enumerate<athena::io::WriteYaml<athena::io::PropType::None>>(athena::io::WriteYaml<athena::io::PropType::None>::StreamT& s); \
|
||||
template bool __Type::Lookup<athena::io::Read<athena::io::PropType::CRC32>>(uint64_t hash, athena::io::Read<athena::io::PropType::CRC32>::StreamT& s); \
|
||||
template void __Type::Enumerate<athena::io::Read<athena::io::PropType::CRC32>>(athena::io::Read<athena::io::PropType::CRC32>::StreamT& s); \
|
||||
template bool __Type::Lookup<athena::io::Write<athena::io::PropType::CRC32>>(uint64_t hash, athena::io::Write<athena::io::PropType::CRC32>::StreamT& s); \
|
||||
template void __Type::Enumerate<athena::io::Write<athena::io::PropType::CRC32>>(athena::io::Write<athena::io::PropType::CRC32>::StreamT& s); \
|
||||
template bool __Type::Lookup<athena::io::BinarySize<athena::io::PropType::CRC32>>(uint64_t hash, athena::io::BinarySize<athena::io::PropType::CRC32>::StreamT& s); \
|
||||
template void __Type::Enumerate<athena::io::BinarySize<athena::io::PropType::CRC32>>(athena::io::BinarySize<athena::io::PropType::CRC32>::StreamT& s); \
|
||||
template bool __Type::Lookup<athena::io::PropCount<athena::io::PropType::CRC32>>(uint64_t hash, athena::io::PropCount<athena::io::PropType::CRC32>::StreamT& s); \
|
||||
template void __Type::Enumerate<athena::io::PropCount<athena::io::PropType::CRC32>>(athena::io::PropCount<athena::io::PropType::CRC32>::StreamT& s); \
|
||||
template bool __Type::Lookup<athena::io::ReadYaml<athena::io::PropType::CRC32>>(uint64_t hash, athena::io::ReadYaml<athena::io::PropType::CRC32>::StreamT& s); \
|
||||
template void __Type::Enumerate<athena::io::ReadYaml<athena::io::PropType::CRC32>>(athena::io::ReadYaml<athena::io::PropType::CRC32>::StreamT& s); \
|
||||
template bool __Type::Lookup<athena::io::WriteYaml<athena::io::PropType::CRC32>>(uint64_t hash, athena::io::WriteYaml<athena::io::PropType::CRC32>::StreamT& s); \
|
||||
template void __Type::Enumerate<athena::io::WriteYaml<athena::io::PropType::CRC32>>(athena::io::WriteYaml<athena::io::PropType::CRC32>::StreamT& s); \
|
||||
template bool __Type::Lookup<athena::io::Read<athena::io::PropType::CRC64>>(uint64_t hash, athena::io::Read<athena::io::PropType::CRC64>::StreamT& s); \
|
||||
template void __Type::Enumerate<athena::io::Read<athena::io::PropType::CRC64>>(athena::io::Read<athena::io::PropType::CRC64>::StreamT& s); \
|
||||
template bool __Type::Lookup<athena::io::Write<athena::io::PropType::CRC64>>(uint64_t hash, athena::io::Write<athena::io::PropType::CRC64>::StreamT& s); \
|
||||
template void __Type::Enumerate<athena::io::Write<athena::io::PropType::CRC64>>(athena::io::Write<athena::io::PropType::CRC64>::StreamT& s); \
|
||||
template bool __Type::Lookup<athena::io::BinarySize<athena::io::PropType::CRC64>>(uint64_t hash, athena::io::BinarySize<athena::io::PropType::CRC64>::StreamT& s); \
|
||||
template void __Type::Enumerate<athena::io::BinarySize<athena::io::PropType::CRC64>>(athena::io::BinarySize<athena::io::PropType::CRC64>::StreamT& s); \
|
||||
template bool __Type::Lookup<athena::io::PropCount<athena::io::PropType::CRC64>>(uint64_t hash, athena::io::PropCount<athena::io::PropType::CRC64>::StreamT& s); \
|
||||
template void __Type::Enumerate<athena::io::PropCount<athena::io::PropType::CRC64>>(athena::io::PropCount<athena::io::PropType::CRC64>::StreamT& s); \
|
||||
template bool __Type::Lookup<athena::io::ReadYaml<athena::io::PropType::CRC64>>(uint64_t hash, athena::io::ReadYaml<athena::io::PropType::CRC64>::StreamT& s); \
|
||||
template void __Type::Enumerate<athena::io::ReadYaml<athena::io::PropType::CRC64>>(athena::io::ReadYaml<athena::io::PropType::CRC64>::StreamT& s); \
|
||||
template bool __Type::Lookup<athena::io::WriteYaml<athena::io::PropType::CRC64>>(uint64_t hash, athena::io::WriteYaml<athena::io::PropType::CRC64>::StreamT& s); \
|
||||
template void __Type::Enumerate<athena::io::WriteYaml<athena::io::PropType::CRC64>>(athena::io::WriteYaml<athena::io::PropType::CRC64>::StreamT& s);
|
||||
|
||||
using namespace athena::io::literals;
|
||||
|
||||
#endif // AT_OP_HPP
|
|
@ -1,15 +1,8 @@
|
|||
#ifndef DNAYAML_HPP
|
||||
#define DNAYAML_HPP
|
||||
|
||||
/* BIG FAT WARNING!!!
|
||||
*
|
||||
* The type-structure of this file is expected to remain consistent for 'atdna'
|
||||
* Any changes to the types or namespacing must be reflected in 'atdna/main.cpp'
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include <yaml.h>
|
||||
#include <utf8proc.h>
|
||||
#include "YAMLDocReader.hpp"
|
||||
#include "YAMLDocWriter.hpp"
|
||||
#include "DNA.hpp"
|
||||
#include "FileReader.hpp"
|
||||
#include "FileWriter.hpp"
|
||||
|
@ -17,713 +10,115 @@
|
|||
namespace athena::io
|
||||
{
|
||||
|
||||
enum class YAMLNodeStyle
|
||||
template <class T>
|
||||
static inline std::string ToYAMLString(const T& dna)
|
||||
{
|
||||
Any,
|
||||
Flow,
|
||||
Block
|
||||
};
|
||||
YAMLDocWriter docWriter(dna.DNAType());
|
||||
|
||||
struct YAMLNode
|
||||
std::string res;
|
||||
yaml_emitter_set_output(docWriter.getEmitter(), (yaml_write_handler_t*)YAMLStdStringWriter, &res);
|
||||
yaml_emitter_set_unicode(docWriter.getEmitter(), true);
|
||||
yaml_emitter_set_width(docWriter.getEmitter(), -1);
|
||||
|
||||
dna.write(docWriter);
|
||||
if (!docWriter.finish(nullptr))
|
||||
return std::string();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline bool FromYAMLString(T& dna, std::string_view str)
|
||||
{
|
||||
yaml_node_type_t m_type;
|
||||
std::string m_scalarString;
|
||||
std::vector<std::unique_ptr<YAMLNode>> m_seqChildren;
|
||||
std::vector<std::pair<std::string, std::unique_ptr<YAMLNode>>> m_mapChildren;
|
||||
YAMLNodeStyle m_style = YAMLNodeStyle::Any;
|
||||
YAMLNode(yaml_node_type_t type) : m_type(type) {}
|
||||
inline const YAMLNode* findMapChild(std::string_view key) const
|
||||
{
|
||||
for (const auto& item : m_mapChildren)
|
||||
if (!item.first.compare(key))
|
||||
return item.second.get();
|
||||
return nullptr;
|
||||
}
|
||||
inline void assignMapChild(std::string_view key, std::unique_ptr<YAMLNode>&& node)
|
||||
{
|
||||
for (auto& item : m_mapChildren)
|
||||
if (!item.first.compare(key))
|
||||
{
|
||||
item.second = std::move(node);
|
||||
return;
|
||||
}
|
||||
m_mapChildren.emplace_back(key, std::move(node));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename RETURNTYPE>
|
||||
RETURNTYPE NodeToVal(const YAMLNode* node);
|
||||
|
||||
template <>
|
||||
bool NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(bool val);
|
||||
|
||||
template <>
|
||||
atInt8 NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(atInt8 val);
|
||||
|
||||
template <>
|
||||
atUint8 NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(atUint8 val);
|
||||
|
||||
template <>
|
||||
atInt16 NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(atInt16 val);
|
||||
|
||||
template <>
|
||||
atUint16 NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(atUint16 val);
|
||||
|
||||
template <>
|
||||
atInt32 NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(atInt32 val);
|
||||
|
||||
template <>
|
||||
atUint32 NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(atUint32 val);
|
||||
|
||||
template <>
|
||||
atInt64 NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(atInt64 val);
|
||||
|
||||
template <>
|
||||
atUint64 NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(atUint64 val);
|
||||
|
||||
template <>
|
||||
float NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(float val);
|
||||
|
||||
template <>
|
||||
double NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(double val);
|
||||
|
||||
template <typename RETURNTYPE>
|
||||
RETURNTYPE NodeToVec(const YAMLNode* node);
|
||||
|
||||
template <>
|
||||
atVec2f NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(const atVec2f& val);
|
||||
|
||||
template <>
|
||||
atVec3f NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(const atVec3f& val);
|
||||
|
||||
template <>
|
||||
atVec4f NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(const atVec4f& val);
|
||||
|
||||
template <>
|
||||
atVec2d NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(const atVec2d& val);
|
||||
|
||||
template <>
|
||||
atVec3d NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(const atVec3d& val);
|
||||
|
||||
template <>
|
||||
atVec4d NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(const atVec4d& val);
|
||||
|
||||
template <>
|
||||
std::unique_ptr<atUint8[]> NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(const std::unique_ptr<atUint8[]>& val, size_t byteCount);
|
||||
|
||||
template <>
|
||||
std::string NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(std::string_view val);
|
||||
|
||||
template <>
|
||||
std::wstring NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(std::wstring_view val);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(std::u16string_view val);
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(std::u32string_view val);
|
||||
|
||||
std::string base64_encode(const atUint8* bytes_to_encode, size_t in_len);
|
||||
std::unique_ptr<atUint8[]> base64_decode(std::string_view encoded_string);
|
||||
|
||||
void HandleYAMLParserError(yaml_parser_t* parser);
|
||||
void HandleYAMLEmitterError(yaml_emitter_t* emitter);
|
||||
|
||||
struct YAMLStdStringViewReaderState
|
||||
{
|
||||
std::string_view::const_iterator begin;
|
||||
std::string_view::const_iterator end;
|
||||
YAMLStdStringViewReaderState(std::string_view str)
|
||||
{
|
||||
begin = str.begin();
|
||||
end = str.end();
|
||||
}
|
||||
};
|
||||
int YAMLStdStringReader(YAMLStdStringViewReaderState* str,
|
||||
unsigned char* buffer, size_t size, size_t* size_read);
|
||||
int YAMLStdStringWriter(std::string* str, unsigned char* buffer, size_t size);
|
||||
|
||||
class YAMLDocReader
|
||||
{
|
||||
std::unique_ptr<YAMLNode> m_rootNode;
|
||||
std::vector<YAMLNode*> m_subStack;
|
||||
std::vector<int> m_seqTrackerStack;
|
||||
yaml_parser_t m_parser;
|
||||
std::unique_ptr<YAMLNode> ParseEvents(athena::io::IStreamReader* reader);
|
||||
void _leaveSubRecord();
|
||||
void _leaveSubVector();
|
||||
|
||||
public:
|
||||
YAMLDocReader();
|
||||
~YAMLDocReader();
|
||||
|
||||
void reset();
|
||||
|
||||
inline yaml_parser_t* getParser() { return &m_parser; }
|
||||
|
||||
bool parse(athena::io::IStreamReader* reader);
|
||||
|
||||
bool ClassTypeOperation(std::function<bool(const char* dnaType)> func);
|
||||
bool ValidateClassType(const char* expectedType);
|
||||
|
||||
inline const YAMLNode* getRootNode() const { return m_rootNode.get(); }
|
||||
inline const YAMLNode* getCurNode() const { return m_subStack.empty() ? nullptr : m_subStack.back(); }
|
||||
std::unique_ptr<YAMLNode> releaseRootNode() { return std::move(m_rootNode); }
|
||||
|
||||
class RecordRAII
|
||||
{
|
||||
friend class YAMLDocReader;
|
||||
YAMLDocReader* m_r = nullptr;
|
||||
RecordRAII(YAMLDocReader* r) : m_r(r) {}
|
||||
RecordRAII() = default;
|
||||
public:
|
||||
operator bool() const { return m_r != nullptr; }
|
||||
~RecordRAII() { if (m_r) m_r->_leaveSubRecord(); }
|
||||
};
|
||||
friend class RecordRAII;
|
||||
|
||||
RecordRAII enterSubRecord(const char* name);
|
||||
|
||||
template <class T>
|
||||
void enumerate(const char* name, T& record)
|
||||
{
|
||||
if (auto rec = enterSubRecord(name))
|
||||
record.read(*this);
|
||||
}
|
||||
|
||||
class VectorRAII
|
||||
{
|
||||
friend class YAMLDocReader;
|
||||
YAMLDocReader* m_r = nullptr;
|
||||
VectorRAII(YAMLDocReader* r) : m_r(r) {}
|
||||
VectorRAII() = default;
|
||||
public:
|
||||
operator bool() const { return m_r != nullptr; }
|
||||
~VectorRAII() { if (m_r) m_r->_leaveSubVector(); }
|
||||
};
|
||||
friend class VectorRAII;
|
||||
|
||||
VectorRAII enterSubVector(const char* name, size_t& countOut);
|
||||
|
||||
template <class T>
|
||||
size_t enumerate(const char* name, std::vector<T>& vector,
|
||||
typename std::enable_if<!std::is_arithmetic<T>::value &&
|
||||
!std::is_same<T, atVec2f>::value &&
|
||||
!std::is_same<T, atVec3f>::value &&
|
||||
!std::is_same<T, atVec4f>::value>::type* = 0)
|
||||
{
|
||||
size_t countOut;
|
||||
if (auto v = enterSubVector(name, countOut))
|
||||
{
|
||||
vector.clear();
|
||||
vector.reserve(countOut);
|
||||
for (size_t i=0 ; i<countOut ; ++i)
|
||||
{
|
||||
vector.emplace_back();
|
||||
if (auto rec = enterSubRecord(nullptr))
|
||||
vector.back().read(*this);
|
||||
}
|
||||
}
|
||||
return countOut;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
size_t enumerate(const char* name, std::vector<T>& vector,
|
||||
typename std::enable_if<std::is_arithmetic<T>::value ||
|
||||
std::is_same<T, atVec2f>::value ||
|
||||
std::is_same<T, atVec3f>::value ||
|
||||
std::is_same<T, atVec4f>::value>::type* = 0)
|
||||
{
|
||||
size_t countOut;
|
||||
if (auto v = enterSubVector(name, countOut))
|
||||
{
|
||||
vector.clear();
|
||||
vector.reserve(countOut);
|
||||
for (size_t i=0 ; i<countOut ; ++i)
|
||||
vector.push_back(readVal<T>(name));
|
||||
}
|
||||
return countOut;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
size_t enumerate(const char* name, std::vector<T>& vector,
|
||||
std::function<void(YAMLDocReader&, T&)> readf)
|
||||
{
|
||||
size_t countOut;
|
||||
if (auto v = enterSubVector(name, countOut))
|
||||
{
|
||||
vector.clear();
|
||||
vector.reserve(countOut);
|
||||
for (size_t i=0 ; i<countOut ; ++i)
|
||||
{
|
||||
vector.emplace_back();
|
||||
if (auto rec = enterSubRecord(nullptr))
|
||||
readf(*this, vector.back());
|
||||
}
|
||||
}
|
||||
return countOut;
|
||||
}
|
||||
|
||||
bool hasVal(const char* name) const
|
||||
{
|
||||
if (m_subStack.size())
|
||||
{
|
||||
const YAMLNode* mnode = m_subStack.back();
|
||||
if (mnode->m_type == YAML_MAPPING_NODE && name)
|
||||
for (const auto& item : mnode->m_mapChildren)
|
||||
if (!item.first.compare(name))
|
||||
return true;
|
||||
}
|
||||
YAMLStdStringViewReaderState reader(str);
|
||||
YAMLDocReader docReader;
|
||||
yaml_parser_set_input(docReader.getParser(), (yaml_read_handler_t*)YAMLStdStringReader, &reader);
|
||||
if (!docReader.parse(nullptr))
|
||||
return false;
|
||||
}
|
||||
dna.read(docReader);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename RETURNTYPE>
|
||||
RETURNTYPE readVal(const char* name);
|
||||
bool readBool(const char* name);
|
||||
atInt8 readByte(const char* name);
|
||||
atUint8 readUByte(const char* name);
|
||||
atInt16 readInt16(const char* name);
|
||||
atUint16 readUint16(const char* name);
|
||||
atInt32 readInt32(const char* name);
|
||||
atUint32 readUint32(const char* name);
|
||||
atInt64 readInt64(const char* name);
|
||||
atUint64 readUint64(const char* name);
|
||||
float readFloat(const char* name);
|
||||
double readDouble(const char* name);
|
||||
atVec2f readVec2f(const char* name);
|
||||
atVec3f readVec3f(const char* name);
|
||||
atVec4f readVec4f(const char* name);
|
||||
atVec2d readVec2d(const char* name);
|
||||
atVec3d readVec3d(const char* name);
|
||||
atVec4d readVec4d(const char* name);
|
||||
std::unique_ptr<atUint8[]> readUBytes(const char* name);
|
||||
std::string readString(const char* name);
|
||||
std::wstring readWString(const char* name);
|
||||
};
|
||||
|
||||
class YAMLDocWriter
|
||||
template<class DNASubtype>
|
||||
static inline bool ValidateFromYAMLString(std::string_view str)
|
||||
{
|
||||
std::unique_ptr<YAMLNode> m_rootNode;
|
||||
std::vector<YAMLNode*> m_subStack;
|
||||
yaml_emitter_t m_emitter;
|
||||
static bool RecursiveFinish(yaml_emitter_t* doc, const YAMLNode& node);
|
||||
void _leaveSubRecord();
|
||||
void _leaveSubVector();
|
||||
public:
|
||||
YAMLDocWriter(const char* classType, athena::io::IStreamReader* reader = nullptr);
|
||||
~YAMLDocWriter();
|
||||
YAMLStdStringViewReaderState reader(str);
|
||||
YAMLDocReader docReader;
|
||||
yaml_parser_set_input(docReader.getParser(), (yaml_read_handler_t*)YAMLStdStringReader, &reader);
|
||||
bool retval = docReader.ValidateClassType(DNASubtype::DNAType());
|
||||
return retval;
|
||||
}
|
||||
|
||||
yaml_emitter_t* getEmitter() { return &m_emitter; }
|
||||
|
||||
bool finish(athena::io::IStreamWriter* fout);
|
||||
|
||||
inline YAMLNode* getCurNode() const { return m_subStack.empty() ? nullptr : m_subStack.back(); }
|
||||
|
||||
class RecordRAII
|
||||
{
|
||||
friend class YAMLDocWriter;
|
||||
YAMLDocWriter* m_w = nullptr;
|
||||
RecordRAII(YAMLDocWriter* w) : m_w(w) {}
|
||||
RecordRAII() = default;
|
||||
public:
|
||||
operator bool() const { return m_w != nullptr; }
|
||||
~RecordRAII() { if (m_w) m_w->_leaveSubRecord(); }
|
||||
};
|
||||
friend class RecordRAII;
|
||||
|
||||
RecordRAII enterSubRecord(const char* name);
|
||||
|
||||
template <class T>
|
||||
void enumerate(const char* name, T& record)
|
||||
{
|
||||
if (auto rec = enterSubRecord(name))
|
||||
record.write(*this);
|
||||
}
|
||||
|
||||
class VectorRAII
|
||||
{
|
||||
friend class YAMLDocWriter;
|
||||
YAMLDocWriter* m_w = nullptr;
|
||||
VectorRAII(YAMLDocWriter* w) : m_w(w) {}
|
||||
VectorRAII() = default;
|
||||
public:
|
||||
operator bool() const { return m_w != nullptr; }
|
||||
~VectorRAII() { if (m_w) m_w->_leaveSubVector(); }
|
||||
};
|
||||
friend class VectorRAII;
|
||||
|
||||
VectorRAII enterSubVector(const char* name);
|
||||
|
||||
template <class T>
|
||||
void enumerate(const char* name, const std::vector<T>& vector,
|
||||
typename std::enable_if<!std::is_arithmetic<T>::value &&
|
||||
!std::is_same<T, atVec2f>::value &&
|
||||
!std::is_same<T, atVec3f>::value &&
|
||||
!std::is_same<T, atVec4f>::value &&
|
||||
!std::is_same<T, atVec2d>::value &&
|
||||
!std::is_same<T, atVec3d>::value &&
|
||||
!std::is_same<T, atVec4d>::value>::type* = 0)
|
||||
{
|
||||
if (auto v = enterSubVector(name))
|
||||
for (const T& item : vector)
|
||||
if (auto rec = enterSubRecord(nullptr))
|
||||
item.write(*this);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void enumerate(const char* name, const std::vector<T>& vector,
|
||||
typename std::enable_if<std::is_arithmetic<T>::value ||
|
||||
std::is_same<T, atVec2f>::value ||
|
||||
std::is_same<T, atVec3f>::value ||
|
||||
std::is_same<T, atVec4f>::value ||
|
||||
std::is_same<T, atVec2d>::value ||
|
||||
std::is_same<T, atVec3d>::value ||
|
||||
std::is_same<T, atVec4d>::value>::type* = 0)
|
||||
{
|
||||
if (auto v = enterSubVector(name))
|
||||
for (T item : vector)
|
||||
writeVal<T>(nullptr, item);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void enumerate(const char* name, const std::vector<T>& vector,
|
||||
std::function<void(YAMLDocWriter&, const T&)> writef)
|
||||
{
|
||||
if (auto v = enterSubVector(name))
|
||||
for (const T& item : vector)
|
||||
if (auto rec = enterSubRecord(nullptr))
|
||||
writef(*this, item);
|
||||
}
|
||||
|
||||
template <typename INTYPE>
|
||||
void writeVal(const char* name, const INTYPE& val);
|
||||
template <typename INTYPE>
|
||||
void writeVal(const char* name, const INTYPE& val, size_t byteCount);
|
||||
void writeBool(const char* name, const bool& val);
|
||||
void writeByte(const char* name, const atInt8& val);
|
||||
void writeUByte(const char* name, const atUint8& val);
|
||||
void writeInt16(const char* name, const atInt16& val);
|
||||
void writeUint16(const char* name, const atUint16& val);
|
||||
void writeInt32(const char* name, const atInt32& val);
|
||||
void writeUint32(const char* name, const atUint32& val);
|
||||
void writeInt64(const char* name, const atInt64& val);
|
||||
void writeUint64(const char* name, const atUint64& val);
|
||||
void writeFloat(const char* name, const float& val);
|
||||
void writeDouble(const char* name, const double& val);
|
||||
void writeVec2f(const char* name, const atVec2f& val);
|
||||
void writeVec3f(const char* name, const atVec3f& val);
|
||||
void writeVec4f(const char* name, const atVec4f& val);
|
||||
void writeVec2d(const char* name, const atVec2d& val);
|
||||
void writeVec3d(const char* name, const atVec3d& val);
|
||||
void writeVec4d(const char* name, const atVec4d& val);
|
||||
void writeUBytes(const char* name, const std::unique_ptr<atUint8[]>& val, size_t byteCount);
|
||||
void writeString(const char* name, std::string_view val);
|
||||
void writeWString(const char* name, std::wstring_view val);
|
||||
void writeU16String(const char* name, std::u16string_view val);
|
||||
void writeU32String(const char* name, std::u32string_view val);
|
||||
|
||||
void setStyle(YAMLNodeStyle s);
|
||||
};
|
||||
|
||||
int YAMLAthenaReader(athena::io::IStreamReader* reader,
|
||||
unsigned char* buffer, size_t size, size_t* size_read);
|
||||
|
||||
int YAMLAthenaWriter(athena::io::IStreamWriter* writer,
|
||||
unsigned char *buffer, size_t size);
|
||||
|
||||
/* forward-declaration dance for recursively-derived types */
|
||||
|
||||
template <size_t sizeVar, Endian VE>
|
||||
struct BufferYaml;
|
||||
|
||||
template <atInt32 sizeVar, Endian VE>
|
||||
struct StringYaml;
|
||||
|
||||
template <atInt32 sizeVar, Endian VE>
|
||||
struct WStringYaml;
|
||||
|
||||
template <atInt32 sizeVar, Endian VE>
|
||||
struct WStringAsStringYaml;
|
||||
|
||||
template <Endian DNAE>
|
||||
struct DNAYaml : DNA<DNAE>
|
||||
template <class T>
|
||||
static inline bool ToYAMLStream(const T& dna, athena::io::IStreamWriter& fout)
|
||||
{
|
||||
virtual ~DNAYaml() = default;
|
||||
YAMLDocWriter docWriter(dna.DNAType());
|
||||
|
||||
virtual void read(IStreamReader& r)=0;
|
||||
virtual void write(IStreamWriter& w) const=0;
|
||||
virtual void read(YAMLDocReader& in)=0;
|
||||
virtual void write(YAMLDocWriter& out) const=0;
|
||||
static const char* DNAType() { return nullptr; }
|
||||
virtual const char* DNATypeV() const { return nullptr; }
|
||||
yaml_emitter_set_unicode(docWriter.getEmitter(), true);
|
||||
yaml_emitter_set_width(docWriter.getEmitter(), -1);
|
||||
|
||||
template <size_t sizeVar>
|
||||
using Buffer = struct athena::io::BufferYaml<sizeVar, DNAE>;
|
||||
dna.write(docWriter);
|
||||
return docWriter.finish(&fout);
|
||||
}
|
||||
|
||||
template <atInt32 sizeVar = -1>
|
||||
using String = struct athena::io::StringYaml<sizeVar, DNAE>;
|
||||
|
||||
template <atInt32 sizeVar = -1, Endian VE = DNAE>
|
||||
using WString = struct athena::io::WStringYaml<sizeVar, VE>;
|
||||
|
||||
template <atInt32 sizeVar = -1>
|
||||
using WStringAsString = struct athena::io::WStringAsStringYaml<sizeVar, DNAE>;
|
||||
|
||||
std::string toYAMLString() const
|
||||
{
|
||||
YAMLDocWriter docWriter(DNATypeV());
|
||||
|
||||
std::string res;
|
||||
yaml_emitter_set_output(docWriter.getEmitter(), (yaml_write_handler_t*)YAMLStdStringWriter, &res);
|
||||
yaml_emitter_set_unicode(docWriter.getEmitter(), true);
|
||||
yaml_emitter_set_width(docWriter.getEmitter(), -1);
|
||||
|
||||
write(docWriter);
|
||||
if (!docWriter.finish(nullptr))
|
||||
return std::string();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool fromYAMLString(std::string_view str)
|
||||
{
|
||||
YAMLStdStringViewReaderState reader(str);
|
||||
YAMLDocReader docReader;
|
||||
yaml_parser_set_input(docReader.getParser(), (yaml_read_handler_t*)YAMLStdStringReader, &reader);
|
||||
if (!docReader.parse(nullptr))
|
||||
return false;
|
||||
read(docReader);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class DNASubtype>
|
||||
static bool ValidateFromYAMLString(std::string_view str)
|
||||
{
|
||||
YAMLStdStringViewReaderState reader(str);
|
||||
YAMLDocReader docReader;
|
||||
yaml_parser_set_input(docReader.getParser(), (yaml_read_handler_t*)YAMLStdStringReader, &reader);
|
||||
bool retval = docReader.ValidateClassType(DNASubtype::DNAType());
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool toYAMLStream(athena::io::IStreamWriter& fout) const
|
||||
{
|
||||
YAMLDocWriter docWriter(DNATypeV());
|
||||
|
||||
yaml_emitter_set_unicode(docWriter.getEmitter(), true);
|
||||
yaml_emitter_set_width(docWriter.getEmitter(), -1);
|
||||
|
||||
write(docWriter);
|
||||
if (!docWriter.finish(&fout))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef void (DNAYaml::*YAMLWriteMemberFn)(YAMLDocWriter& out) const;
|
||||
bool toYAMLStream(athena::io::IStreamWriter& fout, YAMLWriteMemberFn fn) const
|
||||
{
|
||||
YAMLDocWriter docWriter(DNATypeV());
|
||||
|
||||
yaml_emitter_set_unicode(docWriter.getEmitter(), true);
|
||||
yaml_emitter_set_width(docWriter.getEmitter(), -1);
|
||||
|
||||
(this->*fn)(docWriter);
|
||||
if (!docWriter.finish(&fout))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool fromYAMLStream(athena::io::IStreamReader& fin)
|
||||
{
|
||||
YAMLDocReader docReader;
|
||||
if (!docReader.parse(&fin))
|
||||
return false;
|
||||
read(docReader);
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef void (DNAYaml::*YAMLReadMemberFn)(YAMLDocReader& in);
|
||||
bool fromYAMLStream(athena::io::IStreamReader& fin, YAMLReadMemberFn fn)
|
||||
{
|
||||
YAMLDocReader docReader;
|
||||
if (!docReader.parse(&fin))
|
||||
return false;
|
||||
(this->*fn)(docReader);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename NameT>
|
||||
bool mergeToYAMLFile(const NameT& filename)
|
||||
{
|
||||
athena::io::FileReader r(filename);
|
||||
YAMLDocWriter docWriter(DNATypeV(), r.isOpen() ? &r : nullptr);
|
||||
r.close();
|
||||
|
||||
write(docWriter);
|
||||
athena::io::FileWriter w(filename);
|
||||
if (!w.isOpen())
|
||||
return false;
|
||||
return docWriter.finish(&w);
|
||||
}
|
||||
|
||||
template<class DNASubtype>
|
||||
static bool ValidateFromYAMLStream(athena::io::IStreamReader& fin)
|
||||
{
|
||||
YAMLDocReader reader;
|
||||
atUint64 pos = fin.position();
|
||||
yaml_parser_set_input(reader.getParser(), (yaml_read_handler_t*)YAMLAthenaReader, &fin);
|
||||
bool retval = reader.ValidateClassType(DNASubtype::DNAType());
|
||||
fin.seek(pos, athena::Begin);
|
||||
return retval;
|
||||
}
|
||||
};
|
||||
|
||||
template <size_t sizeVar, Endian VE>
|
||||
struct BufferYaml : public DNAYaml<VE>, public std::unique_ptr<atUint8[]>
|
||||
template <class T>
|
||||
static inline bool ToYAMLStream(const T& dna, athena::io::IStreamWriter& fout,
|
||||
void(T::*fn)(YAMLDocWriter& out)const)
|
||||
{
|
||||
typename DNA<VE>::Delete expl;
|
||||
void read(IStreamReader& reader)
|
||||
{
|
||||
reset(new atUint8[sizeVar]);
|
||||
reader.readUBytesToBuf(get(), sizeVar);
|
||||
}
|
||||
void write(IStreamWriter& writer) const
|
||||
{
|
||||
writer.writeUBytes(get(), sizeVar);
|
||||
}
|
||||
size_t binarySize(size_t __isz) const
|
||||
{
|
||||
return __isz + sizeVar;
|
||||
}
|
||||
void read(athena::io::YAMLDocReader& reader)
|
||||
{*this = reader.readUBytes(nullptr);}
|
||||
void write(athena::io::YAMLDocWriter& writer) const
|
||||
{writer.writeUBytes(nullptr, *this, sizeVar);}
|
||||
};
|
||||
YAMLDocWriter docWriter(dna.DNAType());
|
||||
|
||||
template <atInt32 sizeVar, Endian VE>
|
||||
struct StringYaml : public DNAYaml<VE>, public std::string
|
||||
yaml_emitter_set_unicode(docWriter.getEmitter(), true);
|
||||
yaml_emitter_set_width(docWriter.getEmitter(), -1);
|
||||
|
||||
(dna->*fn)(docWriter);
|
||||
return docWriter.finish(&fout);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline bool FromYAMLStream(T& dna, athena::io::IStreamReader& fin)
|
||||
{
|
||||
typename DNA<VE>::Delete expl;
|
||||
void read(IStreamReader& reader)
|
||||
{this->assign(std::move(reader.readString(sizeVar)));}
|
||||
void write(IStreamWriter& writer) const
|
||||
{writer.writeString(*this, sizeVar);}
|
||||
size_t binarySize(size_t __isz) const
|
||||
{return __isz + ((sizeVar<0)?(this->size()+1):sizeVar);}
|
||||
void read(athena::io::YAMLDocReader& reader)
|
||||
{this->assign(std::move(reader.readString(nullptr)));}
|
||||
void write(athena::io::YAMLDocWriter& writer) const
|
||||
{writer.writeString(nullptr, *this);}
|
||||
StringYaml() = default;
|
||||
StringYaml(std::string_view __str) : std::string(__str) {}
|
||||
StringYaml(std::string&& __str) : std::string(std::move(__str)) {}
|
||||
std::string& operator=(std::string_view __str)
|
||||
{return this->assign(__str);}
|
||||
std::string& operator=(std::string&& __str)
|
||||
{static_cast<std::string&>(*this) = std::move(__str); return *this;}
|
||||
};
|
||||
YAMLDocReader docReader;
|
||||
if (!docReader.parse(&fin))
|
||||
return false;
|
||||
dna.read(docReader);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <atInt32 sizeVar, Endian VE>
|
||||
struct WStringYaml : public DNAYaml<VE>, public std::wstring
|
||||
template <class T>
|
||||
static inline bool FromYAMLStream(T& dna, athena::io::IStreamReader& fin,
|
||||
void(T::*fn)(YAMLDocReader& in))
|
||||
{
|
||||
typename DNA<VE>::Delete expl;
|
||||
void read(IStreamReader& reader)
|
||||
{
|
||||
reader.setEndian(VE);
|
||||
this->assign(std::move(reader.readWString(sizeVar)));
|
||||
}
|
||||
void write(IStreamWriter& writer) const
|
||||
{
|
||||
writer.setEndian(VE);
|
||||
writer.writeWString(*this, sizeVar);
|
||||
}
|
||||
size_t binarySize(size_t __isz) const
|
||||
{return __isz + (((sizeVar<0)?(this->size()+1):sizeVar)*2);}
|
||||
void read(athena::io::YAMLDocReader& reader)
|
||||
{this->assign(std::move(reader.readWString(nullptr)));}
|
||||
void write(athena::io::YAMLDocWriter& writer) const
|
||||
{writer.writeWString(nullptr, *this);}
|
||||
std::wstring& operator=(std::wstring_view __str)
|
||||
{return this->assign(__str);}
|
||||
std::wstring& operator=(std::wstring&& __str)
|
||||
{this->swap(__str); return *this;}
|
||||
};
|
||||
YAMLDocReader docReader;
|
||||
if (!docReader.parse(&fin))
|
||||
return false;
|
||||
(dna->*fn)(docReader);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <atInt32 sizeVar, Endian VE>
|
||||
struct WStringAsStringYaml : public DNAYaml<VE>, public std::string
|
||||
template <class T, typename NameT>
|
||||
static inline bool MergeToYAMLFile(const T& dna, const NameT& filename)
|
||||
{
|
||||
typename DNA<VE>::Delete expl;
|
||||
void read(IStreamReader& reader)
|
||||
{*this = reader.readWStringAsString(sizeVar);}
|
||||
void write(IStreamWriter& writer) const
|
||||
{writer.writeStringAsWString(*this, sizeVar);}
|
||||
size_t binarySize(size_t __isz) const
|
||||
{return __isz + (((sizeVar<0)?(this->size()+1):sizeVar)*2);}
|
||||
void read(athena::io::YAMLDocReader& reader)
|
||||
{this->assign(std::move(reader.readString(nullptr)));}
|
||||
void write(athena::io::YAMLDocWriter& writer) const
|
||||
{writer.writeString(nullptr, *this);}
|
||||
std::string& operator=(std::string_view __str)
|
||||
{return this->assign(__str);}
|
||||
std::string& operator=(std::string&& __str)
|
||||
{this->swap(__str); return *this;}
|
||||
};
|
||||
athena::io::FileReader r(filename);
|
||||
YAMLDocWriter docWriter(dna.DNAType(), r.isOpen() ? &r : nullptr);
|
||||
r.close();
|
||||
|
||||
/** Macro to automatically declare YAML read/write methods in subclasses */
|
||||
#define DECL_YAML \
|
||||
DECL_DNA \
|
||||
void read(athena::io::YAMLDocReader&); \
|
||||
void write(athena::io::YAMLDocWriter&) const; \
|
||||
static const char* DNAType(); \
|
||||
const char* DNATypeV() const {return DNAType();} \
|
||||
dna.write(docWriter);
|
||||
athena::io::FileWriter w(filename);
|
||||
if (!w.isOpen())
|
||||
return false;
|
||||
return docWriter.finish(&w);
|
||||
}
|
||||
|
||||
/** Macro to automatically declare YAML read/write methods with client-code's definition */
|
||||
#define DECL_EXPLICIT_YAML \
|
||||
void read(athena::io::YAMLDocReader&); \
|
||||
void write(athena::io::YAMLDocWriter&) const; \
|
||||
static const char* DNAType(); \
|
||||
const char* DNATypeV() const {return DNAType();} \
|
||||
template <class DNASubtype>
|
||||
static inline bool ValidateFromYAMLStream(athena::io::IStreamReader& fin)
|
||||
{
|
||||
YAMLDocReader reader;
|
||||
atUint64 pos = fin.position();
|
||||
yaml_parser_set_input(reader.getParser(), (yaml_read_handler_t*)YAMLAthenaReader, &fin);
|
||||
bool retval = reader.ValidateClassType(DNASubtype::DNAType());
|
||||
fin.seek(pos, athena::Begin);
|
||||
return retval;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -134,8 +134,8 @@ enum SeekOrigin
|
|||
|
||||
enum Endian
|
||||
{
|
||||
LittleEndian,
|
||||
BigEndian
|
||||
Little,
|
||||
Big
|
||||
};
|
||||
} // Athena
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ public:
|
|||
|
||||
inline void setEndian(Endian endian) { m_endian = endian; }
|
||||
inline Endian endian() const { return m_endian; }
|
||||
inline bool isBigEndian() const { return (m_endian == Endian::BigEndian); }
|
||||
inline bool isLittleEndian() const { return (m_endian == Endian::LittleEndian); }
|
||||
inline bool isBigEndian() const { return (m_endian == Endian::Big); }
|
||||
inline bool isLittleEndian() const { return (m_endian == Endian::Little); }
|
||||
virtual void seek(atInt64, SeekOrigin) = 0;
|
||||
virtual bool atEnd() const = 0;
|
||||
virtual atUint64 position() const = 0;
|
||||
|
@ -26,7 +26,7 @@ protected:
|
|||
void setError() { m_hasError = true; }
|
||||
bool m_hasError = false;
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
Endian m_endian = BigEndian;
|
||||
Endian m_endian = Big;
|
||||
#else
|
||||
Endian m_endian = LittleEndian;
|
||||
#endif
|
||||
|
|
|
@ -137,7 +137,7 @@ public:
|
|||
{
|
||||
atInt16 val;
|
||||
readUBytesToBuf(&val, 2);
|
||||
return m_endian == BigEndian ? utility::BigInt16(val) : utility::LittleInt16(val);
|
||||
return m_endian == Big ? utility::BigInt16(val) : utility::LittleInt16(val);
|
||||
}
|
||||
template <class T>
|
||||
inline atInt16 readVal(typename std::enable_if<std::is_same<T, atInt16>::value>::type* = 0)
|
||||
|
@ -223,7 +223,7 @@ public:
|
|||
{
|
||||
atInt32 val;
|
||||
readUBytesToBuf(&val, 4);
|
||||
return m_endian == BigEndian ? utility::BigInt32(val) : utility::LittleInt32(val);
|
||||
return m_endian == Big ? utility::BigInt32(val) : utility::LittleInt32(val);
|
||||
}
|
||||
template <class T>
|
||||
inline atInt32 readVal(typename std::enable_if<std::is_same<T, atInt32>::value>::type* = 0)
|
||||
|
@ -309,7 +309,7 @@ public:
|
|||
{
|
||||
atInt64 val;
|
||||
readUBytesToBuf(&val, 8);
|
||||
return m_endian == BigEndian ? utility::BigInt64(val) : utility::LittleInt64(val);
|
||||
return m_endian == Big ? utility::BigInt64(val) : utility::LittleInt64(val);
|
||||
}
|
||||
template <class T>
|
||||
inline atInt64 readVal(typename std::enable_if<std::is_same<T, atInt64>::value>::type* = 0)
|
||||
|
@ -395,7 +395,7 @@ public:
|
|||
{
|
||||
float val;
|
||||
readUBytesToBuf(&val, 4);
|
||||
return m_endian == BigEndian ? utility::BigFloat(val) : utility::LittleFloat(val);
|
||||
return m_endian == Big ? utility::BigFloat(val) : utility::LittleFloat(val);
|
||||
}
|
||||
template <class T>
|
||||
inline float readVal(typename std::enable_if<std::is_same<T, float>::value>::type* = 0)
|
||||
|
@ -440,7 +440,7 @@ public:
|
|||
{
|
||||
double val;
|
||||
readUBytesToBuf(&val, 8);
|
||||
return m_endian == BigEndian ? utility::BigDouble(val) : utility::LittleDouble(val);
|
||||
return m_endian == Big ? utility::BigDouble(val) : utility::LittleDouble(val);
|
||||
}
|
||||
template <class T>
|
||||
inline double readVal(typename std::enable_if<std::is_same<T, double>::value>::type* = 0)
|
||||
|
@ -505,7 +505,7 @@ public:
|
|||
{
|
||||
atVec2f val;
|
||||
readUBytesToBuf(&val, 8);
|
||||
if (m_endian == BigEndian)
|
||||
if (m_endian == Big)
|
||||
{
|
||||
utility::BigFloat(val.vec[0]);
|
||||
utility::BigFloat(val.vec[1]);
|
||||
|
@ -564,7 +564,7 @@ public:
|
|||
{
|
||||
atVec3f val;
|
||||
readUBytesToBuf(&val, 12);
|
||||
if (m_endian == BigEndian)
|
||||
if (m_endian == Big)
|
||||
{
|
||||
utility::BigFloat(val.vec[0]);
|
||||
utility::BigFloat(val.vec[1]);
|
||||
|
@ -627,7 +627,7 @@ public:
|
|||
{
|
||||
atVec4f val;
|
||||
readUBytesToBuf(&val, 16);
|
||||
if (m_endian == BigEndian)
|
||||
if (m_endian == Big)
|
||||
{
|
||||
utility::BigFloat(val.vec[0]);
|
||||
utility::BigFloat(val.vec[1]);
|
||||
|
@ -694,7 +694,7 @@ public:
|
|||
{
|
||||
atVec2d val;
|
||||
readUBytesToBuf(&val, 16);
|
||||
if (m_endian == BigEndian)
|
||||
if (m_endian == Big)
|
||||
{
|
||||
utility::BigDouble(val.vec[0]);
|
||||
utility::BigDouble(val.vec[1]);
|
||||
|
@ -753,7 +753,7 @@ public:
|
|||
{
|
||||
atVec3d val;
|
||||
readUBytesToBuf(&val, 24);
|
||||
if (m_endian == BigEndian)
|
||||
if (m_endian == Big)
|
||||
{
|
||||
utility::BigDouble(val.vec[0]);
|
||||
utility::BigDouble(val.vec[1]);
|
||||
|
@ -816,7 +816,7 @@ public:
|
|||
{
|
||||
atVec4d val;
|
||||
readUBytesToBuf(&val, 32);
|
||||
if (m_endian == BigEndian)
|
||||
if (m_endian == Big)
|
||||
{
|
||||
utility::BigDouble(val.vec[0]);
|
||||
utility::BigDouble(val.vec[1]);
|
||||
|
@ -874,129 +874,6 @@ public:
|
|||
inline atVec4d readValBig(typename std::enable_if<std::is_same<T, atVec4d>::value>::type* = 0)
|
||||
{return readVec4dBig();}
|
||||
|
||||
/** @brief Reads a wide-char string (using endianness from setEndian),
|
||||
* converts to UTF8 and advances the position in the file
|
||||
*
|
||||
* @param fixedLen If non-negative, this is a fixed-length string read
|
||||
* @return The read string
|
||||
*/
|
||||
inline std::string readWStringAsString(atInt32 fixedLen = -1)
|
||||
{
|
||||
if (fixedLen == 0)
|
||||
return std::string();
|
||||
|
||||
std::string retval;
|
||||
atUint16 chr = readUint16();
|
||||
|
||||
atInt32 i;
|
||||
for (i=0 ;; ++i)
|
||||
{
|
||||
if (fixedLen >= 0 && i >= fixedLen - 1)
|
||||
break;
|
||||
|
||||
if (!chr)
|
||||
break;
|
||||
|
||||
utf8proc_uint8_t mb[4];
|
||||
utf8proc_ssize_t c = utf8proc_encode_char(utf8proc_int32_t(chr), mb);
|
||||
if (c < 0)
|
||||
{
|
||||
atWarning("invalid UTF-8 character while encoding");
|
||||
return retval;
|
||||
}
|
||||
|
||||
retval.append(reinterpret_cast<char*>(mb), c);
|
||||
chr = readUint16();
|
||||
}
|
||||
|
||||
if (fixedLen >= 0 && i < fixedLen)
|
||||
seek(fixedLen - i);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/** @brief Reads a wide-char string (against little-endian),
|
||||
* converts to UTF8 and advances the position in the file
|
||||
*
|
||||
* @param fixedLen If non-negative, this is a fixed-length string read
|
||||
* @return The read string
|
||||
*/
|
||||
inline std::string readWStringAsStringLittle(atInt32 fixedLen = -1)
|
||||
{
|
||||
if (fixedLen == 0)
|
||||
return std::string();
|
||||
|
||||
std::string retval;
|
||||
atUint16 chr = readUint16Little();
|
||||
|
||||
atInt32 i;
|
||||
for (i=0 ;; ++i)
|
||||
{
|
||||
if (fixedLen >= 0 && i >= fixedLen - 1)
|
||||
break;
|
||||
|
||||
if (!chr)
|
||||
break;
|
||||
|
||||
utf8proc_uint8_t mb[4];
|
||||
utf8proc_ssize_t c = utf8proc_encode_char(utf8proc_int32_t(chr), mb);
|
||||
if (c < 0)
|
||||
{
|
||||
atWarning("invalid UTF-8 character while encoding");
|
||||
return retval;
|
||||
}
|
||||
|
||||
retval.append(reinterpret_cast<char*>(mb), c);
|
||||
chr = readUint16Little();
|
||||
}
|
||||
|
||||
if (fixedLen >= 0 && i < fixedLen)
|
||||
seek(fixedLen - i);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/** @brief Reads a wide-char string (against big-endian),
|
||||
* converts to UTF8 and advances the position in the file
|
||||
*
|
||||
* @param fixedLen If non-negative, this is a fixed-length string read
|
||||
* @return The read string
|
||||
*/
|
||||
inline std::string readWStringAsStringBig(atInt32 fixedLen = -1)
|
||||
{
|
||||
if (fixedLen == 0)
|
||||
return std::string();
|
||||
|
||||
std::string retval;
|
||||
atUint16 chr = readUint16Big();
|
||||
|
||||
atInt32 i;
|
||||
for (i = 0 ;; ++i)
|
||||
{
|
||||
if (fixedLen >= 0 && i >= fixedLen - 1)
|
||||
break;
|
||||
|
||||
if (!chr)
|
||||
break;
|
||||
|
||||
utf8proc_uint8_t mb[4];
|
||||
utf8proc_ssize_t c = utf8proc_encode_char(utf8proc_int32_t(chr), mb);
|
||||
if (c < 0)
|
||||
{
|
||||
atWarning("invalid UTF-8 character while encoding");
|
||||
return retval;
|
||||
}
|
||||
|
||||
retval.append(reinterpret_cast<char*>(mb), c);
|
||||
chr = readUint16Big();
|
||||
}
|
||||
|
||||
if (fixedLen >= 0 && i < fixedLen)
|
||||
seek(fixedLen - i);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/** @brief Reads a string and advances the position in the file
|
||||
*
|
||||
* @param fixedLen If non-negative, this is a fixed-length string read
|
||||
|
|
|
@ -90,7 +90,7 @@ public:
|
|||
*/
|
||||
inline void writeInt16(atInt16 val)
|
||||
{
|
||||
if (m_endian == BigEndian)
|
||||
if (m_endian == Big)
|
||||
utility::BigInt16(val);
|
||||
else
|
||||
utility::LittleInt16(val);
|
||||
|
@ -153,7 +153,7 @@ public:
|
|||
*/
|
||||
inline void writeInt32(atInt32 val)
|
||||
{
|
||||
if (m_endian == BigEndian)
|
||||
if (m_endian == Big)
|
||||
utility::BigInt32(val);
|
||||
else
|
||||
utility::LittleInt32(val);
|
||||
|
@ -216,7 +216,7 @@ public:
|
|||
*/
|
||||
inline void writeInt64(atInt64 val)
|
||||
{
|
||||
if (m_endian == BigEndian)
|
||||
if (m_endian == Big)
|
||||
utility::BigInt64(val);
|
||||
else
|
||||
utility::LittleInt64(val);
|
||||
|
@ -279,7 +279,7 @@ public:
|
|||
*/
|
||||
inline void writeFloat(float val)
|
||||
{
|
||||
if (m_endian == BigEndian)
|
||||
if (m_endian == Big)
|
||||
utility::BigFloat(val);
|
||||
else
|
||||
utility::LittleFloat(val);
|
||||
|
@ -318,7 +318,7 @@ public:
|
|||
*/
|
||||
inline void writeDouble(double val)
|
||||
{
|
||||
if (m_endian == BigEndian)
|
||||
if (m_endian == Big)
|
||||
utility::BigDouble(val);
|
||||
else
|
||||
utility::LittleDouble(val);
|
||||
|
@ -368,7 +368,7 @@ public:
|
|||
inline void writeVec2f(const atVec2f& vec)
|
||||
{
|
||||
atVec2f tmp = vec;
|
||||
if (m_endian == BigEndian)
|
||||
if (m_endian == Big)
|
||||
{
|
||||
utility::BigFloat(tmp.vec[0]);
|
||||
utility::BigFloat(tmp.vec[1]);
|
||||
|
@ -418,7 +418,7 @@ public:
|
|||
inline void writeVec3f(const atVec3f& vec)
|
||||
{
|
||||
atVec3f tmp = vec;
|
||||
if (m_endian == BigEndian)
|
||||
if (m_endian == Big)
|
||||
{
|
||||
utility::BigFloat(tmp.vec[0]);
|
||||
utility::BigFloat(tmp.vec[1]);
|
||||
|
@ -472,7 +472,7 @@ public:
|
|||
inline void writeVec4f(const atVec4f& vec)
|
||||
{
|
||||
atVec4f tmp = vec;
|
||||
if (m_endian == BigEndian)
|
||||
if (m_endian == Big)
|
||||
{
|
||||
utility::BigFloat(tmp.vec[0]);
|
||||
utility::BigFloat(tmp.vec[1]);
|
||||
|
@ -530,7 +530,7 @@ public:
|
|||
inline void writeVec2d(const atVec2d& vec)
|
||||
{
|
||||
atVec2d tmp = vec;
|
||||
if (m_endian == BigEndian)
|
||||
if (m_endian == Big)
|
||||
{
|
||||
utility::BigDouble(tmp.vec[0]);
|
||||
utility::BigDouble(tmp.vec[1]);
|
||||
|
@ -580,7 +580,7 @@ public:
|
|||
inline void writeVec3d(const atVec3d& vec)
|
||||
{
|
||||
atVec3d tmp = vec;
|
||||
if (m_endian == BigEndian)
|
||||
if (m_endian == Big)
|
||||
{
|
||||
utility::BigDouble(tmp.vec[0]);
|
||||
utility::BigDouble(tmp.vec[1]);
|
||||
|
@ -634,7 +634,7 @@ public:
|
|||
inline void writeVec4d(const atVec4d& vec)
|
||||
{
|
||||
atVec4d tmp = vec;
|
||||
if (m_endian == BigEndian)
|
||||
if (m_endian == Big)
|
||||
{
|
||||
utility::BigDouble(tmp.vec[0]);
|
||||
utility::BigDouble(tmp.vec[1]);
|
||||
|
|
|
@ -35,7 +35,8 @@ public:
|
|||
* \param m_banner
|
||||
* \param icons
|
||||
*/
|
||||
WiiBanner(atUint32 gameId, const std::string& title, const std::string& subtitle, WiiImage* m_banner, std::vector<WiiImage*> icons);
|
||||
WiiBanner(atUint32 gameId, const std::u16string& title, const std::u16string& subtitle,
|
||||
WiiImage* m_banner, std::vector<WiiImage*> icons);
|
||||
virtual ~WiiBanner();
|
||||
|
||||
/*!
|
||||
|
@ -78,25 +79,25 @@ public:
|
|||
* \brief setTitle
|
||||
* \param title
|
||||
*/
|
||||
void setTitle(const std::string& title);
|
||||
void setTitle(const std::u16string& title);
|
||||
|
||||
/*!
|
||||
* \brief title
|
||||
* \return
|
||||
*/
|
||||
std::string title() const;
|
||||
const std::u16string& title() const;
|
||||
|
||||
/*!
|
||||
* \brief setSubtitle
|
||||
* \param subtitle
|
||||
*/
|
||||
void setSubtitle(const std::string& subtitle);
|
||||
void setSubtitle(const std::u16string& subtitle);
|
||||
|
||||
/*!
|
||||
* \brief subtitle
|
||||
* \return
|
||||
*/
|
||||
std::string subtitle() const;
|
||||
const std::u16string& subtitle() const;
|
||||
|
||||
/*!
|
||||
* \brief addIcon
|
||||
|
@ -168,8 +169,8 @@ private:
|
|||
atUint32 m_flags;
|
||||
atUint32 m_bannerSize;
|
||||
std::vector<WiiImage*> m_icons;
|
||||
std::string m_title;
|
||||
std::string m_subtitle;
|
||||
std::u16string m_title;
|
||||
std::u16string m_subtitle;
|
||||
};
|
||||
} // zelda
|
||||
|
||||
|
|
|
@ -0,0 +1,200 @@
|
|||
//
|
||||
// Created by Jack Andersen on 2/16/18.
|
||||
//
|
||||
|
||||
#ifndef URDE_YAMLCOMMON_HPP
|
||||
#define URDE_YAMLCOMMON_HPP
|
||||
|
||||
#include <cstring>
|
||||
#include <yaml.h>
|
||||
#include <utf8proc.h>
|
||||
#include <vector>
|
||||
#include "Global.hpp"
|
||||
|
||||
namespace athena::io
|
||||
{
|
||||
class IStreamReader;
|
||||
class IStreamWriter;
|
||||
|
||||
enum class YAMLNodeStyle
|
||||
{
|
||||
Any,
|
||||
Flow,
|
||||
Block
|
||||
};
|
||||
|
||||
struct YAMLNode
|
||||
{
|
||||
yaml_node_type_t m_type;
|
||||
std::string m_scalarString;
|
||||
std::vector<std::unique_ptr<YAMLNode>> m_seqChildren;
|
||||
std::vector<std::pair<std::string, std::unique_ptr < YAMLNode>>>
|
||||
m_mapChildren;
|
||||
YAMLNodeStyle m_style = YAMLNodeStyle::Any;
|
||||
|
||||
YAMLNode(yaml_node_type_t type) : m_type(type) {}
|
||||
|
||||
inline const YAMLNode* findMapChild(std::string_view key) const
|
||||
{
|
||||
for (const auto& item : m_mapChildren)
|
||||
if (!item.first.compare(key))
|
||||
return item.second.get();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline void assignMapChild(std::string_view key, std::unique_ptr <YAMLNode>&& node)
|
||||
{
|
||||
for (auto& item : m_mapChildren)
|
||||
if (!item.first.compare(key))
|
||||
{
|
||||
item.second = std::move(node);
|
||||
return;
|
||||
}
|
||||
m_mapChildren.emplace_back(key, std::move(node));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename RETURNTYPE>
|
||||
RETURNTYPE NodeToVal(const YAMLNode* node);
|
||||
|
||||
template<>
|
||||
bool NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(bool val);
|
||||
|
||||
template<>
|
||||
atInt8 NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(atInt8 val);
|
||||
|
||||
template<>
|
||||
atUint8 NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(atUint8 val);
|
||||
|
||||
template<>
|
||||
atInt16 NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(atInt16 val);
|
||||
|
||||
template<>
|
||||
atUint16 NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(atUint16 val);
|
||||
|
||||
template<>
|
||||
atInt32 NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(atInt32 val);
|
||||
|
||||
template<>
|
||||
atUint32 NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(atUint32 val);
|
||||
|
||||
template<>
|
||||
atInt64 NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(atInt64 val);
|
||||
|
||||
template<>
|
||||
atUint64 NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(atUint64 val);
|
||||
|
||||
template<>
|
||||
float NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(float val);
|
||||
|
||||
template<>
|
||||
double NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(double val);
|
||||
|
||||
template<typename RETURNTYPE>
|
||||
RETURNTYPE NodeToVec(const YAMLNode* node);
|
||||
|
||||
template<>
|
||||
atVec2f NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(const atVec2f& val);
|
||||
|
||||
template<>
|
||||
atVec3f NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(const atVec3f& val);
|
||||
|
||||
template<>
|
||||
atVec4f NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(const atVec4f& val);
|
||||
|
||||
template<>
|
||||
atVec2d NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(const atVec2d& val);
|
||||
|
||||
template<>
|
||||
atVec3d NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(const atVec3d& val);
|
||||
|
||||
template<>
|
||||
atVec4d NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(const atVec4d& val);
|
||||
|
||||
template<>
|
||||
std::unique_ptr<atUint8[]> NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(const std::unique_ptr<atUint8[]>& val, size_t byteCount);
|
||||
|
||||
template<>
|
||||
std::string NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(std::string_view val);
|
||||
|
||||
template<>
|
||||
std::wstring NodeToVal(const YAMLNode* node);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(std::wstring_view val);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(std::u16string_view val);
|
||||
|
||||
std::unique_ptr <YAMLNode> ValToNode(std::u32string_view val);
|
||||
|
||||
std::string base64_encode(const atUint8* bytes_to_encode, size_t in_len);
|
||||
|
||||
std::unique_ptr<atUint8[]> base64_decode(std::string_view encoded_string);
|
||||
|
||||
void HandleYAMLParserError(yaml_parser_t* parser);
|
||||
|
||||
void HandleYAMLEmitterError(yaml_emitter_t* emitter);
|
||||
|
||||
struct YAMLStdStringViewReaderState
|
||||
{
|
||||
std::string_view::const_iterator begin;
|
||||
std::string_view::const_iterator end;
|
||||
|
||||
YAMLStdStringViewReaderState(std::string_view str)
|
||||
{
|
||||
begin = str.begin();
|
||||
end = str.end();
|
||||
}
|
||||
};
|
||||
|
||||
int YAMLStdStringReader(YAMLStdStringViewReaderState* str,
|
||||
unsigned char* buffer, size_t size, size_t* size_read);
|
||||
|
||||
int YAMLStdStringWriter(std::string* str, unsigned char* buffer, size_t size);
|
||||
|
||||
int YAMLAthenaReader(athena::io::IStreamReader* reader,
|
||||
unsigned char* buffer, size_t size, size_t* size_read);
|
||||
|
||||
int YAMLAthenaWriter(athena::io::IStreamWriter* writer,
|
||||
unsigned char* buffer, size_t size);
|
||||
|
||||
}
|
||||
|
||||
#endif //URDE_YAMLCOMMON_HPP
|
|
@ -0,0 +1,169 @@
|
|||
#ifndef YAMLDOCREADER
|
||||
#define YAMLDOCREADER
|
||||
|
||||
#include "YAMLCommon.hpp"
|
||||
|
||||
namespace athena::io
|
||||
{
|
||||
|
||||
class YAMLDocReader
|
||||
{
|
||||
std::unique_ptr<YAMLNode> m_rootNode;
|
||||
std::vector<YAMLNode*> m_subStack;
|
||||
std::vector<int> m_seqTrackerStack;
|
||||
yaml_parser_t m_parser;
|
||||
std::unique_ptr<YAMLNode> ParseEvents(athena::io::IStreamReader* reader);
|
||||
void _leaveSubRecord();
|
||||
void _leaveSubVector();
|
||||
|
||||
public:
|
||||
YAMLDocReader();
|
||||
~YAMLDocReader();
|
||||
|
||||
void reset();
|
||||
|
||||
inline yaml_parser_t* getParser() { return &m_parser; }
|
||||
|
||||
bool parse(athena::io::IStreamReader* reader);
|
||||
|
||||
bool ClassTypeOperation(std::function<bool(const char* dnaType)> func);
|
||||
bool ValidateClassType(const char* expectedType);
|
||||
|
||||
inline const YAMLNode* getRootNode() const { return m_rootNode.get(); }
|
||||
inline const YAMLNode* getCurNode() const { return m_subStack.empty() ? nullptr : m_subStack.back(); }
|
||||
std::unique_ptr<YAMLNode> releaseRootNode() { return std::move(m_rootNode); }
|
||||
|
||||
class RecordRAII
|
||||
{
|
||||
friend class YAMLDocReader;
|
||||
YAMLDocReader* m_r = nullptr;
|
||||
RecordRAII(YAMLDocReader* r) : m_r(r) {}
|
||||
RecordRAII() = default;
|
||||
public:
|
||||
operator bool() const { return m_r != nullptr; }
|
||||
~RecordRAII() { if (m_r) m_r->_leaveSubRecord(); }
|
||||
};
|
||||
friend class RecordRAII;
|
||||
|
||||
RecordRAII enterSubRecord(const char* name);
|
||||
|
||||
template <class T>
|
||||
void enumerate(const char* name, T& record)
|
||||
{
|
||||
if (auto rec = enterSubRecord(name))
|
||||
record.read(*this);
|
||||
}
|
||||
|
||||
class VectorRAII
|
||||
{
|
||||
friend class YAMLDocReader;
|
||||
YAMLDocReader* m_r = nullptr;
|
||||
VectorRAII(YAMLDocReader* r) : m_r(r) {}
|
||||
VectorRAII() = default;
|
||||
public:
|
||||
operator bool() const { return m_r != nullptr; }
|
||||
~VectorRAII() { if (m_r) m_r->_leaveSubVector(); }
|
||||
};
|
||||
friend class VectorRAII;
|
||||
|
||||
VectorRAII enterSubVector(const char* name, size_t& countOut);
|
||||
|
||||
template <class T>
|
||||
size_t enumerate(const char* name, std::vector<T>& vector,
|
||||
typename std::enable_if<!std::is_arithmetic<T>::value &&
|
||||
!std::is_same<T, atVec2f>::value &&
|
||||
!std::is_same<T, atVec3f>::value &&
|
||||
!std::is_same<T, atVec4f>::value>::type* = 0)
|
||||
{
|
||||
size_t countOut;
|
||||
if (auto v = enterSubVector(name, countOut))
|
||||
{
|
||||
vector.clear();
|
||||
vector.reserve(countOut);
|
||||
for (size_t i=0 ; i<countOut ; ++i)
|
||||
{
|
||||
vector.emplace_back();
|
||||
if (auto rec = enterSubRecord(nullptr))
|
||||
vector.back().read(*this);
|
||||
}
|
||||
}
|
||||
return countOut;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
size_t enumerate(const char* name, std::vector<T>& vector,
|
||||
typename std::enable_if<std::is_arithmetic<T>::value ||
|
||||
std::is_same<T, atVec2f>::value ||
|
||||
std::is_same<T, atVec3f>::value ||
|
||||
std::is_same<T, atVec4f>::value>::type* = 0)
|
||||
{
|
||||
size_t countOut;
|
||||
if (auto v = enterSubVector(name, countOut))
|
||||
{
|
||||
vector.clear();
|
||||
vector.reserve(countOut);
|
||||
for (size_t i=0 ; i<countOut ; ++i)
|
||||
vector.push_back(readVal<T>(name));
|
||||
}
|
||||
return countOut;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
size_t enumerate(const char* name, std::vector<T>& vector,
|
||||
std::function<void(YAMLDocReader&, T&)> readf)
|
||||
{
|
||||
size_t countOut;
|
||||
if (auto v = enterSubVector(name, countOut))
|
||||
{
|
||||
vector.clear();
|
||||
vector.reserve(countOut);
|
||||
for (size_t i=0 ; i<countOut ; ++i)
|
||||
{
|
||||
vector.emplace_back();
|
||||
if (auto rec = enterSubRecord(nullptr))
|
||||
readf(*this, vector.back());
|
||||
}
|
||||
}
|
||||
return countOut;
|
||||
}
|
||||
|
||||
bool hasVal(const char* name) const
|
||||
{
|
||||
if (m_subStack.size())
|
||||
{
|
||||
const YAMLNode* mnode = m_subStack.back();
|
||||
if (mnode->m_type == YAML_MAPPING_NODE && name)
|
||||
for (const auto& item : mnode->m_mapChildren)
|
||||
if (!item.first.compare(name))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename RETURNTYPE>
|
||||
RETURNTYPE readVal(const char* name);
|
||||
bool readBool(const char* name);
|
||||
atInt8 readByte(const char* name);
|
||||
atUint8 readUByte(const char* name);
|
||||
atInt16 readInt16(const char* name);
|
||||
atUint16 readUint16(const char* name);
|
||||
atInt32 readInt32(const char* name);
|
||||
atUint32 readUint32(const char* name);
|
||||
atInt64 readInt64(const char* name);
|
||||
atUint64 readUint64(const char* name);
|
||||
float readFloat(const char* name);
|
||||
double readDouble(const char* name);
|
||||
atVec2f readVec2f(const char* name);
|
||||
atVec3f readVec3f(const char* name);
|
||||
atVec4f readVec4f(const char* name);
|
||||
atVec2d readVec2d(const char* name);
|
||||
atVec3d readVec3d(const char* name);
|
||||
atVec4d readVec4d(const char* name);
|
||||
std::unique_ptr<atUint8[]> readUBytes(const char* name);
|
||||
std::string readString(const char* name);
|
||||
std::wstring readWString(const char* name);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // YAMLDOCREADER
|
|
@ -0,0 +1,135 @@
|
|||
#ifndef YAMLDOCWRITER
|
||||
#define YAMLDOCWRITER
|
||||
|
||||
#include "YAMLCommon.hpp"
|
||||
|
||||
namespace athena::io
|
||||
{
|
||||
|
||||
class YAMLDocWriter
|
||||
{
|
||||
std::unique_ptr<YAMLNode> m_rootNode;
|
||||
std::vector<YAMLNode*> m_subStack;
|
||||
yaml_emitter_t m_emitter;
|
||||
static bool RecursiveFinish(yaml_emitter_t* doc, const YAMLNode& node);
|
||||
void _leaveSubRecord();
|
||||
void _leaveSubVector();
|
||||
public:
|
||||
YAMLDocWriter(const char* classType, athena::io::IStreamReader* reader = nullptr);
|
||||
~YAMLDocWriter();
|
||||
|
||||
yaml_emitter_t* getEmitter() { return &m_emitter; }
|
||||
|
||||
bool finish(athena::io::IStreamWriter* fout);
|
||||
|
||||
inline YAMLNode* getCurNode() const { return m_subStack.empty() ? nullptr : m_subStack.back(); }
|
||||
|
||||
class RecordRAII
|
||||
{
|
||||
friend class YAMLDocWriter;
|
||||
YAMLDocWriter* m_w = nullptr;
|
||||
RecordRAII(YAMLDocWriter* w) : m_w(w) {}
|
||||
RecordRAII() = default;
|
||||
public:
|
||||
operator bool() const { return m_w != nullptr; }
|
||||
~RecordRAII() { if (m_w) m_w->_leaveSubRecord(); }
|
||||
};
|
||||
friend class RecordRAII;
|
||||
|
||||
RecordRAII enterSubRecord(const char* name);
|
||||
|
||||
template <class T>
|
||||
void enumerate(const char* name, T& record)
|
||||
{
|
||||
if (auto rec = enterSubRecord(name))
|
||||
record.write(*this);
|
||||
}
|
||||
|
||||
class VectorRAII
|
||||
{
|
||||
friend class YAMLDocWriter;
|
||||
YAMLDocWriter* m_w = nullptr;
|
||||
VectorRAII(YAMLDocWriter* w) : m_w(w) {}
|
||||
VectorRAII() = default;
|
||||
public:
|
||||
operator bool() const { return m_w != nullptr; }
|
||||
~VectorRAII() { if (m_w) m_w->_leaveSubVector(); }
|
||||
};
|
||||
friend class VectorRAII;
|
||||
|
||||
VectorRAII enterSubVector(const char* name);
|
||||
|
||||
template <class T>
|
||||
void enumerate(const char* name, const std::vector<T>& vector,
|
||||
typename std::enable_if<!std::is_arithmetic<T>::value &&
|
||||
!std::is_same<T, atVec2f>::value &&
|
||||
!std::is_same<T, atVec3f>::value &&
|
||||
!std::is_same<T, atVec4f>::value &&
|
||||
!std::is_same<T, atVec2d>::value &&
|
||||
!std::is_same<T, atVec3d>::value &&
|
||||
!std::is_same<T, atVec4d>::value>::type* = 0)
|
||||
{
|
||||
if (auto v = enterSubVector(name))
|
||||
for (const T& item : vector)
|
||||
if (auto rec = enterSubRecord(nullptr))
|
||||
item.write(*this);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void enumerate(const char* name, const std::vector<T>& vector,
|
||||
typename std::enable_if<std::is_arithmetic<T>::value ||
|
||||
std::is_same<T, atVec2f>::value ||
|
||||
std::is_same<T, atVec3f>::value ||
|
||||
std::is_same<T, atVec4f>::value ||
|
||||
std::is_same<T, atVec2d>::value ||
|
||||
std::is_same<T, atVec3d>::value ||
|
||||
std::is_same<T, atVec4d>::value>::type* = 0)
|
||||
{
|
||||
if (auto v = enterSubVector(name))
|
||||
for (T item : vector)
|
||||
writeVal<T>(nullptr, item);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void enumerate(const char* name, const std::vector<T>& vector,
|
||||
std::function<void(YAMLDocWriter&, const T&)> writef)
|
||||
{
|
||||
if (auto v = enterSubVector(name))
|
||||
for (const T& item : vector)
|
||||
if (auto rec = enterSubRecord(nullptr))
|
||||
writef(*this, item);
|
||||
}
|
||||
|
||||
template <typename INTYPE>
|
||||
void writeVal(const char* name, const INTYPE& val);
|
||||
template <typename INTYPE>
|
||||
void writeVal(const char* name, const INTYPE& val, size_t byteCount);
|
||||
void writeBool(const char* name, const bool& val);
|
||||
void writeByte(const char* name, const atInt8& val);
|
||||
void writeUByte(const char* name, const atUint8& val);
|
||||
void writeInt16(const char* name, const atInt16& val);
|
||||
void writeUint16(const char* name, const atUint16& val);
|
||||
void writeInt32(const char* name, const atInt32& val);
|
||||
void writeUint32(const char* name, const atUint32& val);
|
||||
void writeInt64(const char* name, const atInt64& val);
|
||||
void writeUint64(const char* name, const atUint64& val);
|
||||
void writeFloat(const char* name, const float& val);
|
||||
void writeDouble(const char* name, const double& val);
|
||||
void writeVec2f(const char* name, const atVec2f& val);
|
||||
void writeVec3f(const char* name, const atVec3f& val);
|
||||
void writeVec4f(const char* name, const atVec4f& val);
|
||||
void writeVec2d(const char* name, const atVec2d& val);
|
||||
void writeVec3d(const char* name, const atVec3d& val);
|
||||
void writeVec4d(const char* name, const atVec4d& val);
|
||||
void writeUBytes(const char* name, const std::unique_ptr<atUint8[]>& val, size_t byteCount);
|
||||
void writeString(const char* name, std::string_view val);
|
||||
void writeWString(const char* name, std::wstring_view val);
|
||||
void writeU16String(const char* name, std::u16string_view val);
|
||||
void writeU32String(const char* name, std::u32string_view val);
|
||||
|
||||
void setStyle(YAMLNodeStyle s);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // YAMLDOCWRITER
|
|
@ -3,7 +3,7 @@
|
|||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
namespace athena::Checksums
|
||||
namespace athena::checksums
|
||||
{
|
||||
|
||||
atUint32 crc32(const atUint8* data, atUint64 length, atUint32 mask, atUint32 seed)
|
||||
|
|
|
@ -341,7 +341,8 @@ std::unique_ptr<atUint8[]> NodeToVal(const YAMLNode* node)
|
|||
std::unique_ptr<YAMLNode> ValToNode(const std::unique_ptr<atUint8[]>& val, size_t byteCount)
|
||||
{
|
||||
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
|
||||
ret->m_scalarString = base64_encode(val.get(), byteCount);
|
||||
if (val)
|
||||
ret->m_scalarString = base64_encode(val.get(), byteCount);
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,11 +28,11 @@ std::ostream& operator<<(std::ostream& os, const athena::Endian& endian)
|
|||
{
|
||||
switch (endian)
|
||||
{
|
||||
case athena::Endian::LittleEndian:
|
||||
case athena::Endian::Little:
|
||||
os << "LittleEndian";
|
||||
break;
|
||||
|
||||
case athena::Endian::BigEndian:
|
||||
case athena::Endian::Big:
|
||||
os << "BigEndian";
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace athena
|
|||
{
|
||||
|
||||
MCSlot::MCSlot(std::unique_ptr<atUint8[]>&& data, atUint32 length)
|
||||
: ZQuestFile(ZQuestFile::MC, Endian::LittleEndian, std::move(data), length)
|
||||
: ZQuestFile(ZQuestFile::MC, Endian::Little, std::move(data), length)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -9,13 +9,13 @@ namespace athena::io
|
|||
SkywardSwordFileReader::SkywardSwordFileReader(atUint8* data, atUint64 length)
|
||||
: MemoryCopyReader(data, length)
|
||||
{
|
||||
setEndian(Endian::BigEndian);
|
||||
setEndian(Endian::Big);
|
||||
}
|
||||
|
||||
SkywardSwordFileReader::SkywardSwordFileReader(const std::string& filename)
|
||||
: MemoryCopyReader(filename)
|
||||
{
|
||||
setEndian(Endian::BigEndian);
|
||||
setEndian(Endian::Big);
|
||||
}
|
||||
|
||||
SkywardSwordFile* SkywardSwordFileReader::read()
|
||||
|
|
|
@ -8,13 +8,13 @@ namespace athena::io
|
|||
SkywardSwordFileWriter::SkywardSwordFileWriter(atUint8* data, atUint64 len)
|
||||
: MemoryCopyWriter(data, len)
|
||||
{
|
||||
setEndian(Endian::BigEndian);
|
||||
setEndian(Endian::Big);
|
||||
}
|
||||
|
||||
SkywardSwordFileWriter::SkywardSwordFileWriter(const std::string& filename)
|
||||
: MemoryCopyWriter(filename)
|
||||
{
|
||||
setEndian(Endian::BigEndian);
|
||||
setEndian(Endian::Big);
|
||||
}
|
||||
|
||||
void SkywardSwordFileWriter::write(SkywardSwordFile* file)
|
||||
|
|
|
@ -38,7 +38,7 @@ union AmmoValues
|
|||
};
|
||||
|
||||
SkywardSwordQuest::SkywardSwordQuest(std::unique_ptr<atUint8[]>&& data, atUint32 len)
|
||||
: ZQuestFile(ZQuestFile::SS, Endian::BigEndian, std::move(data), len)
|
||||
: ZQuestFile(ZQuestFile::SS, Endian::Big, std::move(data), len)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -240,11 +240,11 @@ atUint32 SkywardSwordQuest::skipChecksum()
|
|||
|
||||
void SkywardSwordQuest::fixChecksums()
|
||||
{
|
||||
atUint32 checksum = Checksums::crc32(m_data.get(), priv::CHECKSUM_OFFSET);
|
||||
atUint32 checksum = checksums::crc32(m_data.get(), priv::CHECKSUM_OFFSET);
|
||||
utility::BigUint32(checksum);
|
||||
*(atUint32*)(m_data.get() + priv::CHECKSUM_OFFSET) = checksum;
|
||||
|
||||
checksum = Checksums::crc32(m_skipData.get(), priv::SKIP_CHECKSUM_OFFSET);
|
||||
checksum = checksums::crc32(m_skipData.get(), priv::SKIP_CHECKSUM_OFFSET);
|
||||
utility::BigUint32(checksum);
|
||||
*(atUint32*)(m_skipData.get() + priv::SKIP_CHECKSUM_OFFSET) = checksum;
|
||||
}
|
||||
|
|
|
@ -11,14 +11,12 @@ WiiBanner::WiiBanner() :
|
|||
m_gameId(0),
|
||||
m_banner(NULL),
|
||||
m_flags(0),
|
||||
m_bannerSize(0),
|
||||
m_title(""),
|
||||
m_subtitle("")
|
||||
m_bannerSize(0)
|
||||
{
|
||||
}
|
||||
|
||||
WiiBanner::WiiBanner(atUint32 gameId, const std::string& title,
|
||||
const std::string& subtitle, WiiImage* banner, std::vector<WiiImage*> icons) :
|
||||
WiiBanner::WiiBanner(atUint32 gameId, const std::u16string& title,
|
||||
const std::u16string& subtitle, WiiImage* banner, std::vector<WiiImage*> icons) :
|
||||
m_gameId(gameId),
|
||||
m_banner(banner),
|
||||
m_flags(0),
|
||||
|
@ -44,22 +42,22 @@ atUint64 WiiBanner::gameID() const
|
|||
{
|
||||
return m_gameId;
|
||||
}
|
||||
void WiiBanner::setTitle(const std::string& title)
|
||||
void WiiBanner::setTitle(const std::u16string& title)
|
||||
{
|
||||
m_title = title;
|
||||
}
|
||||
|
||||
std::string WiiBanner::title() const
|
||||
const std::u16string& WiiBanner::title() const
|
||||
{
|
||||
return m_title;
|
||||
}
|
||||
|
||||
void WiiBanner::setSubtitle(const std::string& subtitle)
|
||||
void WiiBanner::setSubtitle(const std::u16string& subtitle)
|
||||
{
|
||||
m_subtitle = subtitle;
|
||||
}
|
||||
|
||||
std::string WiiBanner::subtitle() const
|
||||
const std::u16string& WiiBanner::subtitle() const
|
||||
{
|
||||
return m_subtitle;
|
||||
}
|
||||
|
|
|
@ -22,13 +22,13 @@ namespace io
|
|||
WiiSaveReader::WiiSaveReader(const atUint8* data, atUint64 length)
|
||||
: MemoryCopyReader(data, length)
|
||||
{
|
||||
setEndian(Endian::BigEndian);
|
||||
setEndian(Endian::Big);
|
||||
}
|
||||
|
||||
WiiSaveReader::WiiSaveReader(const std::string& filename)
|
||||
: MemoryCopyReader(filename)
|
||||
{
|
||||
setEndian(Endian::BigEndian);
|
||||
setEndian(Endian::Big);
|
||||
}
|
||||
|
||||
std::unique_ptr<WiiSave> WiiSaveReader::readSave()
|
||||
|
@ -164,8 +164,8 @@ WiiBanner* WiiSaveReader::readBanner()
|
|||
int magic;
|
||||
int flags;
|
||||
short animSpeed;
|
||||
std::string gameTitle;
|
||||
std::string subTitle;
|
||||
std::u16string gameTitle;
|
||||
std::u16string subTitle;
|
||||
|
||||
magic = readUint32();
|
||||
|
||||
|
@ -183,12 +183,12 @@ WiiBanner* WiiSaveReader::readBanner()
|
|||
animSpeed = readUint16();
|
||||
seek(22);
|
||||
|
||||
gameTitle = readWStringAsString();
|
||||
gameTitle = readU16StringBig();
|
||||
|
||||
if (position() != 0x0080)
|
||||
seek(0x0080, SeekOrigin::Begin);
|
||||
|
||||
subTitle = readWStringAsString();
|
||||
subTitle = readU16StringBig();
|
||||
|
||||
if (position() != 0x00C0)
|
||||
seek(0x00C0, SeekOrigin::Begin);
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace io
|
|||
WiiSaveWriter::WiiSaveWriter(const std::string& filename)
|
||||
: MemoryCopyWriter(filename)
|
||||
{
|
||||
setEndian(Endian::BigEndian);
|
||||
setEndian(Endian::Big);
|
||||
}
|
||||
|
||||
|
||||
|
@ -83,7 +83,7 @@ bool WiiSaveWriter::writeSave(WiiSave* save, atUint8* macAddress, atUint32 ngId,
|
|||
|
||||
void WiiSaveWriter::writeBanner(WiiBanner* banner)
|
||||
{
|
||||
setEndian(Endian::BigEndian);
|
||||
setEndian(Endian::Big);
|
||||
writeInt64(banner->gameID());
|
||||
writeInt32((0x60a0 + 0x1200) * (atUint32)banner->icons().size());
|
||||
writeByte((atInt8)banner->permissions());
|
||||
|
|
|
@ -39,7 +39,7 @@ const atUint32 ZQuestFile::Magic = 'Z' | ('Q' << 8) | ('S' << 16) | (('0' + ZQ
|
|||
|
||||
ZQuestFile::ZQuestFile()
|
||||
: m_game(NoGame),
|
||||
m_endian(Endian::LittleEndian),
|
||||
m_endian(Endian::Little),
|
||||
m_length(0)
|
||||
{
|
||||
initGameStrings();
|
||||
|
|
|
@ -75,7 +75,7 @@ ZQuestFile* ZQuestFileReader::read()
|
|||
|
||||
if (version >= ZQUEST_VERSION_CHECK(2, 0, 0))
|
||||
{
|
||||
if (checksum != athena::Checksums::crc32(data.get(), compressedLen))
|
||||
if (checksum != athena::checksums::crc32(data.get(), compressedLen))
|
||||
{
|
||||
atError("Checksum mismatch, data corrupt");
|
||||
return nullptr;
|
||||
|
@ -102,7 +102,7 @@ ZQuestFile* ZQuestFileReader::read()
|
|||
data.reset(dst);
|
||||
}
|
||||
|
||||
return new ZQuestFile(game, BOM == 0xFEFF ? Endian::BigEndian : Endian::LittleEndian, std::move(data), uncompressedLen, gameString);
|
||||
return new ZQuestFile(game, BOM == 0xFEFF ? Endian::Big : Endian::Little, std::move(data), uncompressedLen, gameString);
|
||||
}
|
||||
|
||||
} // zelda
|
||||
|
|
|
@ -59,8 +59,8 @@ void ZQuestFileWriter::write(ZQuestFile* quest, bool compress)
|
|||
|
||||
writeUint32(quest->length());
|
||||
writeBytes((atInt8*)quest->gameString().substr(0, 0x0A).c_str(), 0x0A);
|
||||
writeUint16(quest->endian() == Endian::BigEndian ? 0xFFFE : 0xFEFF);
|
||||
writeUint32(athena::Checksums::crc32(questData, compLen));
|
||||
writeUint16(quest->endian() == Endian::Big ? 0xFFFE : 0xFEFF);
|
||||
writeUint32(athena::checksums::crc32(questData, compLen));
|
||||
writeUBytes(questData, compLen);
|
||||
|
||||
save();
|
||||
|
|
Loading…
Reference in New Issue