Skip to content

Commit

Permalink
Add arena test. Refactor trivial data parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuscu committed Oct 11, 2024
1 parent 5534577 commit 2b19ae6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 deletions.
21 changes: 13 additions & 8 deletions packages/logging/source/common/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ namespace logging {
}
};
Logger::~Logger() {
if (mCondition && (mLevel == LogLevel::LogExpection || mLevel == LogLevel::LogAssertion)) {
return;
}

mStream.flush();
std::string msg = mStream.str();
mStream.str("");
Expand All @@ -116,24 +120,25 @@ namespace logging {
case LogLevel::LogWarning:
case LogLevel::LogError:
case LogLevel::LogTest:
case LogLevel::LogTitle:
break;
case LogLevel::LogExpection:
if (!mCondition) {
// Breaking runtime condition, show popup?
}
else {
msg.clear(); // Error message should not be displayed if condition was right
}
// already handled in early return
//else {
// msg.clear(); // Error message should not be displayed if condition was right
//}
break;
case LogLevel::LogAssertion:
if (!mCondition) {
DEBUG_BREAK;
}
else {
msg.clear(); // Error message should not be displayed if condition was right
}
break;
case LogLevel::LogTitle:
// already handled in early return
//else {
// msg.clear(); // Error message should not be displayed if condition was right
//}
break;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/memory/include/memory/Arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ namespace l::memory {
class Arena {
public:
Arena();
Arena(void* ptr, uint64_t size);
~Arena();

std::vector<MemoryBlock> mBlocks;
};

std::unique_ptr<Arena> CreateArena();
std::unique_ptr<Arena> CreateArena(void* ptr = nullptr, uint64_t size = 0);

// push some bytes onto the 'stack' - the way to allocate
void* ArenaPush(Arena* arena, uint64_t size);
Expand Down
7 changes: 5 additions & 2 deletions packages/memory/source/common/Arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ namespace l::memory {
mBlocks.reserve(16);

}
Arena::Arena(void* ptr, uint64_t size) {
mBlocks.push_back({ ptr, size });
}

Arena::~Arena() {

}

std::unique_ptr<Arena> CreateArena() {
return std::make_unique<Arena>();
std::unique_ptr<Arena> CreateArena(void* ptr, uint64_t size) {
return std::make_unique<Arena>(ptr, size);
}


Expand Down
18 changes: 18 additions & 0 deletions packages/memory/tests/common/ArenaTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "testing/Test.h"
#include "logging/Log.h"

#include "memory/Arena.h"

using namespace l;

TEST(Arena, Basic) {

auto arena = memory::CreateArena();

auto a = memory::ArenaPush(arena.get(), 10);

TEST_TRUE(a != nullptr, "");

return 0;
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "logging/String.h"

namespace l::storage {
namespace l::serialization {

template<size_t size>
std::pair<size_t, std::vector<std::string>> ParseTrivialData(std::stringstream& data, std::string_view separators) {
Expand Down
10 changes: 0 additions & 10 deletions packages/serialization/source/common/CommaSeparatedData.cpp

This file was deleted.

0 comments on commit 2b19ae6

Please sign in to comment.