aboutsummaryrefslogtreecommitdiff
path: root/include/cru/common
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/common')
-rw-r--r--include/cru/common/base.hpp12
-rw-r--r--include/cru/common/logger.hpp51
-rw-r--r--include/cru/common/pre_config.hpp5
3 files changed, 35 insertions, 33 deletions
diff --git a/include/cru/common/base.hpp b/include/cru/common/base.hpp
index 55f43e5c..2c935046 100644
--- a/include/cru/common/base.hpp
+++ b/include/cru/common/base.hpp
@@ -23,19 +23,15 @@ namespace cru {
class Object {
public:
Object() = default;
- Object(const Object&) = default;
- Object& operator=(const Object&) = default;
- Object(Object&&) = default;
- Object& operator=(Object&&) = default;
+ CRU_DEFAULT_COPY(Object)
+ CRU_DEFAULT_MOVE(Object)
virtual ~Object() = default;
};
struct Interface {
Interface() = default;
- Interface(const Interface& other) = delete;
- Interface(Interface&& other) = delete;
- Interface& operator=(const Interface& other) = delete;
- Interface& operator=(Interface&& other) = delete;
+ CRU_DELETE_COPY(Interface)
+ CRU_DELETE_MOVE(Interface)
virtual ~Interface() = default;
};
diff --git a/include/cru/common/logger.hpp b/include/cru/common/logger.hpp
index bbe06331..08765499 100644
--- a/include/cru/common/logger.hpp
+++ b/include/cru/common/logger.hpp
@@ -5,32 +5,33 @@
#include <iostream>
#include <list>
+#include <memory>
#include <string_view>
namespace cru::log {
enum class LogLevel { Debug, Info, Warn, Error };
-struct ILoggerSource : Interface {
- // Write the s. LogLevel is just a helper. It has no effect on the content to
- // write.
- virtual void Write(LogLevel level, const std::wstring_view& s) = 0;
+struct ILogSource : virtual Interface {
+ // Write the string s. LogLevel is just a helper. It has no effect on the
+ // content to write.
+ virtual void Write(LogLevel level, const std::string_view& s) = 0;
};
-class StdioLoggerSource : public ILoggerSource {
+class StdioLogSource : public virtual ILogSource {
public:
- StdioLoggerSource() = default;
+ StdioLogSource() = default;
- CRU_DELETE_COPY(StdioLoggerSource)
- CRU_DELETE_MOVE(StdioLoggerSource)
+ CRU_DELETE_COPY(StdioLogSource)
+ CRU_DELETE_MOVE(StdioLogSource)
- ~StdioLoggerSource() = default;
+ ~StdioLogSource() override = default;
- void Write(LogLevel level, const std::wstring_view& s) override {
+ void Write(LogLevel level, const std::string_view& s) override {
if (level == LogLevel::Error) {
- std::wcerr << s;
+ std::cerr << s;
} else {
- std::wcout << s;
+ std::cout << s;
}
}
};
@@ -45,43 +46,43 @@ class Logger : public Object {
CRU_DELETE_COPY(Logger)
CRU_DELETE_MOVE(Logger)
- ~Logger() override;
+ ~Logger() override = default;
public:
- void AddSource(ILoggerSource* source);
- void RemoveSource(ILoggerSource* source);
+ void AddSource(std::unique_ptr<ILogSource> source);
+ void RemoveSource(ILogSource* source);
public:
- void Log(LogLevel level, const std::wstring_view& s);
+ void Log(LogLevel level, const std::string_view& s);
template <typename... TArgs>
- void Debug(const std::wstring_view& format, TArgs&&... args) {
+ void Debug(const std::string_view& format, TArgs&&... args) {
#ifdef CRU_DEBUG
Log(LogLevel::Debug, util::Format(format, std::forward<TArgs>(args)...));
#endif
}
template <typename... TArgs>
- void Info(const std::wstring_view& format, TArgs&&... args) {
+ void Info(const std::string_view& format, TArgs&&... args) {
Log(LogLevel::Info, util::Format(format, std::forward<TArgs>(args)...));
}
template <typename... TArgs>
- void Warn(const std::wstring_view& format, TArgs&&... args) {
+ void Warn(const std::string_view& format, TArgs&&... args) {
Log(LogLevel::Warn, util::Format(format, std::forward<TArgs>(args)...));
}
template <typename... TArgs>
- void Error(const std::wstring_view& format, TArgs&&... args) {
+ void Error(const std::string_view& format, TArgs&&... args) {
Log(LogLevel::Error, util::Format(format, std::forward<TArgs>(args)...));
}
public:
- std::list<ILoggerSource*> sources_;
+ std::list<std::unique_ptr<ILogSource>> sources_;
};
template <typename... TArgs>
-void Debug(const std::wstring_view& format, TArgs&&... args) {
+void Debug(const std::string_view& format, TArgs&&... args) {
#ifdef CRU_DEBUG
Logger::GetInstance()->Log(
LogLevel::Debug, util::Format(format, std::forward<TArgs>(args)...));
@@ -89,19 +90,19 @@ void Debug(const std::wstring_view& format, TArgs&&... args) {
}
template <typename... TArgs>
-void Info(const std::wstring_view& format, TArgs&&... args) {
+void Info(const std::string_view& format, TArgs&&... args) {
Logger::GetInstance()->Log(
LogLevel::Info, util::Format(format, std::forward<TArgs>(args)...));
}
template <typename... TArgs>
-void Warn(const std::wstring_view& format, TArgs&&... args) {
+void Warn(const std::string_view& format, TArgs&&... args) {
Logger::GetInstance()->Log(
LogLevel::Warn, util::Format(format, std::forward<TArgs>(args)...));
}
template <typename... TArgs>
-void Error(const std::wstring_view& format, TArgs&&... args) {
+void Error(const std::string_view& format, TArgs&&... args) {
Logger::GetInstance()->Log(
LogLevel::Error, util::Format(format, std::forward<TArgs>(args)...));
}
diff --git a/include/cru/common/pre_config.hpp b/include/cru/common/pre_config.hpp
index 96b1bab5..5fcef218 100644
--- a/include/cru/common/pre_config.hpp
+++ b/include/cru/common/pre_config.hpp
@@ -1,5 +1,10 @@
#pragma once
+#ifdef _MSC_VER
+// disable the unnecessary warning about multi-inheritance
+#pragma warning(disable : 4250)
+#endif
+
#ifdef _DEBUG
#define CRU_DEBUG
#endif