]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
remove unused code
[lyx.git] / src / buffer.C
index 73616d31c1cb69074a6d3de5f5df94b86409b5eb..d45fb87f960450fecc75ddcd2b32b5000a282a75 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "buffer.h"
 #include "bufferlist.h"
+#include "counters.h"
 #include "LyXAction.h"
 #include "lyxrc.h"
 #include "lyxlex.h"
@@ -94,6 +95,9 @@
 #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
@@ -132,6 +134,7 @@ using std::max;
 using std::set;
 using std::stack;
 using std::list;
+using std::for_each;
 
 using lyx::pos_type;
 using lyx::textclass_type;
@@ -148,7 +151,7 @@ const int LYX_FORMAT = 220;
 Buffer::Buffer(string const & file, bool ronly)
        : 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;
@@ -240,7 +243,7 @@ void Buffer::setReadonly(bool flag)
        if (read_only != flag) {
                read_only = flag;
                updateTitles();
-               users->owner()->getDialogs()->updateBufferDependent(false);
+               users->owner()->getDialogs().updateBufferDependent(false);
        }
 }
 
@@ -2115,10 +2118,11 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
 
 void Buffer::writeFileAscii(ostream & ofs, int linelen)
 {
-       Paragraph * par = &*(paragraphs.begin());
-       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";
 }
@@ -3620,25 +3624,14 @@ int Buffer::runChktex()
 
 void Buffer::validate(LaTeXFeatures & features) const
 {
-       Paragraph * par = &*(paragraphs.begin());
        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
@@ -3691,20 +3684,20 @@ string const Buffer::getIncludeonlyList(char delim)
 }
 
 
-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());
        }
@@ -3725,17 +3718,17 @@ vector<pair<string, string> > const Buffer::getBibkeyList() const
        }
 
        vector<StringPair> keys;
-       Paragraph * par = &*(paragraphs.begin());
-       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
@@ -3825,10 +3818,8 @@ bool Buffer::dispatch(int action, string const & argument, bool * result)
 void Buffer::resizeInsets(BufferView * bv)
 {
        /// then remove all LyXText in text-insets
-       Paragraph * par = &*(paragraphs.begin());
-       for (; par; par = par->next()) {
-           par->resizeInsetsLyXText(bv);
-       }
+       for_each(paragraphs.begin(), paragraphs.end(),
+                boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
 }
 
 
@@ -3860,6 +3851,12 @@ bool Buffer::isMultiLingual()
 }
 
 
+Counters & Buffer::counters() const
+{
+       return *ctrs.get();
+}
+
+
 Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
        : par(paragraph)
 {
@@ -3901,17 +3898,19 @@ Inset * Buffer::getInsetFromID(int id_arg) const
 
 Paragraph * Buffer::getParFromID(int id) const
 {
-       if (id < 0) return 0;
-       Paragraph * par = &*(paragraphs.begin());
-       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;
 }