summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a50faa6)
raw | patch | inline | side by side (parent: a50faa6)
author | mental <mental@users.sourceforge.net> | |
Sun, 4 Mar 2007 02:08:21 +0000 (02:08 +0000) | ||
committer | mental <mental@users.sourceforge.net> | |
Sun, 4 Mar 2007 02:08:21 +0000 (02:08 +0000) |
diff --git a/src/event-context.cpp b/src/event-context.cpp
index 0cf4f89244a6fb3b15f4e20e85ede51fbce16339..7a3de5e85fb94c5006d2b2814013d94efb76fe9b 100644 (file)
--- a/src/event-context.cpp
+++ b/src/event-context.cpp
@@ -463,8 +463,8 @@ static gint sp_event_context_private_root_handler(SPEventContext *event_context,
zoom_rb = 0;
NR::Maybe<NR::Rect> const b = Inkscape::Rubberband::get()->getRectangle();
Inkscape::Rubberband::get()->stop();
- if (b != NR::Nothing() && !within_tolerance) {
- desktop->set_display_area(b.assume(), 10);
+ if (b && !within_tolerance) {
+ desktop->set_display_area(*b, 10);
}
ret = TRUE;
}
diff --git a/src/libnr/nr-maybe.h b/src/libnr/nr-maybe.h
index 6eed01ec18f8944eef3c808a0653f2da0f4512d7..9c1aa07081fbf9fb45ea61a6cdd0e749ff80c11e 100644 (file)
--- a/src/libnr/nr-maybe.h
+++ b/src/libnr/nr-maybe.h
IsNot() : domain_error(std::string("Is not ") + typeid(T).name()) {}
};
-/** A type with only one value, which (in principle) is only equal to itself.
- *
- * Types that may (at runtime) pretend to be Nothing need only provide an
- * operator bool operator==(Type, Nothing); the rest of the operator
- * definitions will be taken care of automatically.
- *
- * Such types should also provide a casting operator to Nothing, obviously.
- */
-struct Nothing {
- bool operator==(Nothing n) { return true; }
- bool operator!=(Nothing n) { return false; }
- template <typename T>
- bool operator==(T t) { return t == *this; }
- template <typename T>
- bool operator!=(T t) { return t != *this; }
-};
-
-template <typename T>
-bool operator==(T t, Nothing n) { return false; }
-template <typename T>
-bool operator!=(T t, Nothing n) { return !( t == n ); }
+struct Nothing {};
template <typename T>
struct MaybeTraits;
public:
typedef MaybeTraits<T> traits;
typedef typename traits::storage storage;
+ typedef typename traits::pointer pointer;
typedef typename traits::reference reference;
Maybe(Nothing n) : _is_nothing(true), _t() {}
template <typename T2>
Maybe(T2 t) : _is_nothing(false), _t(traits::to_storage(t)) {}
- reference assume() const throw(IsNot<T>) {
- if (_is_nothing) {
- throw IsNot<T>();
- } else {
- return traits::from_storage(_t);
- }
- }
+ bool isNothing() const { return _is_nothing; }
+ operator bool() const { return !_is_nothing; }
- operator reference() const throw(IsNot<T>) {
+ reference assume() const throw(IsNot<T>) {
if (_is_nothing) {
throw IsNot<T>();
} else {
return traits::from_storage(_t);
}
}
- operator Nothing() const throw(IsNot<Nothing>) {
- if (!_is_nothing) {
- throw IsNot<Nothing>();
- } else {
- return Nothing();
- }
+ reference operator*() const throw(IsNot<T>) {
+ return assume();
}
-
- bool operator==(Nothing n) { return _is_nothing; }
- bool operator==(reference r) {
- return traits::from_storage(_t) == r;
+ pointer operator->() const throw(IsNot<T>) {
+ return &assume();
}
private:
template <typename T>
struct MaybeTraits {
typedef T const storage;
+ typedef T const *pointer;
typedef T const &reference;
static reference to_storage(reference t) { return t; }
static reference from_storage(reference t) { return t; }
template <typename T>
struct MaybeTraits<T&> {
typedef T *storage;
+ typedef T *pointer;
typedef T &reference;
static storage to_storage(reference t) { return &t; }
static reference from_storage(storage t) { return *t; }
diff --git a/src/node-context.cpp b/src/node-context.cpp
index 235b89db3d34215391f7e1aeaa6664fe8706ed43..352bac58465b917cb3d2166f8419e761f5109e9b 100644 (file)
--- a/src/node-context.cpp
+++ b/src/node-context.cpp
if (nc->shape_editor->hits_curve() && !event_context->within_tolerance) { //drag curve
nc->shape_editor->finish_drag();
- } else if (b != NR::Nothing() && !event_context->within_tolerance) { // drag to select
- nc->shape_editor->select_rect(b.assume(), event->button.state & GDK_SHIFT_MASK);
+ } else if (b && !event_context->within_tolerance) { // drag to select
+ nc->shape_editor->select_rect(*b, event->button.state & GDK_SHIFT_MASK);
} else {
if (!(nc->rb_escaped)) { // unless something was cancelled
if (nc->shape_editor->has_selection())
case GDK_Escape:
{
NR::Maybe<NR::Rect> const b = Inkscape::Rubberband::get()->getRectangle();
- if (b != NR::Nothing()) {
+ if (b) {
Inkscape::Rubberband::get()->stop();
nc->current_state = SP_NODE_CONTEXT_INACTIVE;
nc->rb_escaped = true;
diff --git a/src/nodepath.cpp b/src/nodepath.cpp
index 78d76404df2b0aacbb732d59eac5558760b35edb..1d854418bcea51b39363d0a75457258a0ee65c21 100644 (file)
--- a/src/nodepath.cpp
+++ b/src/nodepath.cpp
@@ -1549,7 +1549,11 @@ sp_nodepath_select_segment_near_point(Inkscape::NodePath::Path *nodepath, NR::Po
}
sp_nodepath_ensure_livarot_path(nodepath);
- Path::cut_position position = get_nearest_position_on_Path(nodepath->livarot_path, p);
+ NR::Maybe<Path::cut_position> maybe_position = get_nearest_position_on_Path(nodepath->livarot_path, p);
+ if (!maybe_position) {
+ return;
+ }
+ Path::cut_position position = *maybe_position;
//find segment to segment
Inkscape::NodePath::Node *e = sp_nodepath_get_node_by_index(position.piece);
@@ -1581,7 +1585,11 @@ sp_nodepath_add_node_near_point(Inkscape::NodePath::Path *nodepath, NR::Point p)
}
sp_nodepath_ensure_livarot_path(nodepath);
- Path::cut_position position = get_nearest_position_on_Path(nodepath->livarot_path, p);
+ NR::Maybe<Path::cut_position> maybe_position = get_nearest_position_on_Path(nodepath->livarot_path, p);
+ if (!maybe_position) {
+ return;
+ }
+ Path::cut_position position = *maybe_position;
//find segment to split
Inkscape::NodePath::Node *e = sp_nodepath_get_node_by_index(position.piece);
diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp
index 6b51f85085e44da72335c5db9f975c2658756b45..4a21cbc04fbfd32677913accf22567219a1ad5aa 100644 (file)
--- a/src/object-snapper.cpp
+++ b/src/object-snapper.cpp
/* Look for the nearest position on this SPItem to our snap point */
NR::Maybe<Path::cut_position> const o = get_nearest_position_on_Path(livarot_path, p_it);
- if (o != NR::Nothing() && o.assume().t >= 0 && o.assume().t <= 1) {
+ if (o && o->t >= 0 && o->t <= 1) {
/* Convert the nearest point back to desktop coordinates */
NR::Point const o_it = get_point_on_Path(livarot_path, o.assume().piece, o.assume().t);
diff --git a/src/select-context.cpp b/src/select-context.cpp
index 5d8babe57313862d82c2a7e96130a75abb10cb6f..e1649e34f164b07d8bba7fb44bf8512ee8ec3378 100644 (file)
--- a/src/select-context.cpp
+++ b/src/select-context.cpp
}
} else {
NR::Maybe<NR::Rect> const b = Inkscape::Rubberband::get()->getRectangle();
- if (b != NR::Nothing()) {
+ if (b) {
Inkscape::Rubberband::get()->stop();
rb_escaped = 1;
SP_EVENT_CONTEXT(sc)->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Selection canceled."));
@@ -567,12 +567,12 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event)
sc->item = NULL;
} else {
NR::Maybe<NR::Rect> const b = Inkscape::Rubberband::get()->getRectangle();
- if (b != NR::Nothing() && !within_tolerance) {
+ if (b && !within_tolerance) {
// this was a rubberband drag
Inkscape::Rubberband::get()->stop();
seltrans->resetState();
// find out affected items:
- GSList *items = sp_document_items_in_box(sp_desktop_document(desktop), desktop->dkey, b.assume());
+ GSList *items = sp_document_items_in_box(sp_desktop_document(desktop), desktop->dkey, *b);
if (event->button.state & GDK_SHIFT_MASK) {
// with shift, add to selection
selection->addList (items);
diff --git a/src/zoom-context.cpp b/src/zoom-context.cpp
index 62395581f400003b269957e8da74589f68b4431e..d2b0d684992bb2e8000256f71c32236fdd5d7ce2 100644 (file)
--- a/src/zoom-context.cpp
+++ b/src/zoom-context.cpp
@@ -163,8 +163,8 @@ static gint sp_zoom_context_root_handler(SPEventContext *event_context, GdkEvent
case GDK_BUTTON_RELEASE:
if ( event->button.button == 1 ) {
NR::Maybe<NR::Rect> const b = Inkscape::Rubberband::get()->getRectangle();
- if (b != NR::Nothing() && !within_tolerance) {
- desktop->set_display_area(b.assume(), 10);
+ if (b && !within_tolerance) {
+ desktop->set_display_area(*b, 10);
} else if (!escaped) {
NR::Point const button_w(event->button.x, event->button.y);
NR::Point const button_dt(desktop->w2d(button_w));