From 12eaaa6bdfdc4c4e21db3aabdba970fd95b99890 Mon Sep 17 00:00:00 2001 From: Nomango Date: Wed, 13 Nov 2019 14:33:15 +0800 Subject: [PATCH] refactoring --- projects/kiwano/kiwano.vcxproj | 94 ++-- projects/kiwano/kiwano.vcxproj.filters | 208 ++++----- src/kiwano-audio/AudioEngine.cpp | 2 +- src/kiwano-audio/AudioEngine.h | 6 +- src/kiwano-audio/Sound.cpp | 4 +- src/kiwano-audio/Sound.h | 6 +- src/kiwano-audio/SoundPlayer.h | 4 +- src/kiwano-audio/Transcoder.cpp | 8 +- src/kiwano-audio/Transcoder.h | 2 +- src/kiwano-audio/audio-modules.cpp | 2 +- src/kiwano-audio/audio-modules.h | 2 +- src/kiwano-imgui/ImGuiModule.cpp | 10 +- src/kiwano-imgui/ImGuiModule.h | 4 +- src/kiwano-imgui/imgui_impl_dx11.cpp | 2 +- src/kiwano-network/HttpClient.cpp | 60 +-- src/kiwano-network/HttpClient.h | 72 +-- src/kiwano-network/HttpRequest.cpp | 14 - src/kiwano-network/HttpRequest.h | 79 ++-- src/kiwano-network/HttpResponse.hpp | 59 ++- src/kiwano/2d/Actor.cpp | 2 +- src/kiwano/2d/Actor.h | 4 +- src/kiwano/2d/Canvas.cpp | 2 +- src/kiwano/2d/DebugActor.cpp | 2 +- src/kiwano/2d/Frame.h | 2 +- src/kiwano/2d/FrameSequence.cpp | 2 +- src/kiwano/2d/GifSprite.cpp | 2 +- src/kiwano/2d/GifSprite.h | 2 +- src/kiwano/2d/ShapeActor.cpp | 2 +- src/kiwano/2d/Stage.cpp | 2 +- src/kiwano/2d/Text.cpp | 2 +- src/kiwano/2d/Transition.cpp | 4 +- src/kiwano/2d/action/ActionGroup.cpp | 2 +- src/kiwano/2d/action/ActionHelper.h | 46 +- src/kiwano/2d/action/ActionManager.cpp | 2 +- src/kiwano/2d/action/ActionTween.h | 2 +- src/kiwano/2d/include-forwards.h | 10 +- src/kiwano/base/time.cpp | 426 ------------------ src/kiwano/base/time.h | 247 ---------- src/kiwano/{core => common}/any.hpp | 6 +- src/kiwano/{core => common}/basic_json.hpp | 12 +- src/kiwano/{core/core.h => common/common.h} | 34 +- src/kiwano/{core => common}/function.hpp | 12 +- .../{core => common}/intrusive_list.hpp | 6 +- src/kiwano/{core => common}/intrusive_ptr.hpp | 4 +- src/kiwano/{core => common}/noncopyable.hpp | 4 +- src/kiwano/{core => common}/singleton.hpp | 6 +- src/kiwano/{core => common}/string.hpp | 84 ++-- src/kiwano/{core => common}/vector.hpp | 4 +- src/kiwano/{base => core}/AsyncTask.cpp | 2 +- src/kiwano/{base => core}/AsyncTask.h | 2 +- src/kiwano/{base => core}/Component.cpp | 2 +- src/kiwano/{base => core}/Component.h | 2 +- src/kiwano/{base => core}/Director.cpp | 2 +- src/kiwano/{base => core}/Director.h | 2 +- src/kiwano/{base => core}/Event.cpp | 2 +- src/kiwano/{base => core}/Event.h | 54 +-- src/kiwano/{base => core}/EventDispatcher.cpp | 4 +- src/kiwano/{base => core}/EventDispatcher.h | 2 +- src/kiwano/{base => core}/EventListener.cpp | 2 +- src/kiwano/{base => core}/EventListener.h | 8 +- src/kiwano/{base => core}/Library.cpp | 2 +- src/kiwano/{base => core}/Library.h | 2 +- src/kiwano/{base => core}/Logger.cpp | 2 +- src/kiwano/{base => core}/Logger.h | 2 +- src/kiwano/{base => core}/ObjectBase.cpp | 4 +- src/kiwano/{base => core}/ObjectBase.h | 6 +- src/kiwano/{base => core}/RefCounter.hpp | 4 +- src/kiwano/{base => core}/Resource.cpp | 4 +- src/kiwano/{base => core}/Resource.h | 2 +- src/kiwano/{base => core}/SmartPtr.hpp | 6 +- src/kiwano/{base => core}/Timer.cpp | 2 +- src/kiwano/{base => core}/Timer.h | 4 +- src/kiwano/{base => core}/TimerManager.cpp | 4 +- src/kiwano/{base => core}/TimerManager.h | 2 +- src/kiwano/{base/keys.hpp => core/keys.h} | 0 src/kiwano/core/time.cpp | 424 +++++++++++++++++ src/kiwano/core/time.h | 225 +++++++++ src/kiwano/{base => core}/win32/ComPtr.hpp | 4 +- src/kiwano/{base => core}/win32/helper.h | 2 +- src/kiwano/kiwano.h | 55 +-- src/kiwano/math/math.h | 2 +- src/kiwano/math/scalar.h | 4 +- src/kiwano/platform/Application.cpp | 6 +- src/kiwano/platform/Application.h | 12 +- src/kiwano/{utils => platform}/FileSystem.cpp | 2 +- src/kiwano/{utils => platform}/FileSystem.h | 2 +- src/kiwano/{base => platform}/Input.cpp | 4 +- src/kiwano/{base => platform}/Input.h | 6 +- src/kiwano/{base => platform}/Window.cpp | 4 +- src/kiwano/{base => platform}/Window.h | 2 +- src/kiwano/platform/modules.cpp | 2 +- src/kiwano/platform/modules.h | 2 +- src/kiwano/renderer/Brush.cpp | 2 +- src/kiwano/renderer/Color.h | 2 +- src/kiwano/renderer/FontCollection.h | 4 +- src/kiwano/renderer/Geometry.cpp | 2 +- src/kiwano/renderer/Geometry.h | 2 +- src/kiwano/renderer/GifImage.cpp | 2 +- src/kiwano/renderer/GifImage.h | 2 +- src/kiwano/renderer/RenderTarget.cpp | 2 +- src/kiwano/renderer/RenderTarget.h | 4 +- src/kiwano/renderer/Renderer.cpp | 6 +- src/kiwano/renderer/Renderer.h | 2 +- src/kiwano/renderer/TextLayout.cpp | 2 +- src/kiwano/renderer/Texture.cpp | 2 +- src/kiwano/renderer/TextureCache.cpp | 2 +- .../renderer/win32/D2DDeviceResources.cpp | 2 +- .../renderer/win32/D2DDeviceResources.h | 2 +- .../renderer/win32/D3D10DeviceResources.cpp | 2 +- .../renderer/win32/D3D11DeviceResources.cpp | 2 +- src/kiwano/ui/Button.cpp | 2 +- src/kiwano/utils/LocalStorage.h | 2 +- src/kiwano/utils/ResourceCache.cpp | 6 +- src/kiwano/utils/ResourceCache.h | 2 +- src/kiwano/utils/UserData.h | 2 +- 115 files changed, 1272 insertions(+), 1247 deletions(-) delete mode 100644 src/kiwano/base/time.cpp delete mode 100644 src/kiwano/base/time.h rename src/kiwano/{core => common}/any.hpp (98%) rename src/kiwano/{core => common}/basic_json.hpp (99%) rename src/kiwano/{core/core.h => common/common.h} (77%) rename src/kiwano/{core => common}/function.hpp (95%) rename src/kiwano/{core => common}/intrusive_list.hpp (98%) rename src/kiwano/{core => common}/intrusive_ptr.hpp (99%) rename src/kiwano/{core => common}/noncopyable.hpp (97%) rename src/kiwano/{core => common}/singleton.hpp (96%) rename src/kiwano/{core => common}/string.hpp (94%) rename src/kiwano/{core => common}/vector.hpp (99%) rename src/kiwano/{base => core}/AsyncTask.cpp (98%) rename src/kiwano/{base => core}/AsyncTask.h (98%) rename src/kiwano/{base => core}/Component.cpp (98%) rename src/kiwano/{base => core}/Component.h (98%) rename src/kiwano/{base => core}/Director.cpp (99%) rename src/kiwano/{base => core}/Director.h (98%) rename src/kiwano/{base => core}/Event.cpp (98%) rename src/kiwano/{base => core}/Event.h (98%) rename src/kiwano/{base => core}/EventDispatcher.cpp (98%) rename src/kiwano/{base => core}/EventDispatcher.h (98%) rename src/kiwano/{base => core}/EventListener.cpp (97%) rename src/kiwano/{base => core}/EventListener.h (94%) rename src/kiwano/{base => core}/Library.cpp (98%) rename src/kiwano/{base => core}/Library.h (97%) rename src/kiwano/{base => core}/Logger.cpp (99%) rename src/kiwano/{base => core}/Logger.h (99%) rename src/kiwano/{base => core}/ObjectBase.cpp (98%) rename src/kiwano/{base => core}/ObjectBase.h (95%) rename src/kiwano/{base => core}/RefCounter.hpp (95%) rename src/kiwano/{base => core}/Resource.cpp (97%) rename src/kiwano/{base => core}/Resource.h (98%) rename src/kiwano/{base => core}/SmartPtr.hpp (90%) rename src/kiwano/{base => core}/Timer.cpp (98%) rename src/kiwano/{base => core}/Timer.h (96%) rename src/kiwano/{base => core}/TimerManager.cpp (97%) rename src/kiwano/{base => core}/TimerManager.h (98%) rename src/kiwano/{base/keys.hpp => core/keys.h} (100%) create mode 100644 src/kiwano/core/time.cpp create mode 100644 src/kiwano/core/time.h rename src/kiwano/{base => core}/win32/ComPtr.hpp (93%) rename src/kiwano/{base => core}/win32/helper.h (97%) rename src/kiwano/{utils => platform}/FileSystem.cpp (99%) rename src/kiwano/{utils => platform}/FileSystem.h (98%) rename src/kiwano/{base => platform}/Input.cpp (98%) rename src/kiwano/{base => platform}/Input.h (95%) rename src/kiwano/{base => platform}/Window.cpp (99%) rename src/kiwano/{base => platform}/Window.h (98%) diff --git a/projects/kiwano/kiwano.vcxproj b/projects/kiwano/kiwano.vcxproj index 2782d80d..4ec7a3d1 100644 --- a/projects/kiwano/kiwano.vcxproj +++ b/projects/kiwano/kiwano.vcxproj @@ -11,21 +11,21 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -42,21 +42,19 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + @@ -66,7 +64,10 @@ + + + @@ -89,7 +90,6 @@ - @@ -114,23 +114,24 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -151,7 +152,6 @@ - diff --git a/projects/kiwano/kiwano.vcxproj.filters b/projects/kiwano/kiwano.vcxproj.filters index 9f60577e..2f48b1a4 100644 --- a/projects/kiwano/kiwano.vcxproj.filters +++ b/projects/kiwano/kiwano.vcxproj.filters @@ -16,7 +16,7 @@ {896bdedf-6e82-449b-9b6e-0bc69f3699b1} - + {2e18d99a-e906-499a-9e29-4e0783202644} @@ -25,13 +25,13 @@ {9314f30d-5742-48b6-94e5-e3b4284106f6} - + {86e2d0f2-a9d0-4456-b6a5-d480228bbf82} {30333461-e9bc-4709-84bd-ce6e0e1a3079} - + {192a47a9-9df6-4f40-a7d3-888eb00c53ac} @@ -63,26 +63,23 @@ 2d - - base + + core - - base + + core - - base + + core - - base + + core - - base + + core - - base - - - base + + core math @@ -104,27 +101,24 @@ math - - base - - - base + + core - - base + + core - - base + + core - - base + + core 2d - - base + + core 2d @@ -159,32 +153,32 @@ 2d - - core + + common - - core + + common - - core + + common - - core + + common - - core + + common - - core + + common - - core + + common - - core + + common - - core + + common 2d @@ -198,17 +192,14 @@ 2d\action - - base - - - base + + core math - - base + + core renderer @@ -279,29 +270,38 @@ math - - base\win32 + + core\win32 - - base\win32 + + core\win32 utils - - utils - - - core + + common utils - - base + + core - - base + + core + + + platform + + + core + + + platform + + + platform @@ -326,17 +326,17 @@ 2d - - base + + core - - base + + core - - base + + core - - base + + core platform @@ -344,23 +344,20 @@ platform - - base + + core - - base + + core - - base - - - base + + core 2d - - base + + core 2d @@ -404,14 +401,11 @@ 2d\action - - base + + core - - base - - - base + + core renderer @@ -467,23 +461,29 @@ renderer - - base + + core utils - - utils - utils - - base + + core - - base + + core + + + platform + + + platform + + + platform \ No newline at end of file diff --git a/src/kiwano-audio/AudioEngine.cpp b/src/kiwano-audio/AudioEngine.cpp index 53f2d05b..194b180d 100644 --- a/src/kiwano-audio/AudioEngine.cpp +++ b/src/kiwano-audio/AudioEngine.cpp @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include +#include #include #include diff --git a/src/kiwano-audio/AudioEngine.h b/src/kiwano-audio/AudioEngine.h index 4bbd313d..11187a2a 100644 --- a/src/kiwano-audio/AudioEngine.h +++ b/src/kiwano-audio/AudioEngine.h @@ -19,9 +19,9 @@ // THE SOFTWARE. #pragma once -#include -#include -#include +#include +#include +#include #include #include diff --git a/src/kiwano-audio/Sound.cpp b/src/kiwano-audio/Sound.cpp index d0bda67f..622391fb 100644 --- a/src/kiwano-audio/Sound.cpp +++ b/src/kiwano-audio/Sound.cpp @@ -18,8 +18,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include -#include +#include +#include #include #include diff --git a/src/kiwano-audio/Sound.h b/src/kiwano-audio/Sound.h index 5cc66646..e94171a4 100644 --- a/src/kiwano-audio/Sound.h +++ b/src/kiwano-audio/Sound.h @@ -19,9 +19,9 @@ // THE SOFTWARE. #pragma once -#include -#include -#include +#include +#include +#include #include #include diff --git a/src/kiwano-audio/SoundPlayer.h b/src/kiwano-audio/SoundPlayer.h index f3659a5d..913fe04f 100644 --- a/src/kiwano-audio/SoundPlayer.h +++ b/src/kiwano-audio/SoundPlayer.h @@ -19,8 +19,8 @@ // THE SOFTWARE. #pragma once -#include -#include +#include +#include #include namespace kiwano diff --git a/src/kiwano-audio/Transcoder.cpp b/src/kiwano-audio/Transcoder.cpp index 23552f8b..256ebe83 100644 --- a/src/kiwano-audio/Transcoder.cpp +++ b/src/kiwano-audio/Transcoder.cpp @@ -23,10 +23,10 @@ #endif #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include diff --git a/src/kiwano-audio/Transcoder.h b/src/kiwano-audio/Transcoder.h index 7d6d0d78..1ee99cf3 100644 --- a/src/kiwano-audio/Transcoder.h +++ b/src/kiwano-audio/Transcoder.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include #include #include #include diff --git a/src/kiwano-audio/audio-modules.cpp b/src/kiwano-audio/audio-modules.cpp index f46335bb..f140f00d 100644 --- a/src/kiwano-audio/audio-modules.cpp +++ b/src/kiwano-audio/audio-modules.cpp @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include +#include #include namespace kiwano diff --git a/src/kiwano-audio/audio-modules.h b/src/kiwano-audio/audio-modules.h index 97a7e8a9..299beb34 100644 --- a/src/kiwano-audio/audio-modules.h +++ b/src/kiwano-audio/audio-modules.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include #include #include #include diff --git a/src/kiwano-imgui/ImGuiModule.cpp b/src/kiwano-imgui/ImGuiModule.cpp index 5ed0034f..f164f2bd 100644 --- a/src/kiwano-imgui/ImGuiModule.cpp +++ b/src/kiwano-imgui/ImGuiModule.cpp @@ -1,10 +1,10 @@ // Copyright (C) 2019 Nomango -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include diff --git a/src/kiwano-imgui/ImGuiModule.h b/src/kiwano-imgui/ImGuiModule.h index a047da68..c9069a40 100644 --- a/src/kiwano-imgui/ImGuiModule.h +++ b/src/kiwano-imgui/ImGuiModule.h @@ -19,8 +19,8 @@ // THE SOFTWARE. #pragma once -#include -#include +#include +#include namespace kiwano { diff --git a/src/kiwano-imgui/imgui_impl_dx11.cpp b/src/kiwano-imgui/imgui_impl_dx11.cpp index a8f20a45..a8dc29eb 100644 --- a/src/kiwano-imgui/imgui_impl_dx11.cpp +++ b/src/kiwano-imgui/imgui_impl_dx11.cpp @@ -1,6 +1,6 @@ // dear imgui: Renderer for Kiwano (DirectX11) -#include +#include #include // DirectX diff --git a/src/kiwano-network/HttpClient.cpp b/src/kiwano-network/HttpClient.cpp index 4822be25..7e7d97cc 100644 --- a/src/kiwano-network/HttpClient.cpp +++ b/src/kiwano-network/HttpClient.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include <3rd-party/curl/curl.h> // CURL @@ -36,7 +36,7 @@ namespace uint32_t write_data(void* buffer, uint32_t size, uint32_t nmemb, void* userp) { - core::string* recv_buffer = (core::string*)userp; + common::string* recv_buffer = (common::string*)userp; uint32_t total = size * nmemb; // add data to the end of recv_buffer @@ -46,10 +46,10 @@ namespace return total; } - core::string convert_to_utf8(core::wstring const& str) + common::string convert_to_utf8(common::wstring const& str) { std::wstring_convert> utf8_conv; - core::string result; + common::string result; try { @@ -63,10 +63,10 @@ namespace return result; } - core::wstring convert_from_utf8(core::string const& str) + common::wstring convert_from_utf8(common::string const& str) { kiwano::string_convert> utf8_conv; - core::wstring result; + common::wstring result; try { @@ -104,7 +104,7 @@ namespace } } - bool Init(HttpClient* client, Vector const& headers, core::string const& url, core::string* response_data, core::string* response_header, char* error_buffer) + bool Init(HttpClient* client, Vector const& headers, common::string const& url, common::string* response_data, common::string* response_header, char* error_buffer) { if (!SetOption(CURLOPT_ERRORBUFFER, error_buffer)) return false; @@ -170,11 +170,11 @@ namespace public: static inline bool GetRequest( HttpClient* client, - Vector const& headers, - core::string const& url, + Vector const& headers, + common::string const& url, long* response_code, - core::string* response_data, - core::string* response_header, + common::string* response_data, + common::string* response_header, char* error_buffer) { Curl curl; @@ -185,12 +185,12 @@ namespace static inline bool PostRequest( HttpClient* client, - Vector const& headers, - core::string const& url, - core::string const& request_data, + Vector const& headers, + common::string const& url, + common::string const& request_data, long* response_code, - core::string* response_data, - core::string* response_header, + common::string* response_data, + common::string* response_header, char* error_buffer) { Curl curl; @@ -203,12 +203,12 @@ namespace static inline bool PutRequest( HttpClient* client, - Vector const& headers, - core::string const& url, - core::string const& request_data, + Vector const& headers, + common::string const& url, + common::string const& request_data, long* response_code, - core::string* response_data, - core::string* response_header, + common::string* response_data, + common::string* response_header, char* error_buffer) { Curl curl; @@ -221,11 +221,11 @@ namespace static inline bool DeleteRequest( HttpClient* client, - Vector const& headers, - core::string const& url, + Vector const& headers, + common::string const& url, long* response_code, - core::string* response_data, - core::string* response_header, + common::string* response_data, + common::string* response_header, char* error_buffer) { Curl curl; @@ -307,13 +307,13 @@ namespace kiwano bool ok = false; long response_code = 0; char error_message[256] = { 0 }; - core::string response_header; - core::string response_data; + common::string response_header; + common::string response_data; - core::string url = convert_to_utf8(request->GetUrl()); - core::string data = convert_to_utf8(request->GetData()); + common::string url = convert_to_utf8(request->GetUrl()); + common::string data = convert_to_utf8(request->GetData()); - Vector headers; + Vector headers; headers.reserve(request->GetHeaders().size()); for (const auto& pair : request->GetHeaders()) { diff --git a/src/kiwano-network/HttpClient.h b/src/kiwano-network/HttpClient.h index 73b52f7a..31e7bf1f 100644 --- a/src/kiwano-network/HttpClient.h +++ b/src/kiwano-network/HttpClient.h @@ -19,9 +19,9 @@ // THE SOFTWARE. #pragma once -#include -#include -#include +#include +#include +#include #include #include @@ -36,39 +36,19 @@ namespace kiwano KGE_DECLARE_SINGLETON(HttpClient); public: - void Send( - HttpRequestPtr request - ); + void Send(HttpRequestPtr request); - inline void SetTimeoutForConnect(Duration timeout) - { - timeout_for_connect_ = timeout; - } + void SetTimeoutForConnect(Duration timeout); - inline Duration GetTimeoutForConnect() const - { - return timeout_for_connect_; - } + Duration GetTimeoutForConnect() const; - inline void SetTimeoutForRead(Duration timeout) - { - timeout_for_read_ = timeout; - } + void SetTimeoutForRead(Duration timeout); - inline Duration GetTimeoutForRead() const - { - return timeout_for_read_; - } + Duration GetTimeoutForRead() const; - inline void SetSSLVerification(String const& root_certificate_path) - { - ssl_verification_ = root_certificate_path; - } + void SetSSLVerification(String const& root_certificate_path); - inline String const& GetSSLVerification() const - { - return ssl_verification_; - } + String const& GetSSLVerification() const; public: virtual void SetupComponent() override; @@ -101,5 +81,37 @@ namespace kiwano std::condition_variable_any sleep_condition_; }; + + + inline void HttpClient::SetTimeoutForConnect(Duration timeout) + { + timeout_for_connect_ = timeout; + } + + inline Duration HttpClient::GetTimeoutForConnect() const + { + return timeout_for_connect_; + } + + inline void HttpClient::SetTimeoutForRead(Duration timeout) + { + timeout_for_read_ = timeout; + } + + inline Duration HttpClient::GetTimeoutForRead() const + { + return timeout_for_read_; + } + + inline void HttpClient::SetSSLVerification(String const& root_certificate_path) + { + ssl_verification_ = root_certificate_path; + } + + inline String const& HttpClient::GetSSLVerification() const + { + return ssl_verification_; + } + } } diff --git a/src/kiwano-network/HttpRequest.cpp b/src/kiwano-network/HttpRequest.cpp index 0a52f3b4..610df352 100644 --- a/src/kiwano-network/HttpRequest.cpp +++ b/src/kiwano-network/HttpRequest.cpp @@ -30,19 +30,5 @@ namespace kiwano SetHeader(L"Content-Type", L"application/json;charset=UTF-8"); data_ = json.dump(); } - - void HttpRequest::SetHeader(String const& field, String const& content) - { - auto iter = headers_.find(field); - if (iter != headers_.end()) - { - headers_[field] = content; - } - else - { - headers_.insert(std::make_pair(field, content)); - } - } - } } diff --git a/src/kiwano-network/HttpRequest.h b/src/kiwano-network/HttpRequest.h index 942376fe..716f8240 100644 --- a/src/kiwano-network/HttpRequest.h +++ b/src/kiwano-network/HttpRequest.h @@ -19,10 +19,10 @@ // THE SOFTWARE. #pragma once -#include -#include -#include -#include +#include +#include +#include +#include namespace kiwano { @@ -47,35 +47,32 @@ namespace kiwano Delete }; - inline HttpRequest() : type_(Type::Unknown) {} + HttpRequest(); - inline HttpRequest(Type type) : type_(type) {} + HttpRequest(Type type); - inline void SetUrl(String const& url) { url_ = url; } + // 请求地址 + void SetUrl(String const& url); + String const& GetUrl() const; - inline String const& GetUrl() const { return url_; } + // 请求类型 + void SetType(Type type); + Type GetType() const; - inline void SetType(Type type) { type_ = type; } + // 请求数据 + void SetData(String const& data); + void SetJsonData(Json const& json); + String const& GetData() const; - inline Type GetType() const { return type_; } + // 请求头 + void SetHeaders(Map const& headers); + void SetHeader(String const& field, String const& content); + Map& GetHeaders(); + String const& GetHeader(String const& header) const; - inline void SetData(String const& data) { data_ = data; } - - void SetJsonData(Json const& json); - - inline String const& GetData() const { return data_; } - - inline void SetHeaders(Map const& headers) { headers_ = headers; } - - void SetHeader(String const& field, String const& content); - - inline Map& GetHeaders() { return headers_; } - - inline String const& GetHeader(String const& header) const { return headers_.at(header); } - - inline void SetResponseCallback(ResponseCallback const& callback) { response_cb_ = callback; } - - inline ResponseCallback const& GetResponseCallback() const { return response_cb_; } + // 响应回调 + void SetResponseCallback(ResponseCallback const& callback); + ResponseCallback const& GetResponseCallback() const; protected: Type type_; @@ -84,5 +81,33 @@ namespace kiwano Map headers_; ResponseCallback response_cb_; }; + + inline HttpRequest::HttpRequest() : type_(Type::Unknown) {} + + inline HttpRequest::HttpRequest(Type type) : type_(type) {} + + inline void HttpRequest::SetUrl(String const& url) { url_ = url; } + + inline String const& HttpRequest::GetUrl() const { return url_; } + + inline void HttpRequest::SetType(Type type) { type_ = type; } + + inline HttpRequest::Type HttpRequest::GetType() const { return type_; } + + inline void HttpRequest::SetData(String const& data) { data_ = data; } + + inline String const& HttpRequest::GetData() const { return data_; } + + inline void HttpRequest::SetHeaders(Map const& headers) { headers_ = headers; } + + inline void HttpRequest::SetHeader(String const& field, String const& content) { headers_[field] = content; } + + inline Map& HttpRequest::GetHeaders() { return headers_; } + + inline String const& HttpRequest::GetHeader(String const& header) const { return headers_.at(header); } + + inline void HttpRequest::SetResponseCallback(ResponseCallback const& callback) { response_cb_ = callback; } + + inline HttpRequest::ResponseCallback const& HttpRequest::GetResponseCallback() const { return response_cb_; } } } diff --git a/src/kiwano-network/HttpResponse.hpp b/src/kiwano-network/HttpResponse.hpp index 24874db9..a2d043b0 100644 --- a/src/kiwano-network/HttpResponse.hpp +++ b/src/kiwano-network/HttpResponse.hpp @@ -31,29 +31,30 @@ namespace kiwano : public ObjectBase { public: - inline HttpResponse(HttpRequestPtr request) : request_(request), succeed_(false), response_code_(0) {} + HttpResponse(HttpRequestPtr request); - inline HttpRequestPtr GetRequest() const { return request_; } + // 获取请求 + HttpRequestPtr GetRequest() const; - inline void SetSucceed(bool succeed) { succeed_ = succeed; } + // 响应状态 + bool IsSucceed() const; + void SetSucceed(bool succeed); - inline bool IsSucceed() const { return succeed_; } + // 响应状态码 + long GetResponseCode() const; + void SetResponseCode(long response_code); - inline void SetResponseCode(long response_code) { response_code_ = response_code; } + // 响应头 + String GetHeader() const; + void SetHeader(String const& response_header); - inline long GetResponseCode() const { return response_code_; } + // 响应数据 + String const& GetData() const; + void SetData(String const& response_data); - inline void SetHeader(String const& response_header) { response_header_ = response_header; } - - inline String GetHeader() const { return response_header_; } - - inline void SetData(String const& response_data) { response_data_ = response_data; } - - inline String const& GetData() const { return response_data_; } - - inline void SetError(String const& error_buffer) { error_buffer_ = error_buffer; } - - inline String const& GetError() const { return error_buffer_; } + // 错误信息 + String const& GetError() const; + void SetError(String const& error_buffer); protected: bool succeed_; @@ -64,5 +65,29 @@ namespace kiwano String response_data_; String error_buffer_; }; + + inline HttpResponse::HttpResponse(HttpRequestPtr request) : request_(request), succeed_(false), response_code_(0) {} + + inline HttpRequestPtr HttpResponse::GetRequest() const { return request_; } + + inline void HttpResponse::SetSucceed(bool succeed) { succeed_ = succeed; } + + inline bool HttpResponse::IsSucceed() const { return succeed_; } + + inline void HttpResponse::SetResponseCode(long response_code) { response_code_ = response_code; } + + inline long HttpResponse::GetResponseCode() const { return response_code_; } + + inline void HttpResponse::SetHeader(String const& response_header) { response_header_ = response_header; } + + inline String HttpResponse::GetHeader() const { return response_header_; } + + inline void HttpResponse::SetData(String const& response_data) { response_data_ = response_data; } + + inline String const& HttpResponse::GetData() const { return response_data_; } + + inline void HttpResponse::SetError(String const& error_buffer) { error_buffer_ = error_buffer; } + + inline String const& HttpResponse::GetError() const { return error_buffer_; } } } diff --git a/src/kiwano/2d/Actor.cpp b/src/kiwano/2d/Actor.cpp index 9319a8d4..3570d728 100644 --- a/src/kiwano/2d/Actor.cpp +++ b/src/kiwano/2d/Actor.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include namespace kiwano diff --git a/src/kiwano/2d/Actor.h b/src/kiwano/2d/Actor.h index b1e6cbab..8b0e97fd 100644 --- a/src/kiwano/2d/Actor.h +++ b/src/kiwano/2d/Actor.h @@ -22,8 +22,8 @@ #include #include #include -#include -#include +#include +#include namespace kiwano { diff --git a/src/kiwano/2d/Canvas.cpp b/src/kiwano/2d/Canvas.cpp index c4852768..cbb6b60e 100644 --- a/src/kiwano/2d/Canvas.cpp +++ b/src/kiwano/2d/Canvas.cpp @@ -19,7 +19,7 @@ // THE SOFTWARE. #include -#include +#include #include namespace kiwano diff --git a/src/kiwano/2d/DebugActor.cpp b/src/kiwano/2d/DebugActor.cpp index e6f33be9..5d53e1fa 100644 --- a/src/kiwano/2d/DebugActor.cpp +++ b/src/kiwano/2d/DebugActor.cpp @@ -87,7 +87,7 @@ namespace kiwano KGE_NOT_USED(dt); frame_time_.push_back(Time::Now()); - while (frame_time_.back() - frame_time_.front() >= time::Sec) + while (frame_time_.back() - frame_time_.front() >= Duration::Second) { frame_time_.erase(frame_time_.begin()); } diff --git a/src/kiwano/2d/Frame.h b/src/kiwano/2d/Frame.h index 881b3c05..f9b1a947 100644 --- a/src/kiwano/2d/Frame.h +++ b/src/kiwano/2d/Frame.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include #include namespace kiwano diff --git a/src/kiwano/2d/FrameSequence.cpp b/src/kiwano/2d/FrameSequence.cpp index 0bc00b5e..c72e2d01 100644 --- a/src/kiwano/2d/FrameSequence.cpp +++ b/src/kiwano/2d/FrameSequence.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include namespace kiwano { diff --git a/src/kiwano/2d/GifSprite.cpp b/src/kiwano/2d/GifSprite.cpp index 1ff49add..b8dc4e64 100644 --- a/src/kiwano/2d/GifSprite.cpp +++ b/src/kiwano/2d/GifSprite.cpp @@ -19,7 +19,7 @@ // THE SOFTWARE. #include -#include +#include #include #include diff --git a/src/kiwano/2d/GifSprite.h b/src/kiwano/2d/GifSprite.h index bc5c4cb8..10ebb933 100644 --- a/src/kiwano/2d/GifSprite.h +++ b/src/kiwano/2d/GifSprite.h @@ -20,7 +20,7 @@ #pragma once #include -#include +#include #include #include diff --git a/src/kiwano/2d/ShapeActor.cpp b/src/kiwano/2d/ShapeActor.cpp index 759e12e7..f6b9b809 100644 --- a/src/kiwano/2d/ShapeActor.cpp +++ b/src/kiwano/2d/ShapeActor.cpp @@ -19,7 +19,7 @@ // THE SOFTWARE. #include -#include +#include #include namespace kiwano diff --git a/src/kiwano/2d/Stage.cpp b/src/kiwano/2d/Stage.cpp index d3f12fbd..6dcaac31 100644 --- a/src/kiwano/2d/Stage.cpp +++ b/src/kiwano/2d/Stage.cpp @@ -19,7 +19,7 @@ // THE SOFTWARE. #include -#include +#include #include namespace kiwano diff --git a/src/kiwano/2d/Text.cpp b/src/kiwano/2d/Text.cpp index 47d60b9a..5f3fa022 100644 --- a/src/kiwano/2d/Text.cpp +++ b/src/kiwano/2d/Text.cpp @@ -19,7 +19,7 @@ // THE SOFTWARE. #include -#include +#include #include namespace kiwano diff --git a/src/kiwano/2d/Transition.cpp b/src/kiwano/2d/Transition.cpp index 5dc4b8a3..5000a306 100644 --- a/src/kiwano/2d/Transition.cpp +++ b/src/kiwano/2d/Transition.cpp @@ -21,8 +21,8 @@ #include #include #include -#include -#include +#include +#include #include namespace kiwano diff --git a/src/kiwano/2d/action/ActionGroup.cpp b/src/kiwano/2d/action/ActionGroup.cpp index d2e53e52..a913ae20 100644 --- a/src/kiwano/2d/action/ActionGroup.cpp +++ b/src/kiwano/2d/action/ActionGroup.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include namespace kiwano { diff --git a/src/kiwano/2d/action/ActionHelper.h b/src/kiwano/2d/action/ActionHelper.h index 36eef88c..e2ea18e9 100644 --- a/src/kiwano/2d/action/ActionHelper.h +++ b/src/kiwano/2d/action/ActionHelper.h @@ -30,71 +30,71 @@ namespace kiwano struct ActionHelper { // 设置循环次数 - inline ActionHelper& SetLoops(int loops) { base->SetLoops(loops); return (*this); } + inline ActionHelper& SetLoops(int loops) { core->SetLoops(loops); return (*this); } // 设置动作延迟 - inline ActionHelper& SetDelay(Duration delay) { base->SetDelay(delay); return (*this); } + inline ActionHelper& SetDelay(Duration delay) { core->SetDelay(delay); return (*this); } // 设置动作结束回调函数 - inline ActionHelper& SetDoneCallback(ActionCallback const& cb) { base->SetDoneCallback(cb); return (*this); } + inline ActionHelper& SetDoneCallback(ActionCallback const& cb) { core->SetDoneCallback(cb); return (*this); } // 设置动作循环结束时的回调函数 - inline ActionHelper& SetLoopDoneCallback(ActionCallback const& cb) { base->SetLoopDoneCallback(cb); return (*this); } + inline ActionHelper& SetLoopDoneCallback(ActionCallback const& cb) { core->SetLoopDoneCallback(cb); return (*this); } // 动作结束时移除目标角色 - inline ActionHelper& RemoveTargetWhenDone() { base->RemoveTargetWhenDone(); return (*this); } + inline ActionHelper& RemoveTargetWhenDone() { core->RemoveTargetWhenDone(); return (*this); } // 设置名称 - inline ActionHelper& SetName(String const& name) { base->SetName(name); return (*this); } + inline ActionHelper& SetName(String const& name) { core->SetName(name); return (*this); } // 获取指针 - inline ActionPtr Get() const { return base; } + inline ActionPtr Get() const { return core; } - inline ActionHelper(ActionPtr base) : base(base) {} + inline ActionHelper(ActionPtr core) : core(core) {} - inline operator ActionPtr() const { return base; } + inline operator ActionPtr() const { return core; } protected: - ActionPtr base; + ActionPtr core; }; struct TweenHelper { // 设置动画持续时长 - inline TweenHelper& SetDuration(Duration dur) { base->SetDuration(dur); return (*this); } + inline TweenHelper& SetDuration(Duration dur) { core->SetDuration(dur); return (*this); } // 设置循环次数 - inline TweenHelper& SetLoops(int loops) { base->SetLoops(loops); return (*this); } + inline TweenHelper& SetLoops(int loops) { core->SetLoops(loops); return (*this); } // 设置缓动函数 - inline TweenHelper& SetEaseFunc(EaseFunc ease) { base->SetEaseFunc(ease); return (*this); } + inline TweenHelper& SetEaseFunc(EaseFunc ease) { core->SetEaseFunc(ease); return (*this); } // 设置动作延迟 - inline TweenHelper& SetDelay(Duration delay) { base->SetDelay(delay); return (*this); } + inline TweenHelper& SetDelay(Duration delay) { core->SetDelay(delay); return (*this); } // 设置动作结束回调函数 - inline TweenHelper& SetDoneCallback(ActionCallback const& cb) { base->SetDoneCallback(cb); return (*this); } + inline TweenHelper& SetDoneCallback(ActionCallback const& cb) { core->SetDoneCallback(cb); return (*this); } // 设置动作循环结束时的回调函数 - inline TweenHelper& SetLoopDoneCallback(ActionCallback const& cb) { base->SetLoopDoneCallback(cb); return (*this); } + inline TweenHelper& SetLoopDoneCallback(ActionCallback const& cb) { core->SetLoopDoneCallback(cb); return (*this); } // 动作结束时移除目标角色 - inline TweenHelper& RemoveTargetWhenDone() { base->RemoveTargetWhenDone(); return (*this); } + inline TweenHelper& RemoveTargetWhenDone() { core->RemoveTargetWhenDone(); return (*this); } // 设置名称 - inline TweenHelper& SetName(String const& name) { base->SetName(name); return (*this); } + inline TweenHelper& SetName(String const& name) { core->SetName(name); return (*this); } // 获取指针 - inline ActionTweenPtr Get() const { return base; } + inline ActionTweenPtr Get() const { return core; } - inline TweenHelper(ActionTweenPtr base) : base(base) {} + inline TweenHelper(ActionTweenPtr core) : core(core) {} - inline operator ActionPtr() const { return base; } + inline operator ActionPtr() const { return core; } - inline operator ActionTweenPtr() const { return base; } + inline operator ActionTweenPtr() const { return core; } protected: - ActionTweenPtr base; + ActionTweenPtr core; }; // Tween actions helper diff --git a/src/kiwano/2d/action/ActionManager.cpp b/src/kiwano/2d/action/ActionManager.cpp index 52b603f1..d4a790c0 100644 --- a/src/kiwano/2d/action/ActionManager.cpp +++ b/src/kiwano/2d/action/ActionManager.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include namespace kiwano { diff --git a/src/kiwano/2d/action/ActionTween.h b/src/kiwano/2d/action/ActionTween.h index 83eef1cc..27a50115 100644 --- a/src/kiwano/2d/action/ActionTween.h +++ b/src/kiwano/2d/action/ActionTween.h @@ -20,7 +20,7 @@ #pragma once #include -#include +#include namespace kiwano { diff --git a/src/kiwano/2d/include-forwards.h b/src/kiwano/2d/include-forwards.h index 00dd6d33..c4ef9e6e 100644 --- a/src/kiwano/2d/include-forwards.h +++ b/src/kiwano/2d/include-forwards.h @@ -19,11 +19,11 @@ // THE SOFTWARE. #pragma once -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include diff --git a/src/kiwano/base/time.cpp b/src/kiwano/base/time.cpp deleted file mode 100644 index 5010ef5c..00000000 --- a/src/kiwano/base/time.cpp +++ /dev/null @@ -1,426 +0,0 @@ -// Copyright (c) 2016-2018 Kiwano - Nomango -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#include -#include - -#include -#include - -namespace kiwano -{ - namespace time - { - //------------------------------------------------------- - // Time - //------------------------------------------------------- - - Time::Time() - : dur_(0) - { - } - - Time::Time(long dur) - : dur_(dur) - { - } - - const Time Time::operator+(const Duration & dur) const - { - return Time{ dur_ + dur.Milliseconds() }; - } - - const Time Time::operator-(const Duration & dur) const - { - return Time{ dur_ - dur.Milliseconds() }; - } - - Time & Time::operator+=(const Duration & other) - { - dur_ += other.Milliseconds(); - return (*this); - } - - Time & Time::operator-=(const Duration &other) - { - dur_ -= other.Milliseconds(); - return (*this); - } - - const Duration Time::operator-(const Time & other) const - { - return Duration(dur_ - other.dur_); - } - - Time Time::Now() noexcept - { - static LARGE_INTEGER freq = {}; - if (freq.QuadPart == 0LL) - { - // the Function will always succceed on systems that run Windows XP or later - QueryPerformanceFrequency(&freq); - } - - LARGE_INTEGER count; - QueryPerformanceCounter(&count); - - const long long whole = (count.QuadPart / freq.QuadPart) * 1000LL; - const long long part = (count.QuadPart % freq.QuadPart) * 1000LL / freq.QuadPart; - return Time{ static_cast(whole + part) }; - } - - - //------------------------------------------------------- - // Duration - //------------------------------------------------------- - - const Duration Ms = 1L; - const Duration Sec = 1000 * Ms; - const Duration Min = 60 * Sec; - const Duration Hour = 60 * Min; - - namespace - { - const auto duration_regex = std::wregex(LR"(^[-+]?([0-9]*(\.[0-9]*)?(h|m|s|ms)+)+$)"); - - typedef std::unordered_map UnitMap; - const auto unit_map = UnitMap - { - {L"ms", Ms}, - {L"s", Sec}, - {L"m", Min}, - {L"h", Hour} - }; - } - - Duration::Duration() - : milliseconds_(0) - { - } - - Duration::Duration(long milliseconds) - : milliseconds_(milliseconds) - { - } - - float Duration::Seconds() const - { - long sec = milliseconds_ / Sec.milliseconds_; - long ms = milliseconds_ % Sec.milliseconds_; - return static_cast(sec) + static_cast(ms) / 1000.f; - } - - float Duration::Minutes() const - { - long min = milliseconds_ / Min.milliseconds_; - long ms = milliseconds_ % Min.milliseconds_; - return static_cast(min) + static_cast(ms) / (60 * 1000.f); - } - - float Duration::Hours() const - { - long hour = milliseconds_ / Hour.milliseconds_; - long ms = milliseconds_ % Hour.milliseconds_; - return static_cast(hour) + static_cast(ms) / (60 * 60 * 1000.f); - } - - String kiwano::time::Duration::ToString() const - { - if (IsZero()) - { - return String(L"0s"); - } - - String result; - long total_ms = milliseconds_; - if (total_ms < 0) - { - result.append(L"-"); - total_ms = -total_ms; - } - - long hour = total_ms / Hour.milliseconds_; - long min = total_ms / Min.milliseconds_ - hour * 60; - long sec = total_ms / Sec.milliseconds_ - (hour * 60 * 60 + min * 60); - long ms = total_ms % Sec.milliseconds_; - - if (hour) - { - result.append(String::parse(hour)).append(L"h"); - result.append(String::parse(min)).append(L"m"); - } - else if(min) - { - result.append(String::parse(min)).append(L"m"); - } - - if (ms != 0) - { - result.append(String::parse(static_cast(sec) + static_cast(ms) / 1000.f)) - .append(L"s"); - } - else if (sec != 0) - { - result.append(String::parse(sec)).append(L"s"); - } - return result; - } - - bool Duration::operator==(const Duration & other) const - { - return milliseconds_ == other.milliseconds_; - } - - bool Duration::operator!=(const Duration & other) const - { - return milliseconds_ != other.milliseconds_; - } - - bool Duration::operator>(const Duration & other) const - { - return milliseconds_ > other.milliseconds_; - } - - bool Duration::operator>=(const Duration & other) const - { - return milliseconds_ >= other.milliseconds_; - } - - bool Duration::operator<(const Duration & other) const - { - return milliseconds_ < other.milliseconds_; - } - - bool Duration::operator<=(const Duration & other) const - { - return milliseconds_ <= other.milliseconds_; - } - - float kiwano::time::Duration::operator/(const Duration & other) const - { - return static_cast(milliseconds_) / other.milliseconds_; - } - - const Duration Duration::operator+(const Duration & other) const - { - return Duration(milliseconds_ + other.milliseconds_); - } - - const Duration Duration::operator-(const Duration & other) const - { - return Duration(milliseconds_ - other.milliseconds_); - } - - const Duration Duration::operator-() const - { - return Duration(-milliseconds_); - } - - const Duration Duration::operator*(int val) const - { - return Duration(milliseconds_ * val); - } - - const Duration kiwano::time::Duration::operator*(unsigned long long val) const - { - return Duration(static_cast(milliseconds_ * val)); - } - - const Duration Duration::operator*(float val) const - { - return Duration(static_cast(milliseconds_ * val)); - } - - const Duration Duration::operator*(double val) const - { - return Duration(static_cast(milliseconds_ * val)); - } - - const Duration Duration::operator*(long double val) const - { - return Duration(static_cast(milliseconds_ * val)); - } - - const Duration Duration::operator/(int val) const - { - return Duration(milliseconds_ / val); - } - - const Duration Duration::operator/(float val) const - { - return Duration(static_cast(milliseconds_ / val)); - } - - const Duration Duration::operator/(double val) const - { - return Duration(static_cast(milliseconds_ / val)); - } - - Duration & Duration::operator+=(const Duration &other) - { - milliseconds_ += other.milliseconds_; - return (*this); - } - - Duration & Duration::operator-=(const Duration &other) - { - milliseconds_ -= other.milliseconds_; - return (*this); - } - - Duration & Duration::operator*=(int val) - { - milliseconds_ *= val; - return (*this); - } - - Duration & Duration::operator/=(int val) - { - milliseconds_ = static_cast(milliseconds_ / val); - return (*this); - } - - Duration & Duration::operator*=(float val) - { - milliseconds_ = static_cast(milliseconds_ * val); - return (*this); - } - - Duration & Duration::operator/=(float val) - { - milliseconds_ = static_cast(milliseconds_ / val); - return (*this); - } - - Duration & Duration::operator*=(double val) - { - milliseconds_ = static_cast(milliseconds_ * val); - return (*this); - } - - Duration & Duration::operator/=(double val) - { - milliseconds_ = static_cast(milliseconds_ / val); - return (*this); - } - - const Duration kiwano::time::operator*(int val, const Duration & dur) - { - return dur * val; - } - - const Duration kiwano::time::operator/(int val, const Duration & dur) - { - return dur / val; - } - - const Duration kiwano::time::operator*(float val, const Duration & dur) - { - return dur * val; - } - - const Duration kiwano::time::operator/(float val, const Duration & dur) - { - return dur / val; - } - - const Duration kiwano::time::operator*(double val, const Duration & dur) - { - return dur * val; - } - - const Duration kiwano::time::operator/(double val, const Duration & dur) - { - return dur / val; - } - - const Duration kiwano::time::operator*(long double val, const Duration & dur) - { - return dur * val; - } - - Duration Duration::Parse(const String& str) - { - bool negative = false; - size_t len = str.length(); - size_t pos = 0; - Duration ret; - - if (!std::regex_match(str.c_str(), duration_regex)) - { - KGE_ERROR_LOG(L"Duration::Parse failed, invalid duration"); - return ret; - } - - if (str.empty() || str == L"0") { return ret; } - - // 符号位 - if (str[0] == L'-' || str[0] == L'+') - { - negative = (str[0] == L'-'); - pos++; - } - - while (pos < len) - { - // 数值 - size_t i = pos; - for (; i < len; ++i) - { - wchar_t ch = str[i]; - if (!(ch == L'.' || L'0' <= ch && ch <= L'9')) - { - break; - } - } - - String num_str = str.substr(pos, i - pos); - pos = i; - - KGE_ASSERT(!(num_str.empty() || num_str == L".") && "Duration::Parse failed, invalid duration"); - - // 单位 - for (; i < len; ++i) - { - wchar_t ch = str[i]; - if (ch == L'.' || L'0' <= ch && ch <= L'9') - { - break; - } - } - - String unit_str = str.substr(pos, i - pos); - pos = i; - - KGE_ASSERT(unit_map.find(unit_str) != unit_map.end() && "Duration::Parse failed, invalid duration"); - - double num = std::wcstod(num_str.c_str(), nullptr); - Duration unit = unit_map.at(unit_str); - ret += unit * num; - } - - if (negative) - { - ret = -ret; - } - return ret; - } - } -} diff --git a/src/kiwano/base/time.h b/src/kiwano/base/time.h deleted file mode 100644 index 1457db43..00000000 --- a/src/kiwano/base/time.h +++ /dev/null @@ -1,247 +0,0 @@ -// Copyright (c) 2016-2018 Kiwano - Nomango -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#pragma once -#include -#include - -#include -#include - -namespace kiwano -{ - namespace time - { - // 时间段 - // - // 时间段表示法: - // 5 秒: time::Sec * 5 - // 1.5 小时: time::Hour * 1.5 - // 3 小时 45 分 15 秒: time::Hour * 3 + time::Min * 45 + time::Sec * 15 - // 在 VS2015 及更高版本可以使用 time literals: - // 5 秒: 5_s - // 1.5 小时: 1.5_h - // 3 小时 45 分 15 秒: 3_h + 45_m + 15_s - // - struct KGE_API Duration - { - Duration(); - - Duration( - long milliseconds - ); - - // 转化为毫秒 - inline long Milliseconds() const { return milliseconds_; } - - // 转化为秒 - float Seconds() const; - - // 转化为分钟 - float Minutes() const; - - // 转化为小时 - float Hours() const; - - // 时长是否是零 - inline bool IsZero() const { return milliseconds_ == 0LL; } - - inline void SetMilliseconds(long ms) { milliseconds_ = ms; } - - inline void SetSeconds(float seconds) { milliseconds_ = static_cast(seconds * 1000.f); } - - inline void SetMinutes(float minutes) { milliseconds_ = static_cast(minutes * 60 * 1000.f); } - - inline void SetHours(float hours) { milliseconds_ = static_cast(hours * 60 * 60 * 1000.f); } - - // 转为字符串 - String ToString() const; - - inline operator bool() const { return !IsZero(); } - - bool operator== (const Duration &) const; - bool operator!= (const Duration &) const; - bool operator> (const Duration &) const; - bool operator>= (const Duration &) const; - bool operator< (const Duration &) const; - bool operator<= (const Duration &) const; - - float operator / (const Duration &) const; - - const Duration operator + (const Duration &) const; - const Duration operator - (const Duration &) const; - const Duration operator - () const; - const Duration operator * (int) const; - const Duration operator * (unsigned long long) const; - const Duration operator * (float) const; - const Duration operator * (double) const; - const Duration operator * (long double) const; - const Duration operator / (int) const; - const Duration operator / (float) const; - const Duration operator / (double) const; - - Duration& operator += (const Duration &); - Duration& operator -= (const Duration &); - Duration& operator *= (int); - Duration& operator *= (float); - Duration& operator *= (double); - Duration& operator /= (int); - Duration& operator /= (float); - Duration& operator /= (double); - - friend const Duration operator* (int, const Duration &); - friend const Duration operator* (float, const Duration &); - friend const Duration operator* (double, const Duration &); - friend const Duration operator* (long double, const Duration &); - friend const Duration operator/ (int, const Duration &); - friend const Duration operator/ (float, const Duration &); - friend const Duration operator/ (double, const Duration &); - - public: - // 时间段格式化 - // - // 时间段字符串允许是有符号的浮点数, 并且带有时间单位后缀 - // 例如: "300ms", "-1.5h", "2h45m" - // 允许的时间单位有 "ms", "s", "m", "h" - static Duration Parse(const String& parse_str); - - template - friend inline std::basic_ostream<_Char>& operator<<(std::basic_ostream<_Char>& out, const Duration& dur) - { - return out << dur.ToString(); - } - - template - friend inline std::basic_istream<_Char>& operator>>(std::basic_istream<_Char>& in, Duration& dur) - { - String str; - if (in >> str) - { - dur = Duration::Parse(str); - } - return in; - } - - private: - long milliseconds_; - }; - - /* 预定义的时间段 */ - KGE_API extern const Duration Ms; // 毫秒 - KGE_API extern const Duration Sec; // 秒 - KGE_API extern const Duration Min; // 分钟 - KGE_API extern const Duration Hour; // 小时 - - - // 时间 - // - // 获取当前时间: Time now = Time::Now(); - // 两时间相减, 得到一个 Duration 对象, 例如: - // Time t1, t2; - // int ms = (t2 - t1).Milliseconds(); // 获取两时间相差的毫秒数 - // - struct KGE_API Time - { - Time(); - - Time(long); - - // 是否是零时 - inline bool IsZero() const { return dur_ == 0; } - - const Time operator + (const Duration &) const; - const Time operator - (const Duration &) const; - - Time& operator += (const Duration &); - Time& operator -= (const Duration &); - - const Duration operator - (const Time &) const; - - public: - // 获取当前时间 - // 由于该时间点基于系统启动时间开始计算, 所以无法格式化该时间, - // 也无法获得该时间的 Unix 时间戳 - static Time Now() noexcept; - - private: - long dur_; - }; - } -} - -namespace kiwano -{ - using namespace time; -} - -#if KGE_VS_VER > KGE_VS_2013 - -namespace kiwano -{ - inline namespace literals - { - inline const kiwano::time::Duration operator "" _ms(long double val) - { - return kiwano::time::Ms * val; - } - - inline const kiwano::time::Duration operator "" _s(long double val) - { - return kiwano::time::Sec * val; - } - - inline const kiwano::time::Duration operator "" _m(long double val) - { - return kiwano::time::Min * val; - } - - inline const kiwano::time::Duration operator "" _h(long double val) - { - return kiwano::time::Hour * val; - } - - inline const kiwano::time::Duration operator "" _ms(unsigned long long val) - { - return kiwano::time::Ms * val; - } - - inline const kiwano::time::Duration operator "" _s(unsigned long long val) - { - return kiwano::time::Sec * val; - } - - inline const kiwano::time::Duration operator "" _m(unsigned long long val) - { - return kiwano::time::Min * val; - } - - inline const kiwano::time::Duration operator "" _h(unsigned long long val) - { - return kiwano::time::Hour * val; - } - } - - namespace time - { - using namespace kiwano::literals; - } -} - -#endif diff --git a/src/kiwano/core/any.hpp b/src/kiwano/common/any.hpp similarity index 98% rename from src/kiwano/core/any.hpp rename to src/kiwano/common/any.hpp index 81d66390..0b3dfd6d 100644 --- a/src/kiwano/core/any.hpp +++ b/src/kiwano/common/any.hpp @@ -26,7 +26,7 @@ namespace kiwano { -namespace core +namespace common { class bad_any_cast : public std::exception @@ -519,13 +519,13 @@ _Ty any_cast(any&& a) return static_cast<_Ty>(std::move(*ptr)); } -} // namespace core +} // namespace common } // namespace kiwano namespace std { - inline void swap(kiwano::core::any& lhs, kiwano::core::any& rhs) noexcept + inline void swap(kiwano::common::any& lhs, kiwano::common::any& rhs) noexcept { lhs.swap(rhs); } diff --git a/src/kiwano/core/basic_json.hpp b/src/kiwano/common/basic_json.hpp similarity index 99% rename from src/kiwano/core/basic_json.hpp rename to src/kiwano/common/basic_json.hpp index 05080c47..b72653ce 100644 --- a/src/kiwano/core/basic_json.hpp +++ b/src/kiwano/common/basic_json.hpp @@ -28,7 +28,7 @@ namespace kiwano { -namespace core +namespace common { // @@ -1602,14 +1602,14 @@ namespace __json_detail if ((std::isdigit(current) && current != '0') || (current == '-') || (current == '+')) { - float_type base = 10; + float_type core = 10; if (current == '+') { read_next(); } else if (current == '-') { - base = static_cast(0.1); + core = static_cast(0.1); read_next(); } @@ -1620,9 +1620,9 @@ namespace __json_detail } float_type power = 1; - for (; exponent; exponent >>= 1, base *= base) + for (; exponent; exponent >>= 1, core *= core) if (exponent & 1) - power *= base; + power *= core; number_value *= power; return token_type::value_float; @@ -2728,7 +2728,7 @@ private: __json_detail::json_value value_; }; -} // namespace core +} // namespace common } // namespace kiwano diff --git a/src/kiwano/core/core.h b/src/kiwano/common/common.h similarity index 77% rename from src/kiwano/core/core.h rename to src/kiwano/common/common.h index be374b02..c09b8cd4 100644 --- a/src/kiwano/core/core.h +++ b/src/kiwano/common/common.h @@ -28,24 +28,24 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace kiwano { - using String = kiwano::core::wstring; + using String = kiwano::common::wstring; using StringStream = std::wstringstream; template - using Vector = kiwano::core::vector<_Ty, _Args...>; + using Vector = kiwano::common::vector<_Ty, _Args...>; template using List = std::list<_Ty, _Args...>; @@ -72,21 +72,21 @@ namespace kiwano using UnorderedMap = std::unordered_map<_Kty, _Ty, _Args...>; template - using Function = kiwano::core::function<_FuncTy>; + using Function = kiwano::common::function<_FuncTy>; - using Any = kiwano::core::any; + using Any = kiwano::common::any; - using Json = kiwano::core::basic_json; template - using Singleton = core::singleton<_Ty>; + using Singleton = common::singleton<_Ty>; template - using IntrusiveList = core::intrusive_list<_Ty>; + using IntrusiveList = common::intrusive_list<_Ty>; template - using IntrusiveListItem = core::intrusive_list_item<_Ty>; + using IntrusiveListItem = common::intrusive_list_item<_Ty>; } namespace std diff --git a/src/kiwano/core/function.hpp b/src/kiwano/common/function.hpp similarity index 95% rename from src/kiwano/core/function.hpp rename to src/kiwano/common/function.hpp index 3a686226..c561db6f 100644 --- a/src/kiwano/core/function.hpp +++ b/src/kiwano/common/function.hpp @@ -25,7 +25,7 @@ namespace kiwano { -namespace core +namespace common { // // function is a light weight ::std::function<>-like class @@ -321,7 +321,7 @@ private: __function_detail::callable<_Ret, _Args...>* callable_; }; -} // namespace core +} // namespace common } // namespace kiwano @@ -335,9 +335,9 @@ namespace kiwano typename _Ret, typename... _Args > - inline core::function<_Ret(_Args...)> Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...)) + inline common::function<_Ret(_Args...)> Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...)) { - return core::function<_Ret(_Args...)>(ptr, func); + return common::function<_Ret(_Args...)>(ptr, func); } template - inline core::function<_Ret(_Args...)> Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...) const) + inline common::function<_Ret(_Args...)> Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...) const) { - return core::function<_Ret(_Args...)>(ptr, func); + return common::function<_Ret(_Args...)>(ptr, func); } } diff --git a/src/kiwano/core/intrusive_list.hpp b/src/kiwano/common/intrusive_list.hpp similarity index 98% rename from src/kiwano/core/intrusive_list.hpp rename to src/kiwano/common/intrusive_list.hpp index 4ce55f9f..0e49d091 100644 --- a/src/kiwano/core/intrusive_list.hpp +++ b/src/kiwano/common/intrusive_list.hpp @@ -32,7 +32,7 @@ namespace kiwano { -namespace core +namespace common { template @@ -261,7 +261,7 @@ private: // disable warning 4996 using _Unchecked_type = _Ty; - inline iterator_impl(value_type base = nullptr, bool is_end = false) : base_(base), is_end_(is_end) {} + inline iterator_impl(value_type core = nullptr, bool is_end = false) : base_(core), is_end_(is_end) {} inline _Ty operator*() const { KGE_ASSERT(base_); return static_cast<_Ty>(const_cast(base_)); } inline iterator_impl& operator++() { KGE_ASSERT(base_ && !is_end_); value_type next = base_->next_item(); if (next) base_ = next; else is_end_ = true; return (*this);} @@ -307,7 +307,7 @@ private: value_type last_; }; -} // namespace core +} // namespace common } // namespace kiwano diff --git a/src/kiwano/core/intrusive_ptr.hpp b/src/kiwano/common/intrusive_ptr.hpp similarity index 99% rename from src/kiwano/core/intrusive_ptr.hpp rename to src/kiwano/common/intrusive_ptr.hpp index 8a84e987..70aadb9c 100644 --- a/src/kiwano/core/intrusive_ptr.hpp +++ b/src/kiwano/common/intrusive_ptr.hpp @@ -26,7 +26,7 @@ namespace kiwano { -namespace core +namespace common { template @@ -141,6 +141,6 @@ inline void swap(intrusive_ptr<_Ty, manager_type>& lhs, intrusive_ptr<_Ty, manag lhs.swap(rhs); } -} // namespace core +} // namespace common } // namespace kiwano diff --git a/src/kiwano/core/noncopyable.hpp b/src/kiwano/common/noncopyable.hpp similarity index 97% rename from src/kiwano/core/noncopyable.hpp rename to src/kiwano/common/noncopyable.hpp index 741cf806..9328c7e7 100644 --- a/src/kiwano/core/noncopyable.hpp +++ b/src/kiwano/common/noncopyable.hpp @@ -22,7 +22,7 @@ namespace kiwano { -namespace core +namespace common { class noncopyable @@ -36,5 +36,5 @@ private: noncopyable& operator=(const noncopyable&) = delete; }; -} // namespace core +} // namespace common } // namespace kiwano diff --git a/src/kiwano/core/singleton.hpp b/src/kiwano/common/singleton.hpp similarity index 96% rename from src/kiwano/core/singleton.hpp rename to src/kiwano/common/singleton.hpp index be4aabd7..afc3fff4 100644 --- a/src/kiwano/core/singleton.hpp +++ b/src/kiwano/common/singleton.hpp @@ -27,13 +27,13 @@ #ifndef KGE_DECLARE_SINGLETON #define KGE_DECLARE_SINGLETON( CLASS ) \ - friend ::kiwano::core::singleton< CLASS >; \ + friend ::kiwano::common::singleton< CLASS >; \ friend typename std::unique_ptr< CLASS >::deleter_type #endif namespace kiwano { -namespace core +namespace common { template @@ -81,5 +81,5 @@ std::once_flag singleton<_Ty>::once_; template std::unique_ptr<_Ty> singleton<_Ty>::instance_; -} // namespace core +} // namespace common } // namespace kiwano diff --git a/src/kiwano/core/string.hpp b/src/kiwano/common/string.hpp similarity index 94% rename from src/kiwano/core/string.hpp rename to src/kiwano/common/string.hpp index e210387b..a34789e8 100644 --- a/src/kiwano/core/string.hpp +++ b/src/kiwano/common/string.hpp @@ -29,7 +29,7 @@ namespace kiwano { -namespace core +namespace common { // @@ -56,10 +56,10 @@ private: // disable warning 4996 using _Unchecked_type = _Ty; - inline iterator_impl(pointer base = nullptr) : base_(base) {} + inline iterator_impl(pointer core = nullptr) : base_(core) {} inline reference operator*() const { return *base_; } - inline pointer base() const { return base_; } + inline pointer core() const { return base_; } inline iterator_impl& operator++() { ++base_; return (*this); } inline iterator_impl operator++(int) { iterator_impl old = (*this); ++(*this); return old; } @@ -176,8 +176,8 @@ public: inline basic_string& assign(_Iter first, _Iter last) { assign_iter(first, last); return(*this); } basic_string& erase(size_type offset = 0, size_type count = npos); - iterator erase(const const_iterator where) { size_type off = where - cbegin(); erase(off, 1); return begin().base() + off; } - iterator erase(const const_iterator first, const const_iterator last) { size_type off = first - cbegin(); erase(first - cbegin(), last - first); return begin().base() + off; } + iterator erase(const const_iterator where) { size_type off = where - cbegin(); erase(off, 1); return begin().core() + off; } + iterator erase(const const_iterator first, const const_iterator last) { size_type off = first - cbegin(); erase(first - cbegin(), last - first); return begin().core() + off; } basic_string substr(size_type pos = 0, size_type count = npos) const { return basic_string(*this, pos, count); } @@ -186,7 +186,7 @@ public: basic_string& insert(size_type index, const basic_string& str, size_type off, size_type count = npos); inline basic_string& insert(size_type index, const char_type* s) { return insert(index, s, traits_type::length(s)); } inline basic_string& insert(size_type index, const basic_string& str) { return insert(index, str, 0, str.size()); } - inline iterator insert(const_iterator pos, size_type count, char_type ch) { size_type off = pos - cbegin(); insert(off, count, ch); return begin().base() + off; } + inline iterator insert(const_iterator pos, size_type count, char_type ch) { size_type off = pos - cbegin(); insert(off, count, ch); return begin().core() + off; } inline iterator insert(const_iterator pos, char_type ch) { return insert(pos, 1, ch); } inline void push_back(const char_type ch) { append(1, ch); } @@ -425,8 +425,8 @@ basic_string format_string(const wchar_t* const fmt, _Args&& ... args); // // string && wstring // -using string = ::kiwano::core::basic_string; -using wstring = ::kiwano::core::basic_string; +using string = ::kiwano::common::basic_string; +using wstring = ::kiwano::common::basic_string; inline string to_string(int val) { return to_basic_string(val); } @@ -450,7 +450,7 @@ inline wstring to_wstring(double val) { return to_basic_string(val); inline wstring to_wstring(long double val) { return to_basic_string(val); } -} // namespace core +} // namespace common } // namespace kiwano namespace kiwano @@ -515,7 +515,7 @@ namespace __string_details } } -namespace core +namespace common { template @@ -670,7 +670,7 @@ namespace core } size_ = count; - traits_type::move(str_, rhs.begin().base() + pos, size_); + traits_type::move(str_, rhs.begin().core() + pos, size_); traits_type::assign(str_[size_], value_type()); return (*this); } @@ -693,8 +693,8 @@ namespace core } size_type new_size = size_ - count; - iterator erase_at = begin().base() + offset; - traits_type::move(erase_at.base(), erase_at.base() + count, new_size - offset + 1); + iterator erase_at = begin().core() + offset; + traits_type::move(erase_at.core(), erase_at.core() + count, new_size - offset + 1); return (*this); } @@ -807,7 +807,7 @@ namespace core char_type* const insert_at = new_ptr + index; traits_type::move(new_ptr, old_ptr, index); // (0) - (index) - traits_type::move(insert_at, str.begin().base() + off, count); // (index) - (index + count) + traits_type::move(insert_at, str.begin().core() + off, count); // (index) - (index + count) traits_type::move(insert_at + count, old_ptr + index, suffix_size); // (index + count) - (old_size - index) deallocate(str_, old_capacity + 1); @@ -817,7 +817,7 @@ namespace core { char_type* const insert_at = old_ptr + index; traits_type::move(insert_at + count, old_ptr + index, suffix_size); - traits_type::move(insert_at, str.begin().base() + off, count); + traits_type::move(insert_at, str.begin().core() + off, count); } return (*this); @@ -880,7 +880,7 @@ namespace core char_type* new_str = allocate(new_cap); traits_type::move(new_str, str_, size_); - traits_type::move(new_str + size_, other.begin().base() + pos, count); + traits_type::move(new_str + size_, other.begin().core() + pos, count); traits_type::assign(new_str[new_size], value_type()); destroy(); @@ -948,7 +948,7 @@ namespace core if (offset >= size_) return basic_string<_CharTy>::npos; - const_iterator citer = traits_type::find(cbegin().base() + offset, size_, ch); + const_iterator citer = traits_type::find(cbegin().core() + offset, size_, ch); return citer ? (citer - cbegin()) : basic_string<_CharTy>::npos; } @@ -966,7 +966,7 @@ namespace core if (offset >= size_) return basic_string<_CharTy>::npos; - const_iterator citer = std::find_first_of(cbegin().base() + offset, cend().base(), str, str + count); + const_iterator citer = std::find_first_of(cbegin().core() + offset, cend().core(), str, str + count); return (citer != cend()) ? (citer - cbegin()) : basic_string<_CharTy>::npos; } @@ -977,7 +977,7 @@ namespace core return npos; const_reverse_iterator criter = std::find(crbegin(), crend(), ch); - return (criter != crend()) ? (criter.base() - cbegin()) : basic_string<_CharTy>::npos; + return (criter != crend()) ? (criter.core() - cbegin()) : basic_string<_CharTy>::npos; } template @@ -1090,7 +1090,7 @@ namespace core check_offset(pos); count = clamp_suffix_size(pos, count); - traits_type::move(cstr, cbegin().base() + pos, count); + traits_type::move(cstr, cbegin().core() + pos, count); return count; } @@ -1159,31 +1159,31 @@ namespace core // template - inline basic_string<_CharTy> basic_string<_CharTy>::parse(int val) { return ::kiwano::core::to_basic_string(val); } + inline basic_string<_CharTy> basic_string<_CharTy>::parse(int val) { return ::kiwano::common::to_basic_string(val); } template - inline basic_string<_CharTy> basic_string<_CharTy>::parse(unsigned int val) { return ::kiwano::core::to_basic_string(val); } + inline basic_string<_CharTy> basic_string<_CharTy>::parse(unsigned int val) { return ::kiwano::common::to_basic_string(val); } template - inline basic_string<_CharTy> basic_string<_CharTy>::parse(long val) { return ::kiwano::core::to_basic_string(val); } + inline basic_string<_CharTy> basic_string<_CharTy>::parse(long val) { return ::kiwano::common::to_basic_string(val); } template - inline basic_string<_CharTy> basic_string<_CharTy>::parse(unsigned long val) { return ::kiwano::core::to_basic_string(val); } + inline basic_string<_CharTy> basic_string<_CharTy>::parse(unsigned long val) { return ::kiwano::common::to_basic_string(val); } template - inline basic_string<_CharTy> basic_string<_CharTy>::parse(long long val) { return ::kiwano::core::to_basic_string(val); } + inline basic_string<_CharTy> basic_string<_CharTy>::parse(long long val) { return ::kiwano::common::to_basic_string(val); } template - inline basic_string<_CharTy> basic_string<_CharTy>::parse(unsigned long long val) { return ::kiwano::core::to_basic_string(val); } + inline basic_string<_CharTy> basic_string<_CharTy>::parse(unsigned long long val) { return ::kiwano::common::to_basic_string(val); } template - inline basic_string<_CharTy> basic_string<_CharTy>::parse(float val) { return ::kiwano::core::to_basic_string(val); } + inline basic_string<_CharTy> basic_string<_CharTy>::parse(float val) { return ::kiwano::common::to_basic_string(val); } template - inline basic_string<_CharTy> basic_string<_CharTy>::parse(double val) { return ::kiwano::core::to_basic_string(val); } + inline basic_string<_CharTy> basic_string<_CharTy>::parse(double val) { return ::kiwano::common::to_basic_string(val); } template - inline basic_string<_CharTy> basic_string<_CharTy>::parse(long double val) { return ::kiwano::core::to_basic_string(val); } + inline basic_string<_CharTy> basic_string<_CharTy>::parse(long double val) { return ::kiwano::common::to_basic_string(val); } // // details of basic_string::format @@ -1193,7 +1193,7 @@ namespace core template inline basic_string<_CharTy> basic_string<_CharTy>::format(const char_type* fmt, _Args&& ... args) { - return ::kiwano::core::format_string(fmt, std::forward<_Args>(args)...); + return ::kiwano::common::format_string(fmt, std::forward<_Args>(args)...); } // @@ -1527,8 +1527,8 @@ class string_convert enum : size_t { BUFFER_INCREASE = 8, BUFFER_MAX = 16 }; public: - using byte_string = ::kiwano::core::basic_string; - using wide_string = ::kiwano::core::basic_string<_Elem>; + using byte_string = ::kiwano::common::basic_string; + using wide_string = ::kiwano::common::basic_string<_Elem>; using codecvt_type = _Codecvt; using state_type = typename codecvt_type::state_type; using int_type = typename wide_string::traits_type::int_type; @@ -1702,25 +1702,25 @@ class chs_codecvt public: chs_codecvt() : codecvt_byname("chs") {} - static inline ::kiwano::core::wstring string_to_wide(::kiwano::core::string const& str) + static inline ::kiwano::common::wstring string_to_wide(::kiwano::common::string const& str) { string_convert conv; return conv.from_bytes(str); } - static inline ::kiwano::core::string wide_to_string(::kiwano::core::wstring const& str) + static inline ::kiwano::common::string wide_to_string(::kiwano::common::wstring const& str) { string_convert conv; return conv.to_bytes(str); } }; -inline ::kiwano::core::wstring string_to_wide(::kiwano::core::string const& str) +inline ::kiwano::common::wstring string_to_wide(::kiwano::common::string const& str) { return kiwano::chs_codecvt::string_to_wide(str); } -inline ::kiwano::core::string wide_to_string(::kiwano::core::wstring const& str) +inline ::kiwano::common::string wide_to_string(::kiwano::common::wstring const& str) { return kiwano::chs_codecvt::wide_to_string(str); } @@ -1730,18 +1730,18 @@ inline ::kiwano::core::string wide_to_string(::kiwano::core::wstring const& str) namespace std { template<> - struct hash<::kiwano::core::string> + struct hash<::kiwano::common::string> { - inline size_t operator()(const ::kiwano::core::string& key) const + inline size_t operator()(const ::kiwano::common::string& key) const { return key.hash(); } }; template<> - struct hash<::kiwano::core::wstring> + struct hash<::kiwano::common::wstring> { - inline size_t operator()(const ::kiwano::core::wstring& key) const + inline size_t operator()(const ::kiwano::common::wstring& key) const { return key.hash(); } @@ -1751,13 +1751,13 @@ namespace std namespace std { template<> - inline void swap<::kiwano::core::string>(::kiwano::core::string& lhs, ::kiwano::core::string& rhs) noexcept + inline void swap<::kiwano::common::string>(::kiwano::common::string& lhs, ::kiwano::common::string& rhs) noexcept { lhs.swap(rhs); } template<> - inline void swap<::kiwano::core::wstring>(::kiwano::core::wstring& lhs, ::kiwano::core::wstring& rhs) noexcept + inline void swap<::kiwano::common::wstring>(::kiwano::common::wstring& lhs, ::kiwano::common::wstring& rhs) noexcept { lhs.swap(rhs); } diff --git a/src/kiwano/core/vector.hpp b/src/kiwano/common/vector.hpp similarity index 99% rename from src/kiwano/core/vector.hpp rename to src/kiwano/common/vector.hpp index 0194c248..dc8f9e0d 100644 --- a/src/kiwano/core/vector.hpp +++ b/src/kiwano/common/vector.hpp @@ -25,7 +25,7 @@ namespace kiwano { -namespace core +namespace common { @@ -284,5 +284,5 @@ namespace __vector_details }; } -} // namespace core +} // namespace common } // namespace kiwano diff --git a/src/kiwano/base/AsyncTask.cpp b/src/kiwano/core/AsyncTask.cpp similarity index 98% rename from src/kiwano/base/AsyncTask.cpp rename to src/kiwano/core/AsyncTask.cpp index c33cbe17..119b91ff 100644 --- a/src/kiwano/base/AsyncTask.cpp +++ b/src/kiwano/core/AsyncTask.cpp @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include +#include #include namespace kiwano diff --git a/src/kiwano/base/AsyncTask.h b/src/kiwano/core/AsyncTask.h similarity index 98% rename from src/kiwano/base/AsyncTask.h rename to src/kiwano/core/AsyncTask.h index 2b0bac32..095f4bc7 100644 --- a/src/kiwano/base/AsyncTask.h +++ b/src/kiwano/core/AsyncTask.h @@ -22,7 +22,7 @@ #include #include -#include +#include namespace kiwano { diff --git a/src/kiwano/base/Component.cpp b/src/kiwano/core/Component.cpp similarity index 98% rename from src/kiwano/base/Component.cpp rename to src/kiwano/core/Component.cpp index 41e3b0ad..ed18c619 100644 --- a/src/kiwano/base/Component.cpp +++ b/src/kiwano/core/Component.cpp @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include +#include #define KGE_DEFINE_COMPONENT_FLAG(OFFSET) ( 0x01 << (OFFSET % 32) ) diff --git a/src/kiwano/base/Component.h b/src/kiwano/core/Component.h similarity index 98% rename from src/kiwano/base/Component.h rename to src/kiwano/core/Component.h index de531a91..8c556108 100644 --- a/src/kiwano/base/Component.h +++ b/src/kiwano/core/Component.h @@ -20,7 +20,7 @@ #pragma once #include -#include +#include namespace kiwano { diff --git a/src/kiwano/base/Director.cpp b/src/kiwano/core/Director.cpp similarity index 99% rename from src/kiwano/base/Director.cpp rename to src/kiwano/core/Director.cpp index d60ddad7..7d41966f 100644 --- a/src/kiwano/base/Director.cpp +++ b/src/kiwano/core/Director.cpp @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include +#include #include #include #include diff --git a/src/kiwano/base/Director.h b/src/kiwano/core/Director.h similarity index 98% rename from src/kiwano/base/Director.h rename to src/kiwano/core/Director.h index 7a338472..f96ca9b6 100644 --- a/src/kiwano/base/Director.h +++ b/src/kiwano/core/Director.h @@ -20,7 +20,7 @@ #pragma once #include -#include +#include namespace kiwano { diff --git a/src/kiwano/base/Event.cpp b/src/kiwano/core/Event.cpp similarity index 98% rename from src/kiwano/base/Event.cpp rename to src/kiwano/core/Event.cpp index 09e6d544..681d92ee 100644 --- a/src/kiwano/base/Event.cpp +++ b/src/kiwano/core/Event.cpp @@ -1,4 +1,4 @@ -#include +#include namespace kiwano { diff --git a/src/kiwano/base/Event.h b/src/kiwano/core/Event.h similarity index 98% rename from src/kiwano/base/Event.h rename to src/kiwano/core/Event.h index 77688fa0..c5e64394 100644 --- a/src/kiwano/base/Event.h +++ b/src/kiwano/core/Event.h @@ -19,9 +19,9 @@ // THE SOFTWARE. #pragma once -#include +#include #include -#include +#include namespace kiwano { @@ -49,6 +49,31 @@ namespace kiwano }; + namespace event + { + // 鼠标事件 + extern EventType MouseMove; // 移动 + extern EventType MouseDown; // 鼠标按下 + extern EventType MouseUp; // 鼠标抬起 + extern EventType MouseWheel; // 滚轮滚动 + extern EventType MouseHover; // 鼠标移入 + extern EventType MouseOut; // 鼠标移出 + extern EventType MouseClick; // 鼠标点击 + + // 按键事件 + extern EventType KeyDown; // 按键按下 + extern EventType KeyUp; // 按键抬起 + extern EventType KeyChar; // 输出字符 + + // 窗口消息 + extern EventType WindowMoved; // 窗口移动 + extern EventType WindowResized; // 窗口大小变化 + extern EventType WindowFocusChanged; // 获得或失去焦点 + extern EventType WindowTitleChanged; // 标题变化 + extern EventType WindowClosed; // 窗口被关闭 + } + + // 事件 class KGE_API Event { @@ -244,29 +269,4 @@ namespace kiwano WindowClosedEvent(); }; - - namespace event - { - // 鼠标事件 - extern EventType MouseMove; // 移动 - extern EventType MouseDown; // 鼠标按下 - extern EventType MouseUp; // 鼠标抬起 - extern EventType MouseWheel; // 滚轮滚动 - extern EventType MouseHover; // 鼠标移入 - extern EventType MouseOut; // 鼠标移出 - extern EventType MouseClick; // 鼠标点击 - - // 按键事件 - extern EventType KeyDown; // 按键按下 - extern EventType KeyUp; // 按键抬起 - extern EventType KeyChar; // 输出字符 - - // 窗口消息 - extern EventType WindowMoved; // 窗口移动 - extern EventType WindowResized; // 窗口大小变化 - extern EventType WindowFocusChanged; // 获得或失去焦点 - extern EventType WindowTitleChanged; // 标题变化 - extern EventType WindowClosed; // 窗口被关闭 - } - } diff --git a/src/kiwano/base/EventDispatcher.cpp b/src/kiwano/core/EventDispatcher.cpp similarity index 98% rename from src/kiwano/base/EventDispatcher.cpp rename to src/kiwano/core/EventDispatcher.cpp index e9a04d2a..222bd4b7 100644 --- a/src/kiwano/base/EventDispatcher.cpp +++ b/src/kiwano/core/EventDispatcher.cpp @@ -18,8 +18,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include -#include +#include +#include namespace kiwano { diff --git a/src/kiwano/base/EventDispatcher.h b/src/kiwano/core/EventDispatcher.h similarity index 98% rename from src/kiwano/base/EventDispatcher.h rename to src/kiwano/core/EventDispatcher.h index 971aa300..49147faf 100644 --- a/src/kiwano/base/EventDispatcher.h +++ b/src/kiwano/core/EventDispatcher.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include namespace kiwano { diff --git a/src/kiwano/base/EventListener.cpp b/src/kiwano/core/EventListener.cpp similarity index 97% rename from src/kiwano/base/EventListener.cpp rename to src/kiwano/core/EventListener.cpp index f856c94d..1250a80e 100644 --- a/src/kiwano/base/EventListener.cpp +++ b/src/kiwano/core/EventListener.cpp @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include namespace kiwano { diff --git a/src/kiwano/base/EventListener.h b/src/kiwano/core/EventListener.h similarity index 94% rename from src/kiwano/base/EventListener.h rename to src/kiwano/core/EventListener.h index 41612061..5c8f51c2 100644 --- a/src/kiwano/base/EventListener.h +++ b/src/kiwano/core/EventListener.h @@ -19,10 +19,10 @@ // THE SOFTWARE. #pragma once -#include -#include -#include -#include +#include +#include +#include +#include namespace kiwano { diff --git a/src/kiwano/base/Library.cpp b/src/kiwano/core/Library.cpp similarity index 98% rename from src/kiwano/base/Library.cpp rename to src/kiwano/core/Library.cpp index 6756fdab..1f4c0c94 100644 --- a/src/kiwano/base/Library.cpp +++ b/src/kiwano/core/Library.cpp @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include +#include namespace kiwano { diff --git a/src/kiwano/base/Library.h b/src/kiwano/core/Library.h similarity index 97% rename from src/kiwano/base/Library.h rename to src/kiwano/core/Library.h index e6b9f140..64aebf83 100644 --- a/src/kiwano/base/Library.h +++ b/src/kiwano/core/Library.h @@ -20,7 +20,7 @@ #pragma once #include -#include +#include namespace kiwano { diff --git a/src/kiwano/base/Logger.cpp b/src/kiwano/core/Logger.cpp similarity index 99% rename from src/kiwano/base/Logger.cpp rename to src/kiwano/core/Logger.cpp index 7454ab2a..cadc07de 100644 --- a/src/kiwano/base/Logger.cpp +++ b/src/kiwano/core/Logger.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include namespace { diff --git a/src/kiwano/base/Logger.h b/src/kiwano/core/Logger.h similarity index 99% rename from src/kiwano/base/Logger.h rename to src/kiwano/core/Logger.h index d7f7a3c7..9f4732e9 100644 --- a/src/kiwano/base/Logger.h +++ b/src/kiwano/core/Logger.h @@ -24,7 +24,7 @@ #include #include -#include +#include #ifndef KGE_LOG # ifdef KGE_DEBUG diff --git a/src/kiwano/base/ObjectBase.cpp b/src/kiwano/core/ObjectBase.cpp similarity index 98% rename from src/kiwano/base/ObjectBase.cpp rename to src/kiwano/core/ObjectBase.cpp index f0fc6729..ce4b7ff3 100644 --- a/src/kiwano/base/ObjectBase.cpp +++ b/src/kiwano/core/ObjectBase.cpp @@ -19,8 +19,8 @@ // THE SOFTWARE. #include -#include -#include +#include +#include namespace kiwano { diff --git a/src/kiwano/base/ObjectBase.h b/src/kiwano/core/ObjectBase.h similarity index 95% rename from src/kiwano/base/ObjectBase.h rename to src/kiwano/core/ObjectBase.h index 8f4d9b94..88a87500 100644 --- a/src/kiwano/base/ObjectBase.h +++ b/src/kiwano/core/ObjectBase.h @@ -20,9 +20,9 @@ #pragma once #include -#include -#include -#include +#include +#include +#include namespace kiwano { diff --git a/src/kiwano/base/RefCounter.hpp b/src/kiwano/core/RefCounter.hpp similarity index 95% rename from src/kiwano/base/RefCounter.hpp rename to src/kiwano/core/RefCounter.hpp index e4c7eb6e..14bfa5d2 100644 --- a/src/kiwano/base/RefCounter.hpp +++ b/src/kiwano/core/RefCounter.hpp @@ -20,12 +20,12 @@ #pragma once #include -#include +#include namespace kiwano { class KGE_API RefCounter - : protected core::noncopyable + : protected common::noncopyable { public: // 增加引用计数 diff --git a/src/kiwano/base/Resource.cpp b/src/kiwano/core/Resource.cpp similarity index 97% rename from src/kiwano/base/Resource.cpp rename to src/kiwano/core/Resource.cpp index 6dfc3ceb..f2c7c8af 100644 --- a/src/kiwano/base/Resource.cpp +++ b/src/kiwano/core/Resource.cpp @@ -20,8 +20,8 @@ #include -#include -#include +#include +#include namespace kiwano { diff --git a/src/kiwano/base/Resource.h b/src/kiwano/core/Resource.h similarity index 98% rename from src/kiwano/base/Resource.h rename to src/kiwano/core/Resource.h index 53aed99c..f81dc4d1 100644 --- a/src/kiwano/base/Resource.h +++ b/src/kiwano/core/Resource.h @@ -20,7 +20,7 @@ #pragma once #include -#include +#include namespace kiwano { diff --git a/src/kiwano/base/SmartPtr.hpp b/src/kiwano/core/SmartPtr.hpp similarity index 90% rename from src/kiwano/base/SmartPtr.hpp rename to src/kiwano/core/SmartPtr.hpp index 09a60358..15edf87d 100644 --- a/src/kiwano/base/SmartPtr.hpp +++ b/src/kiwano/core/SmartPtr.hpp @@ -19,8 +19,8 @@ // THE SOFTWARE. #pragma once -#include -#include +#include +#include namespace kiwano { @@ -38,7 +38,7 @@ namespace kiwano }; template - using SmartPtr = core::intrusive_ptr<_Ty, DefaultIntrusivePtrManager>; + using SmartPtr = common::intrusive_ptr<_Ty, DefaultIntrusivePtrManager>; } diff --git a/src/kiwano/base/Timer.cpp b/src/kiwano/core/Timer.cpp similarity index 98% rename from src/kiwano/base/Timer.cpp rename to src/kiwano/core/Timer.cpp index 66792e5c..39efeb99 100644 --- a/src/kiwano/base/Timer.cpp +++ b/src/kiwano/core/Timer.cpp @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include +#include namespace kiwano { diff --git a/src/kiwano/base/Timer.h b/src/kiwano/core/Timer.h similarity index 96% rename from src/kiwano/base/Timer.h rename to src/kiwano/core/Timer.h index 2ab574a8..0ac216cb 100644 --- a/src/kiwano/base/Timer.h +++ b/src/kiwano/core/Timer.h @@ -21,8 +21,8 @@ #pragma once #include -#include -#include +#include +#include namespace kiwano { diff --git a/src/kiwano/base/TimerManager.cpp b/src/kiwano/core/TimerManager.cpp similarity index 97% rename from src/kiwano/base/TimerManager.cpp rename to src/kiwano/core/TimerManager.cpp index 67885689..77c5ca2f 100644 --- a/src/kiwano/base/TimerManager.cpp +++ b/src/kiwano/core/TimerManager.cpp @@ -18,8 +18,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include -#include +#include +#include namespace kiwano { diff --git a/src/kiwano/base/TimerManager.h b/src/kiwano/core/TimerManager.h similarity index 98% rename from src/kiwano/base/TimerManager.h rename to src/kiwano/core/TimerManager.h index c1b989ae..3b3a5d8b 100644 --- a/src/kiwano/base/TimerManager.h +++ b/src/kiwano/core/TimerManager.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include namespace kiwano { diff --git a/src/kiwano/base/keys.hpp b/src/kiwano/core/keys.h similarity index 100% rename from src/kiwano/base/keys.hpp rename to src/kiwano/core/keys.h diff --git a/src/kiwano/core/time.cpp b/src/kiwano/core/time.cpp new file mode 100644 index 00000000..568aff2b --- /dev/null +++ b/src/kiwano/core/time.cpp @@ -0,0 +1,424 @@ +// Copyright (c) 2016-2018 Kiwano - Nomango +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#include +#include + +#include +#include + +namespace kiwano +{ + //------------------------------------------------------- + // Time + //------------------------------------------------------- + + Time::Time() + : dur_(0) + { + } + + Time::Time(long dur) + : dur_(dur) + { + } + + const Time Time::operator+(const Duration & dur) const + { + return Time{ dur_ + dur.Milliseconds() }; + } + + const Time Time::operator-(const Duration & dur) const + { + return Time{ dur_ - dur.Milliseconds() }; + } + + Time & Time::operator+=(const Duration & other) + { + dur_ += other.Milliseconds(); + return (*this); + } + + Time & Time::operator-=(const Duration &other) + { + dur_ -= other.Milliseconds(); + return (*this); + } + + const Duration Time::operator-(const Time & other) const + { + return Duration(dur_ - other.dur_); + } + + Time Time::Now() noexcept + { + static LARGE_INTEGER freq = {}; + if (freq.QuadPart == 0LL) + { + // the Function will always succceed on systems that run Windows XP or later + QueryPerformanceFrequency(&freq); + } + + LARGE_INTEGER count; + QueryPerformanceCounter(&count); + + const long long whole = (count.QuadPart / freq.QuadPart) * 1000LL; + const long long part = (count.QuadPart % freq.QuadPart) * 1000LL / freq.QuadPart; + return Time{ static_cast(whole + part) }; + } + + + //------------------------------------------------------- + // Duration + //------------------------------------------------------- + + const Duration Duration::Ms = 1L; + const Duration Duration::Second = 1000 * Duration::Ms; + const Duration Duration::Minute = 60 * Duration::Second; + const Duration Duration::Hour = 60 * Duration::Minute; + + namespace + { + const auto duration_regex = std::wregex(LR"(^[-+]?([0-9]*(\.[0-9]*)?(h|m|s|ms)+)+$)"); + + typedef std::unordered_map UnitMap; + const auto unit_map = UnitMap + { + {L"ms", Duration::Ms}, + {L"s", Duration::Second}, + {L"m", Duration::Minute}, + {L"h", Duration::Hour} + }; + } + + Duration::Duration() + : milliseconds_(0) + { + } + + Duration::Duration(long milliseconds) + : milliseconds_(milliseconds) + { + } + + float Duration::Seconds() const + { + long sec = milliseconds_ / Second.milliseconds_; + long ms = milliseconds_ % Second.milliseconds_; + return static_cast(sec) + static_cast(ms) / 1000.f; + } + + float Duration::Minutes() const + { + long min = milliseconds_ / Minute.milliseconds_; + long ms = milliseconds_ % Minute.milliseconds_; + return static_cast(min) + static_cast(ms) / (60 * 1000.f); + } + + float Duration::Hours() const + { + long hour = milliseconds_ / Hour.milliseconds_; + long ms = milliseconds_ % Hour.milliseconds_; + return static_cast(hour) + static_cast(ms) / (60 * 60 * 1000.f); + } + + String Duration::ToString() const + { + if (IsZero()) + { + return String(L"0s"); + } + + String result; + long total_ms = milliseconds_; + if (total_ms < 0) + { + result.append(L"-"); + total_ms = -total_ms; + } + + long hour = total_ms / Hour.milliseconds_; + long min = total_ms / Minute.milliseconds_ - hour * 60; + long sec = total_ms / Second.milliseconds_ - (hour * 60 * 60 + min * 60); + long ms = total_ms % Second.milliseconds_; + + if (hour) + { + result.append(String::parse(hour)).append(L"h"); + result.append(String::parse(min)).append(L"m"); + } + else if(min) + { + result.append(String::parse(min)).append(L"m"); + } + + if (ms != 0) + { + result.append(String::parse(static_cast(sec) + static_cast(ms) / 1000.f)) + .append(L"s"); + } + else if (sec != 0) + { + result.append(String::parse(sec)).append(L"s"); + } + return result; + } + + bool Duration::operator==(const Duration & other) const + { + return milliseconds_ == other.milliseconds_; + } + + bool Duration::operator!=(const Duration & other) const + { + return milliseconds_ != other.milliseconds_; + } + + bool Duration::operator>(const Duration & other) const + { + return milliseconds_ > other.milliseconds_; + } + + bool Duration::operator>=(const Duration & other) const + { + return milliseconds_ >= other.milliseconds_; + } + + bool Duration::operator<(const Duration & other) const + { + return milliseconds_ < other.milliseconds_; + } + + bool Duration::operator<=(const Duration & other) const + { + return milliseconds_ <= other.milliseconds_; + } + + float Duration::operator/(const Duration & other) const + { + return static_cast(milliseconds_) / other.milliseconds_; + } + + const Duration Duration::operator+(const Duration & other) const + { + return Duration(milliseconds_ + other.milliseconds_); + } + + const Duration Duration::operator-(const Duration & other) const + { + return Duration(milliseconds_ - other.milliseconds_); + } + + const Duration Duration::operator-() const + { + return Duration(-milliseconds_); + } + + const Duration Duration::operator*(int val) const + { + return Duration(milliseconds_ * val); + } + + const Duration Duration::operator*(unsigned long long val) const + { + return Duration(static_cast(milliseconds_ * val)); + } + + const Duration Duration::operator*(float val) const + { + return Duration(static_cast(milliseconds_ * val)); + } + + const Duration Duration::operator*(double val) const + { + return Duration(static_cast(milliseconds_ * val)); + } + + const Duration Duration::operator*(long double val) const + { + return Duration(static_cast(milliseconds_ * val)); + } + + const Duration Duration::operator/(int val) const + { + return Duration(milliseconds_ / val); + } + + const Duration Duration::operator/(float val) const + { + return Duration(static_cast(milliseconds_ / val)); + } + + const Duration Duration::operator/(double val) const + { + return Duration(static_cast(milliseconds_ / val)); + } + + Duration & Duration::operator+=(const Duration &other) + { + milliseconds_ += other.milliseconds_; + return (*this); + } + + Duration & Duration::operator-=(const Duration &other) + { + milliseconds_ -= other.milliseconds_; + return (*this); + } + + Duration & Duration::operator*=(int val) + { + milliseconds_ *= val; + return (*this); + } + + Duration & Duration::operator/=(int val) + { + milliseconds_ = static_cast(milliseconds_ / val); + return (*this); + } + + Duration & Duration::operator*=(float val) + { + milliseconds_ = static_cast(milliseconds_ * val); + return (*this); + } + + Duration & Duration::operator/=(float val) + { + milliseconds_ = static_cast(milliseconds_ / val); + return (*this); + } + + Duration & Duration::operator*=(double val) + { + milliseconds_ = static_cast(milliseconds_ * val); + return (*this); + } + + Duration & Duration::operator/=(double val) + { + milliseconds_ = static_cast(milliseconds_ / val); + return (*this); + } + + const Duration operator*(int val, const Duration & dur) + { + return dur * val; + } + + const Duration operator/(int val, const Duration & dur) + { + return dur / val; + } + + const Duration operator*(float val, const Duration & dur) + { + return dur * val; + } + + const Duration operator/(float val, const Duration & dur) + { + return dur / val; + } + + const Duration operator*(double val, const Duration & dur) + { + return dur * val; + } + + const Duration operator/(double val, const Duration & dur) + { + return dur / val; + } + + const Duration operator*(long double val, const Duration & dur) + { + return dur * val; + } + + Duration Duration::Parse(const String& str) + { + bool negative = false; + size_t len = str.length(); + size_t pos = 0; + Duration ret; + + if (!std::regex_match(str.c_str(), duration_regex)) + { + KGE_ERROR_LOG(L"Duration::Parse failed, invalid duration"); + return ret; + } + + if (str.empty() || str == L"0") { return ret; } + + // 符号位 + if (str[0] == L'-' || str[0] == L'+') + { + negative = (str[0] == L'-'); + pos++; + } + + while (pos < len) + { + // 数值 + size_t i = pos; + for (; i < len; ++i) + { + wchar_t ch = str[i]; + if (!(ch == L'.' || L'0' <= ch && ch <= L'9')) + { + break; + } + } + + String num_str = str.substr(pos, i - pos); + pos = i; + + KGE_ASSERT(!(num_str.empty() || num_str == L".") && "Duration::Parse failed, invalid duration"); + + // 单位 + for (; i < len; ++i) + { + wchar_t ch = str[i]; + if (ch == L'.' || L'0' <= ch && ch <= L'9') + { + break; + } + } + + String unit_str = str.substr(pos, i - pos); + pos = i; + + KGE_ASSERT(unit_map.find(unit_str) != unit_map.end() && "Duration::Parse failed, invalid duration"); + + double num = std::wcstod(num_str.c_str(), nullptr); + Duration unit = unit_map.at(unit_str); + ret += unit * num; + } + + if (negative) + { + ret = -ret; + } + return ret; + } + +} diff --git a/src/kiwano/core/time.h b/src/kiwano/core/time.h new file mode 100644 index 00000000..f6c47257 --- /dev/null +++ b/src/kiwano/core/time.h @@ -0,0 +1,225 @@ +// Copyright (c) 2016-2018 Kiwano - Nomango +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#pragma once +#include +#include + +namespace kiwano +{ + // 时间段 + // + // 时间段表示法: + // 5 秒: time::Second * 5 + // 1.5 小时: time::Hour * 1.5 + // 3 小时 45 分 15 秒: time::Hour * 3 + time::Minute * 45 + time::Second * 15 + // 在 VS2015 及更高版本可以使用 time literals: + // 5 秒: 5_s + // 1.5 小时: 1.5_h + // 3 小时 45 分 15 秒: 3_h + 45_m + 15_s + // + struct KGE_API Duration + { + Duration(); + + Duration( + long milliseconds + ); + + // 转化为毫秒 + long Milliseconds() const; + + // 转化为秒 + float Seconds() const; + + // 转化为分钟 + float Minutes() const; + + // 转化为小时 + float Hours() const; + + // 时长是否是零 + bool IsZero() const; + + void SetMilliseconds(long ms); + + void SetSeconds(float seconds); + + void SetMinutes(float minutes); + + void SetHours(float hours); + + // 转为字符串 + String ToString() const; + + bool operator== (const Duration &) const; + bool operator!= (const Duration &) const; + bool operator> (const Duration &) const; + bool operator>= (const Duration &) const; + bool operator< (const Duration &) const; + bool operator<= (const Duration &) const; + + float operator / (const Duration &) const; + + const Duration operator + (const Duration &) const; + const Duration operator - (const Duration &) const; + const Duration operator - () const; + const Duration operator * (int) const; + const Duration operator * (unsigned long long) const; + const Duration operator * (float) const; + const Duration operator * (double) const; + const Duration operator * (long double) const; + const Duration operator / (int) const; + const Duration operator / (float) const; + const Duration operator / (double) const; + + Duration& operator += (const Duration &); + Duration& operator -= (const Duration &); + Duration& operator *= (int); + Duration& operator *= (float); + Duration& operator *= (double); + Duration& operator /= (int); + Duration& operator /= (float); + Duration& operator /= (double); + + friend const Duration operator* (int, const Duration &); + friend const Duration operator* (float, const Duration &); + friend const Duration operator* (double, const Duration &); + friend const Duration operator* (long double, const Duration &); + friend const Duration operator/ (int, const Duration &); + friend const Duration operator/ (float, const Duration &); + friend const Duration operator/ (double, const Duration &); + + // 时间段格式化 + // + // 时间段字符串允许是有符号的浮点数, 并且带有时间单位后缀 + // 例如: "300ms", "-1.5h", "2h45m" + // 允许的时间单位有 "ms", "s", "m", "h" + static Duration Parse(const String& parse_str); + + static const Duration Ms; // 毫秒 + static const Duration Second; // 秒 + static const Duration Minute; // 分钟 + static const Duration Hour; // 小时 + + private: + long milliseconds_; + }; + + + // 时间 + // + // 获取当前时间: Time now = Time::Now(); + // 两时间相减, 得到一个 Duration 对象, 例如: + // Time t1, t2; + // int ms = (t2 - t1).Milliseconds(); // 获取两时间相差的毫秒数 + // + struct KGE_API Time + { + Time(); + + // 是否是零时 + bool IsZero() const; + + const Duration operator -(const Time&) const; + + const Time operator +(const Duration &) const; + const Time operator -(const Duration &) const; + + Time& operator +=(const Duration &); + Time& operator -=(const Duration &); + + // 获取当前时间 + // 由于该时间点基于系统启动时间开始计算, 所以无法格式化该时间, + // 也无法获得该时间的 Unix 时间戳 + static Time Now() noexcept; + + private: + Time(long ms); + + private: + long dur_; + }; + + + inline long Duration::Milliseconds() const { return milliseconds_; } + + inline bool Duration::IsZero() const { return milliseconds_ == 0LL; } + + inline void Duration::SetMilliseconds(long ms) { milliseconds_ = ms; } + + inline void Duration::SetSeconds(float seconds) { milliseconds_ = static_cast(seconds * 1000.f); } + + inline void Duration::SetMinutes(float minutes) { milliseconds_ = static_cast(minutes * 60 * 1000.f); } + + inline void Duration::SetHours(float hours) { milliseconds_ = static_cast(hours * 60 * 60 * 1000.f); } + + inline bool Time::IsZero() const { return dur_ == 0; } +} + +#if KGE_VS_VER > KGE_VS_2013 + +namespace kiwano +{ + inline namespace literals + { + inline const kiwano::Duration operator "" _ms(long double val) + { + return kiwano::Duration::Ms * val; + } + + inline const kiwano::Duration operator "" _s(long double val) + { + return kiwano::Duration::Second * val; + } + + inline const kiwano::Duration operator "" _m(long double val) + { + return kiwano::Duration::Minute * val; + } + + inline const kiwano::Duration operator "" _h(long double val) + { + return kiwano::Duration::Hour * val; + } + + inline const kiwano::Duration operator "" _ms(unsigned long long val) + { + return kiwano::Duration::Ms * val; + } + + inline const kiwano::Duration operator "" _s(unsigned long long val) + { + return kiwano::Duration::Second * val; + } + + inline const kiwano::Duration operator "" _m(unsigned long long val) + { + return kiwano::Duration::Minute * val; + } + + inline const kiwano::Duration operator "" _h(unsigned long long val) + { + return kiwano::Duration::Hour * val; + } + } +} + +#endif diff --git a/src/kiwano/base/win32/ComPtr.hpp b/src/kiwano/core/win32/ComPtr.hpp similarity index 93% rename from src/kiwano/base/win32/ComPtr.hpp rename to src/kiwano/core/win32/ComPtr.hpp index 6d705861..0cc76527 100644 --- a/src/kiwano/base/win32/ComPtr.hpp +++ b/src/kiwano/core/win32/ComPtr.hpp @@ -20,7 +20,7 @@ #pragma once #include -#include +#include #include namespace kiwano @@ -42,6 +42,6 @@ namespace kiwano template< typename _Ty, typename = typename std::enable_if::value, int>::type> - using ComPtr = core::intrusive_ptr<_Ty, ComPtrManager>; + using ComPtr = common::intrusive_ptr<_Ty, ComPtrManager>; } diff --git a/src/kiwano/base/win32/helper.h b/src/kiwano/core/win32/helper.h similarity index 97% rename from src/kiwano/base/win32/helper.h rename to src/kiwano/core/win32/helper.h index bc8ea1f9..a731dc96 100644 --- a/src/kiwano/base/win32/helper.h +++ b/src/kiwano/core/win32/helper.h @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include +#include #include <3rd-party/StackWalker/StackWalker.h> namespace kiwano diff --git a/src/kiwano/kiwano.h b/src/kiwano/kiwano.h index 1b4030d9..f8b51499 100644 --- a/src/kiwano/kiwano.h +++ b/src/kiwano/kiwano.h @@ -29,19 +29,19 @@ // -// core +// common // -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // @@ -72,23 +72,21 @@ // -// base +// core // -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // @@ -129,6 +127,9 @@ // #include +#include +#include +#include #include @@ -136,7 +137,7 @@ // utils // -#include +#include #include #include diff --git a/src/kiwano/math/math.h b/src/kiwano/math/math.h index 79aa3cd4..775e204b 100644 --- a/src/kiwano/math/math.h +++ b/src/kiwano/math/math.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include #include #include #include diff --git a/src/kiwano/math/scalar.h b/src/kiwano/math/scalar.h index 90a02471..e81edaa2 100644 --- a/src/kiwano/math/scalar.h +++ b/src/kiwano/math/scalar.h @@ -33,8 +33,8 @@ namespace kiwano inline float Sqrt(float val) { return ::sqrtf(val); } inline double Sqrt(double val) { return ::sqrt(val); } - inline float Pow(float base, float exponent) { return ::powf(base, exponent); } - inline double Pow(double base, double exponent) { return ::pow(base, exponent); } + inline float Pow(float core, float exponent) { return ::powf(core, exponent); } + inline double Pow(double core, double exponent) { return ::pow(core, exponent); } inline int Sign(int val) { return val < 0 ? -1 : 1; } inline float Sign(float val) { return val < 0 ? -1.f : 1.f; } diff --git a/src/kiwano/platform/Application.cpp b/src/kiwano/platform/Application.cpp index 4a61c8b7..57f56e4b 100644 --- a/src/kiwano/platform/Application.cpp +++ b/src/kiwano/platform/Application.cpp @@ -22,9 +22,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include diff --git a/src/kiwano/platform/Application.h b/src/kiwano/platform/Application.h index 501f1bd3..7f5280fa 100644 --- a/src/kiwano/platform/Application.h +++ b/src/kiwano/platform/Application.h @@ -19,11 +19,11 @@ // THE SOFTWARE. #pragma once -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include namespace kiwano @@ -50,7 +50,7 @@ namespace kiwano // 应用 class KGE_API Application - : protected core::noncopyable + : protected common::noncopyable { public: Application(); diff --git a/src/kiwano/utils/FileSystem.cpp b/src/kiwano/platform/FileSystem.cpp similarity index 99% rename from src/kiwano/utils/FileSystem.cpp rename to src/kiwano/platform/FileSystem.cpp index 1d23d934..af2ad9c2 100644 --- a/src/kiwano/utils/FileSystem.cpp +++ b/src/kiwano/platform/FileSystem.cpp @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include +#include #include namespace kiwano diff --git a/src/kiwano/utils/FileSystem.h b/src/kiwano/platform/FileSystem.h similarity index 98% rename from src/kiwano/utils/FileSystem.h rename to src/kiwano/platform/FileSystem.h index 3d41f129..7e9d47a3 100644 --- a/src/kiwano/utils/FileSystem.h +++ b/src/kiwano/platform/FileSystem.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include namespace kiwano { diff --git a/src/kiwano/base/Input.cpp b/src/kiwano/platform/Input.cpp similarity index 98% rename from src/kiwano/base/Input.cpp rename to src/kiwano/platform/Input.cpp index 976c8f72..9803760c 100644 --- a/src/kiwano/base/Input.cpp +++ b/src/kiwano/platform/Input.cpp @@ -18,8 +18,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include -#include +#include +#include #include // GET_X_LPARAM, GET_Y_LPARAM namespace kiwano diff --git a/src/kiwano/base/Input.h b/src/kiwano/platform/Input.h similarity index 95% rename from src/kiwano/base/Input.h rename to src/kiwano/platform/Input.h index 9cb9753c..5b17d98e 100644 --- a/src/kiwano/base/Input.h +++ b/src/kiwano/platform/Input.h @@ -20,10 +20,10 @@ #pragma once #include -#include +#include #include -#include -#include +#include +#include namespace kiwano { diff --git a/src/kiwano/base/Window.cpp b/src/kiwano/platform/Window.cpp similarity index 99% rename from src/kiwano/base/Window.cpp rename to src/kiwano/platform/Window.cpp index ff0f1f91..dff73d1e 100644 --- a/src/kiwano/base/Window.cpp +++ b/src/kiwano/platform/Window.cpp @@ -18,8 +18,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include -#include +#include +#include #include #define WINDOW_FIXED_STYLE WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX diff --git a/src/kiwano/base/Window.h b/src/kiwano/platform/Window.h similarity index 98% rename from src/kiwano/base/Window.h rename to src/kiwano/platform/Window.h index d8ace2f0..d2279335 100644 --- a/src/kiwano/base/Window.h +++ b/src/kiwano/platform/Window.h @@ -20,7 +20,7 @@ #pragma once #include -#include +#include #include namespace kiwano diff --git a/src/kiwano/platform/modules.cpp b/src/kiwano/platform/modules.cpp index fe4aec97..dd5d57dd 100644 --- a/src/kiwano/platform/modules.cpp +++ b/src/kiwano/platform/modules.cpp @@ -19,7 +19,7 @@ // THE SOFTWARE. #include -#include +#include namespace kiwano { diff --git a/src/kiwano/platform/modules.h b/src/kiwano/platform/modules.h index 727a79fd..cbb561dc 100644 --- a/src/kiwano/platform/modules.h +++ b/src/kiwano/platform/modules.h @@ -20,7 +20,7 @@ #pragma once #include -#include +#include namespace kiwano { diff --git a/src/kiwano/renderer/Brush.cpp b/src/kiwano/renderer/Brush.cpp index d9b43eee..9ada29e3 100644 --- a/src/kiwano/renderer/Brush.cpp +++ b/src/kiwano/renderer/Brush.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include namespace kiwano { diff --git a/src/kiwano/renderer/Color.h b/src/kiwano/renderer/Color.h index 79afdb74..1771555d 100644 --- a/src/kiwano/renderer/Color.h +++ b/src/kiwano/renderer/Color.h @@ -20,7 +20,7 @@ #pragma once #include -#include +#include namespace kiwano { diff --git a/src/kiwano/renderer/FontCollection.h b/src/kiwano/renderer/FontCollection.h index 711e85bb..92148509 100644 --- a/src/kiwano/renderer/FontCollection.h +++ b/src/kiwano/renderer/FontCollection.h @@ -19,8 +19,8 @@ // THE SOFTWARE. #pragma once -#include -#include +#include +#include #include namespace kiwano diff --git a/src/kiwano/renderer/Geometry.cpp b/src/kiwano/renderer/Geometry.cpp index 41bd7619..6b008ffc 100644 --- a/src/kiwano/renderer/Geometry.cpp +++ b/src/kiwano/renderer/Geometry.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include namespace kiwano { diff --git a/src/kiwano/renderer/Geometry.h b/src/kiwano/renderer/Geometry.h index e522ee7a..859e07cc 100644 --- a/src/kiwano/renderer/Geometry.h +++ b/src/kiwano/renderer/Geometry.h @@ -129,7 +129,7 @@ namespace kiwano // 几何体生成器 class KGE_API GeometrySink - : protected core::noncopyable + : protected common::noncopyable { public: GeometrySink(); diff --git a/src/kiwano/renderer/GifImage.cpp b/src/kiwano/renderer/GifImage.cpp index d2dffb9b..25282aef 100644 --- a/src/kiwano/renderer/GifImage.cpp +++ b/src/kiwano/renderer/GifImage.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include namespace kiwano { diff --git a/src/kiwano/renderer/GifImage.h b/src/kiwano/renderer/GifImage.h index e199f005..a77139e5 100644 --- a/src/kiwano/renderer/GifImage.h +++ b/src/kiwano/renderer/GifImage.h @@ -20,7 +20,7 @@ #pragma once #include -#include +#include namespace kiwano { diff --git a/src/kiwano/renderer/RenderTarget.cpp b/src/kiwano/renderer/RenderTarget.cpp index fddf7b0c..cbe5a428 100644 --- a/src/kiwano/renderer/RenderTarget.cpp +++ b/src/kiwano/renderer/RenderTarget.cpp @@ -19,7 +19,7 @@ // THE SOFTWARE. #include -#include +#include namespace kiwano { diff --git a/src/kiwano/renderer/RenderTarget.h b/src/kiwano/renderer/RenderTarget.h index 2f2ae489..c886da3e 100644 --- a/src/kiwano/renderer/RenderTarget.h +++ b/src/kiwano/renderer/RenderTarget.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include #include #include #include @@ -41,7 +41,7 @@ namespace kiwano // 渲染目标 class KGE_API RenderTarget - : public core::noncopyable + : public common::noncopyable { public: bool IsValid() const; diff --git a/src/kiwano/renderer/Renderer.cpp b/src/kiwano/renderer/Renderer.cpp index 537f5f80..e1573261 100644 --- a/src/kiwano/renderer/Renderer.cpp +++ b/src/kiwano/renderer/Renderer.cpp @@ -19,9 +19,9 @@ // THE SOFTWARE. #include -#include -#include -#include +#include +#include +#include namespace kiwano { diff --git a/src/kiwano/renderer/Renderer.h b/src/kiwano/renderer/Renderer.h index a613ac99..53488183 100644 --- a/src/kiwano/renderer/Renderer.h +++ b/src/kiwano/renderer/Renderer.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include #include #include #include diff --git a/src/kiwano/renderer/TextLayout.cpp b/src/kiwano/renderer/TextLayout.cpp index 21c230ae..9eb57318 100644 --- a/src/kiwano/renderer/TextLayout.cpp +++ b/src/kiwano/renderer/TextLayout.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include namespace kiwano { diff --git a/src/kiwano/renderer/Texture.cpp b/src/kiwano/renderer/Texture.cpp index 42481fa6..01f0f921 100644 --- a/src/kiwano/renderer/Texture.cpp +++ b/src/kiwano/renderer/Texture.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include namespace kiwano { diff --git a/src/kiwano/renderer/TextureCache.cpp b/src/kiwano/renderer/TextureCache.cpp index d69bb537..70ec4990 100644 --- a/src/kiwano/renderer/TextureCache.cpp +++ b/src/kiwano/renderer/TextureCache.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include namespace kiwano { diff --git a/src/kiwano/renderer/win32/D2DDeviceResources.cpp b/src/kiwano/renderer/win32/D2DDeviceResources.cpp index 2f21bad9..4ccdb0cd 100644 --- a/src/kiwano/renderer/win32/D2DDeviceResources.cpp +++ b/src/kiwano/renderer/win32/D2DDeviceResources.cpp @@ -19,7 +19,7 @@ // THE SOFTWARE. #include -#include +#include #pragma comment(lib, "d2d1.lib") #pragma comment(lib, "dwrite.lib") diff --git a/src/kiwano/renderer/win32/D2DDeviceResources.h b/src/kiwano/renderer/win32/D2DDeviceResources.h index 3cae6230..31ca7a0d 100644 --- a/src/kiwano/renderer/win32/D2DDeviceResources.h +++ b/src/kiwano/renderer/win32/D2DDeviceResources.h @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/kiwano/renderer/win32/D3D10DeviceResources.cpp b/src/kiwano/renderer/win32/D3D10DeviceResources.cpp index 604d43ee..274618ec 100644 --- a/src/kiwano/renderer/win32/D3D10DeviceResources.cpp +++ b/src/kiwano/renderer/win32/D3D10DeviceResources.cpp @@ -20,7 +20,7 @@ #include -#include +#include #pragma comment(lib, "d3d10_1.lib") diff --git a/src/kiwano/renderer/win32/D3D11DeviceResources.cpp b/src/kiwano/renderer/win32/D3D11DeviceResources.cpp index b2cf19b7..b6ebbd6c 100644 --- a/src/kiwano/renderer/win32/D3D11DeviceResources.cpp +++ b/src/kiwano/renderer/win32/D3D11DeviceResources.cpp @@ -20,7 +20,7 @@ #include -#include +#include #include // IsWindows10OrGreater #pragma comment(lib, "d3d11.lib") diff --git a/src/kiwano/ui/Button.cpp b/src/kiwano/ui/Button.cpp index 5aa6191b..13c15f1c 100644 --- a/src/kiwano/ui/Button.cpp +++ b/src/kiwano/ui/Button.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include namespace kiwano { diff --git a/src/kiwano/utils/LocalStorage.h b/src/kiwano/utils/LocalStorage.h index 27cf579e..affc43ea 100644 --- a/src/kiwano/utils/LocalStorage.h +++ b/src/kiwano/utils/LocalStorage.h @@ -20,7 +20,7 @@ #pragma once #include -#include +#include namespace kiwano { diff --git a/src/kiwano/utils/ResourceCache.cpp b/src/kiwano/utils/ResourceCache.cpp index 05d657a7..7f36b8ac 100644 --- a/src/kiwano/utils/ResourceCache.cpp +++ b/src/kiwano/utils/ResourceCache.cpp @@ -21,8 +21,8 @@ #include #include -#include -#include +#include +#include #include #include #include @@ -83,7 +83,7 @@ namespace kiwano KGE_WARNING_LOG(L"ResourceCache::LoadFromJsonFile failed: Cannot open file. (%s)", string_to_wide(e.what()).c_str()); return false; } - catch (core::json_exception& e) + catch (common::json_exception& e) { KGE_WARNING_LOG(L"ResourceCache::LoadFromJsonFile failed: Cannot parse to JSON. (%s)", string_to_wide(e.what()).c_str()); return false; diff --git a/src/kiwano/utils/ResourceCache.h b/src/kiwano/utils/ResourceCache.h index a67003c0..15a831e1 100644 --- a/src/kiwano/utils/ResourceCache.h +++ b/src/kiwano/utils/ResourceCache.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include #include #include #include <3rd-party/tinyxml2/tinyxml2.h> diff --git a/src/kiwano/utils/UserData.h b/src/kiwano/utils/UserData.h index 4584e0e7..250f3388 100644 --- a/src/kiwano/utils/UserData.h +++ b/src/kiwano/utils/UserData.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include namespace kiwano {