conversion to c by gemini 4 argon
This commit is contained in:
1 parent
b70e2d21d2
commit
f9356f9ba7
369 files changed
+18074
-107634
No files matched your search
@@ -2,125 +2,102 @@
|
||||
|
||||
#include <Juliet.h>
|
||||
|
||||
#include <Core/Common/CRC32.h>
|
||||
#include <Core/Common/String.h>
|
||||
#include <Core/HAL/IO/IOStream.h>
|
||||
#include <Core/Math/Vector.h>
|
||||
|
||||
// .jasset
|
||||
// AssetFile ::= { CommentLine | EmptyLine | PropertyDeclaration } ;
|
||||
// CommentLine ::= ( "#" | "//" ) { Character } LineEnding ;
|
||||
// EmptyLine ::= { Whitespace } LineEnding ;
|
||||
// PropertyDeclaration ::= KeyHeader LineEnding ValueBlock ;
|
||||
// KeyHeader ::= ";" { Whitespace } Identifier ;
|
||||
// ValueBlock ::= { ValueLine LineEnding } ;
|
||||
// ValueLine ::= { Whitespace } ValueString { Whitespace } ;
|
||||
// LineEnding ::= "\r\n" | "\n" ;
|
||||
// Identifier ::= [a-zA-Z_][a-zA-Z0-9_]* ;
|
||||
|
||||
struct Vector4;
|
||||
struct IOStream;
|
||||
struct Arena;
|
||||
typedef struct IOStream IOStream;
|
||||
typedef struct Arena Arena;
|
||||
typedef struct ArchivePropertyNode ArchivePropertyNode;
|
||||
typedef struct ParsedArchive ParsedArchive;
|
||||
typedef struct Archive Archive;
|
||||
|
||||
struct ArchivePropertyNode
|
||||
{
|
||||
String key;
|
||||
String value;
|
||||
uint32 key_crc;
|
||||
bool consumed;
|
||||
bool8 consumed;
|
||||
};
|
||||
|
||||
struct ParsedArchive
|
||||
{
|
||||
ArchivePropertyNode* nodes = nullptr;
|
||||
uint32 property_count = 0;
|
||||
ArchivePropertyNode* nodes;
|
||||
uint32 property_count;
|
||||
};
|
||||
|
||||
struct Archive
|
||||
{
|
||||
Arena* arena;
|
||||
bool loading;
|
||||
ParsedArchive base = {};
|
||||
IOStream* stream = nullptr;
|
||||
bool8 loading;
|
||||
ParsedArchive base;
|
||||
IOStream* stream;
|
||||
|
||||
// to remove
|
||||
void* base_ptr = nullptr;
|
||||
index_t offset = 0;
|
||||
void* base_ptr;
|
||||
index_t offset;
|
||||
};
|
||||
|
||||
JULIET_API void serialize(Archive& ar, void* data, size_t size);
|
||||
JULIET_API void serialize_bytes(Archive* ar, void* data, size_t size);
|
||||
|
||||
#define serialize_elem(ar, val) serialize((ar), &(val), sizeof(val))
|
||||
#define serialize_elem(ar, val) serialize_bytes((ar), &(val), sizeof(val))
|
||||
|
||||
JULIET_API ParsedArchive tokenize_archive(NonNullPtr<Arena> arena, ByteBuffer file_buffer);
|
||||
JULIET_API ArchivePropertyNode* find_property(NonNullPtr<ParsedArchive> archive, uint32 property_crc);
|
||||
JULIET_API void write_property_header(Archive& archive, String property_name);
|
||||
JULIET_API ParsedArchive tokenize_archive(Arena* arena, ByteBuffer file_buffer);
|
||||
JULIET_API ArchivePropertyNode* find_property(ParsedArchive* archive, uint32 property_crc);
|
||||
JULIET_API void write_property_header(Archive* archive, String property_name);
|
||||
|
||||
JULIET_API bool read_prop(Archive& ar, String value_raw, String& value);
|
||||
JULIET_API void write(NonNullPtr<IOStream> stream, String value);
|
||||
JULIET_API bool read(const char* buffer, float& value, const char** end = nullptr);
|
||||
JULIET_API void write(NonNullPtr<IOStream> stream, float value);
|
||||
JULIET_API bool read(const char* buffer, int8& value);
|
||||
JULIET_API void write(NonNullPtr<IOStream> stream, int8 value);
|
||||
JULIET_API bool read(const char* buffer, int16& value);
|
||||
JULIET_API void write(NonNullPtr<IOStream> stream, int16 value);
|
||||
JULIET_API bool read(const char* buffer, int32& value);
|
||||
JULIET_API void write(NonNullPtr<IOStream> stream, int32 value);
|
||||
JULIET_API bool read(const char* buffer, int64& value);
|
||||
JULIET_API void write(NonNullPtr<IOStream> stream, int64 value);
|
||||
JULIET_API bool read(const char* buffer, uint8& value);
|
||||
JULIET_API void write(NonNullPtr<IOStream> stream, uint8 value);
|
||||
JULIET_API bool read(const char* buffer, uint16& value);
|
||||
JULIET_API void write(NonNullPtr<IOStream> stream, uint16 value);
|
||||
JULIET_API bool read(const char* buffer, uint32& value);
|
||||
JULIET_API void write(NonNullPtr<IOStream> stream, uint32 value);
|
||||
JULIET_API bool read(const char* buffer, uint64& value);
|
||||
JULIET_API void write(NonNullPtr<IOStream> stream, uint64 value);
|
||||
JULIET_API bool read(const char* buffer, bool& value);
|
||||
JULIET_API void write(NonNullPtr<IOStream> stream, bool value);
|
||||
JULIET_API bool read(const char* buffer, Vector4& value);
|
||||
JULIET_API void write(NonNullPtr<IOStream> stream, Vector4 value);
|
||||
JULIET_API bool8 read_prop_str(Archive* ar, String value_raw, String* value);
|
||||
JULIET_API void write_str(IOStream* stream, String value);
|
||||
JULIET_API bool8 read_f32(const char* buffer, float* value, const char** end);
|
||||
JULIET_API void write_f32(IOStream* stream, float value);
|
||||
JULIET_API bool8 read_i8(const char* buffer, int8* value);
|
||||
JULIET_API void write_i8(IOStream* stream, int8 value);
|
||||
JULIET_API bool8 read_i16(const char* buffer, int16* value);
|
||||
JULIET_API void write_i16(IOStream* stream, int16 value);
|
||||
JULIET_API bool8 read_i32(const char* buffer, int32* value);
|
||||
JULIET_API void write_i32(IOStream* stream, int32 value);
|
||||
JULIET_API bool8 read_i64(const char* buffer, int64* value);
|
||||
JULIET_API void write_i64(IOStream* stream, int64 value);
|
||||
JULIET_API bool8 read_u8(const char* buffer, uint8* value);
|
||||
JULIET_API void write_u8(IOStream* stream, uint8 value);
|
||||
JULIET_API bool8 read_u16(const char* buffer, uint16* value);
|
||||
JULIET_API void write_u16(IOStream* stream, uint16 value);
|
||||
JULIET_API bool8 read_u32(const char* buffer, uint32* value);
|
||||
JULIET_API void write_u32(IOStream* stream, uint32 value);
|
||||
JULIET_API bool8 read_u64(const char* buffer, uint64* value);
|
||||
JULIET_API void write_u64(IOStream* stream, uint64 value);
|
||||
JULIET_API bool8 read_b8(const char* buffer, bool8* value);
|
||||
JULIET_API void write_b8(IOStream* stream, bool8 value);
|
||||
JULIET_API bool8 read_vec4(const char* buffer, Vector4* value);
|
||||
JULIET_API void write_vec4(IOStream* stream, Vector4 value);
|
||||
|
||||
// For primitives not needing archive nor allocation
|
||||
template <typename Type>
|
||||
bool read_prop(Archive& /*ar*/, String value_raw, Type& value)
|
||||
{
|
||||
char buffer[64];
|
||||
size_t cpy_size = Min(value_raw.Size, sizeof(buffer) - 1);
|
||||
MemCopy(buffer, value_raw.Str, cpy_size);
|
||||
buffer[cpy_size] = '\0';
|
||||
JULIET_API bool8 serialize_str(Archive* ar, String property_name, String* value);
|
||||
JULIET_API bool8 serialize_f32(Archive* ar, String property_name, float* value);
|
||||
JULIET_API bool8 serialize_i8(Archive* ar, String property_name, int8* value);
|
||||
JULIET_API bool8 serialize_i16(Archive* ar, String property_name, int16* value);
|
||||
JULIET_API bool8 serialize_i32(Archive* ar, String property_name, int32* value);
|
||||
JULIET_API bool8 serialize_i64(Archive* ar, String property_name, int64* value);
|
||||
JULIET_API bool8 serialize_u8(Archive* ar, String property_name, uint8* value);
|
||||
JULIET_API bool8 serialize_u16(Archive* ar, String property_name, uint16* value);
|
||||
JULIET_API bool8 serialize_u32(Archive* ar, String property_name, uint32* value);
|
||||
JULIET_API bool8 serialize_u64(Archive* ar, String property_name, uint64* value);
|
||||
JULIET_API bool8 serialize_b8(Archive* ar, String property_name, bool8* value);
|
||||
JULIET_API bool8 serialize_vec4(Archive* ar, String property_name, Vector4* value);
|
||||
|
||||
return read(buffer, value);
|
||||
}
|
||||
|
||||
#define SERIALIZE(ar, name, var) serialize((ar), ConstString(#name), #name##_crc32, (var))
|
||||
#define SERIALIZE_SIMPLE(ar, var) SERIALIZE(ar, var, var)
|
||||
|
||||
template <typename Type>
|
||||
bool serialize(Archive& ar, String property_name, uint32 property_crc, Type& value)
|
||||
{
|
||||
Assert(IsValid(property_name));
|
||||
|
||||
bool result = false;
|
||||
if (ar.loading)
|
||||
{
|
||||
if (auto* prop = find_property(&ar.base, property_crc))
|
||||
{
|
||||
if (read_prop(ar, prop->value, value))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Save
|
||||
write_property_header(ar, property_name);
|
||||
write(ar.stream, value);
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#define SERIALIZE_STR(ar, name, var_ptr) serialize_str((ar), ConstString(#name), (var_ptr))
|
||||
#define SERIALIZE_F32(ar, name, var_ptr) serialize_f32((ar), ConstString(#name), (var_ptr))
|
||||
#define SERIALIZE_I8(ar, name, var_ptr) serialize_i8((ar), ConstString(#name), (var_ptr))
|
||||
#define SERIALIZE_I16(ar, name, var_ptr) serialize_i16((ar), ConstString(#name), (var_ptr))
|
||||
#define SERIALIZE_I32(ar, name, var_ptr) serialize_i32((ar), ConstString(#name), (var_ptr))
|
||||
#define SERIALIZE_I64(ar, name, var_ptr) serialize_i64((ar), ConstString(#name), (var_ptr))
|
||||
#define SERIALIZE_U8(ar, name, var_ptr) serialize_u8((ar), ConstString(#name), (var_ptr))
|
||||
#define SERIALIZE_U16(ar, name, var_ptr) serialize_u16((ar), ConstString(#name), (var_ptr))
|
||||
#define SERIALIZE_U32(ar, name, var_ptr) serialize_u32((ar), ConstString(#name), (var_ptr))
|
||||
#define SERIALIZE_U64(ar, name, var_ptr) serialize_u64((ar), ConstString(#name), (var_ptr))
|
||||
#define SERIALIZE_B8(ar, name, var_ptr) serialize_b8((ar), ConstString(#name), (var_ptr))
|
||||
#define SERIALIZE_BOOL(ar, name, var_ptr) serialize_b8((ar), ConstString(#name), (var_ptr))
|
||||
#define SERIALIZE_VEC4(ar, name, var_ptr) serialize_vec4((ar), ConstString(#name), (var_ptr))
|
||||
|
||||
#if JULIET_DEBUG
|
||||
JULIET_API void audit_unconsumed_properties(NonNullPtr<ParsedArchive> archive, String context_name);
|
||||
JULIET_API void audit_unconsumed_properties(ParsedArchive* archive, String context_name);
|
||||
#endif
|
||||
Reference in new issue
Block a user