Add DqnBuffer, improve memstack macros
This commit is contained in:
parent
cfb1dc9d19
commit
e0fc9f7b44
@ -2,7 +2,7 @@ void DqnFixedString_Test()
|
|||||||
{
|
{
|
||||||
LOG_HEADER();
|
LOG_HEADER();
|
||||||
{
|
{
|
||||||
DqnFixedString<512> str = DQN_SLICE("hello world");
|
DqnFixedString<512> str = DQN_BUFFER_STR_LIT("hello world");
|
||||||
DQN_ASSERT(DqnStr_Cmp(str.str, "hello world") == 0);
|
DQN_ASSERT(DqnStr_Cmp(str.str, "hello world") == 0);
|
||||||
|
|
||||||
Log(Status::Ok, "Copy constructor DqnSlice<char>");
|
Log(Status::Ok, "Copy constructor DqnSlice<char>");
|
||||||
@ -10,11 +10,11 @@ void DqnFixedString_Test()
|
|||||||
|
|
||||||
{
|
{
|
||||||
DqnFixedString<512> zero = {};
|
DqnFixedString<512> zero = {};
|
||||||
DqnFixedString<512> str = DQN_SLICE("hello world");
|
DqnFixedString<512> str = DQN_BUFFER_STR_LIT("hello world");
|
||||||
str = zero;
|
str = zero;
|
||||||
DQN_ASSERT(str.len == 0 && str.str[0] == 0);
|
DQN_ASSERT(str.len == 0 && str.str[0] == 0);
|
||||||
|
|
||||||
DqnSlice<char const> helloSlice = DQN_SLICE("hello");
|
DqnSlice<char const> helloSlice = DQN_BUFFER_STR_LIT("hello");
|
||||||
str = helloSlice;
|
str = helloSlice;
|
||||||
DQN_ASSERT(DqnStr_Cmp(str.str, "hello") == 0);
|
DQN_ASSERT(DqnStr_Cmp(str.str, "hello") == 0);
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ void DqnFixedString_Test()
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
DqnFixedString<512> str = DQN_SLICE("hello world");
|
DqnFixedString<512> str = DQN_BUFFER_STR_LIT("hello world");
|
||||||
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
||||||
DQN_ASSERTM(DqnStr_Cmp(str.str, "hello sailor") == 0, "Result: %s", str.str);
|
DQN_ASSERTM(DqnStr_Cmp(str.str, "hello sailor") == 0, "Result: %s", str.str);
|
||||||
|
|
||||||
@ -31,14 +31,14 @@ void DqnFixedString_Test()
|
|||||||
|
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
DqnFixedString<512> str = DQN_SLICE("hello world");
|
DqnFixedString<512> str = DQN_BUFFER_STR_LIT("hello world");
|
||||||
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
||||||
str += DQN_SLICE(".end");
|
str += DQN_BUFFER_STR_LIT(".end");
|
||||||
DQN_ASSERTM(DqnStr_Cmp(str.str, "hello sailor.end") == 0, "Result: %s", str.str);
|
DQN_ASSERTM(DqnStr_Cmp(str.str, "hello sailor.end") == 0, "Result: %s", str.str);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
DqnFixedString<512> str = DQN_SLICE("hello world");
|
DqnFixedString<512> str = DQN_BUFFER_STR_LIT("hello world");
|
||||||
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
||||||
DQN_ASSERT(str.SprintfAppend(" %d, %d", 100, 200));
|
DQN_ASSERT(str.SprintfAppend(" %d, %d", 100, 200));
|
||||||
DQN_ASSERT(DqnStr_Cmp(str.str, "hello sailor 100, 200") == 0);
|
DQN_ASSERT(DqnStr_Cmp(str.str, "hello sailor 100, 200") == 0);
|
||||||
@ -58,9 +58,9 @@ void DqnFixedString_Test()
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
DqnFixedString<512> str = DQN_SLICE("hello world");
|
DqnFixedString<512> str = DQN_BUFFER_STR_LIT("hello world");
|
||||||
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
||||||
str = str + " end" + DQN_SLICE(" of");
|
str = str + " end" + DQN_BUFFER_STR_LIT(" of");
|
||||||
DQN_ASSERT(DqnStr_Cmp(str.str, "hello sailor end of") == 0);
|
DQN_ASSERT(DqnStr_Cmp(str.str, "hello sailor end of") == 0);
|
||||||
|
|
||||||
Log(Status::Ok, "Operator +");
|
Log(Status::Ok, "Operator +");
|
||||||
|
74
DqnJson.cpp
74
DqnJson.cpp
@ -28,38 +28,38 @@ void DqnJson_Test()
|
|||||||
}
|
}
|
||||||
)FOO";
|
)FOO";
|
||||||
|
|
||||||
DqnJson result = DqnJson_Get(DqnSlice<const char>(json, DQN_ARRAY_COUNT(json)), DQN_SLICE("result"));
|
DqnJson result = DqnJson_Get(DqnSlice<const char>(json, DQN_ARRAY_COUNT(json)), DQN_BUFFER_STR_LIT("result"));
|
||||||
DqnJson cum_difficulty = DqnJson_Get(result, DQN_SLICE("cumulative_difficulty"));
|
DqnJson cum_difficulty = DqnJson_Get(result, DQN_BUFFER_STR_LIT("cumulative_difficulty"));
|
||||||
DqnJson difficulty = DqnJson_Get(result, DQN_SLICE("difficulty"));
|
DqnJson difficulty = DqnJson_Get(result, DQN_BUFFER_STR_LIT("difficulty"));
|
||||||
DqnJson name = DqnJson_Get(result, DQN_SLICE("name"));
|
DqnJson name = DqnJson_Get(result, DQN_BUFFER_STR_LIT("name"));
|
||||||
DqnJson array_of_objects = DqnJson_Get(result, DQN_SLICE("array_of_objects"));
|
DqnJson array_of_objects = DqnJson_Get(result, DQN_BUFFER_STR_LIT("array_of_objects"));
|
||||||
DqnJson time = DqnJson_Get(result, DQN_SLICE("time"));
|
DqnJson time = DqnJson_Get(result, DQN_BUFFER_STR_LIT("time"));
|
||||||
DqnJson embed_object = DqnJson_Get(result, DQN_SLICE("embed_object"));
|
DqnJson embed_object = DqnJson_Get(result, DQN_BUFFER_STR_LIT("embed_object"));
|
||||||
DqnJson bits = DqnJson_Get(result, DQN_SLICE("bits"));
|
DqnJson bits = DqnJson_Get(result, DQN_BUFFER_STR_LIT("bits"));
|
||||||
DqnJson hex = DqnJson_Get(result, DQN_SLICE("hex"));
|
DqnJson hex = DqnJson_Get(result, DQN_BUFFER_STR_LIT("hex"));
|
||||||
DqnJson extra = DqnJson_Get(result, DQN_SLICE("extra"));
|
DqnJson extra = DqnJson_Get(result, DQN_BUFFER_STR_LIT("extra"));
|
||||||
DqnJson serialise = DqnJson_Get(result, DQN_SLICE("serialise"));
|
DqnJson serialise = DqnJson_Get(result, DQN_BUFFER_STR_LIT("serialise"));
|
||||||
|
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(cum_difficulty.value, DQN_SLICE("282912831023"), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(cum_difficulty.value, DQN_BUFFER_STR_LIT("282912831023"), Dqn::IgnoreCase::No));
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(difficulty.value, DQN_SLICE("18293"), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(difficulty.value, DQN_BUFFER_STR_LIT("18293"), Dqn::IgnoreCase::No));
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(name.value, DQN_SLICE("\"Block\""), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(name.value, DQN_BUFFER_STR_LIT("\"Block\""), Dqn::IgnoreCase::No));
|
||||||
|
|
||||||
{
|
{
|
||||||
DQN_ASSERT(array_of_objects.IsArray() && array_of_objects.num_entries == 2);
|
DQN_ASSERT(array_of_objects.IsArray() && array_of_objects.num_entries == 2);
|
||||||
isize count = 0;
|
isize count = 0;
|
||||||
while(DqnJson it = DqnJson_GetNextArrayItem(&array_of_objects))
|
while(DqnJson it = DqnJson_GetNextArrayItem(&array_of_objects))
|
||||||
{
|
{
|
||||||
DqnJson hash = DqnJson_Get(it, DQN_SLICE("hash"));
|
DqnJson hash = DqnJson_Get(it, DQN_BUFFER_STR_LIT("hash"));
|
||||||
DqnJson time2 = DqnJson_Get(it, DQN_SLICE("time"));
|
DqnJson time2 = DqnJson_Get(it, DQN_BUFFER_STR_LIT("time"));
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
{
|
{
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(hash.value, DQN_SLICE("\"83abdc3f\""), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(hash.value, DQN_BUFFER_STR_LIT("\"83abdc3f\""), Dqn::IgnoreCase::No));
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(time2.value, DQN_SLICE("102981029381"), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(time2.value, DQN_BUFFER_STR_LIT("102981029381"), Dqn::IgnoreCase::No));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(hash.value, DQN_SLICE("\"12acf73d\""), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(hash.value, DQN_BUFFER_STR_LIT("\"12acf73d\""), Dqn::IgnoreCase::No));
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(time2.value, DQN_SLICE("123761239789"), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(time2.value, DQN_BUFFER_STR_LIT("123761239789"), Dqn::IgnoreCase::No));
|
||||||
}
|
}
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
@ -67,13 +67,13 @@ void DqnJson_Test()
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
DqnJson proof = DqnJson_Get(embed_object, DQN_SLICE("proof"));
|
DqnJson proof = DqnJson_Get(embed_object, DQN_BUFFER_STR_LIT("proof"));
|
||||||
DqnJson signature = DqnJson_Get(embed_object, DQN_SLICE("signature"));
|
DqnJson signature = DqnJson_Get(embed_object, DQN_BUFFER_STR_LIT("signature"));
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(proof.value, DQN_SLICE("\"axcbde\""), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(proof.value, DQN_BUFFER_STR_LIT("\"axcbde\""), Dqn::IgnoreCase::No));
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(signature.value, DQN_SLICE("\"l9382kjabmznmx129aslzejs\""), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(signature.value, DQN_BUFFER_STR_LIT("\"l9382kjabmznmx129aslzejs\""), Dqn::IgnoreCase::No));
|
||||||
}
|
}
|
||||||
|
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(time.value, DQN_SLICE("3498573485"), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(time.value, DQN_BUFFER_STR_LIT("3498573485"), Dqn::IgnoreCase::No));
|
||||||
|
|
||||||
{
|
{
|
||||||
DQN_ASSERT(bits.IsArray() && bits.num_entries == 7);
|
DQN_ASSERT(bits.IsArray() && bits.num_entries == 7);
|
||||||
@ -84,13 +84,13 @@ void DqnJson_Test()
|
|||||||
bits_array[bitsIndex++] = it;
|
bits_array[bitsIndex++] = it;
|
||||||
|
|
||||||
DQN_ASSERT(bitsIndex == DQN_ARRAY_COUNT(bits_array));
|
DQN_ASSERT(bitsIndex == DQN_ARRAY_COUNT(bits_array));
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(bits_array[0].value, DQN_SLICE("1"), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(bits_array[0].value, DQN_BUFFER_STR_LIT("1"), Dqn::IgnoreCase::No));
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(bits_array[1].value, DQN_SLICE("0"), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(bits_array[1].value, DQN_BUFFER_STR_LIT("0"), Dqn::IgnoreCase::No));
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(bits_array[2].value, DQN_SLICE("1"), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(bits_array[2].value, DQN_BUFFER_STR_LIT("1"), Dqn::IgnoreCase::No));
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(bits_array[3].value, DQN_SLICE("1"), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(bits_array[3].value, DQN_BUFFER_STR_LIT("1"), Dqn::IgnoreCase::No));
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(bits_array[4].value, DQN_SLICE("0"), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(bits_array[4].value, DQN_BUFFER_STR_LIT("0"), Dqn::IgnoreCase::No));
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(bits_array[5].value, DQN_SLICE("1"), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(bits_array[5].value, DQN_BUFFER_STR_LIT("1"), Dqn::IgnoreCase::No));
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(bits_array[6].value, DQN_SLICE("0"), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(bits_array[6].value, DQN_BUFFER_STR_LIT("0"), Dqn::IgnoreCase::No));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -102,17 +102,17 @@ void DqnJson_Test()
|
|||||||
hex_array[hex_index++] = it;
|
hex_array[hex_index++] = it;
|
||||||
|
|
||||||
DQN_ASSERT(hex_index == DQN_ARRAY_COUNT(hex_array));
|
DQN_ASSERT(hex_index == DQN_ARRAY_COUNT(hex_array));
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(hex_array[0].value, DQN_SLICE("\"AF\""), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(hex_array[0].value, DQN_BUFFER_STR_LIT("\"AF\""), Dqn::IgnoreCase::No));
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(hex_array[1].value, DQN_SLICE("\"BE\""), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(hex_array[1].value, DQN_BUFFER_STR_LIT("\"BE\""), Dqn::IgnoreCase::No));
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(hex_array[2].value, DQN_SLICE("\"0C\""), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(hex_array[2].value, DQN_BUFFER_STR_LIT("\"0C\""), Dqn::IgnoreCase::No));
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(hex_array[3].value, DQN_SLICE("\"FF\""), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(hex_array[3].value, DQN_BUFFER_STR_LIT("\"FF\""), Dqn::IgnoreCase::No));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
DQN_ASSERT(extra.IsArray() && extra.num_entries == 1);
|
DQN_ASSERT(extra.IsArray() && extra.num_entries == 1);
|
||||||
while(DqnJson it = DqnJson_GetNextArrayItem(&extra))
|
while(DqnJson it = DqnJson_GetNextArrayItem(&extra))
|
||||||
{
|
{
|
||||||
DQN_ASSERT(DQN_SLICE_CMP(it.value, DQN_SLICE("123"), Dqn::IgnoreCase::No));
|
DQN_ASSERT(DQN_BUFFER_STRCMP(it.value, DQN_BUFFER_STR_LIT("123"), Dqn::IgnoreCase::No));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log(Status::Ok, "DqnJson sample structure parsed");
|
Log(Status::Ok, "DqnJson sample structure parsed");
|
||||||
|
@ -665,7 +665,7 @@ void DqnString_Test()
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
DqnString str = DQN_SLICE("hello world");
|
DqnString str = DQN_BUFFER_STR_LIT("hello world");
|
||||||
DQN_DEFER(str.Free());
|
DQN_DEFER(str.Free());
|
||||||
DQN_ASSERT(DqnStr_Cmp(str.str, "hello world") == 0);
|
DQN_ASSERT(DqnStr_Cmp(str.str, "hello world") == 0);
|
||||||
|
|
||||||
@ -674,11 +674,11 @@ void DqnString_Test()
|
|||||||
|
|
||||||
{
|
{
|
||||||
DqnString zero = {};
|
DqnString zero = {};
|
||||||
DqnString str = DQN_SLICE("hello world");
|
DqnString str = DQN_BUFFER_STR_LIT("hello world");
|
||||||
str.Free();
|
str.Free();
|
||||||
str = zero;
|
str = zero;
|
||||||
|
|
||||||
DqnSlice<char const> helloSlice = DQN_SLICE("hello");
|
DqnBuffer<char const> helloSlice = DQN_BUFFER_STR_LIT("hello");
|
||||||
str = helloSlice;
|
str = helloSlice;
|
||||||
DQN_DEFER(str.Free());
|
DQN_DEFER(str.Free());
|
||||||
DQN_ASSERT(DqnStr_Cmp(str.str, "hello") == 0);
|
DQN_ASSERT(DqnStr_Cmp(str.str, "hello") == 0);
|
||||||
@ -687,7 +687,7 @@ void DqnString_Test()
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
DqnString str = DQN_SLICE("hello world");
|
DqnString str = DQN_BUFFER_STR_LIT("hello world");
|
||||||
DQN_DEFER(str.Free());
|
DQN_DEFER(str.Free());
|
||||||
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
||||||
DQN_ASSERTM(DqnStr_Cmp(str.str, "hello sailor") == 0, "Result: %s", str.str);
|
DQN_ASSERTM(DqnStr_Cmp(str.str, "hello sailor") == 0, "Result: %s", str.str);
|
||||||
@ -697,15 +697,15 @@ void DqnString_Test()
|
|||||||
|
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
DqnString str = DQN_SLICE("hello world");
|
DqnString str = DQN_BUFFER_STR_LIT("hello world");
|
||||||
DQN_DEFER(str.Free());
|
DQN_DEFER(str.Free());
|
||||||
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
||||||
str += DQN_SLICE(".end");
|
str += DQN_BUFFER_STR_LIT(".end");
|
||||||
DQN_ASSERTM(DqnStr_Cmp(str.str, "hello sailor.end") == 0, "Result: %s", str.str);
|
DQN_ASSERTM(DqnStr_Cmp(str.str, "hello sailor.end") == 0, "Result: %s", str.str);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
DqnString str = DQN_SLICE("hello world");
|
DqnString str = DQN_BUFFER_STR_LIT("hello world");
|
||||||
DQN_DEFER(str.Free());
|
DQN_DEFER(str.Free());
|
||||||
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
||||||
DQN_ASSERT(str.SprintfAppend(" %d, %d", 100, 200));
|
DQN_ASSERT(str.SprintfAppend(" %d, %d", 100, 200));
|
||||||
@ -727,10 +727,10 @@ void DqnString_Test()
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
DqnString str = DQN_SLICE("hello world");
|
DqnString str = DQN_BUFFER_STR_LIT("hello world");
|
||||||
DQN_DEFER(str.Free());
|
DQN_DEFER(str.Free());
|
||||||
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
||||||
str = str + " end" + DQN_SLICE(" of");
|
str = str + " end" + DQN_BUFFER_STR_LIT(" of");
|
||||||
DQN_ASSERT(DqnStr_Cmp(str.str, "hello sailor end of") == 0);
|
DQN_ASSERT(DqnStr_Cmp(str.str, "hello sailor end of") == 0);
|
||||||
|
|
||||||
Log(Status::Ok, "Operator +");
|
Log(Status::Ok, "Operator +");
|
||||||
|
48
dqn.h
48
dqn.h
@ -24,7 +24,8 @@
|
|||||||
// #Portable Code
|
// #Portable Code
|
||||||
// #DqnSprintf Cross-platform Sprintf Implementation (Public Domain lib stb_sprintf)
|
// #DqnSprintf Cross-platform Sprintf Implementation (Public Domain lib stb_sprintf)
|
||||||
// #DqnAssert Assertions and Logging
|
// #DqnAssert Assertions and Logging
|
||||||
// #DqnSlice Slices
|
// #DqnSlice A ptr and length into memory but doesn't imply ownership of memory
|
||||||
|
// #DqnBuffer Typedef to slices, but indicates ownership of the memory
|
||||||
// #DqnChar Char Operations (IsDigit(), IsAlpha() etc)
|
// #DqnChar Char Operations (IsDigit(), IsAlpha() etc)
|
||||||
// #DqnStr Str Operations (Str_Len(), Str_Copy() etc)
|
// #DqnStr Str Operations (Str_Len(), Str_Copy() etc)
|
||||||
// #DqnWChar WChar Operations (IsDigit(), IsAlpha() etc)
|
// #DqnWChar WChar Operations (IsDigit(), IsAlpha() etc)
|
||||||
@ -758,20 +759,30 @@ DQN_FILE_SCOPE void DqnLogExpr(char const *file, char const *function_name, i32
|
|||||||
|
|
||||||
DQN_COMPILE_ASSERT(sizeof(isize) == sizeof(usize));
|
DQN_COMPILE_ASSERT(sizeof(isize) == sizeof(usize));
|
||||||
|
|
||||||
// #DqnSlice API
|
// #DqnSlice/#DqnBuffer
|
||||||
// =================================================================================================
|
// =================================================================================================
|
||||||
|
// NOTE: A slice and buffer is the same thing but, slices have the pre-existing concepts of being a
|
||||||
|
// a ptr and length into pre-existing allocated memory. So instead, I use buffer to indicate the
|
||||||
|
// data structure it self owns the memory it's holding.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct DqnSlice
|
struct DqnSlice
|
||||||
{
|
{
|
||||||
T *data;
|
union { T *data; T *str; };
|
||||||
i32 len;
|
int len;
|
||||||
|
|
||||||
DqnSlice() = default;
|
DqnSlice() = default;
|
||||||
DqnSlice(T *str, i32 len) { this->data = str; this->len = len; }
|
DqnSlice(T *data_, int len_) : data(data_), len(len_) {}
|
||||||
};
|
};
|
||||||
#define DQN_SLICE(literal) DqnSlice<char const>(literal, DQN_CHAR_COUNT(literal))
|
|
||||||
|
|
||||||
#define DQN_SLICE_CMP(a, b, ignoreCase) (a.len == b.len && (DqnStr_Cmp(a.data, b.data, a.len, ignoreCase) == 0))
|
template<typename T>
|
||||||
|
using DqnBuffer = DqnSlice<T>;
|
||||||
|
|
||||||
|
#define DQN_BUFFER_STR_LIT(literal) DqnBuffer<char const>(literal, DQN_CHAR_COUNT(literal))
|
||||||
|
#define DQN_BUFFER_STRCMP(a, b, ignore_case) ((a).len == (b).len && (DqnStr_Cmp((char *)((a).str), (char *)((b).str), (a).len, ignore_case) == 0))
|
||||||
|
#define DQN_BUFFER_MEMCMP(a, b) ((a).len == (b).len && (DqnMem_Cmp((void *)((a).str), (void *)((b).str), (a).len) == 0))
|
||||||
|
|
||||||
|
#define DQN_BUFFER_STR_LIT_STRCMP(a, b, ignore_case) ((a).len == (b).len && (DqnStr_Cmp((char *)((a).str), (char *)((b).str), (a).len, ignore_case) == 0))
|
||||||
|
#define DQN_BUFFER_STR_LIT_MEMCMP(a, b) ((a).len == (b).len && (DqnMem_Cmp((void *)((a).str), (void *)((b).str), (a).len) == 0))
|
||||||
// #DqnChar API
|
// #DqnChar API
|
||||||
// =================================================================================================
|
// =================================================================================================
|
||||||
DQN_FILE_SCOPE char DqnChar_ToLower (char c);
|
DQN_FILE_SCOPE char DqnChar_ToLower (char c);
|
||||||
@ -1470,7 +1481,8 @@ struct DqnMemTracker
|
|||||||
// stack.Init(DQN_MEGABYTE(1), true, DqnMemStack::Flag::BoundsGuard);
|
// stack.Init(DQN_MEGABYTE(1), true, DqnMemStack::Flag::BoundsGuard);
|
||||||
// u8 *data = stack.Push(128);
|
// u8 *data = stack.Push(128);
|
||||||
|
|
||||||
#define DQN_MEM_STACK_PUSH_STRUCT(memStack, Type, num) (Type *)(memStack)->Push(sizeof(Type) * num)
|
#define DQN_MEMSTACK_PUSH_STRUCT(memstack, Type) (Type *)(memstack)->Push(sizeof(Type))
|
||||||
|
#define DQN_MEMSTACK_PUSH_ARRAY(memstack, Type, num) (Type *)(memstack)->Push(sizeof(Type) * (num))
|
||||||
struct DqnMemStack
|
struct DqnMemStack
|
||||||
{
|
{
|
||||||
static const i32 MINIMUM_BLOCK_SIZE = DQN_KILOBYTE(64);
|
static const i32 MINIMUM_BLOCK_SIZE = DQN_KILOBYTE(64);
|
||||||
@ -1509,7 +1521,7 @@ struct DqnMemStack
|
|||||||
DqnMemAPI *mem_api; // Read: API used to add additional memory blocks to this stack.
|
DqnMemAPI *mem_api; // Read: API used to add additional memory blocks to this stack.
|
||||||
Block *block; // Read: Memory block allocated for the stack
|
Block *block; // Read: Memory block allocated for the stack
|
||||||
u32 flags; // Read
|
u32 flags; // Read
|
||||||
i32 tmp_region_count; // Read: The number of temp memory regions in use
|
i32 tmp_region_count;// Read: The number of temp memory regions in use
|
||||||
|
|
||||||
DqnMemStack() = default;
|
DqnMemStack() = default;
|
||||||
|
|
||||||
@ -1550,7 +1562,7 @@ struct DqnMemStack
|
|||||||
void ResetTail ();
|
void ResetTail ();
|
||||||
|
|
||||||
// Reset the current memory block usage to 0.
|
// Reset the current memory block usage to 0.
|
||||||
void ClearCurrBlock(Dqn::ZeroClear clear);
|
void ClearCurrBlock(Dqn::ZeroClear clear = Dqn::ZeroClear::No);
|
||||||
Info GetInfo () const;
|
Info GetInfo () const;
|
||||||
|
|
||||||
// Temporary Memory Regions API
|
// Temporary Memory Regions API
|
||||||
@ -1949,7 +1961,8 @@ struct DqnLogger
|
|||||||
#define LOG_TYPES \
|
#define LOG_TYPES \
|
||||||
X(Warning, "WARN ") \
|
X(Warning, "WARN ") \
|
||||||
X(Error, "ERROR") \
|
X(Error, "ERROR") \
|
||||||
X(Debug, "DEBUG")
|
X(Debug, "DEBUG") \
|
||||||
|
X(Message, "MSG ")
|
||||||
|
|
||||||
#define X(type, prefix) type,
|
#define X(type, prefix) type,
|
||||||
enum struct Type { LOG_TYPES };
|
enum struct Type { LOG_TYPES };
|
||||||
@ -1974,9 +1987,10 @@ struct DqnLogger
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define DQN_LOGGER_CONTEXT {__FILE__, DQN_CHAR_COUNT(__FILE__), __func__, DQN_CHAR_COUNT(__func__), __LINE__}
|
#define DQN_LOGGER_CONTEXT {__FILE__, DQN_CHAR_COUNT(__FILE__), __func__, DQN_CHAR_COUNT(__func__), __LINE__}
|
||||||
#define DQN_LOGGER_D(logger, fmt, ...) logger.Log(DqnLogger::Type::Debug, {__FILE__, DQN_CHAR_COUNT(__FILE__), __func__, DQN_CHAR_COUNT(__func__), __LINE__}, fmt, ## __VA_ARGS__)
|
#define DQN_LOGGER_D(logger, fmt, ...) (logger)->Log(DqnLogger::Type::Debug, {__FILE__, DQN_CHAR_COUNT(__FILE__), __func__, DQN_CHAR_COUNT(__func__), __LINE__}, fmt, ## __VA_ARGS__)
|
||||||
#define DQN_LOGGER_W(logger, fmt, ...) logger.Log(DqnLogger::Type::Warning, {__FILE__, DQN_CHAR_COUNT(__FILE__), __func__, DQN_CHAR_COUNT(__func__), __LINE__}, fmt, ## __VA_ARGS__)
|
#define DQN_LOGGER_W(logger, fmt, ...) (logger)->Log(DqnLogger::Type::Warning, {__FILE__, DQN_CHAR_COUNT(__FILE__), __func__, DQN_CHAR_COUNT(__func__), __LINE__}, fmt, ## __VA_ARGS__)
|
||||||
#define DQN_LOGGER_E(logger, fmt, ...) logger.Log(DqnLogger::Type::Error, {__FILE__, DQN_CHAR_COUNT(__FILE__), __func__, DQN_CHAR_COUNT(__func__), __LINE__}, fmt, ## __VA_ARGS__)
|
#define DQN_LOGGER_E(logger, fmt, ...) (logger)->Log(DqnLogger::Type::Error, {__FILE__, DQN_CHAR_COUNT(__FILE__), __func__, DQN_CHAR_COUNT(__func__), __LINE__}, fmt, ## __VA_ARGS__)
|
||||||
|
#define DQN_LOGGER_M(logger, fmt, ...) (logger)->Log(DqnLogger::Type::Message, {__FILE__, DQN_CHAR_COUNT(__FILE__), __func__, DQN_CHAR_COUNT(__func__), __LINE__}, fmt, ## __VA_ARGS__)
|
||||||
|
|
||||||
DqnFixedString1024 log_builder;
|
DqnFixedString1024 log_builder;
|
||||||
b32 no_console; // Log to console if false.
|
b32 no_console; // Log to console if false.
|
||||||
@ -6045,7 +6059,7 @@ DQN_FILE_SCOPE DqnJson DqnJson_GetNextArrayItem(DqnJson *iterator)
|
|||||||
|
|
||||||
if (iterator->type == DqnJson::Type::ArrayOfObjects)
|
if (iterator->type == DqnJson::Type::ArrayOfObjects)
|
||||||
{
|
{
|
||||||
if (result = DqnJson_Get(iterator->value, DQN_SLICE("{")))
|
if (result = DqnJson_Get(iterator->value, DQN_BUFFER_STR_LIT("{")))
|
||||||
{
|
{
|
||||||
char const *end = iterator->value.data + iterator->value.len;
|
char const *end = iterator->value.data + iterator->value.len;
|
||||||
iterator->value.data = result.value.data + result.value.len;
|
iterator->value.data = result.value.data + result.value.len;
|
||||||
@ -8860,7 +8874,7 @@ DQN_OS_GET_THREADS_AND_CORES(DqnOS_GetThreadsAndCores)
|
|||||||
{
|
{
|
||||||
*num_threads_per_core = 0;
|
*num_threads_per_core = 0;
|
||||||
// Find the offset to the processor field and move to it
|
// Find the offset to the processor field and move to it
|
||||||
DqnSlice<char const> processor = DQN_SLICE("processor");
|
DqnBuffer<char const> processor = DQN_BUFFER_STR_LIT("processor");
|
||||||
i32 processorOffset = DqnStr_FindFirstOccurence(src_ptr, src_len, processor.data, processor.len);
|
i32 processorOffset = DqnStr_FindFirstOccurence(src_ptr, src_len, processor.data, processor.len);
|
||||||
|
|
||||||
DQN_ASSERT(processorOffset != -1);
|
DQN_ASSERT(processorOffset != -1);
|
||||||
@ -8880,7 +8894,7 @@ DQN_OS_GET_THREADS_AND_CORES(DqnOS_GetThreadsAndCores)
|
|||||||
{
|
{
|
||||||
*num_cores = 0;
|
*num_cores = 0;
|
||||||
// Find the offset to the cpu cores field and move to it
|
// Find the offset to the cpu cores field and move to it
|
||||||
DqnSlice<char const> cpuCores = DQN_SLICE("cpu cores");
|
DqnBuffer<char const> cpuCores = DQN_BUFFER_STR_LIT("cpu cores");
|
||||||
i32 cpu_cores_offset = DqnStr_FindFirstOccurence(src_ptr, src_len, cpuCores.data, cpuCores.len);
|
i32 cpu_cores_offset = DqnStr_FindFirstOccurence(src_ptr, src_len, cpuCores.data, cpuCores.len);
|
||||||
DQN_ASSERT(cpu_cores_offset != -1);
|
DQN_ASSERT(cpu_cores_offset != -1);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user