diff options
author | crupest <crupest@outlook.com> | 2020-04-02 20:51:19 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-04-02 20:51:19 +0800 |
commit | e38ea3de29ede0e45aab8e595da5e8e3782a396d (patch) | |
tree | 1e0fae414abea5b5cf1fd4fb4194f8c6a9795d7e /src | |
parent | 7dd9494e957af8280f7221395333f886c500edf5 (diff) | |
download | cru-e38ea3de29ede0e45aab8e595da5e8e3782a396d.tar.gz cru-e38ea3de29ede0e45aab8e595da5e8e3782a396d.tar.bz2 cru-e38ea3de29ede0e45aab8e595da5e8e3782a396d.zip |
...
Diffstat (limited to 'src')
25 files changed, 41 insertions, 70 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index f84a954a..6e621bf1 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -12,5 +12,7 @@ target_sources(cru_base PUBLIC ${CRU_BASE_INCLUDE_DIR}/self_resolvable.hpp ) target_include_directories(cru_base PUBLIC ${CRU_INCLUDE_DIR}) - target_compile_definitions(cru_base PUBLIC $<$<CONFIG:Debug>:CRU_DEBUG>) + +find_path(GSL_INCLUDE_DIR NAMES gsl PATH_SUFFIXES ms-gsl) +target_include_directories(cru_base PUBLIC ${GSL_INCLUDE_DIR}) diff --git a/src/ui/click_detector.cpp b/src/ui/click_detector.cpp index b620201c..3f342a31 100644 --- a/src/ui/click_detector.cpp +++ b/src/ui/click_detector.cpp @@ -2,12 +2,11 @@ #include "cru/common/logger.hpp" -#include <cassert> #include <optional> namespace cru::ui { ClickDetector::ClickDetector(Control* control) { - assert(control); + Expects(control); control_ = control; event_rovoker_guards_.push_back( diff --git a/src/ui/content_control.cpp b/src/ui/content_control.cpp index 5bc8eda4..5dcd89d9 100644 --- a/src/ui/content_control.cpp +++ b/src/ui/content_control.cpp @@ -2,8 +2,6 @@ #include "cru/ui/window.hpp" -#include <cassert> - namespace cru::ui { ContentControl::ContentControl() : child_vector_{nullptr}, child_(child_vector_[0]) {} @@ -11,7 +9,7 @@ ContentControl::ContentControl() ContentControl::~ContentControl() { delete child_; } void ContentControl::SetChild(Control* child) { - assert(!dynamic_cast<Window*>(child)); // Can't add a window as child. + Expects(!dynamic_cast<Window*>(child)); // Can't add a window as child. if (child == child_) return; const auto window = GetWindow(); diff --git a/src/ui/control.cpp b/src/ui/control.cpp index e3b7b967..180ba476 100644 --- a/src/ui/control.cpp +++ b/src/ui/control.cpp @@ -7,7 +7,6 @@ #include "cru/ui/window.hpp" #include "routed_event_dispatch.hpp" -#include <cassert> #include <memory> namespace cru::ui { @@ -38,7 +37,7 @@ void Control::_SetDescendantWindow(Window* window) { if (window == nullptr && window_ == nullptr) return; // You can only attach or detach window. - assert((window != nullptr && window_ == nullptr) || + Expects((window != nullptr && window_ == nullptr) || (window == nullptr && window_ != nullptr)); if (window == nullptr) { diff --git a/src/ui/controls/flex_layout.cpp b/src/ui/controls/flex_layout.cpp index 1c649e3b..c881b6f1 100644 --- a/src/ui/controls/flex_layout.cpp +++ b/src/ui/controls/flex_layout.cpp @@ -29,14 +29,14 @@ int FindPosition(render::RenderObject* parent, render::RenderObject* child) { } // namespace FlexChildLayoutData FlexLayout::GetChildLayoutData(Control* control) { - assert(control); + Expects(control); return *render_object_->GetChildLayoutData( FindPosition(render_object_.get(), control->GetRenderObject())); } void FlexLayout::SetChildLayoutData(Control* control, const FlexChildLayoutData& data) { - assert(control); + Expects(control); *render_object_->GetChildLayoutData( FindPosition(render_object_.get(), control->GetRenderObject())) = data; } diff --git a/src/ui/controls/text_control_service.hpp b/src/ui/controls/text_control_service.hpp index d4f3ecf9..0da8abed 100644 --- a/src/ui/controls/text_control_service.hpp +++ b/src/ui/controls/text_control_service.hpp @@ -141,7 +141,7 @@ void TextControlService<TControl>::AbortSelection() { template <typename TControl> void TextControlService<TControl>::SetupCaretTimer() { #ifdef CRU_DEBUG - assert(!caret_timer_set_); + Expects(!caret_timer_set_); caret_timer_set_ = true; #endif caret_timer_tag_ = @@ -155,7 +155,7 @@ void TextControlService<TControl>::SetupCaretTimer() { template <typename TControl> void TextControlService<TControl>::TearDownCaretTimer() { #ifdef CRU_DEBUG - assert(!caret_timer_set_); + Expects(!caret_timer_set_); caret_timer_set_ = false; #endif platform::native::IUiApplication::GetInstance()->CancelTimer( @@ -164,7 +164,7 @@ void TextControlService<TControl>::TearDownCaretTimer() { template <typename TControl> void TextControlService<TControl>::SetupHandlers() { - assert(event_revoker_guards_.empty()); + Expects(event_revoker_guards_.empty()); event_revoker_guards_.push_back( EventRevokerGuard{control_->MouseMoveEvent()->Direct()->AddHandler( std::bind(&TextControlService::MouseMoveHandler, this, diff --git a/src/ui/layout_control.cpp b/src/ui/layout_control.cpp index 3b4646e5..cb71da30 100644 --- a/src/ui/layout_control.cpp +++ b/src/ui/layout_control.cpp @@ -2,17 +2,15 @@ #include "cru/ui/window.hpp" -#include <cassert> - namespace cru::ui { LayoutControl::~LayoutControl() { for (const auto child : children_) delete child; } void LayoutControl::AddChild(Control* control, const int position) { - assert(control->GetParent() == nullptr); // The control already has a parent. - assert(!dynamic_cast<Window*>(control)); // Can't add a window as child. - assert(position >= 0 || + Expects(control->GetParent() == nullptr); // The control already has a parent. + Expects(!dynamic_cast<Window*>(control)); // Can't add a window as child. + Expects(position >= 0 || position <= static_cast<int>( this->children_.size())); // The position is out of range. @@ -26,7 +24,7 @@ void LayoutControl::AddChild(Control* control, const int position) { } void LayoutControl::RemoveChild(const int position) { - assert(position >= 0 && + Expects(position >= 0 && position < static_cast<int>( this->children_.size())); // The position is out of range. diff --git a/src/ui/render/border_render_object.cpp b/src/ui/render/border_render_object.cpp index 5b6cdb3c..7c96a3b6 100644 --- a/src/ui/render/border_render_object.cpp +++ b/src/ui/render/border_render_object.cpp @@ -7,7 +7,6 @@ #include "cru/platform/graph/util/painter.hpp" #include <algorithm> -#include <cassert> namespace cru::ui::render { BorderRenderObject::BorderRenderObject() { diff --git a/src/ui/render/flex_layout_render_object.cpp b/src/ui/render/flex_layout_render_object.cpp index 791e705a..f40a9b3e 100644 --- a/src/ui/render/flex_layout_render_object.cpp +++ b/src/ui/render/flex_layout_render_object.cpp @@ -3,7 +3,6 @@ #include "cru/platform/graph/util/painter.hpp" #include <algorithm> -#include <cassert> #include <functional> namespace cru::ui::render { diff --git a/src/ui/render/render_object.cpp b/src/ui/render/render_object.cpp index 5cce6d0d..c1b1b19b 100644 --- a/src/ui/render/render_object.cpp +++ b/src/ui/render/render_object.cpp @@ -3,18 +3,18 @@ #include "cru/common/logger.hpp" #include <algorithm> -#include <cassert> namespace cru::ui::render { void RenderObject::AddChild(RenderObject* render_object, const int position) { - assert(child_mode_ != ChildMode::None); - assert(!(child_mode_ == ChildMode::Single && children_.size() > 0)); + Expects(child_mode_ != ChildMode::None); + Expects(!(child_mode_ == ChildMode::Single && children_.size() > 0)); - assert(render_object->GetParent() == - nullptr); // Render object already has a parent. - assert(position >= 0); // Position index is less than 0. - assert(position <= static_cast<int>( - children_.size())); // Position index is out of bound. + Expects(render_object->GetParent() == + nullptr); // Render object already has a parent. + Expects(position >= 0); // Position index is less than 0. + Expects( + position <= + static_cast<int>(children_.size())); // Position index is out of bound. children_.insert(children_.cbegin() + position, render_object); render_object->SetParent(this); @@ -23,9 +23,9 @@ void RenderObject::AddChild(RenderObject* render_object, const int position) { } void RenderObject::RemoveChild(const int position) { - assert(position >= 0); // Position index is less than 0. - assert(position < static_cast<int>( - children_.size())); // Position index is out of bound. + Expects(position >= 0); // Position index is less than 0. + Expects(position < static_cast<int>( + children_.size())); // Position index is out of bound. const auto i = children_.cbegin() + position; const auto removed_child = *i; @@ -45,7 +45,7 @@ Point RenderObject::GetTotalOffset() const { result.y += o.y; render_object = render_object->GetParent(); } - + return result; } diff --git a/src/ui/render/text_render_object.cpp b/src/ui/render/text_render_object.cpp index d14a46e2..be02f8fe 100644 --- a/src/ui/render/text_render_object.cpp +++ b/src/ui/render/text_render_object.cpp @@ -6,7 +6,6 @@ #include "cru/platform/graph/util/painter.hpp" #include <algorithm> -#include <cassert> // TODO: Null Check!!! @@ -15,9 +14,9 @@ TextRenderObject::TextRenderObject( std::shared_ptr<platform::graph::IBrush> brush, std::shared_ptr<platform::graph::IFont> font, std::shared_ptr<platform::graph::IBrush> selection_brush) { - assert(brush); - assert(font); - assert(selection_brush); + Expects(brush); + Expects(font); + Expects(selection_brush); SetChildMode(ChildMode::None); diff --git a/src/ui/render/window_render_object.cpp b/src/ui/render/window_render_object.cpp index 43269d09..29313645 100644 --- a/src/ui/render/window_render_object.cpp +++ b/src/ui/render/window_render_object.cpp @@ -7,15 +7,13 @@ #include "cru/platform/native/window.hpp" #include "cru/ui/window.hpp" -#include <cassert> - namespace cru::ui::render { class WindowRenderHost : public IRenderHost, public SelfResolvable<WindowRenderHost> { public: WindowRenderHost(WindowRenderObject* render_object) : render_object_(render_object) { - assert(render_object != nullptr); + Expects(render_object != nullptr); } void InvalidateLayout() override; diff --git a/src/ui/window.cpp b/src/ui/window.cpp index dbe90478..a3279ba7 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -6,7 +6,6 @@ #include "cru/ui/render/window_render_object.hpp" #include "routed_event_dispatch.hpp" -#include <cassert> #include <list> namespace cru::ui { @@ -151,7 +150,7 @@ platform::native::INativeWindow* Window::ResolveNativeWindow() { } bool Window::RequestFocusFor(Control* control) { - assert(control != nullptr); // The control to request focus can't be null. + Expects(control != nullptr); // The control to request focus can't be null. // You can set it as the window. if (focus_control_ == control) return true; diff --git a/src/win/graph/direct/brush.cpp b/src/win/graph/direct/brush.cpp index b30d8c24..329ce509 100644 --- a/src/win/graph/direct/brush.cpp +++ b/src/win/graph/direct/brush.cpp @@ -4,8 +4,6 @@ #include "cru/win/graph/direct/exception.hpp" #include "cru/win/graph/direct/factory.hpp" -#include <cassert> - namespace cru::platform::graph::win::direct { D2DSolidColorBrush::D2DSolidColorBrush(DirectGraphFactory* factory) : DirectGraphResource(factory) { diff --git a/src/win/graph/direct/factory.cpp b/src/win/graph/direct/factory.cpp index e67bdafe..0f4739ee 100644 --- a/src/win/graph/direct/factory.cpp +++ b/src/win/graph/direct/factory.cpp @@ -7,7 +7,6 @@ #include "cru/win/graph/direct/geometry.hpp" #include "cru/win/graph/direct/text_layout.hpp" -#include <cassert> #include <cstdlib> #include <utility> diff --git a/src/win/graph/direct/font.cpp b/src/win/graph/direct/font.cpp index 6bd43078..9b5eb477 100644 --- a/src/win/graph/direct/font.cpp +++ b/src/win/graph/direct/font.cpp @@ -5,7 +5,6 @@ #include "cru/win/string.hpp" #include <array> -#include <cassert> #include <utility> namespace cru::platform::graph::win::direct { diff --git a/src/win/graph/direct/geometry.cpp b/src/win/graph/direct/geometry.cpp index 5540edab..57b7f237 100644 --- a/src/win/graph/direct/geometry.cpp +++ b/src/win/graph/direct/geometry.cpp @@ -4,8 +4,6 @@ #include "cru/win/graph/direct/exception.hpp" #include "cru/win/graph/direct/factory.hpp" -#include <cassert> - namespace cru::platform::graph::win::direct { D2DGeometryBuilder::D2DGeometryBuilder(DirectGraphFactory* factory) : DirectGraphResource(factory) { diff --git a/src/win/graph/direct/painter.cpp b/src/win/graph/direct/painter.cpp index fb2a6e7f..c5150ad4 100644 --- a/src/win/graph/direct/painter.cpp +++ b/src/win/graph/direct/painter.cpp @@ -7,12 +7,11 @@ #include "cru/win/graph/direct/geometry.hpp" #include "cru/win/graph/direct/text_layout.hpp" -#include <cassert> #include <type_traits> namespace cru::platform::graph::win::direct { D2DPainter::D2DPainter(ID2D1RenderTarget* render_target) { - assert(render_target); + Expects(render_target); render_target_ = render_target; } diff --git a/src/win/graph/direct/resource.cpp b/src/win/graph/direct/resource.cpp index 2acc91e4..c2be27ed 100644 --- a/src/win/graph/direct/resource.cpp +++ b/src/win/graph/direct/resource.cpp @@ -2,12 +2,10 @@ #include "cru/win/graph/direct/factory.hpp" -#include <cassert> - namespace cru::platform::graph::win::direct { DirectGraphResource::DirectGraphResource(DirectGraphFactory* factory) : factory_(factory) { - assert(factory); + Expects(factory); } IGraphFactory* DirectGraphResource::GetGraphFactory() { return factory_; } diff --git a/src/win/graph/direct/text_layout.cpp b/src/win/graph/direct/text_layout.cpp index 59101163..6a6a2c45 100644 --- a/src/win/graph/direct/text_layout.cpp +++ b/src/win/graph/direct/text_layout.cpp @@ -7,7 +7,6 @@ #include "cru/win/graph/direct/font.hpp" #include "cru/win/string.hpp" -#include <cassert> #include <utility> namespace cru::platform::graph::win::direct { @@ -18,7 +17,7 @@ DWriteTextLayout::DWriteTextLayout(DirectGraphFactory* factory, std::shared_ptr<IFont> font, std::string text) : DirectGraphResource(factory), text_(std::move(text)) { - assert(font); + Expects(font); font_ = CheckPlatform<DWriteFont>(font, GetPlatformId()); w_text_ = cru::platform::win::ToUtf16String(text_); diff --git a/src/win/native/ui_application.cpp b/src/win/native/ui_application.cpp index 892acd50..80460b29 100644 --- a/src/win/native/ui_application.cpp +++ b/src/win/native/ui_application.cpp @@ -12,8 +12,6 @@ #include "timer.hpp" #include "window_manager.hpp" -#include <cassert> - namespace cru::platform::native::win { WinUiApplication* WinUiApplication::instance = nullptr; diff --git a/src/win/native/window.cpp b/src/win/native/window.cpp index fea269d2..1b590026 100644 --- a/src/win/native/window.cpp +++ b/src/win/native/window.cpp @@ -15,7 +15,6 @@ #include "window_manager.hpp" #include <windowsx.h> -#include <cassert> namespace cru::platform::native::win { inline Point PiToDip(const POINT& pi_point) { @@ -28,7 +27,7 @@ WinNativeWindow::WinNativeWindow(WinUiApplication* application, : application_(application), resolver_(std::make_shared<WinNativeWindowResolver>(this)), parent_window_(parent) { - assert(application); // application can't be null. + Expects(application); // application can't be null. if (parent != nullptr) { throw new std::runtime_error("Can't use a invalid window as parent."); @@ -418,7 +417,7 @@ void WinNativeWindow::OnActivatedInternal() {} void WinNativeWindow::OnDeactivatedInternal() {} void WinNativeWindowResolver::Reset() { - assert(window_); // already reset, can't reset again + Expects(window_); // already reset, can't reset again window_ = nullptr; } } // namespace cru::platform::native::win diff --git a/src/win/native/window_d2d_painter.cpp b/src/win/native/window_d2d_painter.cpp index 023559f4..54343fbf 100644 --- a/src/win/native/window_d2d_painter.cpp +++ b/src/win/native/window_d2d_painter.cpp @@ -4,8 +4,6 @@ #include "cru/win/graph/direct/factory.hpp" #include "cru/win/native/window_render_target.hpp" -#include <cassert> - namespace cru::platform::native::win { using namespace cru::platform::graph::win::direct; diff --git a/src/win/native/window_manager.cpp b/src/win/native/window_manager.cpp index 0bf7656a..e1b14f4b 100644 --- a/src/win/native/window_manager.cpp +++ b/src/win/native/window_manager.cpp @@ -4,8 +4,6 @@ #include "cru/win/native/window.hpp" #include "cru/win/native/window_class.hpp" -#include <cassert> - namespace cru::platform::native::win { LRESULT __stdcall GeneralWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { @@ -31,13 +29,13 @@ WindowManager::~WindowManager() { } void WindowManager::RegisterWindow(HWND hwnd, WinNativeWindow* window) { - assert(window_map_.count(hwnd) == 0); // The hwnd is already in the map. + Expects(window_map_.count(hwnd) == 0); // The hwnd is already in the map. window_map_.emplace(hwnd, window); } void WindowManager::UnregisterWindow(HWND hwnd) { const auto find_result = window_map_.find(hwnd); - assert(find_result != window_map_.end()); // The hwnd is not in the map. + Expects(find_result != window_map_.end()); // The hwnd is not in the map. window_map_.erase(find_result); if (window_map_.empty()) application_->RequestQuit(0); } diff --git a/src/win/native/window_render_target.cpp b/src/win/native/window_render_target.cpp index 23ad2afa..eb6673c6 100644 --- a/src/win/native/window_render_target.cpp +++ b/src/win/native/window_render_target.cpp @@ -4,13 +4,11 @@ #include "cru/win/graph/direct/factory.hpp" #include "dpi_util.hpp" -#include <cassert> - namespace cru::platform::native::win { using namespace cru::platform::graph::win::direct; WindowRenderTarget::WindowRenderTarget(DirectGraphFactory* factory, HWND hwnd) : factory_(factory) { - assert(factory); + Expects(factory); const auto d3d11_device = factory->GetD3D11Device(); const auto dxgi_factory = factory->GetDxgiFactory(); @@ -56,7 +54,7 @@ void WindowRenderTarget::Present() { } void WindowRenderTarget::CreateTargetBitmap() { - assert(target_bitmap_ == nullptr); // target bitmap must not exist. + Expects(target_bitmap_ == nullptr); // target bitmap must not exist. // Direct2D needs the dxgi version of the backbuffer surface pointer. Microsoft::WRL::ComPtr<IDXGISurface> dxgi_back_buffer; |