summaryrefslogtreecommitdiffstats
path: root/src/libnr
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2008-08-05 22:40:31 +0000
committerjohanengelen <johanengelen@users.sourceforge.net>2008-08-05 22:40:31 +0000
commit900577c7e71534ec32dcb4e0677a509a6e517b12 (patch)
tree8d5b4c6201b0728bff338e89106d1a8c5a0b7fef /src/libnr
parentcodedread's patch for bug 254850 (fixes handling of description field in Obje... (diff)
downloadinkscape-900577c7e71534ec32dcb4e0677a509a6e517b12.tar.gz
inkscape-900577c7e71534ec32dcb4e0677a509a6e517b12.zip
NR::Maybe => boost::optional
(bzr r6569)
Diffstat (limited to 'src/libnr')
-rw-r--r--src/libnr/nr-convex-hull.h8
-rw-r--r--src/libnr/nr-rect-l.cpp4
-rw-r--r--src/libnr/nr-rect-l.h6
-rw-r--r--src/libnr/nr-rect.cpp14
-rw-r--r--src/libnr/nr-rect.h37
5 files changed, 26 insertions, 43 deletions
diff --git a/src/libnr/nr-convex-hull.h b/src/libnr/nr-convex-hull.h
index 51dabcf07..dafdd8840 100644
--- a/src/libnr/nr-convex-hull.h
+++ b/src/libnr/nr-convex-hull.h
@@ -20,11 +20,11 @@ public:
ConvexHull() : _bounds() {}
explicit ConvexHull(Point const &p) : _bounds(Rect(p, p)) {}
- Maybe<Point> midpoint() const {
+ boost::optional<Point> midpoint() const {
if (_bounds) {
return _bounds->midpoint();
} else {
- return Nothing();
+ return boost::optional<Point>();
}
}
@@ -46,12 +46,12 @@ public:
}
}
- Maybe<Rect> const &bounds() const {
+ boost::optional<Rect> const &bounds() const {
return _bounds;
}
private:
- Maybe<Rect> _bounds;
+ boost::optional<Rect> _bounds;
};
} /* namespace NR */
diff --git a/src/libnr/nr-rect-l.cpp b/src/libnr/nr-rect-l.cpp
index fa3c687c5..4f6c5c866 100644
--- a/src/libnr/nr-rect-l.cpp
+++ b/src/libnr/nr-rect-l.cpp
@@ -1,8 +1,8 @@
#include <libnr/nr-rect-l.h>
-NR::Maybe<NR::Rect> NRRectL::upgrade() const {
+boost::optional<NR::Rect> NRRectL::upgrade() const {
if (nr_rect_l_test_empty_ptr(this)) {
- return NR::Nothing();
+ return boost::optional<NR::Rect>();
} else {
return NR::Rect(NR::Point(x0, y0), NR::Point(x1, y1));
}
diff --git a/src/libnr/nr-rect-l.h b/src/libnr/nr-rect-l.h
index 18065d1d7..f21ba8fc6 100644
--- a/src/libnr/nr-rect-l.h
+++ b/src/libnr/nr-rect-l.h
@@ -2,12 +2,12 @@
#define SEEN_NR_RECT_L_H
#include <libnr/nr-i-coord.h>
-#include <libnr/nr-maybe.h>
+#include <boost/optional.hpp>
#include <libnr/nr-rect.h>
#include <libnr/nr-point-l.h>
struct NRRectL {
- NR::Maybe<NR::Rect> upgrade() const;
+ boost::optional<NR::Rect> upgrade() const;
NR::ICoord x0, y0, x1, y1;
};
@@ -79,7 +79,7 @@ public:
void expandTo(const IRect &r);
/** Returns the set of points shared by both rectangles. */
- static Maybe<IRect> intersection(const IRect &a, const IRect &b);
+ static boost::optional<IRect> intersection(const IRect &a, const IRect &b);
/** Returns the smallest rectangle that encloses both rectangles. */
static IRect union_bounds(const IRect &a, const IRect &b);
diff --git a/src/libnr/nr-rect.cpp b/src/libnr/nr-rect.cpp
index 04d93ae04..77af27417 100644
--- a/src/libnr/nr-rect.cpp
+++ b/src/libnr/nr-rect.cpp
@@ -17,7 +17,7 @@ NRRect::NRRect(NR::Rect const &rect)
x1(rect.max()[NR::X]), y1(rect.max()[NR::Y])
{}
-NRRect::NRRect(NR::Maybe<NR::Rect> const &rect) {
+NRRect::NRRect(boost::optional<NR::Rect> const &rect) {
if (rect) {
x0 = rect->min()[NR::X];
y0 = rect->min()[NR::Y];
@@ -28,9 +28,9 @@ NRRect::NRRect(NR::Maybe<NR::Rect> const &rect) {
}
}
-NR::Maybe<NR::Rect> NRRect::upgrade() const {
+boost::optional<NR::Rect> NRRect::upgrade() const {
if (nr_rect_d_test_empty_ptr(this)) {
- return NR::Nothing();
+ return boost::optional<NR::Rect>();
} else {
return NR::Rect(NR::Point(x0, y0), NR::Point(x1, y1));
}
@@ -308,17 +308,17 @@ void Rect::growBy(double size) {
}
/** Returns the set of points shared by both rectangles. */
-Maybe<Rect> intersection(Maybe<Rect> const & a, Maybe<Rect> const & b) {
+boost::optional<Rect> intersection(boost::optional<Rect> const & a, boost::optional<Rect> const & b) {
if ( !a || !b ) {
- return Nothing();
+ return boost::optional<Rect>();
} else {
Rect r;
for ( int i=0 ; i < 2 ; i++ ) {
r._min[i] = std::max(a->_min[i], b->_min[i]);
r._max[i] = std::min(a->_max[i], b->_max[i]);
if ( r._min[i] > r._max[i] ) {
- return Nothing();
- }
+ return boost::optional<Rect>();
+ }
}
return r;
}
diff --git a/src/libnr/nr-rect.h b/src/libnr/nr-rect.h
index da1299b2b..7d130fd18 100644
--- a/src/libnr/nr-rect.h
+++ b/src/libnr/nr-rect.h
@@ -22,7 +22,7 @@
#include <libnr/nr-i-coord.h>
#include <libnr/nr-dim2.h>
#include <libnr/nr-point.h>
-#include <libnr/nr-maybe.h>
+#include <boost/optional.hpp>
#include <libnr/nr-point-matrix-ops.h>
#include <libnr/nr-forward.h>
@@ -147,7 +147,7 @@ public:
friend inline std::ostream &operator<<(std::ostream &out_file, NR::Rect const &in_rect);
private:
- Rect(Nothing) : _min(1, 1), _max(-1, -1) {}
+// Rect(Nothing) : _min(1, 1), _max(-1, -1) {}
static double _inf() {
return std::numeric_limits<double>::infinity();
@@ -180,47 +180,30 @@ private:
Point _min, _max;
- friend class MaybeStorage<Rect>;
- friend Maybe<Rect> intersection(Maybe<Rect> const &, Maybe<Rect> const &);
+ friend boost::optional<Rect> intersection(boost::optional<Rect> const &, boost::optional<Rect> const &);
friend Rect union_bounds(Rect const &, Rect const &);
};
-template <>
-class MaybeStorage<Rect> {
-public:
- MaybeStorage() : _rect(Nothing()) {}
- MaybeStorage(Rect const &rect) : _rect(rect) {}
-
- bool is_nothing() const {
- return _rect._min[X] > _rect._max[X];
- }
- Rect const &value() const { return _rect; }
- Rect &value() { return _rect; }
-
-private:
- Rect _rect;
-};
-
/** Returns the set of points shared by both rectangles. */
-Maybe<Rect> intersection(Maybe<Rect> const & a, Maybe<Rect> const & b);
+boost::optional<Rect> intersection(boost::optional<Rect> const & a, boost::optional<Rect> const & b);
/** Returns the smallest rectangle that encloses both rectangles. */
Rect union_bounds(Rect const &a, Rect const &b);
-inline Rect union_bounds(Maybe<Rect> const & a, Rect const &b) {
+inline Rect union_bounds(boost::optional<Rect> const & a, Rect const &b) {
if (a) {
return union_bounds(*a, b);
} else {
return b;
}
}
-inline Rect union_bounds(Rect const &a, Maybe<Rect> const & b) {
+inline Rect union_bounds(Rect const &a, boost::optional<Rect> const & b) {
if (b) {
return union_bounds(a, *b);
} else {
return a;
}
}
-inline Maybe<Rect> union_bounds(Maybe<Rect> const & a, Maybe<Rect> const & b)
+inline boost::optional<Rect> union_bounds(boost::optional<Rect> const & a, boost::optional<Rect> const & b)
{
if (!a) {
return b;
@@ -257,9 +240,9 @@ struct NRRect {
: x0(xmin), y0(ymin), x1(xmax), y1(ymax)
{}
explicit NRRect(NR::Rect const &rect);
- explicit NRRect(NR::Maybe<NR::Rect> const &rect);
- operator NR::Maybe<NR::Rect>() const { return upgrade(); }
- NR::Maybe<NR::Rect> upgrade() const;
+ explicit NRRect(boost::optional<NR::Rect> const &rect);
+ operator boost::optional<NR::Rect>() const { return upgrade(); }
+ boost::optional<NR::Rect> upgrade() const;
NR::Coord x0, y0, x1, y1;
};