From: Mikko Rasa Date: Sun, 16 Jun 2013 08:26:58 +0000 (+0300) Subject: Add some sanity checks to arrangements X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=304500a51a1a9d00e3c84ed2a6ffda0f829445b4;p=libs%2Fgltk.git Add some sanity checks to arrangements --- diff --git a/source/arrangement.h b/source/arrangement.h index 284d3f7..ed1798b 100644 --- a/source/arrangement.h +++ b/source/arrangement.h @@ -2,6 +2,7 @@ #define MSP_GLTK_ARRANGEMENT_H_ #include +#include #include "layout.h" namespace Msp { @@ -9,6 +10,13 @@ namespace GLtk { class Widget; +class arrangement_error: public std::logic_error +{ +public: + arrangement_error(const std::string &w): std::logic_error(w) { } + virtual ~arrangement_error() throw() { } +}; + class Arrangement { protected: diff --git a/source/column.cpp b/source/column.cpp index d31544a..811185d 100644 --- a/source/column.cpp +++ b/source/column.cpp @@ -12,6 +12,9 @@ Column::Column(Layout &l): void Column::split() { + if(gravity<0) + throw arrangement_error("already split"); + split_here = true; gravity = -1; } diff --git a/source/grid.cpp b/source/grid.cpp index 6296098..3b44ac8 100644 --- a/source/grid.cpp +++ b/source/grid.cpp @@ -17,6 +17,9 @@ void Grid::skip() void Grid::next_row() { + if(row_bottom.empty()) + throw arrangement_error("empty row not allowed"); + finish_row(); } diff --git a/source/row.cpp b/source/row.cpp index ae13e49..92f3fe6 100644 --- a/source/row.cpp +++ b/source/row.cpp @@ -12,6 +12,9 @@ Row::Row(Layout &l): void Row::split() { + if(gravity>0) + throw arrangement_error("already split"); + split_here = true; gravity = 1; }