+#include <msp/core/maputils.h>
#include "connector.h"
#include "logic.h"
for(list<Logic::WidgetBinding>::const_iterator i=logic_binds.begin(); i!=logic_binds.end(); ++i)
{
- map<string, ConnAction *>::const_iterator j = actions.find(i->type);
- if(j!=actions.end())
- j->second->connect(*this, *i->wdg, i->data);
- else
- throw KeyError("Unknown binding type", i->type);
+ ConnAction *action = get_item(actions, i->type);
+ action->connect(*this, *i->wdg, i->data);
}
}
namespace Msp {
namespace GLtk {
+hierarchy_error::hierarchy_error(const string &w):
+ logic_error(w)
+{ }
+
+
Container::Container():
click_focus(0),
click_button(0)
return;
}
- throw InvalidState("That Widget is not in this Container");
+ throw hierarchy_error("widget not in container");
}
Container::Child *Container::create_child(Widget *wdg)
#define MSP_GLTK_CONTAINER_H_
#include <list>
+#include <stdexcept>
#include <sigc++/trackable.h>
#include "widget.h"
namespace Msp {
namespace GLtk {
+class hierarchy_error: public std::logic_error
+{
+public:
+ hierarchy_error(const std::string &);
+ virtual ~hierarchy_error() throw() { }
+};
+
+
class Container: virtual public Widget
{
protected:
void Layout::set_container(Container &c)
{
if(container)
- throw InvalidState("This layout is already assigned to a Container");
+ throw logic_error("container!=0");
container = &c;
}
void Layout::add_widget(Widget &wdg)
{
if(!container)
- throw InvalidState("Can't add Widgets without a Container");
+ throw logic_error("!container");
Slot *slot = create_slot(wdg);
for(list<Constraint>::iterator i=slot->constraints.begin(); i!=slot->constraints.end(); ++i)
if(&(*i)->widget==&wdg)
return **i;
- throw InvalidParameterValue("Widget is not in the Layout");
+ throw hierarchy_error("widget not in layout");
}
Layout::ConstraintType Layout::complement(ConstraintType type)
void Layout::add_constraint(Widget &src, ConstraintType type, Widget &tgt)
{
if(&src==&tgt)
- throw InvalidParameterValue("Can't add a self-referencing constraint");
+ throw invalid_argument("&src==&tgt");
Slot &src_slot = get_slot_for_widget(src);
Slot &tgt_slot = get_slot_for_widget(tgt);
Layout::LinearProgram::Row Layout::LinearProgram::operator[](unsigned r)
{
if(r>=n_rows)
- throw InvalidParameterValue("Row index out of range");
+ throw out_of_range("LinearProgram::operator[]");
return Row(*this, r);
}
float Layout::LinearProgram::get_variable(unsigned i)
{
if(!solved || infeasible)
- throw InvalidState("Not solved");
+ throw logic_error("not solved");
if(i+1>=n_columns)
- throw InvalidParameterValue("Variable index out of range");
+ throw out_of_range("LinearProgram::get_variable");
unsigned r = columns[i].basic;
return columns.back().values[r];
float &Layout::LinearProgram::Row::operator[](unsigned c)
{
if(c>=linprog.n_columns)
- throw InvalidParameterValue("Column index out of range");
+ throw out_of_range("Row::operator[]");
Column &column = linprog.columns[c];
if(column.values.size()<=index)
void List::insert(unsigned i, const string &v)
{
if(i>items.size())
- throw InvalidParameterValue("Index out of range");
+ throw out_of_range("List::insert");
items.insert(items.begin()+i, v);
check_view_range();
void List::remove(unsigned i)
{
if(i>items.size())
- throw InvalidParameterValue("Index out of range");
+ throw out_of_range("List::remove");
items.erase(items.begin()+i);
if(sel_index>static_cast<int>(i))
signal_item_selected.emit(sel_index, items[sel_index]);
}
else
- throw InvalidParameterValue("Index out of range");
+ throw out_of_range("List::set_selected_index");
}
const string &List::get_selected() const
{
if(sel_index<0)
- throw InvalidState("No selection");
+ throw logic_error("sel_index<0");
return items[sel_index];
}
+#include <msp/core/maputils.h>
#include "logic.h"
using namespace std;
void Logic::Loader::bind(const string &wdg, const string &data)
{
- map<string, Widget *>::const_iterator i = widgets.find(wdg);
- if(i==widgets.end())
- throw KeyError("Unknown widget", wdg);
+ WidgetBinding act;
+ act.wdg = get_item(widgets, wdg);
string::size_type colon = data.find(':');
- WidgetBinding act;
- act.wdg = i->second;
act.type = data.substr(0, colon);
if(colon!=string::npos)
act.data = data.substr(colon+1);
#include <map>
#include <string>
#include <sigc++/slot.h>
-#include <msp/core/except.h>
#include <msp/datafile/loader.h>
namespace Msp {
return;
}
- throw InvalidState("That Widget is not in this Panel");
+ throw hierarchy_error("widget not in panel");
}
Widget *Panel::get_final_input_focus() const
const Graphic *Part::get_graphic(State state) const
{
if(state>N_STATES_)
- throw InvalidParameterValue("Invalid state");
+ throw invalid_argument("Part::get_graphic");
return graphic[state];
}
-#include <msp/core/except.h>
#include <msp/fs/utils.h>
#include "resources.h"
const GL::Font &Resources::get_default_font() const
{
if(!default_font)
- throw InvalidState("No default font");
+ throw logic_error("!default_font");
return *default_font;
}
+#include <stdexcept>
#include <msp/gl/matrix.h>
#include <msp/gl/transform.h>
#include "part.h"
void Table::set_column_width(unsigned c, unsigned w)
{
if(c>=columns)
- throw InvalidParameterValue("Column index out of bounds");
+ throw invalid_argument("Table::set_column_width");
col_w[c] = w;
}
void Table::set_cell_text(unsigned r, unsigned c, const string &t)
{
if(r>=rows || c>=columns)
- throw InvalidParameterValue("Cell coordinates out of bounds");
+ throw out_of_range("Table::set_cell_text");
data[r*columns+c] = t;
}
unsigned Text::get_line_length(unsigned i) const
{
if(i>=lines.size())
- throw InvalidParameterValue("Invalid line number");
+ throw out_of_range("Text::get_line_length");
return lines[i].length;
}
#ifndef MSP_GLTK_USERINTERFACE_H_
#define MSP_GLTK_USERINTERFACE_H_
+#include <msp/core/maputils.h>
#include "logic.h"
#include "root.h"
template<typename W>
W &get_widget(const std::string &n) const
{
- WidgetMap::const_iterator i = widgets.find(n);
- if(i==widgets.end())
- throw KeyError("Unknown widget", n);
-
- W *w = dynamic_cast<W *>(i->second);
- if(!w)
- throw Exception("Widget type mismatch");
-
- return *w;
+ return dynamic_cast<W &>(*get_item(widgets, n));
}
template<typename W>
void Widget::set_parent(Container *p)
{
if(parent && p)
- throw InvalidState("Widget is already in a Container");
+ throw hierarchy_error("widget already parented");
else if(p==parent)
return;
parent = p;
void Widget::set_focus()
{
if(!parent)
- throw InvalidState("No parent");
+ throw hierarchy_error("no parent");
if(!visible)
- throw InvalidState("Can't set focus on invisible widget");
+ throw logic_error("!visible");
signal_request_focus.emit();
}
void Widget::render() const
{
if(!style)
- throw InvalidState(format("Attempt to render a widget with null style (class=\"%s\", style_name=\"%s\")", get_class(), style_name));
+ throw logic_error(format("Attempt to render a widget with null style (class=\"%s\", style_name=\"%s\")", get_class(), style_name));
GL::push_matrix();
GL::translate(geom.x, geom.y, 0);