#include "buffer.h"
#include "bufferlist.h"
-#include "lyx_main.h"
+#include "counters.h"
#include "LyXAction.h"
#include "lyxrc.h"
#include "lyxlex.h"
#include "ParagraphParameters.h"
#include "iterators.h"
#include "lyxtextclasslist.h"
+#include "sgml.h"
#include "mathed/formulamacro.h"
#include "mathed/formula.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>
-
#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;
// all these externs should eventually be removed.
extern BufferList bufferlist;
-extern LyXAction lyxaction;
-
namespace {
const int LYX_FORMAT = 220;
} // namespace anon
-extern int tex_code_break_column;
-
-
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 ");
for(string::const_iterator cit = str.begin();
cit != str.end(); ++cit) {
if (*cit == '\n') {
- if (autobreakrows && (par->size() || layout->keepempty)) {
+ if (autobreakrows && (!par->empty() || layout->keepempty)) {
par->breakParagraph(params, pos,
layout->isEnvironment());
par = par->next();
// 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";
}
{
niceFile = nice; // this will be used by Insetincludes.
- tex_code_break_column = lyxrc.ascii_linelen;
-
// validate the buffer.
lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
LaTeXFeatures features(params);
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. "
// usual is \batchmode and has a
// special input@path to allow the including of figures
// with either \input or \includegraphics (what figinsets do).
- // batchmode is not set if there is a tex_code_break_column.
- // In this case somebody is interested in the generated LaTeX,
- // so this is OK. input@path is set when the actual parameter
+ // input@path is set when the actual parameter
// original_path is set. This is done for usual tex-file, but not
// for nice-latex-file. (Matthias 250696)
if (!only_body) {
texrow.newline();
}
- latexParagraphs(os, paragraph, 0, texrow);
+ latexParagraphs(os, &*(paragraphs.begin()), 0, texrow);
// add this just in case after all the paragraphs
os << endl;
// Just to be sure. (Asger)
texrow.newline();
- // tex_code_break_column's value is used to decide
- // if we are in batchmode or not (within mathed_write()
- // in math_write.C) so we must set it to a non-zero
- // value when we leave otherwise we save incorrect .lyx files.
- tex_code_break_column = lyxrc.ascii_linelen;
-
lyxerr[Debug::INFO] << "Finished making latex file." << endl;
lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
<< " -->\n";
Paragraph::depth_type depth = 0; // paragraph depth
- Paragraph * par = paragraph;
+ Paragraph * par = &*(paragraphs.begin());
string item_name;
vector<string> environment_stack(5);
os << c;
++char_line_count;
} else {
- string sgml_string;
- if (par->sgmlConvertChar(c, sgml_string)
- && !style->free_spacing && !par->isFreeSpacing())
- {
+ bool ws;
+ string str;
+ boost::tie(ws, str) = sgml::escapeChar(c);
+ if (ws && !style->free_spacing && !par->isFreeSpacing()) {
// in freespacing mode, spaces are
// non-breaking characters
if (desc_on) {// if char is ' ' then...
os << c;
}
} else {
- os << sgml_string;
- char_line_count += sgml_string.length();
+ os << str;
+ char_line_count += str.length();
}
}
font_old = font;
return;
}
- Paragraph * par = paragraph;
+ Paragraph * par = &*(paragraphs.begin());
niceFile = nice; // this will be used by Insetincludes.
}
} else {
char c = par->getChar(i);
- string sgml_string;
- par->sgmlConvertChar(c, sgml_string);
+ bool ws;
+ string str;
+ boost::tie(ws, str) = sgml::escapeChar(c);
if (style->pass_thru) {
os << c;
} else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
- os << sgml_string;
+ os << str;
} else if (desc_on ==1) {
++char_line_count;
os << "\n</term><listitem><para>";
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)
{
- it = par->InsetIterator(pos);
- if (it == par->inset_iterator_end()) {
+ it = par->insetlist.insetIterator(pos);
+ if (it == par->insetlist.end()) {
par = par->next();
setParagraph();
}
void Buffer::inset_iterator::setParagraph()
{
while (par) {
- it = par->inset_iterator_begin();
- if (it != par->inset_iterator_end())
+ it = par->insetlist.begin();
+ if (it != par->insetlist.end())
return;
par = par->next();
}
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()));
}