66
This commit is contained in:
parent
a6f83bab34
commit
6a1eae90d9
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -7,5 +7,6 @@
|
||||
"istream": "c",
|
||||
"ranges": "c",
|
||||
"streambuf": "c"
|
||||
}
|
||||
},
|
||||
"C_Cpp.errorSquiggles": "Disabled"
|
||||
}
|
||||
@ -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) {
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -0,0 +1,2 @@
|
||||
#include "DtsodV24.h"
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include "../base/base.h"
|
||||
#include "../Autoarr/Autoarr.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;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "std.h"
|
||||
#include "base_types.h"
|
||||
#include "types.h"
|
||||
#include "errors.h"
|
||||
|
||||
// just sleeping function
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
59
DtsodC/src/base/types.c
Normal file
59
DtsodC/src/base/types.c
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
43
DtsodC/src/base/types.h
Normal file
43
DtsodC/src/base/types.h
Normal file
@ -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;
|
||||
@ -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]");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user