diff options
| author | MenTaLguY <mental@rydia.net> | 2007-03-04 02:08:21 +0000 |
|---|---|---|
| committer | mental <mental@users.sourceforge.net> | 2007-03-04 02:08:21 +0000 |
| commit | 4f7fe42548e3f91dffc8df220c04f16911497346 (patch) | |
| tree | e72476964c14896870222829d38e55f387ed3995 /src | |
| parent | remove debug messages that sneaked in (diff) | |
| download | inkscape-4f7fe42548e3f91dffc8df220c04f16911497346.tar.gz inkscape-4f7fe42548e3f91dffc8df220c04f16911497346.zip | |
make conversions away from NR::Maybe explicit
(bzr r2530)
Diffstat (limited to 'src')
| -rw-r--r-- | src/event-context.cpp | 4 | ||||
| -rw-r--r-- | src/libnr/nr-maybe.h | 50 | ||||
| -rw-r--r-- | src/node-context.cpp | 6 | ||||
| -rw-r--r-- | src/nodepath.cpp | 12 | ||||
| -rw-r--r-- | src/object-snapper.cpp | 2 | ||||
| -rw-r--r-- | src/select-context.cpp | 6 | ||||
| -rw-r--r-- | src/zoom-context.cpp | 4 |
7 files changed, 32 insertions, 52 deletions
diff --git a/src/event-context.cpp b/src/event-context.cpp index 0cf4f8924..7a3de5e85 100644 --- 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 6eed01ec1..9c1aa0708 100644 --- a/src/libnr/nr-maybe.h +++ b/src/libnr/nr-maybe.h @@ -29,27 +29,7 @@ public: 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; @@ -59,6 +39,7 @@ class Maybe { 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() {} @@ -73,32 +54,21 @@ public: 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: @@ -111,6 +81,7 @@ 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; } @@ -119,6 +90,7 @@ struct MaybeTraits { 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 235b89db3..352bac584 100644 --- a/src/node-context.cpp +++ b/src/node-context.cpp @@ -419,8 +419,8 @@ sp_node_context_root_handler(SPEventContext *event_context, GdkEvent *event) 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()) @@ -584,7 +584,7 @@ sp_node_context_root_handler(SPEventContext *event_context, GdkEvent *event) 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 78d76404d..1d854418b 100644 --- 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 6b51f8508..4a21cbc04 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -128,7 +128,7 @@ void Inkscape::ObjectSnapper::_snapPaths(Inkscape::SnappedPoint &s, /* 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 5d8babe57..e1649e34f 100644 --- a/src/select-context.cpp +++ b/src/select-context.cpp @@ -229,7 +229,7 @@ sp_select_context_abort(SPEventContext *event_context) } } 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 62395581f..d2b0d6849 100644 --- 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)); |
