I am slowly beginning to look at LyX code again and thought I should look at removing some warnings (this led to other stuff...)
- Get rid of some warninings in mathed. macroarg. Are the changes ok Andre? - Move some code aroudn to get rid of some unused vars warnings. - Make InsetTable store a share_ptr, this makes InsetList copyable. (more work might be needed here) - Get rid of InsetList::release, this is a dangeroush function that was luckily only used one place. Release had the potential of mucking up the inherit invariant that a position with META_INSET should always have a inset connected too it. Would be nice if you could tell me if I have completely lost it, or if I should clean it up further and get it in.
? InsetList.lo ? paragraph.lo ? paragraph_funcs.lo ? text.lo Index: CutAndPaste.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/CutAndPaste.C,v retrieving revision 1.138 diff -u -p -b -r1.138 CutAndPaste.C --- CutAndPaste.C 17 May 2004 11:28:26 -0000 1.138 +++ CutAndPaste.C 17 Jun 2004 01:49:44 -0000 @@ -169,7 +169,7 @@ pasteSelectionHelper(Buffer const & buff for (; lit != eit; ++lit) { switch (lit->inset->lyxCode()) { case InsetOld::TABULAR_CODE: { - InsetTabular * it = static_cast<InsetTabular*>(lit->inset); + InsetTabular * it = static_cast<InsetTabular*>(lit->inset.get()); it->buffer(&buffer); break; } Index: InsetList.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/InsetList.C,v retrieving revision 1.23 diff -u -p -b -r1.23 InsetList.C --- InsetList.C 30 Mar 2004 12:36:30 -0000 1.23 +++ InsetList.C 17 Jun 2004 01:49:44 -0000 @@ -41,23 +41,10 @@ struct InsetTablePosLess : public std::b } // namespace anon - -InsetList::~InsetList() -{ - // If we begin storing a shared_ptr in the List - // this code can be removed. (Lgb) - List::iterator it = list.begin(); - List::iterator end = list.end(); - for (; it != end; ++it) { - delete it->inset; - } -} - - InsetList::iterator InsetList::insetIterator(pos_type pos) { InsetTable search_elem(pos, 0); - return lower_bound(list.begin(), list.end(), search_elem, + return lower_bound(list_.begin(), list_.end(), search_elem, InsetTablePosLess()); } @@ -65,61 +52,47 @@ InsetList::iterator InsetList::insetIter InsetList::const_iterator InsetList::insetIterator(pos_type pos) const { InsetTable search_elem(pos, 0); - return lower_bound(list.begin(), list.end(), search_elem, + return lower_bound(list_.begin(), list_.end(), search_elem, InsetTablePosLess()); } void InsetList::insert(InsetBase * inset, lyx::pos_type pos) { - List::iterator end = list.end(); + List::iterator end = list_.end(); List::iterator it = insetIterator(pos); if (it != end && it->pos == pos) { lyxerr << "ERROR (InsetList::insert): " << "There is an inset in position: " << pos << endl; } else { - list.insert(it, InsetTable(pos, inset)); + list_.insert(it, InsetTable(pos, inset)); } } void InsetList::erase(pos_type pos) { - List::iterator end = list.end(); - List::iterator it = insetIterator(pos); - if (it != end && it->pos == pos) { - delete it->inset; - list.erase(it); - } -} - - -InsetBase * InsetList::release(pos_type pos) -{ - List::iterator end = list.end(); + List::iterator end = list_.end(); List::iterator it = insetIterator(pos); if (it != end && it->pos == pos) { - InsetBase * tmp = it->inset; - it->inset = 0; - return tmp; + list_.erase(it); } - return 0; } -InsetBase * InsetList::get(pos_type pos) const +boost::shared_ptr<InsetBase> InsetList::get(pos_type pos) const { - List::const_iterator end = list.end(); + List::const_iterator end = list_.end(); List::const_iterator it = insetIterator(pos); if (it != end && it->pos == pos) return it->inset; - return 0; + return boost::shared_ptr<InsetBase>(); } void InsetList::increasePosAfterPos(pos_type pos) { - List::iterator end = list.end(); + List::iterator end = list_.end(); List::iterator it = insetIterator(pos); for (; it != end; ++it) { ++it->pos; @@ -129,7 +102,7 @@ void InsetList::increasePosAfterPos(pos_ void InsetList::decreasePosAfterPos(pos_type pos) { - List::iterator end = list.end(); + List::iterator end = list_.end(); List::iterator it = insetIterator(pos); for (; it != end; ++it) { --it->pos; Index: InsetList.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/InsetList.h,v retrieving revision 1.13 diff -u -p -b -r1.13 InsetList.h --- InsetList.h 3 Apr 2004 08:36:54 -0000 1.13 +++ InsetList.h 17 Jun 2004 01:49:44 -0000 @@ -12,11 +12,13 @@ #ifndef INSET_LIST_H #define INSET_LIST_H +#include "insets/insetbase.h" #include "support/types.h" +#include <boost/shared_ptr.hpp> + #include <vector> -class InsetBase; class Buffer; @@ -28,9 +30,17 @@ public: /// lyx::pos_type pos; /// - InsetBase * inset; + boost::shared_ptr<InsetBase> inset; + /// + InsetTable(lyx::pos_type p, InsetBase * i) + : pos(p), inset(i) {} /// - InsetTable(lyx::pos_type p, InsetBase * i) : pos(p), inset(i) {} + InsetTable(InsetTable const & it) + : pos(it.pos) + { + std::auto_ptr<InsetBase> tmp(it.inset->clone()); + inset = tmp; + } }; /// typedef std::vector<InsetTable> List; @@ -40,17 +50,15 @@ public: typedef List::const_iterator const_iterator; /// - ~InsetList(); + iterator begin() { return list_.begin(); } /// - iterator begin() { return list.begin(); } + iterator end() { return list_.end(); } /// - iterator end() { return list.end(); } + const_iterator begin() const { return list_.begin(); } /// - const_iterator begin() const { return list.begin(); } + const_iterator end() const { return list_.end(); } /// - const_iterator end() const { return list.end(); } - /// - bool empty() const { return list.empty(); } + bool empty() const { return list_.empty(); } /// iterator insetIterator(lyx::pos_type pos); /// @@ -60,9 +68,7 @@ public: /// void erase(lyx::pos_type pos); /// - InsetBase * release(lyx::pos_type); - /// - InsetBase * get(lyx::pos_type pos) const; + boost::shared_ptr<InsetBase> get(lyx::pos_type pos) const; /// void increasePosAfterPos(lyx::pos_type pos); /// @@ -70,7 +76,7 @@ public: private: /// - List list; + List list_; }; #endif Index: buffer.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v retrieving revision 1.577 diff -u -p -b -r1.577 buffer.C --- buffer.C 14 May 2004 15:47:34 -0000 1.577 +++ buffer.C 17 Jun 2004 01:49:45 -0000 @@ -750,7 +750,7 @@ bool Buffer::writeFile(string const & fn if (finfo.exist() && !finfo.writable()) return false; - bool retval; + bool retval = false; if (params().compressed) { gz::ogzstream ofs(fname.c_str()); Index: output_latex.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/output_latex.C,v retrieving revision 1.13 diff -u -p -b -r1.13 output_latex.C --- output_latex.C 17 May 2004 11:28:26 -0000 1.13 +++ output_latex.C 17 Jun 2004 01:49:45 -0000 @@ -200,7 +200,7 @@ InsetOptArg * optArgInset(Paragraph cons InsetList::const_iterator it = par.insetlist.begin(); InsetList::const_iterator end = par.insetlist.end(); for (; it != end; ++it) { - InsetBase * ins = it->inset; + InsetBase * ins = it->inset.get(); if (ins->lyxCode() == InsetBase::OPTARG_CODE) { return static_cast<InsetOptArg *>(ins); } Index: paragraph.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v retrieving revision 1.368 diff -u -p -b -r1.368 paragraph.C --- paragraph.C 17 May 2004 11:28:26 -0000 1.368 +++ paragraph.C 17 Jun 2004 01:49:45 -0000 @@ -87,10 +87,6 @@ Paragraph::Paragraph(Paragraph const & p pimpl_(new Paragraph::Pimpl(*par.pimpl_, this)) { //lyxerr << "Paragraph::Paragraph(Paragraph const&)" << endl; - InsetList::iterator it = insetlist.begin(); - InsetList::iterator end = insetlist.end(); - for (; it != end; ++it) - it->inset = it->inset->clone().release(); } @@ -101,10 +97,6 @@ Paragraph & Paragraph::operator=(Paragra itemdepth = par.itemdepth; insetlist = par.insetlist; - InsetList::iterator it = insetlist.begin(); - InsetList::iterator end = insetlist.end(); - for (; it != end; ++it) - it->inset = it->inset->clone().release(); rows = par.rows; y = par.y; @@ -313,14 +305,14 @@ bool Paragraph::insetAllowed(InsetOld_co InsetBase * Paragraph::getInset(pos_type pos) { BOOST_ASSERT(pos < size()); - return insetlist.get(pos); + return insetlist.get(pos).get(); } InsetBase const * Paragraph::getInset(pos_type pos) const { BOOST_ASSERT(pos < size()); - return insetlist.get(pos); + return insetlist.get(pos).get(); } @@ -696,7 +688,7 @@ int Paragraph::getPositionOfInset(InsetB InsetList::const_iterator it = insetlist.begin(); InsetList::const_iterator end = insetlist.end(); for (; it != end; ++it) - if (it->inset == inset) + if (it->inset.get() == inset) return it->pos; return -1; } @@ -705,7 +697,7 @@ int Paragraph::getPositionOfInset(InsetB InsetBibitem * Paragraph::bibitem() const { if (!insetlist.empty()) { - InsetBase * inset = insetlist.begin()->inset; + InsetBase * inset = insetlist.begin()->inset.get(); if (inset->lyxCode() == InsetBase::BIBTEX_CODE) return static_cast<InsetBibitem *>(inset); } Index: paragraph_funcs.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_funcs.C,v retrieving revision 1.104 diff -u -p -b -r1.104 paragraph_funcs.C --- paragraph_funcs.C 17 May 2004 11:28:27 -0000 1.104 +++ paragraph_funcs.C 17 Jun 2004 01:49:45 -0000 @@ -64,19 +64,22 @@ bool moveItem(Paragraph & from, Paragrap LyXFont tmpfont = from.getFontSettings(params, i); if (tmpchar == Paragraph::META_INSET) { - InsetBase * tmpinset = 0; + boost::shared_ptr<InsetBase> tmpinset; if (from.getInset(i)) { // the inset is not in a paragraph anymore - tmpinset = from.insetlist.release(i); + tmpinset = from.insetlist.get(i); from.insetlist.erase(i); } if (!to.insetAllowed(tmpinset->lyxCode())) { - delete tmpinset; return false; } - if (tmpinset) - to.insertInset(j, tmpinset, tmpfont); + if (tmpinset) { + // Ok this is not a proper move, but does it matter? + std::auto_ptr<InsetBase> tmp(tmpinset->clone()); + to.insertInset(j, tmp.release(), tmpfont); + } + } else { if (!to.checkInsertChar(tmpfont)) return false; @@ -309,7 +312,7 @@ par_type outerPar(Buffer const & buf, In InsetList::const_iterator ii = pit->insetlist.begin(); InsetList::const_iterator iend = pit->insetlist.end(); for ( ; ii != iend; ++ii) - if (ii->inset == inset) + if (ii->inset.get() == inset) return pit.outerPar(); } lyxerr << "outerPar: should not happen" << endl; @@ -332,7 +335,7 @@ Paragraph const & ownerPar(Buffer const InsetList::const_iterator ii = pit->insetlist.begin(); InsetList::const_iterator iend = pit->insetlist.end(); for ( ; ii != iend; ++ii) - if (ii->inset == inset) + if (ii->inset.get() == inset) return *pit; } lyxerr << "ownerPar: should not happen" << endl; Index: text.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v retrieving revision 1.564 diff -u -p -b -r1.564 text.C --- text.C 17 May 2004 11:28:27 -0000 1.564 +++ text.C 17 Jun 2004 01:49:46 -0000 @@ -68,6 +68,8 @@ #include "support/tostr.h" #include "support/std_sstream.h" +#include <boost/bind.hpp> + using lyx::par_type; using lyx::pos_type; using lyx::word_location; @@ -112,14 +114,19 @@ int numberOfSeparators(Paragraph const & } +struct WidthCmp { + bool operator()(Paragraph const & p1, Paragraph const & p2) const + { + return p1.width < p2.width; + } +}; + + unsigned int maxParagraphWidth(ParagraphList const & plist) { - unsigned int width = 0; - ParagraphList::const_iterator pit = plist.begin(); - ParagraphList::const_iterator end = plist.end(); - for (; pit != end; ++pit) - width = std::max(width, pit->width); - return width; + ParagraphList::const_iterator res = + max_element(plist.begin(), plist.end(), WidthCmp()); + return res->width; } @@ -1764,7 +1771,7 @@ void LyXText::redoParagraphInternal(par_ void LyXText::redoParagraphs(par_type pit, par_type end) { - for ( ; pit != end; ++pit) + for (; pit != end; ++pit) redoParagraphInternal(pit); updateParPositions(); updateCounters(); @@ -1838,7 +1845,7 @@ bool LyXText::isFirstRow(par_type pit, R void LyXText::getWord(CursorSlice & from, CursorSlice & to, word_location const loc) { - Paragraph & from_par = pars_[from.par()]; + Paragraph const & from_par = pars_[from.par()]; switch (loc) { case lyx::WHOLE_WORD_STRICT: if (from.pos() == 0 || from.pos() == from_par.size() @@ -1872,7 +1879,7 @@ void LyXText::getWord(CursorSlice & from break; } to = from; - Paragraph & to_par = pars_[to.par()]; + Paragraph const & to_par = pars_[to.par()]; while (to.pos() < to_par.size() && !to_par.isSeparator(to.pos()) && !to_par.isKomma(to.pos()) @@ -1904,7 +1911,7 @@ bool LyXText::read(Buffer const & buf, L while (lex.isOK()) { lex.nextToken(); - string token = lex.getString(); + string const token = lex.getString(); if (token.empty()) continue; @@ -2034,8 +2041,8 @@ int LyXText::cursorX(CursorSlice const & int LyXText::cursorY(CursorSlice const & cur) const { - Paragraph & par = getPar(cur.par()); - Row & row = *par.getRow(cur.pos()); + Paragraph const & par = getPar(cur.par()); + Row const & row = *par.getRow(cur.pos()); return yo_ + par.y + row.y_offset() + row.baseline(); } Index: text3.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v retrieving revision 1.253 diff -u -p -b -r1.253 text3.C --- text3.C 18 May 2004 07:18:02 -0000 1.253 +++ text3.C 17 Jun 2004 01:49:46 -0000 @@ -199,7 +199,7 @@ InsetBase * LyXText::checkInsetHit(int x InsetList::iterator iit = pars_[pit].insetlist.begin(); InsetList::iterator iend = pars_[pit].insetlist.end(); for ( ; iit != iend; ++iit) { - InsetBase * inset = iit->inset; + InsetBase * inset = iit->inset.get(); #if 0 lyxerr << "examining inset " << inset << " xo: " << inset->xo() << "..." << inset->xo() + inset->width() Index: toc.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/toc.C,v retrieving revision 1.39 diff -u -p -b -r1.39 toc.C --- toc.C 28 Mar 2004 22:00:21 -0000 1.39 +++ toc.C 17 Jun 2004 01:49:47 -0000 @@ -87,10 +87,10 @@ TocList const getTocList(Buffer const & InsetList::const_iterator end = pit->insetlist.end(); for (; it != end; ++it) { if (it->inset->lyxCode() == InsetOld::FLOAT_CODE) { - static_cast<InsetFloat*>(it->inset) + static_cast<InsetFloat*>(it->inset.get()) ->addToToc(toclist, buf); } else if (it->inset->lyxCode() == InsetOld::WRAP_CODE) { - static_cast<InsetWrap*>(it->inset) + static_cast<InsetWrap*>(it->inset.get()) ->addToToc(toclist, buf); } } Index: frontends/controllers/ControlErrorList.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlErrorList.C,v retrieving revision 1.24 diff -u -p -b -r1.24 ControlErrorList.C --- frontends/controllers/ControlErrorList.C 19 May 2004 15:11:30 -0000 1.24 +++ frontends/controllers/ControlErrorList.C 17 Jun 2004 01:49:47 -0000 @@ -68,16 +68,15 @@ void ControlErrorList::goTo(int item) return; } - pos_type const end = std::min(err.pos_end, pit->size()); - pos_type const start = std::min(err.pos_start, end); - pos_type const range = end - start; - // Now make the selection. #ifdef WITH_WARNINGS #warning FIXME (goto error) #warning This should be implemented using an LFUN. (Angus) #endif #if 0 + pos_type const end = std::min(err.pos_end, pit->size()); + pos_type const start = std::min(err.pos_start, end); + pos_type const range = end - start; PosIterator const pos(pit, start); kernel().bufferview()->putSelectionAt(pos, range, false); #endif Index: insets/insetlabel.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetlabel.C,v retrieving revision 1.95 diff -u -p -b -r1.95 insetlabel.C --- insets/insetlabel.C 14 May 2004 15:47:35 -0000 1.95 +++ insets/insetlabel.C 17 Jun 2004 01:49:47 -0000 @@ -77,7 +77,7 @@ void changeRefsIfUnique(BufferView & bv, for (InsetList::iterator it2 = it->insetlist.begin(); it2 != it->insetlist.end(); ++it2) { if (it2->inset->lyxCode() == code) { - InsetCommand * inset = static_cast<InsetCommand *>(it2->inset); + InsetCommand * inset = static_cast<InsetCommand *>(it2->inset.get()); if (inset->getContents() == from) { inset->setContents(to); //inset->setButtonLabel(); Index: mathed/math_macroarg.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macroarg.C,v retrieving revision 1.50 diff -u -p -b -r1.50 math_macroarg.C --- mathed/math_macroarg.C 13 Apr 2004 06:27:29 -0000 1.50 +++ mathed/math_macroarg.C 17 Jun 2004 01:49:47 -0000 @@ -19,11 +19,13 @@ using std::endl; using std::auto_ptr; +using std::size_t; -MathMacroArgument::MathMacroArgument(int n) +MathMacroArgument::MathMacroArgument(size_t n) : number_(n) { +#warning Is this really all the error handling needed? (Lgb) if (n < 1 || n > 9) { lyxerr << "MathMacroArgument::MathMacroArgument: wrong Argument id: " << n << endl; Index: mathed/math_macroarg.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macroarg.h,v retrieving revision 1.35 diff -u -p -b -r1.35 math_macroarg.h --- mathed/math_macroarg.h 13 Apr 2004 06:27:29 -0000 1.35 +++ mathed/math_macroarg.h 17 Jun 2004 01:49:47 -0000 @@ -20,7 +20,7 @@ class MathMacroArgument : public MathDimInset { public: /// - explicit MathMacroArgument(int); + explicit MathMacroArgument(std::size_t); /// std::auto_ptr<InsetBase> clone() const; /// @@ -28,7 +28,7 @@ public: /// void draw(PainterInfo &, int x, int y) const; /// - int number() const { return number_; } + std::size_t number() const { return number_; } /// InsetBase::Code lyxCode() const { return MATHMACROARG_CODE; } @@ -39,7 +39,7 @@ public: private: /// A number between 1 and 9 - int number_; + std::size_t number_; /// char str_[3]; }; Index: mathed/math_macrotable.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macrotable.C,v retrieving revision 1.72 diff -u -p -b -r1.72 math_macrotable.C --- mathed/math_macrotable.C 20 Apr 2004 08:51:15 -0000 1.72 +++ mathed/math_macrotable.C 17 Jun 2004 01:49:47 -0000 @@ -54,7 +54,7 @@ void MacroData::expand(vector<MathArray> continue; //it.cell().erase(it.pos()); //it.cell().insert(it.pos(), it.nextInset()->asMathInset() - int n = static_cast<MathMacroArgument*>(it.nextInset())->number(); + size_t n = static_cast<MathMacroArgument*>(it.nextInset())->number(); if (n <= args.size()) { it.cell().erase(it.pos()); it.cell().insert(it.pos(), args[n - 1]); Index: mathed/math_parser.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_parser.C,v retrieving revision 1.298 diff -u -p -b -r1.298 math_parser.C --- mathed/math_parser.C 13 Apr 2004 13:54:58 -0000 1.298 +++ mathed/math_parser.C 17 Jun 2004 01:49:47 -0000 @@ -1282,6 +1282,3 @@ void initParser() theCatcode[int('~')] = catActive; theCatcode[int('%')] = catComment; } - - -
-- Lgb