aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/cru/common/Base.hpp33
-rw-r--r--include/cru/common/Logger.hpp6
-rw-r--r--include/cru/common/PreConfig.hpp4
-rw-r--r--include/cru/common/StringUtil.hpp67
4 files changed, 77 insertions, 33 deletions
diff --git a/include/cru/common/Base.hpp b/include/cru/common/Base.hpp
index 560f83bb..93b0008c 100644
--- a/include/cru/common/Base.hpp
+++ b/include/cru/common/Base.hpp
@@ -1,9 +1,19 @@
#pragma once
#include "PreConfig.hpp"
-#include <exception>
+#ifdef CRU_PLATFORM_WINDOWS
+#ifdef CRU_BASE_EXPORT_API
+#define CRU_BASE_API __declspec(dllexport)
+#else
+#define CRU_BASE_API __declspec(dllimport)
+#endif
+#else
+#define CRU_BASE_API
+#endif
+
#include <gsl/gsl>
#include <stdexcept>
+#include <string>
#define CRU_UNUSED(entity) static_cast<void>(entity);
@@ -27,7 +37,7 @@
classname& operator=(classname&&) = delete;
namespace cru {
-class Object {
+class CRU_BASE_API Object {
public:
Object() = default;
CRU_DEFAULT_COPY(Object)
@@ -35,7 +45,7 @@ class Object {
virtual ~Object() = default;
};
-struct Interface {
+struct CRU_BASE_API Interface {
Interface() = default;
CRU_DELETE_COPY(Interface)
CRU_DELETE_MOVE(Interface)
@@ -56,4 +66,21 @@ inline void hash_combine(std::size_t& s, const T& v) {
#define CRU_DEFINE_CLASS_LOG_TAG(tag) \
private: \
constexpr static std::u16string_view log_tag = tag;
+
+class CRU_BASE_API Exception {
+ public:
+ Exception() = default;
+ Exception(std::u16string message) : message_(std::move(message)) {}
+
+ CRU_DEFAULT_COPY(Exception)
+ CRU_DEFAULT_MOVE(Exception)
+
+ virtual ~Exception() = default;
+
+ public:
+ std::u16string GetMessage() const { return message_; }
+
+ private:
+ std::u16string message_;
+};
} // namespace cru
diff --git a/include/cru/common/Logger.hpp b/include/cru/common/Logger.hpp
index daf2e7d2..239a25cd 100644
--- a/include/cru/common/Logger.hpp
+++ b/include/cru/common/Logger.hpp
@@ -10,13 +10,13 @@ namespace cru::log {
enum class LogLevel { Debug, Info, Warn, Error };
-struct ILogSource : virtual Interface {
+struct CRU_BASE_API 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::u16string& s) = 0;
};
-class Logger : public Object {
+class CRU_BASE_API Logger : public Object {
public:
static Logger* GetInstance();
@@ -36,7 +36,7 @@ class Logger : public Object {
void Log(LogLevel level, std::u16string_view s);
void Log(LogLevel level, std::u16string_view tag, std::u16string_view s);
- public:
+ private:
std::list<std::unique_ptr<ILogSource>> sources_;
};
diff --git a/include/cru/common/PreConfig.hpp b/include/cru/common/PreConfig.hpp
index 4bccef1d..6011dc54 100644
--- a/include/cru/common/PreConfig.hpp
+++ b/include/cru/common/PreConfig.hpp
@@ -3,6 +3,10 @@
#ifdef _MSC_VER
// disable the unnecessary warning about multi-inheritance
#pragma warning(disable : 4250)
+// disable dll export template issue warning
+#pragma warning(disable : 4251)
#endif
+#ifdef CRU_PLATFORM_WINDOWS
#define _CRT_SECURE_NO_WARNINGS
+#endif
diff --git a/include/cru/common/StringUtil.hpp b/include/cru/common/StringUtil.hpp
index 912106c3..0ea842c2 100644
--- a/include/cru/common/StringUtil.hpp
+++ b/include/cru/common/StringUtil.hpp
@@ -9,9 +9,9 @@ namespace cru {
using CodePoint = std::int32_t;
constexpr CodePoint k_invalid_code_point = -1;
-class TextEncodeException : public std::runtime_error {
+class CRU_BASE_API TextEncodeException : public Exception {
public:
- using runtime_error::runtime_error;
+ using Exception::Exception;
};
inline bool IsUtf16SurrogatePairCodeUnit(char16_t c) {
@@ -26,13 +26,14 @@ inline bool IsUtf16SurrogatePairTrailing(char16_t c) {
return c >= 0xDC00 && c <= 0xDFFF;
}
-CodePoint Utf8NextCodePoint(std::string_view str, Index current,
- Index* next_position);
+CodePoint CRU_BASE_API Utf8NextCodePoint(std::string_view str, Index current,
+ Index* next_position);
-CodePoint Utf16NextCodePoint(std::u16string_view str, Index current,
- Index* next_position);
-CodePoint Utf16PreviousCodePoint(std::u16string_view str, Index current,
- Index* previous_position);
+CodePoint CRU_BASE_API Utf16NextCodePoint(std::u16string_view str,
+ Index current, Index* next_position);
+CodePoint CRU_BASE_API Utf16PreviousCodePoint(std::u16string_view str,
+ Index current,
+ Index* previous_position);
template <typename StringType>
using NextCodePointFunctionType = CodePoint (*)(StringType, Index, Index*);
@@ -117,37 +118,49 @@ class CodePointIterator {
mutable Index next_position_cache_;
};
+extern template CRU_BASE_API class CodePointIterator<std::string_view,
+ &Utf8NextCodePoint>;
+extern template CRU_BASE_API class CodePointIterator<std::u16string_view,
+ &Utf16NextCodePoint>;
+
using Utf8CodePointIterator =
CodePointIterator<std::string_view, &Utf8NextCodePoint>;
using Utf16CodePointIterator =
CodePointIterator<std::u16string_view, &Utf16NextCodePoint>;
-void Utf8EncodeCodePointAppend(CodePoint code_point, std::string& str);
-void Utf16EncodeCodePointAppend(CodePoint code_point, std::u16string& str);
+void CRU_BASE_API Utf8EncodeCodePointAppend(CodePoint code_point,
+ std::string& str);
+void CRU_BASE_API Utf16EncodeCodePointAppend(CodePoint code_point,
+ std::u16string& str);
-std::string ToUtf8(std::u16string_view s);
-std::u16string ToUtf16(std::string_view s);
+std::string CRU_BASE_API ToUtf8(std::u16string_view s);
+std::u16string CRU_BASE_API ToUtf16(std::string_view s);
// If given s is not a valid utf16 string, return value is UD.
-bool Utf16IsValidInsertPosition(std::u16string_view s, gsl::index position);
+bool CRU_BASE_API Utf16IsValidInsertPosition(std::u16string_view s,
+ gsl::index position);
// Return position after the character making predicate returns true or 0 if no
// character doing so.
-gsl::index Utf16BackwardUntil(std::u16string_view str, gsl::index position,
- const std::function<bool(CodePoint)>& predicate);
+gsl::index CRU_BASE_API
+Utf16BackwardUntil(std::u16string_view str, gsl::index position,
+ const std::function<bool(CodePoint)>& predicate);
// Return position before the character making predicate returns true or
// str.size() if no character doing so.
-gsl::index Utf16ForwardUntil(std::u16string_view str, gsl::index position,
- const std::function<bool(CodePoint)>& predicate);
-
-gsl::index Utf16PreviousWord(std::u16string_view str, gsl::index position,
- bool* is_space = nullptr);
-gsl::index Utf16NextWord(std::u16string_view str, gsl::index position,
- bool* is_space = nullptr);
-
-char16_t ToLower(char16_t c);
-char16_t ToUpper(char16_t c);
-std::u16string ToLower(std::u16string_view s);
-std::u16string ToUpper(std::u16string_view s);
+gsl::index CRU_BASE_API
+Utf16ForwardUntil(std::u16string_view str, gsl::index position,
+ const std::function<bool(CodePoint)>& predicate);
+
+gsl::index CRU_BASE_API Utf16PreviousWord(std::u16string_view str,
+ gsl::index position,
+ bool* is_space = nullptr);
+gsl::index CRU_BASE_API Utf16NextWord(std::u16string_view str,
+ gsl::index position,
+ bool* is_space = nullptr);
+
+char16_t CRU_BASE_API ToLower(char16_t c);
+char16_t CRU_BASE_API ToUpper(char16_t c);
+std::u16string CRU_BASE_API ToLower(std::u16string_view s);
+std::u16string CRU_BASE_API ToUpper(std::u16string_view s);
} // namespace cru