From 6f489a77fe759d4d58dd1dd8b6260ac7f8f24e6d Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Mon, 10 Sep 2018 20:55:20 +0800 Subject: [PATCH] remove: SystemException --- core/e2daction.h | 84 +++++++++++++-------------- core/e2dcomponent.h | 8 +-- core/e2dimpl.h | 42 +++++--------- core/e2dobject.h | 38 ++++++------ core/e2dtool.h | 4 +- core/e2dtransition.h | 20 +++---- core/e2dutil.h | 12 ++-- core/impl/Exception.cpp | 37 ------------ core/impl/SystemException.cpp | 11 ---- core/modules/Window.cpp | 2 +- core/objects/Node.cpp | 6 +- project/vs2012/Easy2D.vcxproj | 2 - project/vs2012/Easy2D.vcxproj.filters | 6 -- project/vs2013/Easy2D.vcxproj | 2 - project/vs2013/Easy2D.vcxproj.filters | 6 -- project/vs2017/Easy2D.vcxproj | 2 - project/vs2017/Easy2D.vcxproj.filters | 6 -- 17 files changed, 101 insertions(+), 187 deletions(-) delete mode 100644 core/impl/Exception.cpp delete mode 100644 core/impl/SystemException.cpp diff --git a/core/e2daction.h b/core/e2daction.h index 458806c8..82dd1326 100644 --- a/core/e2daction.h +++ b/core/e2daction.h @@ -14,8 +14,8 @@ namespace e2d // 基础动作 - class Action : - public Ref + class Action + : public Ref { friend class ActionManager; friend class Loop; @@ -90,8 +90,8 @@ namespace e2d // 持续动作 - class FiniteTimeAction : - public Action + class FiniteTimeAction + : public Action { public: // 创建特定时长的持续动作 @@ -121,8 +121,8 @@ namespace e2d // 相对位移动作 - class MoveBy : - public FiniteTimeAction + class MoveBy + : public FiniteTimeAction { public: explicit MoveBy( @@ -153,8 +153,8 @@ namespace e2d // 位移动作 - class MoveTo : - public MoveBy + class MoveTo + : public MoveBy { public: explicit MoveTo( @@ -184,8 +184,8 @@ namespace e2d // 相对跳跃动作 - class JumpBy : - public FiniteTimeAction + class JumpBy + : public FiniteTimeAction { public: explicit JumpBy( @@ -220,8 +220,8 @@ namespace e2d // 跳跃动作 - class JumpTo : - public JumpBy + class JumpTo + : public JumpBy { public: explicit JumpTo( @@ -253,8 +253,8 @@ namespace e2d // 相对缩放动作 - class ScaleBy : - public FiniteTimeAction + class ScaleBy + : public FiniteTimeAction { public: explicit ScaleBy( @@ -292,8 +292,8 @@ namespace e2d // 缩放动作 - class ScaleTo : - public ScaleBy + class ScaleTo + : public ScaleBy { public: explicit ScaleTo( @@ -330,8 +330,8 @@ namespace e2d // 透明度相对渐变动作 - class OpacityBy : - public FiniteTimeAction + class OpacityBy + : public FiniteTimeAction { public: explicit OpacityBy( @@ -361,8 +361,8 @@ namespace e2d // 透明度渐变动作 - class OpacityTo : - public OpacityBy + class OpacityTo + : public OpacityBy { public: explicit OpacityTo( @@ -392,8 +392,8 @@ namespace e2d // 淡入动作 - class FadeIn : - public OpacityTo + class FadeIn + : public OpacityTo { public: // 创建淡入动作 @@ -407,8 +407,8 @@ namespace e2d // 淡出动作 - class FadeOut : - public OpacityTo + class FadeOut + : public OpacityTo { public: // 创建淡出动作 @@ -422,8 +422,8 @@ namespace e2d // 相对旋转动作 - class RotateBy : - public FiniteTimeAction + class RotateBy + : public FiniteTimeAction { public: explicit RotateBy( @@ -453,8 +453,8 @@ namespace e2d // 旋转动作 - class RotateTo : - public RotateBy + class RotateTo + : public RotateBy { public: explicit RotateTo( @@ -484,8 +484,8 @@ namespace e2d // 延时动作 - class Delay : - public Action + class Delay + : public Action { public: explicit Delay( @@ -520,8 +520,8 @@ namespace e2d // 循环动作 - class Loop : - public Action + class Loop + : public Action { public: explicit Loop( @@ -560,8 +560,8 @@ namespace e2d // 回调动作 - class Callback : - public Action + class Callback + : public Action { public: explicit Callback( @@ -589,8 +589,8 @@ namespace e2d // 顺序动作 - class Sequence : - public Action + class Sequence + : public Action { public: typedef std::vector Actions; @@ -641,8 +641,8 @@ namespace e2d // 同步动作 - class Spawn : - public Action + class Spawn + : public Action { public: typedef std::vector Actions; @@ -692,8 +692,8 @@ namespace e2d // 帧动画 - class Animation : - public Ref + class Animation + : public Ref { public: typedef std::vector Images; @@ -752,8 +752,8 @@ namespace e2d // 精灵动作 - class Animate : - public Action + class Animate + : public Action { public: Animate(); diff --git a/core/e2dcomponent.h b/core/e2dcomponent.h index c24ddf7c..21a607e7 100644 --- a/core/e2dcomponent.h +++ b/core/e2dcomponent.h @@ -5,8 +5,8 @@ namespace e2d { - class Button : - public Node + class Button + : public Node { public: Button(); @@ -113,8 +113,8 @@ namespace e2d // 菜单 - class Menu : - public Node + class Menu + : public Node { public: Menu(); diff --git a/core/e2dimpl.h b/core/e2dimpl.h index e2332c37..7dccba16 100644 --- a/core/e2dimpl.h +++ b/core/e2dimpl.h @@ -137,36 +137,22 @@ namespace e2d }; - // 异常 - class Exception + // 运行时异常 + class RuntimeException + : public std::exception { public: - Exception() E2D_NOEXCEPT; + RuntimeException() E2D_NOEXCEPT + : exception("unknown runtime exception", 1) + { + } - explicit Exception(const char * message) E2D_NOEXCEPT; - - Exception(Exception const& other) E2D_NOEXCEPT; - - virtual ~Exception() E2D_NOEXCEPT; - - Exception& operator=(Exception const& other) E2D_NOEXCEPT; - - // 获取异常信息 - virtual const char * GetMsg() const; - - private: - const char * message_; - }; - - - // 系统异常 - class SystemException - : public Exception - { - public: - SystemException() E2D_NOEXCEPT; - - explicit SystemException(const char * message) E2D_NOEXCEPT; + explicit RuntimeException( + char const* const message + ) E2D_NOEXCEPT + : exception(message, 1) + { + } }; @@ -177,7 +163,7 @@ namespace e2d // 在此处设置断点以捕获 D2D API 异常. static char s_str[64] = {}; sprintf_s(s_str, "Failure with HRESULT of %08X", static_cast(hr)); - throw SystemException(s_str); + throw RuntimeException(s_str); } } diff --git a/core/e2dobject.h b/core/e2dobject.h index 4a51fbca..145a6f21 100644 --- a/core/e2dobject.h +++ b/core/e2dobject.h @@ -8,8 +8,8 @@ namespace e2d // 图片 - class Image : - public Ref + class Image + : public Ref { public: Image(); @@ -111,9 +111,9 @@ namespace e2d class Node; // 场景 - class Scene : - public Ref, - public EventTarget + class Scene + : public Ref + , public EventTarget { public: Scene(); @@ -306,8 +306,8 @@ namespace e2d // 定时任务 - class Task : - public Ref + class Task + : public Ref { friend class Node; @@ -406,9 +406,9 @@ namespace e2d class Action; // 节点 - class Node : - public Ref, - public EventTarget + class Node + : public Ref + , public EventTarget { friend class Scene; friend class Collider; @@ -875,9 +875,9 @@ namespace e2d // 精灵 - class Sprite : - public Node, - public Drawable + class Sprite + : public Node + , public Drawable { public: Sprite(); @@ -941,9 +941,9 @@ namespace e2d // 文本 - class Text : - public Node, - public Drawable + class Text + : public Node + , public Drawable { public: // 文本对齐方式 @@ -1159,9 +1159,9 @@ namespace e2d // 画布 - class Canvas : - public Node, - public Drawable + class Canvas + : public Node + , public Drawable { public: Canvas( diff --git a/core/e2dtool.h b/core/e2dtool.h index c1dfd359..0b763d2c 100644 --- a/core/e2dtool.h +++ b/core/e2dtool.h @@ -50,8 +50,8 @@ namespace e2d // 音乐 - class Music : - public Ref + class Music + : public Ref { public: Music(); diff --git a/core/e2dtransition.h b/core/e2dtransition.h index 2b98e03d..a2f2a713 100644 --- a/core/e2dtransition.h +++ b/core/e2dtransition.h @@ -9,8 +9,8 @@ namespace e2d class Scene; // 场景过渡 - class Transition : - public Ref + class Transition + : public Ref { friend class Game; @@ -58,8 +58,8 @@ namespace e2d // 淡入淡出过渡 - class FadeTransition : - public Transition + class FadeTransition + : public Transition { public: explicit FadeTransition( @@ -78,8 +78,8 @@ namespace e2d // 渐变过渡 - class EmergeTransition : - public Transition + class EmergeTransition + : public Transition { public: explicit EmergeTransition( @@ -97,8 +97,8 @@ namespace e2d // 盒状过渡 - class BoxTransition : - public Transition + class BoxTransition + : public Transition { public: explicit BoxTransition( @@ -116,8 +116,8 @@ namespace e2d // 移入过渡 - class MoveTransition : - public Transition + class MoveTransition + : public Transition { public: explicit MoveTransition( diff --git a/core/e2dutil.h b/core/e2dutil.h index 518a2f9f..8715a332 100644 --- a/core/e2dutil.h +++ b/core/e2dutil.h @@ -468,15 +468,15 @@ namespace e2d ); template - Function(Func func) : func_(func) {} + Function(Func func) + : func_(func) + { + } template - Function( - Func&& func, /* 对象的成员函数 */ - Object&& obj /* 对象指针 */ - ) + Function(Func&& func, Object&& obj) + : func_(std::bind(func, obj)) { - func_ = std::bind(func, obj); } void operator() (void) const; diff --git a/core/impl/Exception.cpp b/core/impl/Exception.cpp deleted file mode 100644 index fdf25b05..00000000 --- a/core/impl/Exception.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "..\e2dimpl.h" - - -e2d::Exception::Exception() E2D_NOEXCEPT - : message_() -{ -} - -e2d::Exception::Exception(const char * message) E2D_NOEXCEPT - : message_(message) -{ -} - -e2d::Exception::Exception(Exception const& other) E2D_NOEXCEPT - : message_(other.message_) -{ -} - -e2d::Exception& e2d::Exception::operator=(Exception const& other) E2D_NOEXCEPT -{ - if (this == &other) - { - return *this; - } - - message_ = other.message_; - return *this; -} - -e2d::Exception::~Exception() E2D_NOEXCEPT -{ -} - -const char * e2d::Exception::GetMsg() const -{ - return message_; -} diff --git a/core/impl/SystemException.cpp b/core/impl/SystemException.cpp deleted file mode 100644 index 91e45d73..00000000 --- a/core/impl/SystemException.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "..\e2dimpl.h" - -e2d::SystemException::SystemException() E2D_NOEXCEPT - : Exception("Unknown system exception") -{ -} - -e2d::SystemException::SystemException(const char * message) E2D_NOEXCEPT - : Exception(message) -{ -} diff --git a/core/modules/Window.cpp b/core/modules/Window.cpp index 2bdb0f75..52193c9e 100644 --- a/core/modules/Window.cpp +++ b/core/modules/Window.cpp @@ -200,7 +200,7 @@ HWND e2d::Window::GetHWnd() else { ::UnregisterClass(REGISTER_CLASS, HINST_THISCOMPONENT); - throw SystemException("Create window failed"); + throw RuntimeException("Create window failed"); } } return hWnd_; diff --git a/core/objects/Node.cpp b/core/objects/Node.cpp index d29f346e..997080aa 100644 --- a/core/objects/Node.cpp +++ b/core/objects/Node.cpp @@ -671,14 +671,14 @@ void e2d::Node::AddChild(Node * child, int order /* = 0 */) { if (child->parent_ != nullptr) { - throw Exception("节点已有父节点, 不能再添加到其他节点"); + throw RuntimeException("节点已有父节点, 不能再添加到其他节点"); } for (Node * parent = this; parent != nullptr; parent = parent->GetParent()) { if (child == parent) { - throw Exception("一个节点不能同时是另一个节点的父节点和子节点"); + throw RuntimeException("一个节点不能同时是另一个节点的父节点和子节点"); } } @@ -855,7 +855,7 @@ void e2d::Node::RunAction(Action * action) } else { - throw Exception("该 Action 已有执行目标"); + throw RuntimeException("该 Action 已有执行目标"); } } } diff --git a/project/vs2012/Easy2D.vcxproj b/project/vs2012/Easy2D.vcxproj index f0d3e643..e045201a 100644 --- a/project/vs2012/Easy2D.vcxproj +++ b/project/vs2012/Easy2D.vcxproj @@ -45,8 +45,6 @@ - - diff --git a/project/vs2012/Easy2D.vcxproj.filters b/project/vs2012/Easy2D.vcxproj.filters index 92c39f1a..35b3d936 100644 --- a/project/vs2012/Easy2D.vcxproj.filters +++ b/project/vs2012/Easy2D.vcxproj.filters @@ -150,12 +150,6 @@ components - - impl - - - impl - impl diff --git a/project/vs2013/Easy2D.vcxproj b/project/vs2013/Easy2D.vcxproj index 63772cad..25795ca8 100644 --- a/project/vs2013/Easy2D.vcxproj +++ b/project/vs2013/Easy2D.vcxproj @@ -189,8 +189,6 @@ - - diff --git a/project/vs2013/Easy2D.vcxproj.filters b/project/vs2013/Easy2D.vcxproj.filters index 92c39f1a..35b3d936 100644 --- a/project/vs2013/Easy2D.vcxproj.filters +++ b/project/vs2013/Easy2D.vcxproj.filters @@ -150,12 +150,6 @@ components - - impl - - - impl - impl diff --git a/project/vs2017/Easy2D.vcxproj b/project/vs2017/Easy2D.vcxproj index f373dd9d..8a92fa4d 100644 --- a/project/vs2017/Easy2D.vcxproj +++ b/project/vs2017/Easy2D.vcxproj @@ -222,8 +222,6 @@ - - diff --git a/project/vs2017/Easy2D.vcxproj.filters b/project/vs2017/Easy2D.vcxproj.filters index 92c39f1a..35b3d936 100644 --- a/project/vs2017/Easy2D.vcxproj.filters +++ b/project/vs2017/Easy2D.vcxproj.filters @@ -150,12 +150,6 @@ components - - impl - - - impl - impl