Skip to content

Commit 0c4ef4f

Browse files
committed
small refactor
1 parent e487568 commit 0c4ef4f

File tree

41 files changed

+467
-459
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+467
-459
lines changed

sources/Core/Application/Application.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
2+
#include "patterns/Singleton.h"
23

34
class Application : public Singleton<Application>
45
{

sources/Core/Data/Data.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "pch.h"
2+
#include "Data.h"
23

34
namespace DataPacker
45
{

sources/Core/Data/Data.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#pragma once
2+
#include "Debug/Exceptions.h"
3+
#include "Utils/utils.h"
4+
15
namespace DataPacker
26
{
37

sources/Core/Debug/Debug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "pch.h"
2-
2+
#include "Exceptions.h"
33
#include <DbgHelp.h>
44

55
namespace Exceptions

sources/Core/Debug/Debug.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <boost/stacktrace.hpp>
22

3+
#include "patterns/Singleton.h"
4+
#include "Log/Log.h"
35

46
// #define LEAK_TEST_ENABLE
57
#ifdef LEAK_TEST_ENABLE

sources/Core/Events/Events.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#pragma once
2+
#include "Data/Data.h"
3+
#include "Serialization/serialization.h"
24
namespace Events
35
{
46

sources/Core/Events/Tasks.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#include "pch.h"
2+
#include "Events/Tasks.h"
3+
#include "Log/Log.h"
4+
#include "Events/Events.h"
25

36
std::shared_ptr<Task> TaskInfoManager::create_task(std::wstring name)
47
{

sources/Core/Events/Tasks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22
#include "Events.h"
3-
3+
#include "patterns/Singleton.h"
44

55
class Task
66
{

sources/Core/Log/Log.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#include "pch.h"
2+
3+
#include "Log.h"
4+
25
#define BOOST_DECL_EXPORTS
36
#define BOOST_WARCHIVE_SOURCE
47
#define BOOST_ARCHIVE_DECL
@@ -67,7 +70,7 @@ void Log::crash_error(HRESULT hr, std::string at /*= ""*/)
6770

6871
std::string LogBlock::get_string() const
6972
{
70-
return "[" + current_level_name + "] : " + s->str();
73+
return "[" + current_level_name + "] : " + data->s.str();
7174
}
7275

7376
Log& LogBlock::operator<<(const Log::endline&)
@@ -78,28 +81,36 @@ Log& LogBlock::operator<<(const Log::endline&)
7881
LogBlock& LogBlock::operator<<(string_view smth)
7982
{
8083
if (need_logging())
81-
*s << smth;
84+
data->s << smth;
8285

8386
return (*this);
8487
}
8588

8689
LogBlock& LogBlock::operator<<(wstring_view smth)
8790
{
8891
if (need_logging())
89-
*s << convert(smth);
92+
data->s << convert(smth);
9093

9194
return (*this);
9295
}
9396

97+
98+
LogBlock::shared_data::shared_data():archive(s)
99+
{
100+
101+
}
102+
94103
LogBlock::LogBlock(Log& output, log_level_internal level) : log(output)
95104
{
96105
log_level = level;
97106
current_level =log_level_internal::level_info;
98107
current_level_name = LogLevel<log_level_internal::level_info>::NAME;
99-
s.reset(new std::ostringstream());
108+
109+
data = std::make_shared<shared_data>();
110+
// s.reset(new std::ostringstream());
100111
auto delta = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start_time).count();
101112
// auto now_c = std::chrono::system_clock::to_time_t(now);
102-
*s << delta << ' ';
113+
data->s << delta << ' ';
103114
}
104115

105116
LogListener::~LogListener()
@@ -111,7 +122,8 @@ LogListener::LogListener()
111122
{
112123
// Log::get().listeners.insert(this);
113124
active = true;
114-
Log::get().on_log.register_handler(this, std::bind(&LogListener::on_log, this, std::placeholders::_1));
125+
Log::get().on_log.register_handler(this, [this](const LogBlock& v) { on_log(v); } );
126+
115127
}
116128

117129

0 commit comments

Comments
 (0)