aboutsummaryrefslogtreecommitdiff
path: root/src/ui/layout_control.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-03-21 22:44:31 +0800
committercrupest <crupest@outlook.com>2019-03-21 22:44:31 +0800
commitafdac77a66143375b5bebd4ff128b0fba87c5d21 (patch)
tree8c003a2d32e9411e55544114a3c2c14128909910 /src/ui/layout_control.cpp
parentb514247f79469c15959b00ca3276879033f932ff (diff)
downloadcru-afdac77a66143375b5bebd4ff128b0fba87c5d21.tar.gz
cru-afdac77a66143375b5bebd4ff128b0fba87c5d21.tar.bz2
cru-afdac77a66143375b5bebd4ff128b0fba87c5d21.zip
Change all error handling.
Diffstat (limited to 'src/ui/layout_control.cpp')
-rw-r--r--src/ui/layout_control.cpp21
1 files changed, 5 insertions, 16 deletions
diff --git a/src/ui/layout_control.cpp b/src/ui/layout_control.cpp
index d2b430dd..c0c4a7fe 100644
--- a/src/ui/layout_control.cpp
+++ b/src/ui/layout_control.cpp
@@ -3,24 +3,14 @@
#include "window.hpp"
namespace cru::ui {
-void ControlAddChildCheck(Control* control) {
- if (control->GetParent() != nullptr)
- throw std::invalid_argument("The control already has a parent.");
-
- if (dynamic_cast<Window*>(control))
- throw std::invalid_argument("Can't add a window as child.");
-}
-
LayoutControl::~LayoutControl() {
for (const auto child : children_) delete child;
}
void LayoutControl::AddChild(Control* control, const int position) {
- ControlAddChildCheck(control);
-
- if (position < 0 || static_cast<decltype(children_.size())>(position) >
- this->children_.size())
- throw std::invalid_argument("The position is out of range.");
+ 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 || position <= this->children_.size()); // The position is out of range.
children_.insert(this->children_.cbegin() + position, control);
@@ -31,9 +21,8 @@ void LayoutControl::AddChild(Control* control, const int position) {
}
void LayoutControl::RemoveChild(const int position) {
- if (position < 0 || static_cast<decltype(this->children_.size())>(position) >=
- this->children_.size())
- throw std::invalid_argument("The position is out of range.");
+ assert(position >= 0 &&
+ position < this->children_.size()); // The position is out of range.
const auto i = children_.cbegin() + position;
const auto child = *i;