On Tue, Feb 03, 2004 at 10:34:16PM +0100, Lars Gullik Bjønnes spake thusly:

...

> All this is just so super ugly that I cannot fathom why all other
> compilers than 2.95 has to suffer by this.

Agreed...
 
> IMHO const_cast is the wrong fix. even a ptr_cmp function would have
> been better...

No... a colourful ribbon around a turd...
 
> And are you sure that the correct fix wouldn't be to make both insets
> const? (that is after all the safer transition)

That sounds better... like the attached? It compiles, but I wonder...

> 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.

...

> -- 
>       Lgb
 
BTW a general question: if the number of 'const' keywords in the code
increases, does that tend to make the code better?

- Martin

Index: converter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/converter.C,v
retrieving revision 1.96
diff -u -p -r1.96 converter.C
--- converter.C 31 Jan 2004 15:30:20 -0000      1.96
+++ converter.C 4 Feb 2004 07:05:48 -0000
@@ -50,6 +50,7 @@ using std::endl;
 using std::find_if;
 using std::string;
 using std::vector;
+using std::distance;
 
 
 namespace {
Index: cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v
retrieving revision 1.45
diff -u -p -r1.45 cursor.C
--- cursor.C    3 Feb 2004 11:49:05 -0000       1.45
+++ cursor.C    4 Feb 2004 07:05:48 -0000
@@ -119,7 +119,7 @@ DispatchResult LCursor::dispatch(FuncReq
 }
 
 
-void LCursor::push(InsetBase * inset)
+void LCursor::push(InsetBase const * inset)
 {
        lyxerr << "LCursor::push()  inset: " << inset << endl;
        cursor_.push_back(CursorSlice(inset));
@@ -313,7 +313,7 @@ void LCursor::paste(string const & data)
 }
 
 
-InsetBase * LCursor::innerInsetOfType(int code) const
+InsetBase const * LCursor::innerInsetOfType(int code) const
 {
        for (int i = cursor_.size() - 1; i >= 1; --i)
                if (cursor_[i].inset_->lyxCode() == code)
@@ -324,7 +324,7 @@ InsetBase * LCursor::innerInsetOfType(in
 
 InsetTabular * LCursor::innerInsetTabular() const
 {
-       return static_cast<InsetTabular *>(innerInsetOfType(InsetBase::TABULAR_CODE));
+       return static_cast<InsetTabular *>(const_cast<InsetBase 
*>(innerInsetOfType(InsetBase::TABULAR_CODE)));
 }
 
 
@@ -504,7 +504,7 @@ LCursor::par_type LCursor::lastpar() con
 
 LCursor::pos_type LCursor::lastpos() const
 {
-       InsetBase * inset = current().inset();
+       InsetBase const * inset = current().inset();
        return inset && inset->asMathInset() ? cell().size() : paragraph().size();
 }
 
@@ -589,7 +589,7 @@ void region(CursorSlice const & i1, Curs
        LCursor::row_type & r1, LCursor::row_type & r2,
        LCursor::col_type & c1, LCursor::col_type & c2)
 {
-       InsetBase * p = i1.inset();
+       InsetBase const * p = i1.inset();
        c1 = p->col(i1.idx_);
        c2 = p->col(i2.idx_);
        if (c1 > c2)
@@ -1224,7 +1224,7 @@ MathHullInset * LCursor::formula() const
 {
        for (int i = cursor_.size() - 1; i >= 1; --i)
                if (cursor_[i].inset()->lyxCode() == InsetBase::MATH_CODE)
-                       return static_cast<MathHullInset *>(cursor_[i].inset());
+                       return static_cast<MathHullInset *>(const_cast<InsetBase 
*>(cursor_[i].inset()));
        return 0;
 }
 
Index: cursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.h,v
retrieving revision 1.28
diff -u -p -r1.28 cursor.h
--- cursor.h    3 Feb 2004 11:49:05 -0000       1.28
+++ cursor.h    4 Feb 2004 07:05:48 -0000
@@ -65,7 +65,7 @@ public:
        /// dispatch from innermost inset upwards
        DispatchResult dispatch(FuncRequest const & cmd);
        /// add a new cursor slice
-       void push(InsetBase * inset);
+       void push(InsetBase const * inset);
        /// add a new cursor slice, place cursor on left end
        void pushLeft(InsetBase * inset);
        /// pop one level off the cursor
@@ -138,7 +138,7 @@ public:
        // access to the 'current' cursor slice
        //
        /// the containing inset
-       InsetBase * inset() const { return current().inset(); }
+       InsetBase const * inset() const { return current().inset(); }
        /// return the cell of the inset this cursor is in
        idx_type idx() const { return current().idx(); }
        /// return the cell of the inset this cursor is in
@@ -214,7 +214,7 @@ public:
        ///
        LyXText * text() const;
        ///
-       InsetBase * innerInsetOfType(int code) const;
+       InsetBase const * innerInsetOfType(int code) const;
        ///
        InsetTabular * innerInsetTabular() const;
        ///
Index: cursor_slice.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor_slice.C,v
retrieving revision 1.13
diff -u -p -r1.13 cursor_slice.C
--- cursor_slice.C      2 Feb 2004 11:56:50 -0000       1.13
+++ cursor_slice.C      4 Feb 2004 07:05:48 -0000
@@ -34,7 +34,7 @@ CursorSlice::CursorSlice()
 {}
 
 
-CursorSlice::CursorSlice(InsetBase * p)
+CursorSlice::CursorSlice(InsetBase const * p)
        : inset_(p), idx_(0), par_(0), pos_(0), boundary_(false)
 {
        ///BOOST_ASSERT(inset_);
Index: cursor_slice.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor_slice.h,v
retrieving revision 1.10
diff -u -p -r1.10 cursor_slice.h
--- cursor_slice.h      30 Jan 2004 11:40:57 -0000      1.10
+++ cursor_slice.h      4 Feb 2004 07:05:48 -0000
@@ -54,10 +54,10 @@ public:
        ///
        CursorSlice();
        ///
-       explicit CursorSlice(InsetBase *);
+       explicit CursorSlice(InsetBase const *);
 
        /// the current inset
-       InsetBase * inset() const { return inset_; }
+       InsetBase const * inset() const { return inset_; }
        /// set the paragraph that contains this cursor
        void idx(idx_type idx);
        /// return the cell this cursor is in
@@ -121,7 +121,7 @@ public:
        friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
 public:
        /// pointer to an inset
-       InsetBase * inset_;
+       InsetBase const * inset_;
        /// cell index of a position in this inset
        idx_type idx_;
        /// paragraph in this cell (used by texted)
Index: format.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/format.C,v
retrieving revision 1.21
diff -u -p -r1.21 format.C
--- format.C    31 Jan 2004 15:30:21 -0000      1.21
+++ format.C    4 Feb 2004 07:05:48 -0000
@@ -35,6 +35,7 @@ using lyx::support::subst;
 using lyx::support::Systemcall;
 
 using std::string;
+using std::distance;
 
 extern LyXServerSocket * lyxsocket;
 
Index: insets/insetbase.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbase.C,v
retrieving revision 1.19
diff -u -p -r1.19 insetbase.C
--- insets/insetbase.C  2 Feb 2004 17:32:56 -0000       1.19
+++ insets/insetbase.C  4 Feb 2004 07:05:48 -0000
@@ -27,13 +27,13 @@
 
 
 
-DispatchResult InsetBase::dispatch(LCursor & cur, FuncRequest const & cmd)
+DispatchResult InsetBase::dispatch(LCursor & cur, FuncRequest const & cmd) const
 {
        return priv_dispatch(cur, cmd);
 }
 
 
-DispatchResult InsetBase::priv_dispatch(LCursor &, FuncRequest const &)
+DispatchResult InsetBase::priv_dispatch(LCursor &, FuncRequest const &) const
 {
        return DispatchResult(false);
 }
Index: insets/insetbase.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbase.h,v
retrieving revision 1.27
diff -u -p -r1.27 insetbase.h
--- insets/insetbase.h  2 Feb 2004 17:32:56 -0000       1.27
+++ insets/insetbase.h  4 Feb 2004 07:05:48 -0000
@@ -63,12 +63,12 @@ public:
        virtual std::auto_ptr<InsetBase> clone() const = 0;
 
        /// identification as math inset
-       virtual MathInset * asMathInset() { return 0; }
+       virtual MathInset * asMathInset() const { return 0; }
        /// identification as non-math inset
-       virtual UpdatableInset * asUpdatableInset() { return 0; }
+       virtual UpdatableInset * asUpdatableInset() const { return 0; }
 
        // the real dispatcher
-       DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
+       DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd) const;
 
        /// cursor enters
        virtual void edit(LCursor & cur, bool left);
@@ -129,9 +129,9 @@ public:
        virtual bool idxEnd(LCursor &) const { return false; }
 
        /// Delete a cell and move cursor
-       virtual bool idxDelete(idx_type &) { return false; }
+       virtual bool idxDelete(idx_type &) const { return false; }
        /// pulls cell after pressing erase
-       virtual void idxGlue(idx_type) {}
+       virtual void idxGlue(idx_type) const {}
        // returns list of cell indices that are "between" from and to for
        // selection purposes
        virtual bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
@@ -155,7 +155,7 @@ public:
        /// number of columns in gridlike structures
        virtual size_t ncols() const { return 0; }
        /// is called when the cursor leaves this inset
-       virtual void notifyCursorLeaves(idx_type) {}
+       virtual void notifyCursorLeaves(idx_type) const {}
 
        /// request "external features"
        virtual void validate(LaTeXFeatures &) const {}
@@ -355,7 +355,7 @@ public:
 protected:
        // the real dispatcher
        virtual
-       DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+       DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd) const;
 public:
        /// returns LyX code associated with the inset. Used for TOC, ...)
        virtual Code lyxCode() const { return NO_CODE; }
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 07:05:48 -0000
@@ -72,7 +72,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(cur.inset() == this);
        MathArray const & ar = cur.cell();
        x = ar.xo() + ar.pos2x(cur.pos());
        y = ar.yo();
@@ -99,7 +99,7 @@ void MathNestInset::metrics(MetricsInfo 
 
 bool MathNestInset::idxNext(LCursor & cur) const
 {
-       BOOST_ASSERT(cur.inset() == const_cast<MathNestInset *>(this));
+       BOOST_ASSERT(cur.inset() == this);
        if (cur.idx() == cur.lastidx())
                return false;
        ++cur.idx();
@@ -116,7 +116,7 @@ bool MathNestInset::idxRight(LCursor & c
 
 bool MathNestInset::idxPrev(LCursor & cur) const
 {
-       BOOST_ASSERT(cur.inset() == const_cast<MathNestInset *>(this));
+       BOOST_ASSERT(cur.inset() == this);
        if (cur.idx() == 0)
                return false;
        --cur.idx();
@@ -133,7 +133,7 @@ bool MathNestInset::idxLeft(LCursor & cu
 
 bool MathNestInset::idxFirst(LCursor & cur) const
 {
-       BOOST_ASSERT(cur.inset() == const_cast<MathNestInset *>(this));
+       BOOST_ASSERT(cur.inset() == this);
        if (nargs() == 0)
                return false;
        cur.idx() = 0;
@@ -144,7 +144,7 @@ bool MathNestInset::idxFirst(LCursor & c
 
 bool MathNestInset::idxLast(LCursor & cur) const
 {
-       BOOST_ASSERT(cur.inset() == const_cast<MathNestInset *>(this));
+       BOOST_ASSERT(cur.inset() == this);
        if (nargs() == 0)
                return false;
        cur.idx() = cur.lastidx();
@@ -155,7 +155,7 @@ bool MathNestInset::idxLast(LCursor & cu
 
 bool MathNestInset::idxHome(LCursor & cur) const
 {
-       BOOST_ASSERT(cur.inset() ==  const_cast<MathNestInset *>(this));
+       BOOST_ASSERT(cur.inset() ==  this);
        if (cur.pos() == 0)
                return false;
        cur.pos() = 0;
@@ -165,7 +165,7 @@ bool MathNestInset::idxHome(LCursor & cu
 
 bool MathNestInset::idxEnd(LCursor & cur) const
 {
-       BOOST_ASSERT(cur.inset() ==  const_cast<MathNestInset *>(this));
+       BOOST_ASSERT(cur.inset() ==  this);
        if (cur.lastpos() == cur.lastpos())
                return false;
        cur.pos() = cur.lastpos();
@@ -202,7 +202,7 @@ void MathNestInset::drawSelection(Painte
        LCursor & cur = pi.base.bv->cursor();
        if (!cur.selection())
                return;
-       if (cur.inset() != const_cast<MathNestInset *>(this))
+       if (cur.inset() != this)
                return;
        CursorSlice & s1 = cur.selBegin();
        CursorSlice & s2 = cur.selEnd();
Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.498
diff -u -p -r1.498 BufferView_pimpl.C
--- BufferView_pimpl.C  3 Feb 2004 11:49:04 -0000       1.498
+++ BufferView_pimpl.C  4 Feb 2004 07:11:05 -0000
@@ -1296,7 +1296,7 @@ void BufferView::Pimpl::updateParagraphD
        params2string(par, data);
 
        // Will the paragraph accept changes from the dialog?
-       InsetBase * const inset = cur.inset();
+       InsetBase const * const inset = cur.inset();
        bool const accept =
                !(inset && inset->forceDefaultParagraphs(inset));
 
Index: lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.567
diff -u -p -r1.567 lyxfunc.C
--- lyxfunc.C   3 Feb 2004 09:08:14 -0000       1.567
+++ lyxfunc.C   4 Feb 2004 07:28:02 -0000
@@ -540,7 +540,7 @@ FuncStatus LyXFunc::getStatus(FuncReques
                        disable = !Exporter::IsExportable(*buf, "dvi") ||
                                lyxrc.print_command == "none";
                } else if (name == "character") {
-                       InsetBase * inset = view()->cursor().inset();
+                       InsetBase const * inset = view()->cursor().inset();
                        disable = inset && inset->lyxCode() == InsetOld::ERT_CODE;
                } else if (name == "vclog") {
                        disable = !buf->lyxvc().inUse();

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to