From 6a1eae90d9de344260a560f1f988677a42c9b777 Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Mon, 7 Feb 2022 23:33:56 +0300 Subject: [PATCH] 66 --- .vscode/settings.json | 3 +- DtsodC/src/Autoarr/Autoarr.c | 18 ++++++-- DtsodC/src/Autoarr/Autoarr.h | 8 +++- DtsodC/src/DtsodParser/DtsodV24.c | 2 + DtsodC/src/DtsodParser/DtsodV24.h | 4 ++ DtsodC/src/SearchTree/SearchTree.h | 18 -------- DtsodC/src/base/base.h | 2 +- DtsodC/src/base/base_types.c | 62 ---------------------------- DtsodC/src/base/base_types.h | 24 ----------- DtsodC/src/base/types.c | 59 ++++++++++++++++++++++++++ DtsodC/src/base/types.h | 43 +++++++++++++++++++ TestProgram/DtsodV2X/TestDtsodV23.cs | 2 +- 12 files changed, 133 insertions(+), 112 deletions(-) delete mode 100644 DtsodC/src/base/base_types.c delete mode 100644 DtsodC/src/base/base_types.h create mode 100644 DtsodC/src/base/types.c create mode 100644 DtsodC/src/base/types.h diff --git a/.vscode/settings.json b/.vscode/settings.json index 5e8b592..568cbfb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,5 +7,6 @@ "istream": "c", "ranges": "c", "streambuf": "c" - } + }, + "C_Cpp.errorSquiggles": "Disabled" } \ No newline at end of file diff --git a/DtsodC/src/Autoarr/Autoarr.c b/DtsodC/src/Autoarr/Autoarr.c index 788d15e..1fdd45d 100644 --- a/DtsodC/src/Autoarr/Autoarr.c +++ b/DtsodC/src/Autoarr/Autoarr.c @@ -1,6 +1,6 @@ #include "Autoarr.h" -Autoarr Autoarr_create(uint16 _max_block_count, uint16 _max_block_length, base_type _type){ +Autoarr Autoarr_create(uint16 _max_block_count, uint16 _max_block_length, my_type _type){ Autoarr ar={ .type=_type, .max_block_count=_max_block_count, @@ -23,7 +23,7 @@ void __Autoarr_create_block(Autoarr *ar){ ar->curr_block_count++; } -void __Autoarr_add_pre(Autoarr* ar, base_type t){ +void __Autoarr_add_pre(Autoarr* ar, my_type t){ if(ar->type!=t) throw(ERR_WRONGTYPE); if(ar->curr_length>=ar->max_length) throw(ERR_MAXLENGTH); if (ar->curr_block_length==ar->max_block_length) @@ -64,10 +64,14 @@ void Autoarr_add_uint64(Autoarr *ar, uint64 element){ __Autoarr_add_pre(ar,UInt64); *(*((uint64**)ar->values+ar->curr_block_count-1)+ar->curr_block_length-1)=element; } +void Autoarr_add_uni(Autoarr *ar, Unitype element){ + __Autoarr_add_pre(ar,UniversalType); + *(*((Unitype**)ar->values+ar->curr_block_count-1)+ar->curr_block_length-1)=element; +} // calculates a block number and element position in the block // also verifies type of array -div_t __Autoarr_div_index(Autoarr* ar, uint32 i, base_type t){ +div_t __Autoarr_div_index(Autoarr* ar, uint32 i, my_type t){ if(ar->type!=t) throw(ERR_WRONGTYPE); if(i>=ar->curr_length) throw(ERR_WRONGINDEX); return (div_t){ @@ -108,6 +112,10 @@ uint64 Autoarr_get_uint64(Autoarr *ar, uint32 index){ div_t d = __Autoarr_div_index(ar, index, UInt64); return *(*((uint64**)ar->values+d.quot)+d.rem); } +Unitype Autoarr_get_uni(Autoarr *ar, uint32 index){ + div_t d = __Autoarr_div_index(ar, index, UniversalType); + return *(*((Unitype**)ar->values+d.quot)+d.rem); +} void Autoarr_set_int8(Autoarr *ar, uint32 index, int8 element){ div_t d =__Autoarr_div_index(ar, index, Int8); @@ -141,6 +149,10 @@ void Autoarr_set_uint64(Autoarr *ar, uint32 index, uint64 element){ div_t d =__Autoarr_div_index(ar, index, UInt64); *(*((uint64**)ar->values+d.quot)+d.rem)=element; } +void Autoarr_set_uni(Autoarr *ar, uint32 index, Unitype element){ + div_t d =__Autoarr_div_index(ar, index, UniversalType); + *(*((Unitype**)ar->values+d.quot)+d.rem)=element; +} void Autoarr_clear(Autoarr* ar){ switch (ar->type) { diff --git a/DtsodC/src/Autoarr/Autoarr.h b/DtsodC/src/Autoarr/Autoarr.h index 158bac9..df8f5e0 100644 --- a/DtsodC/src/Autoarr/Autoarr.h +++ b/DtsodC/src/Autoarr/Autoarr.h @@ -3,7 +3,7 @@ #include "../base/base.h" typedef struct Autoarr{ // a collection with dynamic memory allocation - base_type type; // type of data + my_type type; // type of data uint16 max_block_count; // max amount of blocks uint16 curr_block_count; // amount of blocks uint16 max_block_length; // max amount of data in block @@ -13,7 +13,7 @@ typedef struct Autoarr{ // a collection with dynamic memory allocation void** values; // pointers to blocks } Autoarr; -Autoarr Autoarr_create(uint16 _max_block_count, uint16 _max_block_length, base_type _type); +Autoarr Autoarr_create(uint16 _max_block_count, uint16 _max_block_length, my_type _type); void Autoarr_clear(Autoarr* ar); void Autoarr_add_int8(Autoarr *ar, int8 element); @@ -42,3 +42,7 @@ void Autoarr_set_int32(Autoarr *ar, uint32 index, int32 element); void Autoarr_set_uint32(Autoarr *ar, uint32 index, uint32 element); void Autoarr_set_int64(Autoarr *ar, uint32 index, int64 element); void Autoarr_set_uint64(Autoarr *ar, uint32 index, uint64 element); + +void Autoarr_add_uni(Autoarr *ar, Unitype element); +Unitype Autoarr_get_uni(Autoarr *ar, uint32 index); +void Autoarr_set_uni(Autoarr *ar, uint32 index, Unitype element); diff --git a/DtsodC/src/DtsodParser/DtsodV24.c b/DtsodC/src/DtsodParser/DtsodV24.c index e69de29..8363a10 100644 --- a/DtsodC/src/DtsodParser/DtsodV24.c +++ b/DtsodC/src/DtsodParser/DtsodV24.c @@ -0,0 +1,2 @@ +#include "DtsodV24.h" + diff --git a/DtsodC/src/DtsodParser/DtsodV24.h b/DtsodC/src/DtsodParser/DtsodV24.h index e69de29..c52d69d 100644 --- a/DtsodC/src/DtsodParser/DtsodV24.h +++ b/DtsodC/src/DtsodParser/DtsodV24.h @@ -0,0 +1,4 @@ +#pragma once +#include "../base/base.h" +#include "../Autoarr/Autoarr.h" + diff --git a/DtsodC/src/SearchTree/SearchTree.h b/DtsodC/src/SearchTree/SearchTree.h index 14c28e2..3e4d6e5 100644 --- a/DtsodC/src/SearchTree/SearchTree.h +++ b/DtsodC/src/SearchTree/SearchTree.h @@ -2,24 +2,6 @@ #include "../base/base.h" -// can store any base type -typedef struct UniversalType{ - base_type type; - union { - int8 Int8; - uint8 UInt8; - int16 Int16; - uint16 UInt16; - int32 Int32; - uint32 UInt32; - int64 Int64; - uint64 UInt64; - float Float; - double Double; - void* VoidPtr; - }; -} Unitype; - typedef struct SearchTreeNode{ struct SearchTreeNode**** branches; //*STNode[8][8][4] Unitype value; diff --git a/DtsodC/src/base/base.h b/DtsodC/src/base/base.h index 21e382d..bc63125 100644 --- a/DtsodC/src/base/base.h +++ b/DtsodC/src/base/base.h @@ -1,7 +1,7 @@ #pragma once #include "std.h" -#include "base_types.h" +#include "types.h" #include "errors.h" // just sleeping function diff --git a/DtsodC/src/base/base_types.c b/DtsodC/src/base/base_types.c deleted file mode 100644 index 3e6d34a..0000000 --- a/DtsodC/src/base/base_types.c +++ /dev/null @@ -1,62 +0,0 @@ -#include "std.h" -#include "base_types.h" -#include "errors.h" - -const char* typename(base_type t){ - switch (t) { - case Null: return "Null"; - case Double: return "Double"; - case Float: return "Float"; - case Bool: return "Bool"; - case Char: return "Char"; - case Int8: return "Int8"; - case UInt8: return "UInt8"; - case Int16: return "Int16"; - case UInt16: return "UInt16"; - case Int32: return "Int32"; - case UInt32: return "UInt32"; - case Int64: return "Int64"; - case UInt64: return "UInt64"; - case Int8Ptr: return "Int8Ptr"; - case UInt8Ptr: return "UInt8Ptr"; - case Int16Ptr: return "Int16Ptr"; - case UInt16Ptr: return "UInt16Ptr"; - case Int32Ptr: return "Int32Ptr"; - case UInt32Ptr: return "UInt32Ptr"; - case Int64Ptr: return "Int64Ptr"; - case UInt64Ptr: return "UInt64Ptr"; - default: throw(ERR_WRONGTYPE); return "EEEEEE"; - } -} - -int8 typesize(base_type type){ - int8 type_size=0; - switch (type) - { - case Int8: type_size=8; break; - case UInt8: type_size=8; break; - case Int16: type_size=16; break; - case UInt16: type_size=16; break; - case Int32: type_size=32; break; - case UInt32: type_size=32; break; - case Int64: type_size=64; break; - case UInt64: type_size=64; break; - default: throw(ERR_WRONGTYPE); - } - return type_size; -} - -void AssignVoidToVoid(void* a, void*b, base_type type){ - switch (type) - { - case Int8: *((int8*)a)=*((int8*)b); break; - case UInt8: *((uint8*)a)=*((uint8*)b); break; - case Int16: *((int16*)a)=*((int16*)b); break; - case UInt16: *((uint16*)a)=*((uint16*)b); break; - case Int32: *((int32*)a)=*((int32*)b); break; - case UInt32: *((uint32*)a)=*((uint32*)b); break; - case Int64: *((int64*)a)=*((int64*)b); break; - case UInt64: *((uint64*)a)=*((uint64*)b); break; - default: throw(ERR_WRONGTYPE); - } -} \ No newline at end of file diff --git a/DtsodC/src/base/base_types.h b/DtsodC/src/base/base_types.h deleted file mode 100644 index 5882fda..0000000 --- a/DtsodC/src/base/base_types.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "std.h" -#include "errors.h" - -typedef int8_t int8; -typedef uint8_t uint8; -typedef int16_t int16; -typedef uint16_t uint16; -typedef int32_t int32; -typedef uint32_t uint32; -typedef int64_t int64; -typedef uint64_t uint64; -typedef enum base_type{ - Null, Float, Double, Char, Bool, - UInt8, Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64, - UInt8Ptr, Int8Ptr, UInt16Ptr, Int16Ptr, UInt32Ptr, Int32Ptr, UInt64Ptr, Int64Ptr -} __attribute__ ((__packed__)) base_type; - -const char* typename(base_type t); - -int8 typesize(base_type type); - -void AssignVoidToVoid(void* a, void*b, base_type type); diff --git a/DtsodC/src/base/types.c b/DtsodC/src/base/types.c new file mode 100644 index 0000000..fe4bfac --- /dev/null +++ b/DtsodC/src/base/types.c @@ -0,0 +1,59 @@ +#include "std.h" +#include "types.h" +#include "errors.h" + +const char* typename(my_type t){ + switch (t) { + case Null: return "Null"; + case Double: return "Double"; + case Float: return "Float"; + case Bool: return "Bool"; + case Char: return "Char"; + case Int8: return "Int8"; + case UInt8: return "UInt8"; + case Int16: return "Int16"; + case UInt16: return "UInt16"; + case Int32: return "Int32"; + case UInt32: return "UInt32"; + case Int64: return "Int64"; + case UInt64: return "UInt64"; + case Int8Ptr: return "Int8Ptr"; + case UInt8Ptr: return "UInt8Ptr"; + case Int16Ptr: return "Int16Ptr"; + case UInt16Ptr: return "UInt16Ptr"; + case Int32Ptr: return "Int32Ptr"; + case UInt32Ptr: return "UInt32Ptr"; + case Int64Ptr: return "Int64Ptr"; + case UInt64Ptr: return "UInt64Ptr"; + case UniversalType: return "Unitype"; + default: throw(ERR_WRONGTYPE); + } +} + +int8 typesize(my_type type){ + switch (type){ + case Null: return 0; + case Double: return sizeof(double); + case Float: return sizeof(float); + case Bool: sizeof(bool); + case Char: + case Int8: + case UInt8: return 1; + case Int16: + case UInt16: return 2; + case Int32: + case UInt32: return 4; + case Int64: + case UInt64: return 8; + case Int8Ptr: + case UInt8Ptr: + case Int16Ptr: + case UInt16Ptr: + case Int32Ptr: + case UInt32Ptr: + case Int64Ptr: + case UInt64Ptr: return sizeof(void*); + case UniversalType: return "Unitype"; + default: throw(ERR_WRONGTYPE); + } +} diff --git a/DtsodC/src/base/types.h b/DtsodC/src/base/types.h new file mode 100644 index 0000000..fb838a8 --- /dev/null +++ b/DtsodC/src/base/types.h @@ -0,0 +1,43 @@ +#pragma once + +#include "std.h" +#include "errors.h" + +typedef int8_t int8; +typedef uint8_t uint8; +typedef int16_t int16; +typedef uint16_t uint16; +typedef int32_t int32; +typedef uint32_t uint32; +typedef int64_t int64; +typedef uint64_t uint64; +typedef enum my_type{ + Null, Float, Double, Char, Bool, + UInt8, Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64, + UInt8Ptr, Int8Ptr, UInt16Ptr, Int16Ptr, UInt32Ptr, Int32Ptr, UInt64Ptr, Int64Ptr, + UniversalType +} __attribute__ ((__packed__)) my_type; + +//returns type name +const char* typename(my_type t); + +// returns size of type in bytes +int8 typesize(my_type type); + +// can store any base type +typedef struct Unitype{ + my_type type; + union { + int8 Int8; + uint8 UInt8; + int16 Int16; + uint16 UInt16; + int32 Int32; + uint32 UInt32; + int64 Int64; + uint64 UInt64; + float Float; + double Double; + void* VoidPtr; + }; +} Unitype; diff --git a/TestProgram/DtsodV2X/TestDtsodV23.cs b/TestProgram/DtsodV2X/TestDtsodV23.cs index 798b67d..0f079a0 100644 --- a/TestProgram/DtsodV2X/TestDtsodV23.cs +++ b/TestProgram/DtsodV2X/TestDtsodV23.cs @@ -20,7 +20,7 @@ public static class TestDtsodV23 public static void TestBaseTypes() { Info.Log("b", "[TestDtsodV23/TestBaseTypes]"); - DtsodV23 dtsod = new(File.ReadAllText($"DtsodV2X{Path.Sep}base_types.dtsod")); + DtsodV23 dtsod = new(File.ReadAllText($"DtsodV2X{Path.Sep}my_types.dtsod")); foreach (var pair in dtsod) Info.LogNoTime("b", pair.Value.GetType().Name + ' ', "w", pair.Key + ' ', "c", pair.Value.ToString()); Info.Log("g", "[test completed]");