#include "buffer.h"
#include "bufferlist.h"
+#include "counters.h"
#include "LyXAction.h"
#include "lyxrc.h"
#include "lyxlex.h"
#include "support/lyxmanip.h"
#include "support/lyxalgo.h" // for lyx::count
+#include <boost/bind.hpp>
+#include <boost/tuple/tuple.hpp>
+
#include <fstream>
#include <iomanip>
#include <map>
#include <sys/types.h>
#include <utime.h>
-#include <boost/tuple/tuple.hpp>
-
#ifdef HAVE_LOCALE
#include <locale>
#endif
using std::set;
using std::stack;
using std::list;
+using std::for_each;
using lyx::pos_type;
using lyx::textclass_type;
} // namespace anon
Buffer::Buffer(string const & file, bool ronly)
- : paragraph(0), niceFile(true), lyx_clean(true), bak_clean(true),
+ : niceFile(true), lyx_clean(true), bak_clean(true),
unnamed(false), dep_clean(0), read_only(ronly),
- filename_(file), users(0)
+ filename_(file), users(0), ctrs(new Counters)
{
lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
// filename = file;
filepath_ = OnlyPath(file);
-// paragraph = 0;
// lyx_clean = true;
// bak_clean = true;
// dep_clean = 0;
DestroyBufferTmpDir(tmppath);
}
- Paragraph * par = paragraph;
- Paragraph * tmppar;
- while (par) {
- tmppar = par->next();
- delete par;
- par = tmppar;
- }
- paragraph = 0;
+ paragraphs.clear();
// Remove any previewed LaTeX snippets assocoated with this buffer.
grfx::Previews::get().removeLoader(this);
if (read_only != flag) {
read_only = flag;
updateTitles();
- users->owner()->getDialogs()->updateBufferDependent(false);
+ users->owner()->getDialogs().updateBufferDependent(false);
}
}
if (!first_par)
first_par = par;
- paragraph = first_par;
+ paragraphs.set(first_par);
if (unknown_layouts > 0) {
string s = _("Couldn't set the layout for ");
// this will write out all the paragraphs
// using recursive descent.
- paragraph->writeFile(this, ofs, params, depth);
+ paragraphs.begin()->writeFile(this, ofs, params, depth);
// Write marker that shows file is complete
ofs << "\n\\the_end" << endl;
void Buffer::writeFileAscii(ostream & ofs, int linelen)
{
- Paragraph * par = paragraph;
- while (par) {
- ofs << asciiParagraph(par, linelen, par->previous() == 0);
- par = par->next();
+ ParagraphList::iterator beg = paragraphs.begin();
+ ParagraphList::iterator end = paragraphs.end();
+ ParagraphList::iterator it = beg;
+ for (; it != end; ++it) {
+ ofs << asciiParagraph(&*it, linelen, it == beg);
}
ofs << "\n";
}
texrow.reset();
// The starting paragraph of the coming rows is the
// first paragraph of the document. (Asger)
- texrow.start(paragraph, 0);
+ texrow.start(&*(paragraphs.begin()), 0);
if (!only_body && nice) {
os << "%% " << lyx_docversion << " created this file. "
texrow.newline();
}
- latexParagraphs(os, paragraph, 0, texrow);
+ latexParagraphs(os, &*(paragraphs.begin()), 0, texrow);
// add this just in case after all the paragraphs
os << endl;
<< " -->\n";
Paragraph::depth_type depth = 0; // paragraph depth
- Paragraph * par = paragraph;
+ Paragraph * par = &*(paragraphs.begin());
string item_name;
vector<string> environment_stack(5);
return;
}
- Paragraph * par = paragraph;
+ Paragraph * par = &*(paragraphs.begin());
niceFile = nice; // this will be used by Insetincludes.
void Buffer::validate(LaTeXFeatures & features) const
{
- Paragraph * par = paragraph;
LyXTextClass const & tclass = params.getLyXTextClass();
// AMS Style is at document level
if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
features.require("amsmath");
- while (par) {
- // We don't use "lyxerr.debug" because of speed. (Asger)
- if (lyxerr.debugging(Debug::LATEX))
- lyxerr << "Paragraph: " << par << endl;
-
- // Now just follow the list of paragraphs and run
- // validate on each of them.
- par->validate(features);
-
- // and then the next paragraph
- par = par->next();
- }
+ for_each(paragraphs.begin(), paragraphs.end(),
+ boost::bind(&Paragraph::validate, _1, boost::ref(features)));
// the bullet shapes are buffer level not paragraph level
// so they are tested here
}
-vector<string> const Buffer::getLabelList()
+vector<string> const Buffer::getLabelList() const
{
/// if this is a child document and the parent is already loaded
/// Use the parent's list instead [ale990407]
if (!params.parentname.empty()
&& bufferlist.exists(params.parentname)) {
- Buffer * tmp = bufferlist.getBuffer(params.parentname);
+ Buffer const * tmp = bufferlist.getBuffer(params.parentname);
if (tmp)
return tmp->getLabelList();
}
vector<string> label_list;
- for (inset_iterator it = inset_iterator_begin();
- it != inset_iterator_end(); ++it) {
+ for (inset_iterator it = inset_const_iterator_begin();
+ it != inset_const_iterator_end(); ++it) {
vector<string> const l = (*it)->getLabelList();
label_list.insert(label_list.end(), l.begin(), l.end());
}
}
vector<StringPair> keys;
- Paragraph * par = paragraph;
- while (par) {
- if (par->bibkey) {
- string const key = par->bibkey->getContents();
- string const opt = par->bibkey->getOptions();
- string const ref = par->asString(this, false);
+ ParagraphList::iterator pit = paragraphs.begin();
+ ParagraphList::iterator pend = paragraphs.end();
+ for (; pit != pend; ++pit) {
+ if (pit->bibkey) {
+ string const key = pit->bibkey->getContents();
+ string const opt = pit->bibkey->getOptions();
+ string const ref = pit->asString(this, false);
string const info = opt + "TheBibliographyRef" + ref;
keys.push_back(StringPair(key, info));
}
- par = par->next();
}
// Might be either using bibtex or a child has bibliography
void Buffer::resizeInsets(BufferView * bv)
{
/// then remove all LyXText in text-insets
- Paragraph * par = paragraph;
- for (; par; par = par->next()) {
- par->resizeInsetsLyXText(bv);
- }
+ for_each(paragraphs.begin(), paragraphs.end(),
+ boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
}
}
+Counters & Buffer::counters() const
+{
+ return *ctrs.get();
+}
+
+
Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
: par(paragraph)
{
Paragraph * Buffer::getParFromID(int id) const
{
- if (id < 0) return 0;
- Paragraph * par = paragraph;
- while (par) {
- if (par->id() == id) {
- return par;
+ if (id < 0)
+ return 0;
+
+ ParagraphList::iterator it = paragraphs.begin();
+ ParagraphList::iterator end = paragraphs.end();
+ for (; it != end; ++it) {
+ if (it->id() == id) {
+ return &*it;
}
- Paragraph * tmp = par->getParFromID(id);
+ Paragraph * tmp = it->getParFromID(id);
if (tmp) {
return tmp;
}
- par = par->next();
}
return 0;
}
ParIterator Buffer::par_iterator_begin()
{
- return ParIterator(paragraph);
+ return ParIterator(&*(paragraphs.begin()));
}