return !(i1 == i2);
}
+////////// The ParagraphList::const_iterator
+
+ParagraphList::const_iterator::const_iterator()
+ : ptr(0)
+{}
+
+
+ParagraphList::const_iterator::const_iterator(Paragraph * p)
+ : ptr(p)
+{}
+
+
+ParagraphList::const_iterator::const_reference
+ParagraphList::const_iterator::operator*()
+{
+ return *ptr;
+}
+
+
+ParagraphList::const_iterator::const_pointer
+ParagraphList::const_iterator::operator->()
+{
+ return ptr;
+}
+
+
+ParagraphList::const_iterator &
+ParagraphList::const_iterator::operator++()
+{
+ ptr = ptr->next_par_;
+ return *this;
+}
+
+
+ParagraphList::const_iterator
+ParagraphList::const_iterator::operator++(int)
+{
+ const_iterator tmp = *this;
+ ++*this;
+ return tmp;
+}
+
+
+ParagraphList::const_iterator &
+ParagraphList::const_iterator::operator--()
+{
+ ptr = ptr->prev_par_;
+ return *this;
+}
+
+
+ParagraphList::const_iterator
+ParagraphList::const_iterator::operator--(int)
+{
+ const_iterator tmp = *this;
+ --*this;
+ return tmp;
+}
+
+
+bool operator==(ParagraphList::const_iterator const & i1,
+ ParagraphList::const_iterator const & i2)
+{
+ return &(*const_cast<ParagraphList::const_iterator&>(i1))
+ == &(*const_cast<ParagraphList::const_iterator&>(i2));
+}
+
+
+bool operator!=(ParagraphList::const_iterator const & i1,
+ ParagraphList::const_iterator const & i2)
+{
+ return !(i1 == i2);
+}
+
//////////
////////// The ParagraphList proper
//////////
: parlist(0)
{
// Deep copy.
- ParagraphList::iterator it = pl.begin();
- ParagraphList::iterator end = pl.end();
+ ParagraphList::const_iterator it = pl.begin();
+ ParagraphList::const_iterator end = pl.end();
for (; it != end; ++it) {
push_back(*it);
}
}
-ParagraphList::iterator ParagraphList::begin() const
+ParagraphList::const_iterator ParagraphList::begin() const
{
- return iterator(parlist);
+ return const_iterator(parlist);
}
}
-ParagraphList::iterator ParagraphList::end() const
+ParagraphList::const_iterator ParagraphList::end() const
{
- return iterator();
+ return const_iterator();
}
Paragraph * ptr;
};
///
+ class const_iterator {
+ public:
+ friend class ParagraphList;
+ ///
+ typedef std::bidirectional_iterator_tag iterator_category;
+ ///
+ typedef Paragraph * value_type;
+ ///
+ typedef ptrdiff_t difference_type;
+ ///
+ typedef Paragraph const * const_pointer;
+ ///
+ typedef Paragraph const & const_reference;
+ ///
+ const_iterator();
+ ///
+ const_reference operator*();
+ ///
+ const_pointer operator->();
+ ///
+ const_iterator & operator++();
+ ///
+ const_iterator operator++(int);
+ ///
+ const_iterator & operator--();
+ ///
+ const_iterator operator--(int);
+ private:
+ ///
+ const_iterator(value_type);
+ ///
+ Paragraph * ptr;
+ };
+ ///
ParagraphList();
///
ParagraphList(ParagraphList const &);
///
iterator begin();
///
- iterator begin() const;
+ const_iterator begin() const;
///
iterator end();
///
- iterator end() const;
+ const_iterator end() const;
///
void push_back(Paragraph const &);
///
bool operator!=(ParagraphList::iterator const & i1,
ParagraphList::iterator const & i2);
+///
+bool operator==(ParagraphList::const_iterator const & i1,
+ ParagraphList::const_iterator const & i2);
+///
+bool operator!=(ParagraphList::const_iterator const & i1,
+ ParagraphList::const_iterator const & i2);
+
#endif
#endif
// this will write out all the paragraphs
// using recursive descent.
- ParagraphList::iterator pit = paragraphs.begin();
- ParagraphList::iterator pend = paragraphs.end();
+ ParagraphList::const_iterator pit = paragraphs.begin();
+ ParagraphList::const_iterator pend = paragraphs.end();
for (; pit != pend; ++pit)
pit->write(this, ofs, params, depth);
ParConstIterator Buffer::par_iterator_begin() const
{
- return ParConstIterator(paragraphs.begin(), paragraphs);
+ return ParConstIterator(const_cast<ParagraphList&>(paragraphs).begin(), paragraphs);
}
ParConstIterator Buffer::par_iterator_end() const
{
- return ParConstIterator(paragraphs.end(), paragraphs);
+ return ParConstIterator(const_cast<ParagraphList&>(paragraphs).end(), paragraphs);
}
///
inset_iterator inset_const_iterator_begin() const {
- return inset_iterator(paragraphs.begin(), paragraphs.end());
+ return inset_iterator(const_cast<ParagraphList&>(paragraphs).begin(), const_cast<ParagraphList&>(paragraphs).end());
}
///
int w = 0;
// Does look like a hack? It is! (but will change at 0.13)
- InsetBibitem * bitem = 0;
+ InsetBibitem const * bitem = 0;
LyXFont font;
- ParagraphList::iterator it = buffer->paragraphs.begin();
- ParagraphList::iterator end = buffer->paragraphs.end();
+ ParagraphList::const_iterator it = buffer->paragraphs.begin();
+ ParagraphList::const_iterator end = buffer->paragraphs.end();
for (; it != end; ++it) {
if (it->bibitem()) {
int const wx =
void InsetText::saveLyXTextState(LyXText * t) const
{
// check if my paragraphs are still valid
- ParagraphList::iterator it = paragraphs.begin();
- ParagraphList::iterator end = paragraphs.end();
+ ParagraphList::iterator it = const_cast<ParagraphList&>(paragraphs).begin();
+ ParagraphList::iterator end = const_cast<ParagraphList&>(paragraphs).end();
for (; it != end; ++it) {
if (it == t->cursor.par())
break;
sstate.selection = t->selection.set();
sstate.mark_set = t->selection.mark();
} else {
- sstate.lpar = paragraphs.end();
+ sstate.lpar = const_cast<ParagraphList&>(paragraphs).end();
}
}
void InsetText::restoreLyXTextState(LyXText * t) const
{
- if (sstate.lpar == paragraphs.end())
+ if (sstate.lpar == const_cast<ParagraphList&>(paragraphs).end())
return;
t->selection.set(true);
void InsetText::writeParagraphData(Buffer const * buf, ostream & os) const
{
- ParagraphList::iterator it = paragraphs.begin();
- ParagraphList::iterator end = paragraphs.end();
+ ParagraphList::const_iterator it = paragraphs.begin();
+ ParagraphList::const_iterator end = paragraphs.end();
Paragraph::depth_type dth = 0;
for (; it != end; ++it) {
it->write(buf, os, buf->params, dth);
{
unsigned int lines = 0;
- ParagraphList::iterator beg = paragraphs.begin();
- ParagraphList::iterator end = paragraphs.end();
- ParagraphList::iterator it = beg;
+ ParagraphList::const_iterator beg = paragraphs.begin();
+ ParagraphList::const_iterator end = paragraphs.end();
+ ParagraphList::const_iterator it = beg;
for (; it != end; ++it) {
string const tmp = buf->asciiParagraph(*it, linelen, it == beg);
lines += lyx::count(tmp.begin(), tmp.end(), '\n');
Paragraph::depth_type depth = 0; // paragraph depth
- ParagraphList::iterator pit = paragraphs.begin();
- ParagraphList::iterator pend = paragraphs.end();
+ ParagraphList::iterator pit = const_cast<ParagraphList&>(paragraphs).begin();
+ ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
for (; pit != pend; ++pit) {
string sgmlparam;
{
vector<string> label_list;
- ParagraphList::iterator pit = paragraphs.begin();
- ParagraphList::iterator pend = paragraphs.end();
+ 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();
// See if this can be simplified when std::list is in effect.
paragraphs.clear();
- ParagraphList::iterator it = plist.begin();
- ParagraphList::iterator end = plist.end();
+ ParagraphList::const_iterator it = plist.begin();
+ ParagraphList::const_iterator end = plist.end();
for (; it != end; ++it) {
paragraphs.push_back(*it);
Paragraph & tmp = paragraphs.back();
if (recursive && the_locking_inset)
return the_locking_inset->getLyXText(lbv, true);
LyXText * lt = cached_text.get();
- lyx::Assert(lt && lt->rows().begin()->par() == paragraphs.begin());
+ lyx::Assert(lt && lt->rows().begin()->par() == const_cast<ParagraphList&>(paragraphs).begin());
return lt;
}
// Super UGLY! (Lgb)
if (locked) {
saveLyXTextState(it->second.text.get());
} else {
- sstate.lpar = paragraphs.end();
+ sstate.lpar = const_cast<ParagraphList&>(paragraphs).end();
}
}
//
it->second.remove = true;
if (recursive) {
/// then remove all LyXText in text-insets
- for_each(paragraphs.begin(), paragraphs.end(),
+ for_each(const_cast<ParagraphList&>(paragraphs).begin(),
+ const_cast<ParagraphList&>(paragraphs).end(),
boost::bind(&Paragraph::deleteInsetsLyXText, _1, bv));
}
}
LyXText * t = it->second.text.get();
saveLyXTextState(t);
- for_each(paragraphs.begin(), paragraphs.end(),
+ for_each(const_cast<ParagraphList&>(paragraphs).begin(),
+ const_cast<ParagraphList&>(paragraphs).end(),
boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
t->init(bv, true);
saveLyXTextState(t);
- for_each(paragraphs.begin(), paragraphs.end(),
+ for_each(const_cast<ParagraphList&>(paragraphs).begin(),
+ const_cast<ParagraphList&>(paragraphs).end(),
boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
t->init(bv, true);
if (id_arg == id())
return const_cast<InsetText *>(this);
- ParagraphList::iterator pit = paragraphs.begin();
- ParagraphList::iterator pend = paragraphs.end();
+ 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();
void InsetText::addPreview(grfx::PreviewLoader & loader) const
{
- ParagraphList::iterator pit = paragraphs.begin();
- ParagraphList::iterator pend = paragraphs.end();
+ ParagraphList::const_iterator pit = paragraphs.begin();
+ ParagraphList::const_iterator pend = paragraphs.end();
for (; pit != pend; ++pit) {
InsetList::iterator it = pit->insetlist.begin();
ParPosition::ParPosition(ParagraphList::iterator p, ParagraphList const & pl)
: pit(p), plist(&pl)
{
- if (p != pl.end()) {
+ if (p != const_cast<ParagraphList&>(pl).end()) {
it.reset(p->insetlist.begin());
}
}
}
// Try to go to the next paragarph
- if (next(p.pit) != p.plist->end()
+ if (next(p.pit) != const_cast<ParagraphList*>(p.plist)->end()
|| pimpl_->positions.size() == 1) {
++p.pit;
p.index.reset();
}
// Try to go to the next paragarph
- if (next(p.pit) != p.plist->end()
+ if (next(p.pit) != const_cast<ParagraphList*>(p.plist)->end()
|| pimpl_->positions.size() == 1) {
++p.pit;
p.index.reset();
}
-InsetBibitem * Paragraph::bibitem()
+InsetBibitem * Paragraph::bibitem() const
{
InsetList::iterator it = insetlist.begin();
if (it != insetlist.end() && it.getInset()->lyxCode() == Inset::BIBTEX_CODE)
// Remove this whan ParagraphList transition is over. (Lgb)
friend class ParagraphList;
friend class ParagraphList::iterator;
+ friend class ParagraphList::const_iterator;
#endif
///
enum META_KIND {
char itemdepth;
///
- InsetBibitem * bibitem(); // ale970302
+ InsetBibitem * bibitem() const; // ale970302
/// initialise tracking for this par
void trackChanges(Change::Type = Change::UNCHANGED);
Paragraph::depth_type depth)
{
ParagraphList::iterator newpit = pit;
- ParagraphList::iterator beg = plist.begin();
+ ParagraphList::iterator beg = const_cast<ParagraphList&>(plist).begin();
if (newpit != beg)
--newpit;
ParagraphList const & plist)
{
if (!pit->getDepth())
- return plist.end();
+ return const_cast<ParagraphList&>(plist).end();
return depthHook(pit, plist,
Paragraph::depth_type(pit->getDepth() - 1));
}
{
ParagraphList::iterator pit = p;
Paragraph::depth_type par_depth = p->getDepth();
- while (pit != plist.end()) {
+ while (pit != const_cast<ParagraphList&>(plist).end()) {
LyXLayout_ptr const & layout = pit->layout();
int const endlabeltype = layout->endlabeltype;
if (endlabeltype != END_LABEL_NO_LABEL) {
- if (boost::next(p) == plist.end())
+ if (boost::next(p) == const_cast<ParagraphList&>(plist).end())
return endlabeltype;
Paragraph::depth_type const next_depth = boost::next(p)->getDepth();
if (par_depth == 0)
break;
pit = outerHook(pit, plist);
- if (pit != plist.end())
+ if (pit != const_cast<ParagraphList&>(plist).end())
par_depth = pit->getDepth();
}
return END_LABEL_NO_LABEL;
lyxerr[Debug::LATEX] << "TeXDeeper... " << &*pit << endl;
ParagraphList::iterator par = pit;
- while (par != paragraphs.end() &&
+ while (par != const_cast<ParagraphList&>(paragraphs).end() &&
par->params().depth() == pit->params().depth()) {
if (par->layout()->isEnvironment()) {
par = TeXEnvironment(buf, paragraphs, par,
Language const * language = pit->getParLanguage(bparams);
Language const * doc_language = bparams.language;
Language const * previous_language =
- (pit != paragraphs.begin())
+ (pit != const_cast<ParagraphList&>(paragraphs).begin())
? boost::prior(pit)->getParLanguage(bparams)
: doc_language;
if (language->babel() != previous_language->babel()) {
do {
par = TeXOnePar(buf, paragraphs, par, os, texrow, runparams);
- if (par != paragraphs.end()&& par->params().depth() > pit->params().depth()) {
+ if (par != const_cast<ParagraphList&>(paragraphs).end()&& par->params().depth() > pit->params().depth()) {
if (par->layout()->isParagraph()) {
// Thinko!
par = TeXDeeper(buf, paragraphs, par, os, texrow,
runparams);
}
- } while (par != paragraphs.end()
+ } while (par != const_cast<ParagraphList&>(paragraphs).end()
&& par->layout() == pit->layout()
&& par->params().depth() == pit->params().depth()
&& par->params().leftIndent() == pit->params().leftIndent());
}
if (!pit->params().spacing().isDefault()
- && (pit == paragraphs.begin() || !boost::prior(pit)->hasSameLayout(*pit))) {
+ && (pit == const_cast<ParagraphList&>(paragraphs).begin() || !boost::prior(pit)->hasSameLayout(*pit))) {
os << pit->params().spacing().writeEnvirBegin() << '\n';
texrow.newline();
}
Language const * language = pit->getParLanguage(bparams);
Language const * doc_language = bparams.language;
Language const * previous_language =
- (pit != paragraphs.begin())
+ (pit != const_cast<ParagraphList&>(paragraphs).begin())
? boost::prior(pit)->getParLanguage(bparams)
: doc_language;
if (language->babel() != previous_language->babel()
// check if we already put language command in TeXEnvironment()
&& !(style->isEnvironment()
- && (pit == paragraphs.begin() ||
+ && (pit == const_cast<ParagraphList&>(paragraphs).begin() ||
(boost::prior(pit)->layout() != pit->layout() &&
boost::prior(pit)->getDepth() <= pit->getDepth())
|| boost::prior(pit)->getDepth() < pit->getDepth())))
bool is_command = style->isCommand();
if (style->resfont.size() != font.size()
- && boost::next(pit) != paragraphs.end()
+ && boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
&& !is_command) {
if (!need_par)
os << '{';
switch (style->latextype) {
case LATEX_ITEM_ENVIRONMENT:
case LATEX_LIST_ENVIRONMENT:
- if (boost::next(pit) != paragraphs.end()
+ if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
&& (pit->params().depth() < boost::next(pit)->params().depth())) {
os << '\n';
texrow.newline();
case LATEX_ENVIRONMENT:
// if its the last paragraph of the current environment
// skip it otherwise fall through
- if (boost::next(pit) != paragraphs.end()
+ if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()
&& (boost::next(pit)->layout() != pit->layout()
|| boost::next(pit)->params().depth() != pit->params().depth()))
break;
// fall through possible
default:
// we don't need it for the last paragraph!!!
- if (boost::next(pit) != paragraphs.end()) {
+ if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
os << '\n';
texrow.newline();
}
}
if (!pit->params().spacing().isDefault()
- && (boost::next(pit) == paragraphs.end()|| !boost::next(pit)->hasSameLayout(*pit))) {
+ && (boost::next(pit) == const_cast<ParagraphList&>(paragraphs).end()|| !boost::next(pit)->hasSameLayout(*pit))) {
os << pit->params().spacing().writeEnvirEnd() << '\n';
texrow.newline();
}
}
// we don't need it for the last paragraph!!!
- if (boost::next(pit) != paragraphs.end()) {
+ if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) {
os << '\n';
texrow.newline();
} else {
bool was_title = false;
bool already_title = false;
LyXTextClass const & tclass = buf->params.getLyXTextClass();
- ParagraphList::iterator par = paragraphs.begin();
- ParagraphList::iterator endpar = paragraphs.end();
+ ParagraphList::iterator par = const_cast<ParagraphList&>(paragraphs).begin();
+ ParagraphList::iterator endpar = const_cast<ParagraphList&>(paragraphs).end();
// if only_body
while (par != endpar) {
LyXFont tmpfont(LyXFont::ALL_INHERIT);
// Resolve against environment font information
- while (pit != plist.end() &&
+ while (pit != const_cast<ParagraphList&>(plist).end() &&
par_depth && !tmpfont.resolved()) {
pit = outerHook(pit, plist);
- if (pit != plist.end()) {
+ if (pit != const_cast<ParagraphList&>(plist).end()) {
tmpfont.realize(pit->layout()->font);
par_depth = pit->getDepth();
}
LyXTabular::BoxType LyXTabular::UseParbox(int cell) const
{
ParagraphList const & parlist = GetCellInset(cell)->paragraphs;
- ParagraphList::iterator cit = parlist.begin();
- ParagraphList::iterator end = parlist.end();
+ ParagraphList::const_iterator cit = parlist.begin();
+ ParagraphList::const_iterator end = parlist.end();
for (; cit != end; ++cit) {
for (int i = 0; i < cit->size(); ++i) {