Reduce header dependencies in Paragraph.h

- Move Changes.h out of Paragraph.h
- pimpl the inset list.



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21033 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-10-18 15:29:51 +00:00
parent 2cb62f5e8b
commit 6725b2db59
19 changed files with 155 additions and 87 deletions

View File

@ -30,6 +30,7 @@
#include "FuncRequest.h"
#include "gettext.h"
#include "InsetIterator.h"
#include "InsetList.h"
#include "Language.h"
#include "LaTeX.h"
#include "LaTeXFeatures.h"
@ -1801,7 +1802,7 @@ void Buffer::buildMacros()
for (size_t i = 0, n = pars.size(); i != n; ++i) {
//lyxerr << "searching main par " << i
// << " for macro definitions" << std::endl;
InsetList const & insets = pars[i].insetlist;
InsetList const & insets = pars[i].insetList();
InsetList::const_iterator it = insets.begin();
InsetList::const_iterator end = insets.end();
for ( ; it != end; ++it) {

View File

@ -19,12 +19,14 @@
#include "buffer_funcs.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "Changes.h"
#include "Cursor.h"
#include "debug.h"
#include "ErrorList.h"
#include "FuncRequest.h"
#include "gettext.h"
#include "InsetIterator.h"
#include "InsetList.h"
#include "Language.h"
#include "lfuns.h"
#include "LyXFunc.h"
@ -218,8 +220,8 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
ParIterator fend = par_iterator_end(in);
for (; fpit != fend; ++fpit) {
InsetList::const_iterator lit = fpit->insetlist.begin();
InsetList::const_iterator eit = fpit->insetlist.end();
InsetList::const_iterator lit = fpit->insetList().begin();
InsetList::const_iterator eit = fpit->insetList().end();
for (; lit != eit; ++lit) {
switch (lit->inset->lyxCode()) {

View File

@ -15,8 +15,9 @@
#include "DocIterator.h"
#include "debug.h"
#include "Text.h"
#include "InsetList.h"
#include "Paragraph.h"
#include "Text.h"
#include "mathed/MathData.h"
#include "mathed/InsetMath.h"
@ -303,7 +304,7 @@ void DocIterator::forwardPar()
pos_type const lastp = lastpos();
Paragraph const & par = paragraph();
pos_type & pos = top().pos();
if (par.insetlist.empty())
if (par.insetList().empty())
pos = lastp;
else
while (pos < lastp && !par.isInset(pos))

View File

@ -138,4 +138,12 @@ void InsetList::decreasePosAfterPos(pos_type pos)
}
void InsetList::clone()
{
List::iterator it = list_.begin();
List::iterator end = list_.end();
for (; it != end; ++it)
it->inset = it->inset->clone();
}
} // namespace lyx

View File

@ -22,7 +22,6 @@ namespace lyx {
class Inset;
class Buffer;
///
class InsetList {
public:
@ -72,6 +71,11 @@ public:
///
void decreasePosAfterPos(pos_type pos);
/// replicate ourselves.
/// Warning: this should be used with care, only
/// Paragraph::Pimpl should use it actually.
void clone();
private:
///
List list_;

View File

@ -21,10 +21,12 @@
#include "Buffer.h"
#include "BufferParams.h"
#include "Changes.h"
#include "Counters.h"
#include "Encoding.h"
#include "debug.h"
#include "gettext.h"
#include "InsetList.h"
#include "Language.h"
#include "LaTeXFeatures.h"
#include "Color.h"
@ -229,6 +231,9 @@ public:
/// Who owns us?
Paragraph * owner_;
///
InsetList insetlist_;
};
@ -277,6 +282,8 @@ Paragraph::Pimpl::Pimpl(Pimpl const & p, Paragraph * owner)
inset_owner = p.inset_owner;
fontlist = p.fontlist;
id_ = paragraph_id++;
insetlist_ = p.insetlist_;
insetlist_.clone();
}
@ -461,7 +468,7 @@ void Paragraph::Pimpl::insertChar(pos_type pos, value_type c, Change const & cha
}
// Update the insets
owner_->insetlist.increasePosAfterPos(pos);
insetlist_.increasePosAfterPos(pos);
}
@ -474,8 +481,8 @@ void Paragraph::Pimpl::insertInset(pos_type pos, Inset * inset,
insertChar(pos, META_INSET, change);
BOOST_ASSERT(owner_->text_[pos] == META_INSET);
// Add a new entry in the insetlist.
owner_->insetlist.insert(inset, pos);
// Add a new entry in the insetlist_.
insetlist_.insert(inset, pos);
}
@ -514,7 +521,7 @@ bool Paragraph::Pimpl::eraseChar(pos_type pos, bool trackChanges)
// if it is an inset, delete the inset entry
if (owner_->text_[pos] == Paragraph::META_INSET) {
owner_->insetlist.erase(pos);
insetlist_.erase(pos);
}
owner_->text_.erase(owner_->text_.begin() + pos);
@ -549,8 +556,8 @@ bool Paragraph::Pimpl::eraseChar(pos_type pos, bool trackChanges)
for (; it != fend; ++it)
it->pos(it->pos() - 1);
// Update the insetlist
owner_->insetlist.decreasePosAfterPos(pos);
// Update the insetlist_
insetlist_.decreasePosAfterPos(pos);
return true;
}
@ -1104,8 +1111,8 @@ void Paragraph::Pimpl::validate(LaTeXFeatures & features,
features.require("ParagraphLeftIndent");
// then the insets
InsetList::const_iterator icit = owner_->insetlist.begin();
InsetList::const_iterator iend = owner_->insetlist.end();
InsetList::const_iterator icit = insetlist_.begin();
InsetList::const_iterator iend = insetlist_.end();
for (; icit != iend; ++icit) {
if (icit->inset) {
icit->inset->validate(features);
@ -1149,16 +1156,11 @@ Paragraph::Paragraph()
Paragraph::Paragraph(Paragraph const & par)
: itemdepth(par.itemdepth), insetlist(par.insetlist),
: itemdepth(par.itemdepth),
layout_(par.layout_),
text_(par.text_), begin_of_body_(par.begin_of_body_),
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();
}
@ -1167,13 +1169,6 @@ Paragraph & Paragraph::operator=(Paragraph const & par)
// needed as we will destroy the pimpl_ before copying it
if (&par != this) {
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();
layout_ = par.layout();
text_ = par.text_;
begin_of_body_ = par.begin_of_body_;
@ -1804,8 +1799,8 @@ void Paragraph::setBeginOfBody()
int Paragraph::getPositionOfInset(Inset const * inset) const
{
// Find the entry.
InsetList::const_iterator it = insetlist.begin();
InsetList::const_iterator end = insetlist.end();
InsetList::const_iterator it = pimpl_->insetlist_.begin();
InsetList::const_iterator end = pimpl_->insetlist_.end();
for (; it != end; ++it)
if (it->inset == inset)
return it->pos;
@ -1815,8 +1810,8 @@ int Paragraph::getPositionOfInset(Inset const * inset) const
InsetBibitem * Paragraph::bibitem() const
{
if (!insetlist.empty()) {
Inset * inset = insetlist.begin()->inset;
if (!pimpl_->insetlist_.empty()) {
Inset * inset = pimpl_->insetlist_.begin()->inset;
if (inset->lyxCode() == BIBITEM_CODE)
return static_cast<InsetBibitem *>(inset);
}
@ -2707,10 +2702,10 @@ int Paragraph::checkBiblio(bool track_changes)
if (layout()->labeltype != LABEL_BIBLIO)
return 0;
bool hasbibitem = !insetlist.empty()
bool hasbibitem = !pimpl_->insetlist_.empty()
// Insist on it being in pos 0
&& getChar(0) == Paragraph::META_INSET
&& insetlist.begin()->inset->lyxCode() == BIBITEM_CODE;
&& pimpl_->insetlist_.begin()->inset->lyxCode() == BIBITEM_CODE;
docstring oldkey;
docstring oldlabel;
@ -2721,8 +2716,8 @@ int Paragraph::checkBiblio(bool track_changes)
// we're assuming there's only one of these, which there
// should be.
int erasedInsetPosition = -1;
InsetList::iterator it = insetlist.begin();
InsetList::iterator end = insetlist.end();
InsetList::iterator it = pimpl_->insetlist_.begin();
InsetList::iterator end = pimpl_->insetlist_.end();
for (; it != end; ++it)
if (it->inset->lyxCode() == BIBITEM_CODE
&& it->pos > 0) {
@ -2743,7 +2738,7 @@ int Paragraph::checkBiblio(bool track_changes)
//erase one. So we give its properties to the beginning inset.
if (hasbibitem) {
InsetBibitem * inset =
static_cast<InsetBibitem *>(insetlist.begin()->inset);
static_cast<InsetBibitem *>(pimpl_->insetlist_.begin()->inset);
if (!oldkey.empty())
inset->setParam("key", oldkey);
inset->setParam("label", oldlabel);
@ -2769,4 +2764,49 @@ void Paragraph::checkAuthors(AuthorList const & authorList)
pimpl_->changes_.checkAuthors(authorList);
}
bool Paragraph::isUnchanged(pos_type pos) const
{
return lookupChange(pos).type == Change::UNCHANGED;
}
bool Paragraph::isInserted(pos_type pos) const
{
return lookupChange(pos).type == Change::INSERTED;
}
bool Paragraph::isDeleted(pos_type pos) const
{
return lookupChange(pos).type == Change::DELETED;
}
InsetList const & Paragraph::insetList() const
{
return pimpl_->insetlist_;
}
Inset * Paragraph::releaseInset(pos_type pos)
{
Inset * inset = pimpl_->insetlist_.release(pos);
/// does not honour change tracking!
eraseChar(pos, false);
return inset;
}
Inset * Paragraph::getInset(pos_type pos)
{
return pimpl_->insetlist_.get(pos);
}
Inset const * Paragraph::getInset(pos_type pos) const
{
return pimpl_->insetlist_.get(pos);
}
} // namespace lyx

View File

@ -16,23 +16,29 @@
#ifndef PARAGRAPH_H
#define PARAGRAPH_H
#include "Changes.h"
#include "InsetList.h"
#include "lyxlayout_ptr_fwd.h"
#include "insets/InsetCode.h"
#include "support/docstring.h"
// FIXME: would be nice to forward declare odocstream instead of
// including this:
#include "support/docstream.h"
#include <vector>
namespace lyx {
class AuthorList;
class Buffer;
class BufferParams;
class Change;
class Counters;
class Inset;
class InsetBibitem;
class LaTeXFeatures;
class Inset_code;
class InsetList;
class Language;
class Font;
class Font_size;
@ -186,17 +192,11 @@ public:
/// is there a change within the given range ?
bool isChanged(pos_type start, pos_type end) const;
/// is there an unchanged char at the given pos ?
bool isUnchanged(pos_type pos) const {
return lookupChange(pos).type == Change::UNCHANGED;
}
bool isUnchanged(pos_type pos) const;
/// is there an insertion at the given pos ?
bool isInserted(pos_type pos) const {
return lookupChange(pos).type == Change::INSERTED;
}
bool isInserted(pos_type pos) const;
/// is there a deletion at the given pos ?
bool isDeleted(pos_type pos) const {
return lookupChange(pos).type == Change::DELETED;
}
bool isDeleted(pos_type pos) const;
/// will the paragraph be physically merged with the next
/// one if the imaginary end-of-par character is logically deleted?
@ -309,13 +309,18 @@ public:
///
bool insetAllowed(InsetCode code);
///
Inset * getInset(pos_type pos) {
return insetlist.get(pos);
}
Inset * getInset(pos_type pos);
///
Inset const * getInset(pos_type pos) const {
return insetlist.get(pos);
}
Inset const * getInset(pos_type pos) const;
/// Release inset at given position.
/// \warning does not honour change tracking!
/// Therefore, it should only be used for breaking and merging
/// paragraphs
Inset * releaseInset(pos_type pos);
///
InsetList const & insetList() const;
///
bool isHfill(pos_type pos) const;
@ -366,10 +371,6 @@ public:
/// by this author in the paragraph.
void checkAuthors(AuthorList const & authorList);
public:
///
InsetList insetlist;
private:
///

View File

@ -25,6 +25,7 @@
#include "buffer_funcs.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "Changes.h"
#include "Cursor.h"
#include "ParIterator.h"
#include "CutAndPaste.h"

View File

@ -28,6 +28,7 @@
#include "BufferParams.h"
#include "BufferView.h"
#include "Bullet.h"
#include "Changes.h"
#include "Color.h"
#include "Cursor.h"
#include "CutAndPaste.h"

View File

@ -29,6 +29,7 @@
#include "debug.h"
#include "FontIterator.h"
#include "FuncRequest.h"
#include "InsetList.h"
#include "Layout.h"
#include "Length.h"
#include "LyXRC.h"
@ -381,8 +382,8 @@ bool TextMetrics::redoParagraph(pit_type const pit)
// FIXME: We should always use getFont(), see documentation of
// noFontChange() in Inset.h.
Font const bufferfont = buffer.params().getFont();
InsetList::const_iterator ii = par.insetlist.begin();
InsetList::const_iterator iend = par.insetlist.end();
InsetList::const_iterator ii = par.insetList().begin();
InsetList::const_iterator iend = par.insetList().end();
for (; ii != iend; ++ii) {
Dimension dim;
int const w = max_width_ - leftMargin(max_width_, pit, ii->pos)
@ -863,8 +864,8 @@ boost::tuple<int, int> TextMetrics::rowHeight(pit_type const pit, pos_type const
// insets may be taller
ParagraphMetrics const & pm = par_metrics_[pit];
InsetList::const_iterator ii = par.insetlist.begin();
InsetList::const_iterator iend = par.insetlist.end();
InsetList::const_iterator ii = par.insetList().begin();
InsetList::const_iterator iend = par.insetList().end();
for ( ; ii != iend; ++ii) {
Dimension const & dim = pm.insetDimension(ii->inset);
if (ii->pos >= first && ii->pos < end) {
@ -1411,8 +1412,8 @@ Inset * TextMetrics::checkInsetHit(int x, int y)
<< " y: " << y
<< " pit: " << pit
<< endl;
InsetList::const_iterator iit = par.insetlist.begin();
InsetList::const_iterator iend = par.insetlist.end();
InsetList::const_iterator iit = par.insetList().begin();
InsetList::const_iterator iend = par.insetList().end();
for (; iit != iend; ++iit) {
Inset * inset = iit->inset;

View File

@ -19,6 +19,7 @@
#include "debug.h"
#include "FloatList.h"
#include "FuncRequest.h"
#include "InsetList.h"
#include "Layout.h"
#include "LyXAction.h"
#include "Paragraph.h"
@ -109,8 +110,8 @@ void TocBackend::updateItem(ParConstIterator const & par_it)
// For each paragraph, traverse its insets and let them add
// their toc items
InsetList::const_iterator it = toc_item->par_it_->insetlist.begin();
InsetList::const_iterator end = toc_item->par_it_->insetlist.end();
InsetList::const_iterator it = toc_item->par_it_->insetList().begin();
InsetList::const_iterator end = toc_item->par_it_->insetList().end();
for (; it != end; ++it) {
Inset & inset = *it->inset;
if (inset.lyxCode() == OPTARG_CODE) {
@ -152,8 +153,8 @@ void TocBackend::update()
// For each paragraph, traverse its insets and let them add
// their toc items
InsetList::const_iterator it = pit->insetlist.begin();
InsetList::const_iterator end = pit->insetlist.end();
InsetList::const_iterator it = pit->insetList().begin();
InsetList::const_iterator end = pit->insetList().end();
for (; it != end; ++it) {
Inset & inset = *it->inset;
inset.addToToc(tocs_, *buffer_, pit);

View File

@ -23,6 +23,7 @@
#include "Floating.h"
#include "FloatList.h"
#include "gettext.h"
#include "InsetList.h"
#include "InsetIterator.h"
#include "Language.h"
#include "LaTeX.h"
@ -575,8 +576,8 @@ void updateLabels(Buffer const & buf, ParIterator & parit)
setLabel(buf, parit);
// Now the insets
InsetList::const_iterator iit = parit->insetlist.begin();
InsetList::const_iterator end = parit->insetlist.end();
InsetList::const_iterator iit = parit->insetList().begin();
InsetList::const_iterator end = parit->insetList().end();
for (; iit != end; ++iit) {
parit.pos() = iit->pos;
iit->inset->updateLabels(buf, parit);

View File

@ -38,6 +38,7 @@ class FuncRequest;
class FuncStatus;
class InsetIterator;
class InsetLayout;
class InsetList;
class InsetMath;
class InsetText;
class LaTeXFeatures;
@ -46,7 +47,6 @@ class MathAtom;
class MetricsInfo;
class OutputParams;
class PainterInfo;
class Paragraph;
class ParConstIterator;
class ParIterator;
class Text;
@ -391,7 +391,7 @@ protected:
Inset();
/// replicate ourselves
friend class Paragraph;
friend class InsetList;
friend class MathAtom;
virtual Inset * clone() const = 0;

View File

@ -17,13 +17,15 @@
#include "Buffer.h"
#include "BufferParams.h"
#include "Counters.h"
#include "Language.h"
#include "gettext.h"
#include "Cursor.h"
#include "DispatchResult.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "gettext.h"
#include "InsetList.h"
#include "Language.h"
#include "MetricsInfo.h"
#include "Cursor.h"
#include "support/lstrings.h"
#include <sstream>
@ -326,8 +328,8 @@ docstring InsetListings::getCaption(Buffer const & buf,
ParagraphList::const_iterator pit = paragraphs().begin();
for (; pit != paragraphs().end(); ++pit) {
InsetList::const_iterator it = pit->insetlist.begin();
for (; it != pit->insetlist.end(); ++it) {
InsetList::const_iterator it = pit->insetList().begin();
for (; it != pit->insetList().end(); ++it) {
Inset & inset = *it->inset;
if (inset.lyxCode() == CAPTION_CODE) {
odocstringstream ods;

View File

@ -25,6 +25,7 @@
#include "ErrorList.h"
#include "FuncRequest.h"
#include "gettext.h"
#include "InsetList.h"
#include "Intl.h"
#include "Color.h"
#include "lyxfind.h"
@ -403,8 +404,8 @@ void InsetText::addPreview(PreviewLoader & loader) const
ParagraphList::const_iterator pend = paragraphs().end();
for (; pit != pend; ++pit) {
InsetList::const_iterator it = pit->insetlist.begin();
InsetList::const_iterator end = pit->insetlist.end();
InsetList::const_iterator it = pit->insetList().begin();
InsetList::const_iterator end = pit->insetList().end();
for (; it != end; ++it)
it->inset->addPreview(loader);
}

View File

@ -21,6 +21,7 @@
#include "CutAndPaste.h"
#include "buffer_funcs.h"
#include "BufferView.h"
#include "Changes.h"
#include "debug.h"
#include "FuncRequest.h"
#include "gettext.h"

View File

@ -16,6 +16,7 @@
#include "BufferParams.h"
#include "debug.h"
#include "Encoding.h"
#include "InsetList.h"
#include "Language.h"
#include "Layout.h"
#include "LyXRC.h"
@ -223,8 +224,8 @@ int latexOptArgInsets(Buffer const & buf, Paragraph const & par,
{
int lines = 0;
InsetList::const_iterator it = par.insetlist.begin();
InsetList::const_iterator end = par.insetlist.end();
InsetList::const_iterator it = par.insetList().begin();
InsetList::const_iterator end = par.insetList().end();
for (; it != end && number > 0 ; ++it) {
if (it->inset->lyxCode() == OPTARG_CODE) {
InsetOptArg * ins =

View File

@ -13,11 +13,13 @@
#include "paragraph_funcs.h"
#include "BufferParams.h"
#include "Changes.h"
#include "debug.h"
#include "InsetList.h"
#include "Layout.h"
#include "Text.h"
#include "Paragraph.h"
#include "ParagraphParameters.h"
#include "Text.h"
#include <boost/next_prior.hpp>
@ -41,11 +43,9 @@ static bool moveItem(Paragraph & fromPar, pos_type fromPos,
Inset * tmpInset = 0;
if (fromPar.getInset(fromPos)) {
// the inset is not in the paragraph any more
tmpInset = fromPar.insetlist.release(fromPos);
tmpInset = fromPar.releaseInset(fromPos);
}
fromPar.eraseChar(fromPos, false);
if (!toPar.insetAllowed(tmpInset->lyxCode())) {
delete tmpInset;
return false;
@ -313,8 +313,8 @@ int numberOfOptArgs(Paragraph const & par)
{
int num = 0;
InsetList::const_iterator it = par.insetlist.begin();
InsetList::const_iterator end = par.insetlist.end();
InsetList::const_iterator it = par.insetList().begin();
InsetList::const_iterator end = par.insetList().end();
for (; it != end ; ++it) {
if (it->inset->lyxCode() == OPTARG_CODE)
++num;

View File

@ -21,6 +21,7 @@
#include "debug.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "Changes.h"
#include "Encoding.h"
#include "gettext.h"
#include "Language.h"