On Wed, Feb 04, 2004 at 09:01:58AM +0100, Lars Gullik Bjønnes spake thusly:
 
> 
> >> BOOST_ASSERT(ptr_cmp(cur.inset(), this));
> >> 
> >> template <typename A, typename B>
> >> bool ptr_cmp(A const * a, B const * b)
> >> {
> >>         return a == b;
> >> }
> >
> | Ribbon, meet turd.

The good news is: the turd works. Shall I check it in as it is better
than what is there now? As you say it's not pretty, but localized.

- Martin

PS perhaps the namespace could be named differently...

Index: cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v
retrieving revision 1.48
diff -u -p -r1.48 cursor.C
--- cursor.C    3 Feb 2004 17:12:34 -0000       1.48
+++ cursor.C    4 Feb 2004 11:24:41 -0000
@@ -860,7 +860,7 @@ bool LCursor::openable(MathAtom const & 
        // we can't move into anything new during selection
        if (depth() == anchor_.size())
                return false;
-       if (t.nucleus() != anchor_[depth()].inset())
+       if (!turd::ptr_cmp(t.nucleus(), anchor_[depth()].inset()))
                return false;
 
        return true;
Index: cursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.h,v
retrieving revision 1.29
diff -u -p -r1.29 cursor.h
--- cursor.h    3 Feb 2004 16:44:56 -0000       1.29
+++ cursor.h    4 Feb 2004 11:24:41 -0000
@@ -33,6 +33,18 @@ class PainterInfo;
 class MathUnknownInset;
 class MathGridInset;
 
+
+namespace turd {
+
+template <typename A, typename B>
+bool ptr_cmp(A const * a, B const * b)
+{
+return a == b;
+}
+
+} // end namespace
+
+
 // this is used for traversing math insets
 typedef std::vector<CursorSlice> CursorBase;
 /// move on one step
Index: mathed/math_nestinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_nestinset.C,v
retrieving revision 1.88
diff -u -p -r1.88 math_nestinset.C
--- mathed/math_nestinset.C     3 Feb 2004 16:49:09 -0000       1.88
+++ mathed/math_nestinset.C     4 Feb 2004 11:24:41 -0000
@@ -45,6 +45,8 @@ using std::endl;
 using std::string;
 using std::istringstream;
 
+using turd::ptr_cmp;
+
 
 MathNestInset::MathNestInset(idx_type nargs)
        : cells_(nargs), lock_(false)
@@ -72,7 +74,7 @@ MathArray const & MathNestInset::cell(id
 void MathNestInset::getCursorPos(CursorSlice const & cur,
        int & x, int & y) const
 {
-       BOOST_ASSERT(cur.inset() == const_cast<MathNestInset *>(this));
+       BOOST_ASSERT(ptr_cmp(cur.inset(), this));
        MathArray const & ar = cur.cell();
        x = ar.xo() + ar.pos2x(cur.pos());
        y = ar.yo();
@@ -99,7 +101,7 @@ void MathNestInset::metrics(MetricsInfo 
 
 bool MathNestInset::idxNext(LCursor & cur) const
 {
-       BOOST_ASSERT(cur.inset() == const_cast<MathNestInset *>(this));
+       BOOST_ASSERT(ptr_cmp(cur.inset(), this));
        if (cur.idx() == cur.lastidx())
                return false;
        ++cur.idx();
@@ -116,7 +118,7 @@ bool MathNestInset::idxRight(LCursor & c
 
 bool MathNestInset::idxPrev(LCursor & cur) const
 {
-       BOOST_ASSERT(cur.inset() == const_cast<MathNestInset *>(this));
+       BOOST_ASSERT(ptr_cmp(cur.inset(), this));
        if (cur.idx() == 0)
                return false;
        --cur.idx();
@@ -133,7 +135,7 @@ bool MathNestInset::idxLeft(LCursor & cu
 
 bool MathNestInset::idxFirst(LCursor & cur) const
 {
-       BOOST_ASSERT(cur.inset() == const_cast<MathNestInset *>(this));
+       BOOST_ASSERT(ptr_cmp(cur.inset(), this));
        if (nargs() == 0)
                return false;
        cur.idx() = 0;
@@ -144,7 +146,7 @@ bool MathNestInset::idxFirst(LCursor & c
 
 bool MathNestInset::idxLast(LCursor & cur) const
 {
-       BOOST_ASSERT(cur.inset() == const_cast<MathNestInset *>(this));
+       BOOST_ASSERT(ptr_cmp(cur.inset(), this));
        if (nargs() == 0)
                return false;
        cur.idx() = cur.lastidx();
@@ -155,7 +157,7 @@ bool MathNestInset::idxLast(LCursor & cu
 
 bool MathNestInset::idxHome(LCursor & cur) const
 {
-       BOOST_ASSERT(cur.inset() ==  const_cast<MathNestInset *>(this));
+       BOOST_ASSERT(ptr_cmp(cur.inset(), this));
        if (cur.pos() == 0)
                return false;
        cur.pos() = 0;
@@ -165,7 +167,7 @@ bool MathNestInset::idxHome(LCursor & cu
 
 bool MathNestInset::idxEnd(LCursor & cur) const
 {
-       BOOST_ASSERT(cur.inset() ==  const_cast<MathNestInset *>(this));
+       BOOST_ASSERT(ptr_cmp(cur.inset(), this));
        if (cur.lastpos() == cur.lastpos())
                return false;
        cur.pos() = cur.lastpos();
@@ -202,7 +204,7 @@ void MathNestInset::drawSelection(Painte
        LCursor & cur = pi.base.bv->cursor();
        if (!cur.selection())
                return;
-       if (cur.inset() != const_cast<MathNestInset *>(this))
+       if (!ptr_cmp(cur.inset(), this))
                return;
        CursorSlice & s1 = cur.selBegin();
        CursorSlice & s2 = cur.selEnd();

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to