mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 21:21:32 +00:00
simplify InsetList a bit and constify a bit too
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7062 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
b2284c1a07
commit
0d90321817
@ -535,15 +535,15 @@ bool BufferView::lockInset(UpdatableInset * inset)
|
||||
InsetList::iterator it = pit->insetlist.begin();
|
||||
InsetList::iterator end = pit->insetlist.end();
|
||||
for (; it != end; ++it) {
|
||||
if (it.getInset() == inset) {
|
||||
text->setCursorIntern(pit, it.getPos());
|
||||
if (it->inset == inset) {
|
||||
text->setCursorIntern(pit, it->pos);
|
||||
theLockingInset(inset);
|
||||
return true;
|
||||
}
|
||||
if (it.getInset()->getInsetFromID(id)) {
|
||||
text->setCursorIntern(pit, it.getPos());
|
||||
if (it->inset->getInsetFromID(id)) {
|
||||
text->setCursorIntern(pit, it->pos);
|
||||
FuncRequest cmd(this, LFUN_INSET_EDIT, "left");
|
||||
it.getInset()->localDispatch(cmd);
|
||||
it->inset->localDispatch(cmd);
|
||||
return theLockingInset()->lockInsetInInset(this, inset);
|
||||
}
|
||||
}
|
||||
@ -629,8 +629,8 @@ bool BufferView::ChangeInsets(Inset::Code code,
|
||||
bool changed_inset = false;
|
||||
for (InsetList::iterator it2 = it->insetlist.begin();
|
||||
it2 != it->insetlist.end(); ++it2) {
|
||||
if (it2.getInset()->lyxCode() == code) {
|
||||
InsetCommand * inset = static_cast<InsetCommand *>(it2.getInset());
|
||||
if (it2->inset->lyxCode() == code) {
|
||||
InsetCommand * inset = static_cast<InsetCommand *>(it2->inset);
|
||||
if (inset->getContents() == from) {
|
||||
inset->setContents(to);
|
||||
changed_inset = true;
|
||||
|
@ -1,5 +1,25 @@
|
||||
2003-05-29 Lars Gullik Bjønnes <larsbj@gullik.net>
|
||||
|
||||
* toc.C (getTocList): adjust
|
||||
|
||||
* paragraph_pimpl.C (validate): adjust
|
||||
|
||||
* paragraph_funcs.C (optArgInset): use const_iterator, adjust
|
||||
|
||||
* paragraph.C (Paragraph): adjust
|
||||
(getPositionOfInset): use const_iterator, adjust
|
||||
(bibitem): use const_iterator, adjust
|
||||
(setInsetOwner): adjust
|
||||
|
||||
* iterators.C (operator++): adjust
|
||||
|
||||
* InsetList.[Ch]: Replace selfmade iterator with standard
|
||||
vector::iterator also introduce const_iterator. Remove getPos,
|
||||
getInset and setInset from InsetTable. Adjust accordingly.
|
||||
|
||||
* BufferView.C (lockInset): adjust
|
||||
(ChangeInsets): adjust
|
||||
|
||||
* tabular.[Ch]: delete commented same_id functions
|
||||
|
||||
2003-05-28 John Levon <levon@movementarian.org>
|
||||
|
100
src/InsetList.C
100
src/InsetList.C
@ -25,45 +25,7 @@ struct MatchIt {
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
InsetList::iterator::iterator(InsetList::List::iterator const & iter)
|
||||
: it(iter)
|
||||
{}
|
||||
|
||||
|
||||
InsetList::iterator & InsetList::iterator::operator++()
|
||||
{
|
||||
++it;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
InsetList::iterator InsetList::iterator::operator++(int)
|
||||
{
|
||||
iterator tmp = *this;
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
pos_type InsetList::iterator::getPos() const
|
||||
{
|
||||
return it->pos;
|
||||
}
|
||||
|
||||
|
||||
Inset * InsetList::iterator::getInset() const
|
||||
{
|
||||
return it->inset;
|
||||
}
|
||||
|
||||
|
||||
void InsetList::iterator::setInset(Inset * inset)
|
||||
{
|
||||
it->inset = inset;
|
||||
}
|
||||
} // namespace anon
|
||||
|
||||
|
||||
InsetList::~InsetList()
|
||||
@ -80,25 +42,25 @@ InsetList::~InsetList()
|
||||
|
||||
InsetList::iterator InsetList::begin()
|
||||
{
|
||||
return iterator(list.begin());
|
||||
return list.begin();
|
||||
}
|
||||
|
||||
|
||||
InsetList::iterator InsetList::end()
|
||||
{
|
||||
return iterator(list.end());
|
||||
return list.end();
|
||||
}
|
||||
|
||||
|
||||
InsetList::iterator InsetList::begin() const
|
||||
InsetList::const_iterator InsetList::begin() const
|
||||
{
|
||||
return iterator(const_cast<InsetList*>(this)->list.begin());
|
||||
return list.begin();
|
||||
}
|
||||
|
||||
|
||||
InsetList::iterator InsetList::end() const
|
||||
InsetList::const_iterator InsetList::end() const
|
||||
{
|
||||
return iterator(const_cast<InsetList*>(this)->list.end());
|
||||
return list.end();
|
||||
}
|
||||
|
||||
|
||||
@ -109,17 +71,18 @@ InsetList::insetIterator(pos_type pos)
|
||||
List::iterator it = lower_bound(list.begin(),
|
||||
list.end(),
|
||||
search_elem, MatchIt());
|
||||
return iterator(it);
|
||||
return it;
|
||||
}
|
||||
|
||||
|
||||
void InsetList::insert(Inset * inset, lyx::pos_type pos)
|
||||
{
|
||||
InsetTable search_elem(pos, 0);
|
||||
List::iterator end = list.end();
|
||||
List::iterator it = lower_bound(list.begin(),
|
||||
list.end(),
|
||||
end,
|
||||
search_elem, MatchIt());
|
||||
if (it != list.end() && it->pos == pos) {
|
||||
if (it != end && it->pos == pos) {
|
||||
lyxerr << "ERROR (InsetList::insert): "
|
||||
<< "There is an inset in position: " << pos << endl;
|
||||
} else {
|
||||
@ -131,11 +94,12 @@ void InsetList::insert(Inset * inset, lyx::pos_type pos)
|
||||
void InsetList::erase(pos_type pos)
|
||||
{
|
||||
InsetTable search_elem(pos, 0);
|
||||
List::iterator end = list.end();
|
||||
List::iterator it =
|
||||
lower_bound(list.begin(),
|
||||
list.end(),
|
||||
end,
|
||||
search_elem, MatchIt());
|
||||
if (it != list.end() && it->pos == pos) {
|
||||
if (it != end && it->pos == pos) {
|
||||
delete it->inset;
|
||||
list.erase(it);
|
||||
}
|
||||
@ -145,11 +109,12 @@ void InsetList::erase(pos_type pos)
|
||||
Inset * InsetList::release(pos_type pos)
|
||||
{
|
||||
InsetTable search_elem(pos, 0);
|
||||
List::iterator end = list.end();
|
||||
List::iterator it =
|
||||
lower_bound(list.begin(),
|
||||
list.end(),
|
||||
end,
|
||||
search_elem, MatchIt());
|
||||
if (it != list.end() && it->pos == pos) {
|
||||
if (it != end && it->pos == pos) {
|
||||
Inset * tmp = it->inset;
|
||||
it->inset = 0;
|
||||
return tmp;
|
||||
@ -161,11 +126,12 @@ Inset * InsetList::release(pos_type pos)
|
||||
Inset * InsetList::get(pos_type pos) const
|
||||
{
|
||||
InsetTable search_elem(pos, 0);
|
||||
List::iterator it =
|
||||
lower_bound(const_cast<InsetList*>(this)->list.begin(),
|
||||
const_cast<InsetList*>(this)->list.end(),
|
||||
List::const_iterator end = list.end();
|
||||
List::const_iterator it =
|
||||
lower_bound(list.begin(),
|
||||
end,
|
||||
search_elem, MatchIt());
|
||||
if (it != const_cast<InsetList*>(this)->list.end() && it->pos == pos)
|
||||
if (it != end && it->pos == pos)
|
||||
return it->inset;
|
||||
return 0;
|
||||
}
|
||||
@ -174,10 +140,10 @@ Inset * InsetList::get(pos_type pos) const
|
||||
void InsetList::increasePosAfterPos(pos_type pos)
|
||||
{
|
||||
InsetTable search_elem(pos, 0);
|
||||
List::iterator it = lower_bound(list.begin(),
|
||||
list.end(),
|
||||
search_elem, MatchIt());
|
||||
List::iterator end = list.end();
|
||||
List::iterator it = lower_bound(list.begin(),
|
||||
end,
|
||||
search_elem, MatchIt());
|
||||
for (; it != end; ++it) {
|
||||
++it->pos;
|
||||
}
|
||||
@ -225,19 +191,3 @@ void InsetList::resizeInsetsLyXText(BufferView * bv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool operator==(InsetList::iterator const & i1,
|
||||
InsetList::iterator const & i2)
|
||||
{
|
||||
return i1.it == i2.it;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool operator!=(InsetList::iterator const & i1,
|
||||
InsetList::iterator const & i2)
|
||||
{
|
||||
return !(i1 == i2);
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
|
||||
#include "support/types.h"
|
||||
|
||||
|
||||
class Inset;
|
||||
class BufferView;
|
||||
|
||||
@ -24,30 +23,11 @@ public:
|
||||
};
|
||||
///
|
||||
typedef std::vector<InsetTable> List;
|
||||
|
||||
///
|
||||
class iterator {
|
||||
public:
|
||||
///
|
||||
iterator() {}
|
||||
//
|
||||
iterator(List::iterator const & iter);
|
||||
///
|
||||
iterator & operator++();
|
||||
///
|
||||
iterator operator++(int);
|
||||
///
|
||||
lyx::pos_type getPos() const;
|
||||
///
|
||||
Inset * getInset() const;
|
||||
///
|
||||
void setInset(Inset * inset);
|
||||
///
|
||||
friend bool operator==(iterator const &, iterator const &);
|
||||
private:
|
||||
///
|
||||
List::iterator it;
|
||||
};
|
||||
typedef List::iterator iterator;
|
||||
///
|
||||
typedef List::const_iterator const_iterator;
|
||||
|
||||
///
|
||||
~InsetList();
|
||||
///
|
||||
@ -55,9 +35,9 @@ public:
|
||||
///
|
||||
iterator end();
|
||||
///
|
||||
iterator begin() const;
|
||||
const_iterator begin() const;
|
||||
///
|
||||
iterator end() const;
|
||||
const_iterator end() const;
|
||||
///
|
||||
iterator insetIterator(lyx::pos_type pos);
|
||||
///
|
||||
@ -81,11 +61,4 @@ private:
|
||||
List list;
|
||||
};
|
||||
|
||||
///
|
||||
bool operator==(InsetList::iterator const & i1,
|
||||
InsetList::iterator const & i2);
|
||||
///
|
||||
bool operator!=(InsetList::iterator const & i1,
|
||||
InsetList::iterator const & i2);
|
||||
|
||||
#endif
|
||||
|
@ -2417,13 +2417,13 @@ Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
|
||||
|
||||
Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
|
||||
{
|
||||
return *it.getInset();
|
||||
return *it->inset;
|
||||
}
|
||||
|
||||
|
||||
Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
|
||||
{
|
||||
return it.getInset();
|
||||
return it->inset;
|
||||
}
|
||||
|
||||
|
||||
@ -2435,7 +2435,7 @@ ParagraphList::iterator Buffer::inset_iterator::getPar() const
|
||||
|
||||
lyx::pos_type Buffer::inset_iterator::getPos() const
|
||||
{
|
||||
return it.getPos();
|
||||
return it->pos;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,10 @@
|
||||
2003-05-29 Lars Gullik Bjønnes <larsbj@gullik.net>
|
||||
|
||||
* insettext.C (lockInsetInInset): adjust
|
||||
(getLabelList): use const_iterator, adjust
|
||||
(getInsetFromID): use const_iterator, adjust
|
||||
(addPreview): use const_iterator, adjust
|
||||
|
||||
* insetwrap.C (clone): remove const_cast
|
||||
|
||||
* insetnote.C (clone): remove const_cast
|
||||
|
@ -681,14 +681,14 @@ bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
|
||||
InsetList::iterator const end =
|
||||
pit->insetlist.end();
|
||||
for (; it != end; ++it) {
|
||||
if (it.getInset() == inset) {
|
||||
getLyXText(bv)->setCursorIntern(pit, it.getPos());
|
||||
if (it->inset == inset) {
|
||||
getLyXText(bv)->setCursorIntern(pit, it->pos);
|
||||
lockInset(bv, inset);
|
||||
return true;
|
||||
}
|
||||
if (it.getInset()->getInsetFromID(id)) {
|
||||
getLyXText(bv)->setCursorIntern(pit, it.getPos());
|
||||
it.getInset()->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
|
||||
if (it->inset->getInsetFromID(id)) {
|
||||
getLyXText(bv)->setCursorIntern(pit, it->pos);
|
||||
it->inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
|
||||
return the_locking_inset->lockInsetInInset(bv, inset);
|
||||
}
|
||||
}
|
||||
@ -1821,10 +1821,10 @@ vector<string> const InsetText::getLabelList() const
|
||||
ParagraphList::const_iterator pit = paragraphs.begin();
|
||||
ParagraphList::const_iterator pend = paragraphs.end();
|
||||
for (; pit != pend; ++pit) {
|
||||
InsetList::iterator beg = pit->insetlist.begin();
|
||||
InsetList::iterator end = pit->insetlist.end();
|
||||
InsetList::const_iterator beg = pit->insetlist.begin();
|
||||
InsetList::const_iterator end = pit->insetlist.end();
|
||||
for (; beg != end; ++beg) {
|
||||
vector<string> const l = beg.getInset()->getLabelList();
|
||||
vector<string> const l = beg->inset->getLabelList();
|
||||
label_list.insert(label_list.end(), l.begin(), l.end());
|
||||
}
|
||||
}
|
||||
@ -2359,12 +2359,12 @@ Inset * InsetText::getInsetFromID(int id_arg) const
|
||||
ParagraphList::const_iterator pit = paragraphs.begin();
|
||||
ParagraphList::const_iterator pend = paragraphs.end();
|
||||
for (; pit != pend; ++pit) {
|
||||
InsetList::iterator it = pit->insetlist.begin();
|
||||
InsetList::iterator end = pit->insetlist.end();
|
||||
InsetList::const_iterator it = pit->insetlist.begin();
|
||||
InsetList::const_iterator end = pit->insetlist.end();
|
||||
for (; it != end; ++it) {
|
||||
if (it.getInset()->id() == id_arg)
|
||||
return it.getInset();
|
||||
Inset * in = it.getInset()->getInsetFromID(id_arg);
|
||||
if (it->inset->id() == id_arg)
|
||||
return it->inset;
|
||||
Inset * in = it->inset->getInsetFromID(id_arg);
|
||||
if (in)
|
||||
return in;
|
||||
}
|
||||
@ -2654,10 +2654,10 @@ void InsetText::addPreview(grfx::PreviewLoader & loader) const
|
||||
ParagraphList::const_iterator pend = paragraphs.end();
|
||||
|
||||
for (; pit != pend; ++pit) {
|
||||
InsetList::iterator it = pit->insetlist.begin();
|
||||
InsetList::iterator end = pit->insetlist.end();
|
||||
InsetList::const_iterator it = pit->insetlist.begin();
|
||||
InsetList::const_iterator end = pit->insetlist.end();
|
||||
for (; it != end; ++it) {
|
||||
it.getInset()->addPreview(loader);
|
||||
it->inset->addPreview(loader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ ParIterator & ParIterator::operator++()
|
||||
// Does the current inset contain more "cells" ?
|
||||
if (p.index) {
|
||||
++(*p.index);
|
||||
ParagraphList * plist = p.it->getInset()->getParagraphs(*p.index);
|
||||
ParagraphList * plist = (*p.it)->inset->getParagraphs(*p.index);
|
||||
if (plist && !plist->empty()) {
|
||||
pimpl_->positions.push(ParPosition(plist->begin(), *plist));
|
||||
return *this;
|
||||
@ -118,7 +118,7 @@ ParIterator & ParIterator::operator++()
|
||||
// Try to find the next inset that contains paragraphs
|
||||
InsetList::iterator end = p.pit->insetlist.end();
|
||||
for (; *p.it != end; ++(*p.it)) {
|
||||
ParagraphList * plist = p.it->getInset()->getParagraphs(0);
|
||||
ParagraphList * plist = (*p.it)->inset->getParagraphs(0);
|
||||
if (plist && !plist->empty()) {
|
||||
p.index.reset(0);
|
||||
pimpl_->positions.push(ParPosition(plist->begin(), *plist));
|
||||
@ -215,7 +215,7 @@ ParConstIterator & ParConstIterator::operator++()
|
||||
// Does the current inset contain more "cells" ?
|
||||
if (p.index) {
|
||||
++(*p.index);
|
||||
ParagraphList * plist = p.it->getInset()->getParagraphs(*p.index);
|
||||
ParagraphList * plist = (*p.it)->inset->getParagraphs(*p.index);
|
||||
if (plist && !plist->empty()) {
|
||||
pimpl_->positions.push(ParPosition(plist->begin(), *plist));
|
||||
return *this;
|
||||
@ -230,7 +230,7 @@ ParConstIterator & ParConstIterator::operator++()
|
||||
// Try to find the next inset that contains paragraphs
|
||||
InsetList::iterator end = p.pit->insetlist.end();
|
||||
for (; *p.it != end; ++(*p.it)) {
|
||||
ParagraphList * plist = p.it->getInset()->getParagraphs(0);
|
||||
ParagraphList * plist = (*p.it)->inset->getParagraphs(0);
|
||||
if (plist && !plist->empty()) {
|
||||
p.index.reset(0);
|
||||
pimpl_->positions.push(ParPosition(plist->begin(), *plist));
|
||||
|
@ -142,7 +142,7 @@ void InsetFormulaBase::validate(LaTeXFeatures &) const
|
||||
|
||||
|
||||
void InsetFormulaBase::metrics(BufferView * bv, LyXFont const & f,
|
||||
Dimension & dim) const
|
||||
Dimension & /*dim*/) const
|
||||
{
|
||||
font_ = f;
|
||||
metrics(bv);
|
||||
|
@ -99,9 +99,9 @@ Paragraph::Paragraph(Paragraph const & lp)
|
||||
InsetList::iterator it = insetlist.begin();
|
||||
InsetList::iterator end = insetlist.end();
|
||||
for (; it != end; ++it) {
|
||||
it.setInset(it.getInset()->clone(**buffer_));
|
||||
it->inset = it->inset->clone(**buffer_);
|
||||
// tell the new inset who is the boss now
|
||||
it.getInset()->parOwner(this);
|
||||
it->inset->parOwner(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -718,20 +718,20 @@ int Paragraph::beginningOfBody() const
|
||||
int Paragraph::getPositionOfInset(Inset const * inset) const
|
||||
{
|
||||
// Find the entry.
|
||||
InsetList::iterator it = insetlist.begin();
|
||||
InsetList::iterator end = insetlist.end();
|
||||
InsetList::const_iterator it = insetlist.begin();
|
||||
InsetList::const_iterator end = insetlist.end();
|
||||
for (; it != end; ++it)
|
||||
if (it.getInset() == inset)
|
||||
return it.getPos();
|
||||
if (it->inset == inset)
|
||||
return it->pos;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
InsetBibitem * Paragraph::bibitem() const
|
||||
{
|
||||
InsetList::iterator it = insetlist.begin();
|
||||
if (it != insetlist.end() && it.getInset()->lyxCode() == Inset::BIBTEX_CODE)
|
||||
return static_cast<InsetBibitem *>(it.getInset());
|
||||
InsetList::const_iterator it = insetlist.begin();
|
||||
if (it != insetlist.end() && it->inset->lyxCode() == Inset::BIBTEX_CODE)
|
||||
return static_cast<InsetBibitem *>(it->inset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1220,8 +1220,8 @@ void Paragraph::setInsetOwner(Inset * i)
|
||||
InsetList::iterator it = insetlist.begin();
|
||||
InsetList::iterator end = insetlist.end();
|
||||
for (; it != end; ++it)
|
||||
if (it.getInset())
|
||||
it.getInset()->setOwner(i);
|
||||
if (it->inset)
|
||||
it->inset->setOwner(i);
|
||||
}
|
||||
|
||||
|
||||
|
@ -425,10 +425,10 @@ TeXEnvironment(Buffer const * buf,
|
||||
InsetOptArg * optArgInset(Paragraph const & par)
|
||||
{
|
||||
// Find the entry.
|
||||
InsetList::iterator it = par.insetlist.begin();
|
||||
InsetList::iterator end = par.insetlist.end();
|
||||
InsetList::const_iterator it = par.insetlist.begin();
|
||||
InsetList::const_iterator end = par.insetlist.end();
|
||||
for (; it != end; ++it) {
|
||||
Inset * ins = it.getInset();
|
||||
Inset * ins = it->inset;
|
||||
if (ins->lyxCode() == Inset::OPTARG_CODE) {
|
||||
return static_cast<InsetOptArg *>(ins);
|
||||
}
|
||||
|
@ -821,10 +821,10 @@ void Paragraph::Pimpl::validate(LaTeXFeatures & features,
|
||||
InsetList::iterator icit = owner_->insetlist.begin();
|
||||
InsetList::iterator iend = owner_->insetlist.end();
|
||||
for (; icit != iend; ++icit) {
|
||||
if (icit.getInset()) {
|
||||
icit.getInset()->validate(features);
|
||||
if (icit->inset) {
|
||||
icit->inset->validate(features);
|
||||
if (layout.needprotect &&
|
||||
icit.getInset()->lyxCode() == Inset::FOOT_CODE)
|
||||
icit->inset->lyxCode() == Inset::FOOT_CODE)
|
||||
features.require("NeedLyXFootnoteCode");
|
||||
}
|
||||
}
|
||||
|
@ -97,13 +97,13 @@ TocList const getTocList(Buffer const * buf)
|
||||
InsetList::iterator it = pit->insetlist.begin();
|
||||
InsetList::iterator end = pit->insetlist.end();
|
||||
for (; it != end; ++it) {
|
||||
if (it.getInset()->lyxCode() == Inset::FLOAT_CODE) {
|
||||
if (it->inset->lyxCode() == Inset::FLOAT_CODE) {
|
||||
InsetFloat * il =
|
||||
static_cast<InsetFloat*>(it.getInset());
|
||||
static_cast<InsetFloat*>(it->inset);
|
||||
il->addToToc(toclist, buf);
|
||||
} else if (it.getInset()->lyxCode() == Inset::WRAP_CODE) {
|
||||
} else if (it->inset->lyxCode() == Inset::WRAP_CODE) {
|
||||
InsetWrap * il =
|
||||
static_cast<InsetWrap*>(it.getInset());
|
||||
static_cast<InsetWrap*>(it->inset);
|
||||
il->addToToc(toclist, buf);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user