From f619414ed49d0829baf0af2d07568a3ac33edcb9 Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Tue, 12 Dec 2017 12:18:28 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E8=BD=BD=E4=BA=86EString=E5=8A=A0?= =?UTF-8?q?=E5=8F=B7=E8=BF=90=E7=AE=97=E7=AC=A6=EF=BC=9B=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BA=86=E5=9C=BA=E6=99=AF=E5=8A=A8=E7=94=BB=E7=BB=93=E6=9D=9F?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E5=85=B6=E4=BB=96=E5=8A=A8=E7=94=BB=E8=B7=B3?= =?UTF-8?q?=E5=B8=A7=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Demo/main.cpp | 9 ++++----- Easy2D/Base/EApp.cpp | 2 ++ Easy2D/Common/EString.cpp | 28 ++++++++++++++++++++++++++++ Easy2D/ecommon.h | 15 +++++++++++++-- Easy2D/etools.h | 4 ++-- 5 files changed, 49 insertions(+), 9 deletions(-) diff --git a/Demo/main.cpp b/Demo/main.cpp index 6ff350d7..8ffc99f0 100644 --- a/Demo/main.cpp +++ b/Demo/main.cpp @@ -11,13 +11,12 @@ int WINAPI WinMain( if (!EApp::init(L"Demo", 250, 150)) return -1; - EString str = L"1245"; + wchar_t str[] = L"1245"; EString str2 = L"1243"; - bool b = str > str2; - bool b2 = str >= str2; - bool b3 = str < str2; - bool b4 = str <= str2; + EString str3; + str + str2; + str3 = str + str2; auto scene = new EScene(); EApp::enterScene(scene); diff --git a/Easy2D/Base/EApp.cpp b/Easy2D/Base/EApp.cpp index 3c64439b..1647a675 100644 --- a/Easy2D/Base/EApp.cpp +++ b/Easy2D/Base/EApp.cpp @@ -341,6 +341,8 @@ void e2d::EApp::_update() m_pTransition = nullptr; // 进入下一场景 _enterNextScene(); + // 刷新计时器 + _updateTime(); } return; } diff --git a/Easy2D/Common/EString.cpp b/Easy2D/Common/EString.cpp index dc56ba42..ea29e761 100644 --- a/Easy2D/Common/EString.cpp +++ b/Easy2D/Common/EString.cpp @@ -9,6 +9,14 @@ EString::EString() _string = nullptr; } +e2d::EString::EString(const wchar_t ch) +{ + _size = 1; + _string = new wchar_t[2]; + _string[0] = ch; + _string[1] = 0; +} + EString::EString(const wchar_t *str) { if (str) @@ -293,6 +301,26 @@ unsigned int e2d::EString::hash() const return (hash); } +EString e2d::operator+(const wchar_t ch, const EString &str) +{ + return std::move((EString(ch) + str)); +} + +EString e2d::operator+(const wchar_t *str1, const EString &str2) +{ + return std::move((EString(str1) + str2)); +} + +EString e2d::operator+(const EString &str1, const EString &str2) +{ + return std::move((EString(str1) + str2)); +} + +EString e2d::operator+(const std::wstring &str1, const EString &str2) +{ + return std::move((EString(str1) + str2)); +} + std::wistream & e2d::operator>>(std::wistream &cin, EString &str) { const int limit_string_size = 4096; diff --git a/Easy2D/ecommon.h b/Easy2D/ecommon.h index a5d9a5c9..4c3212df 100644 --- a/Easy2D/ecommon.h +++ b/Easy2D/ecommon.h @@ -134,6 +134,7 @@ class EString { public: EString(); + EString(const wchar_t); EString(const wchar_t *); EString(const EString &); EString(const std::wstring &); @@ -187,11 +188,21 @@ public: bool operator > (EString const&) const; bool operator >= (EString const&) const; - friend std::wistream &operator>>(std::wistream &, EString &); - operator const wchar_t*() const { return _string; } operator bool() const { return _size != 0; } + friend EString operator+(const wchar_t, const EString &); + friend EString operator+(const wchar_t*, const EString &); + friend EString operator+(const EString &, const EString &); + friend EString operator+(const std::wstring &, const EString &); + template + friend EString operator+(const T &value, const EString &str) + { + return std::move((EString::parse(value) + str2)); + } + + friend std::wistream &operator>>(std::wistream &, EString &); + // 判断字符串是否为空 bool isEmpty() const { return _size == 0; } diff --git a/Easy2D/etools.h b/Easy2D/etools.h index da2bf206..ea82c1e6 100644 --- a/Easy2D/etools.h +++ b/Easy2D/etools.h @@ -159,11 +159,11 @@ public: /** * 打开保存文件对话框,得到有效保存路径返回 true - * 参数:返回文件路径的字符串,窗口标题,设置扩展名过滤,设置默认扩展名 + * 参数:窗口标题,默认扩展名 */ static EString getSaveFilePath( const EString & title = L"保存到", - const EString & defExt = NULL + const EString & defExt = L"" ); };