]> git.lyx.org Git - features.git/commitdiff
some further work on the float lists
authorLars Gullik Bjønnes <larsbj@gullik.org>
Mon, 12 Mar 2001 01:43:12 +0000 (01:43 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Mon, 12 Mar 2001 01:43:12 +0000 (01:43 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1734 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
src/ChangeLog
src/ShareContainer.h
src/buffer.C
src/buffer.h
src/frontends/xforms/ChangeLog
src/frontends/xforms/FormToc.C
src/frontends/xforms/FormToc.h
src/frontends/xforms/Menubar_pimpl.C
src/insets/ChangeLog
src/insets/insettoc.C
src/lyx_cb.C
src/lyx_cb.h

index 6e03538ed5ff2ff375ef36b5f47b689bdd1de2f0..5834d2b4754667205c6f41ddbb3e312d61be2e84 100644 (file)
@@ -1,3 +1,18 @@
+2001-03-12  Lars Gullik Bjønnes  <larsbj@trylle.birdstep.com>
+
+       * buffer.h: add some typedefs
+       * buffer.C (getLists): use them
+       (getLists): renamed from getTocList.
+       add a counter for the different float types and use it in the
+       generated string.
+       (getLists): use the same counter for the NEW_INSETS and the "non"
+       NEW_INSETS
+
+       * lyx_cb.h: remove unused items, includes, using etc.
+
+       * ShareContainer.h: remove some commented code, add more comments
+       and "documentation".
+
 2001-03-11  Lars Gullik Bjønnes  <larsbj@trylle.birdstep.com>
 
        * buffer.C (getTocList): make the list also when NEW_INSETS is
index 570f4110724b8e0806db21b4099d1ef3c2b57a1d..b4b5206b5d2fcbb06c2e10ca70658741c6064acf 100644 (file)
@@ -9,7 +9,13 @@
 #include <boost/utility.hpp>
 #include <boost/smart_ptr.hpp>
 
-///
+/// Share objects between several users.
+/**
+   This class can be used to reduce memory consuption when you have a lot
+   of equal objects used all over you code.
+
+   \author Lars Gullik Bjønnes
+*/
 template<class Share>
 class ShareContainer : public noncopyable {
 public:
@@ -17,7 +23,7 @@ public:
        typedef std::vector<boost::shared_ptr<Share> > Params;
        ///
        typedef typename Params::value_type value_type;
-       ///
+       /// Return a shared_ptr that points to a element equal to ps.
        value_type
        get(Share const & ps) const {
                // First see if we already have this ps in the container
@@ -34,18 +40,18 @@ public:
                        // some (one) unique elemements some times
                        // but we should gain a lot in speed.
                        clean();
-                       //std::sort(params.rbegin(), params.rend(), comp());
                } else {
                        // yes we have it already
                        tmp = *it;
-                       // move it forward
+                       // move it forward - optimization
+                       // makes the next find faster.
                        if (it != params.begin())
                                swap(*it, *(it - 1));
                }
                return tmp;
        }
 private:
-       ///
+       /// A functor returning true if the elements are equal.
        struct isEqual {
                isEqual(Share const & s) : p_(s) {}
                bool operator()(value_type const & p1) const {
@@ -54,32 +60,26 @@ private:
        private:
                Share const & p_;
        };
-       ///
-       //struct comp {
-       //      int operator()(value_type const & p1,
-       //                     value_type const & p2) const {
-       //              return p1.use_count() < p2.use_count();
-       //      }
-       //};
-       ///
+       /// A functor returning true if the element is unque.
        struct isUnique {
                bool operator()(value_type const & p) const {
                        return p.unique();
                }
        };
        
-       ///
+       /** Remove all unique items.
+           This removes all elements from params that is only referenced
+           from the private container. This can be considered a memory
+           optimizaton.
+       */
        void clean() const {
-               // Remove all unique items. (i.e. entries that only
-               // exists in the conatainer and does not have a
-               // corresponding paragrah.
                Params::iterator it = std::remove_if(params.begin(),
                                                     params.end(),
                                                     isUnique());
                params.erase(it, params.end());
        }
        
-       ///
+       /// The actual container.
        mutable Params params;
 };
 #endif
index 9a23ab802f9166fe7a866cc761080100b82137f4..7adb42fc791c64d89e24459b135da3a133e6ca2d 100644 (file)
@@ -3599,14 +3599,10 @@ vector<string> const Buffer::getLabelList()
 }
 
 
-map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
+Buffer::Lists const Buffer::getLists() const
 {
-#ifndef NEW_INSETS
-       int figs = 0;
-       int tables = 0;
-       int algs = 0;
-#endif
-       map<string, vector<TocItem> > l;
+       map<string, int> count;
+       Lists l;
        LyXParagraph * par = paragraph;
        while (par) {
 #ifndef NEW_INSETS
@@ -3622,11 +3618,12 @@ map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
                                case LyXParagraph::FIG:
                                case LyXParagraph::WIDE_FIG:
                                {
-                                       tmp.str = tostr(++figs) + ". "
+                                       count["figs"]++;
+                                       tmp.str = tostr(count["figs"]) + ". "
                                                + tmp.str;
-                                       map<string, vector<TocItem> >::iterator it = l.find("LOF");
+                                       Lists::iterator it = l.find("LOF");
                                        if (it == l.end()) {
-                                               vector<TocItem> vti;
+                                               SingleList vti;
                                                vti.push_back(tmp);
                                                l["LOF"] = vti;
                                        } else {
@@ -3638,11 +3635,12 @@ map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
                                case LyXParagraph::TAB:
                                case LyXParagraph::WIDE_TAB:
                                {
-                                       tmp.str = tostr(++tables) + ". "
+                                       count["tables"]++;
+                                       tmp.str = tostr(count["tables"]) + ". "
                                                + tmp.str;
-                                       map<string, vector<TocItem> >::iterator it = l.find("LOT");
+                                       Lists::iterator it = l.find("LOT");
                                        if (it == l.end()) {
-                                               vector<TocItem> vti;
+                                               SingleList vti;
                                                vti.push_back(tmp);
                                                l["LOT"] = vti;
                                        } else {
@@ -3653,11 +3651,12 @@ map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
                                
                                case LyXParagraph::ALGORITHM:
                                {
-                                       tmp.str = tostr(++algs) + ". "
+                                       count["algs"]++;
+                                       tmp.str = tostr(count["algs"]) + ". "
                                                + tmp.str;
-                                       map<string, vector<TocItem> >::iterator it = l.find("LOA");
+                                       Lists::iterator it = l.find("LOA");
                                        if (it == l.end()) {
-                                               vector<TocItem> vti;
+                                               SingleList vti;
                                                vti.push_back(tmp);
                                                l["LOA"] = vti;
                                        } else {
@@ -3686,9 +3685,9 @@ map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
                                                labeltype - 
                                                textclasslist.TextClass(params.textclass).maxcounter());
                                tmp.str =  par->String(this, true);
-                               map<string, vector<TocItem> >::iterator it = l.find("TOC");
+                               Lists::iterator it = l.find("TOC");
                                if (it == l.end()) {
-                                       vector<TocItem> vti;
+                                       SingleList vti;
                                        vti.push_back(tmp);
                                        l["TOC"] = vti;
                                } else {
@@ -3698,6 +3697,7 @@ map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
 #ifdef NEW_INSETS
                        // For each paragrph, traverse its insets and look for
                        // FLOAT_CODE
+                       
                        LyXParagraph::inset_iterator it =
                                par->inset_iterator_begin();
                        LyXParagraph::inset_iterator end =
@@ -3712,21 +3712,22 @@ map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
                                                InsetFloat * il =
                                                        static_cast<InsetFloat*>(*it);
                                                
-                                               //lyxerr << "Found a float!" << endl;
                                                string const type = il->type();
+                                               
                                                // Now find the caption in the float...
                                                // We now tranverse the paragraphs of
                                                // the inset...
                                                LyXParagraph * tmp = il->inset->par;
                                                while (tmp) {
                                                        if (tmp->layout == cap) {
+                                                               count[type]++;
                                                                TocItem ti;
                                                                ti.par = tmp;
                                                                ti.depth = 0;
-                                                               ti.str = tmp->String(this, false);
-                                                               map<string, vector<TocItem> >::iterator it = l.find(type);
+                                                               ti.str = tostr(count[type]) + ". " + tmp->String(this, false);
+                                                               Lists::iterator it = l.find(type);
                                                                if (it == l.end()) {
-                                                                       vector<TocItem> vti;
+                                                                       SingleList vti;
                                                                        vti.push_back(ti);
                                                                        l[type] = vti;
                                                                } else {
@@ -3735,7 +3736,6 @@ map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
                                                        }
                                                        tmp = tmp->next();
                                                }
-                                               
                                        }
                                }
                        } else {
@@ -3755,7 +3755,7 @@ map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
 
 
 // This is also a buffer property (ale)
-vector<pair<string,string> > const Buffer::getBibkeyList()
+vector<pair<string, string> > const Buffer::getBibkeyList()
 {
        /// if this is a child document and the parent is already loaded
        /// Use the parent's list instead  [ale990412]
index 4e1eeee2ea97a0f0251331d984b06a2ea8b72303..3e522952d5d9af4b5d834a2e2826989959254307 100644 (file)
@@ -273,7 +273,11 @@ public:
                string str;
        };
        ///
-       std::map<string, std::vector<TocItem> > const getTocList() const;
+       typedef std::vector<TocItem> SingleList;
+       ///
+       typedef std::map<string, SingleList> Lists;
+       ///
+       Lists const getLists() const;
        ///
        std::vector<string> const getLabelList();
 
index fd7b79f2a923bd29d526c7c6899b1ec05dd1126a..9808217b9f38a5945b3ac3331f58be284f12fc8e 100644 (file)
@@ -1,3 +1,11 @@
+2001-03-12  Lars Gullik Bjønnes  <larsbj@trylle.birdstep.com>
+
+       * FormToc.h: use Buffer::typedef
+
+       * Menubar_pimpl.C (add_toc): use the Buffer::typedefs
+       * FormToc.C (build): ditto
+       (updateToc): ditto
+
 2001-03-11  Lars Gullik Bjønnes  <larsbj@trylle.birdstep.com>
 
        * FormToc.C (build): implement for dynamic number of lists
index baad36d8b74a2e651b061026e4bd146bd399fcde..d4a59fc02331bc7f857d5d8b3910e11a968be458 100644 (file)
@@ -71,11 +71,9 @@ void FormToc::build()
        fl_addto_choice(dialog_->choice_toc_type,
                        _(" TOC | LOF | LOT | LOA "));
 #else
-       map<string, vector<Buffer::TocItem> > tmp =
-               lv_->view()->buffer()->getTocList();
-       string types;
-       map<string, vector<Buffer::TocItem> >::const_iterator cit = tmp.begin();
-       map<string, vector<Buffer::TocItem> >::const_iterator end = tmp.end();
+       Buffer::Lists const tmp = lv_->view()->buffer()->getLists();
+       Buffer::Lists::const_iterator cit = tmp.begin();
+       Buffer::Lists::const_iterator end = tmp.end();
        for (; cit != end; ++cit) {
                fl_addto_choice(dialog_->choice_toc_type, cit->first.c_str());
        }
@@ -174,13 +172,12 @@ void FormToc::updateToc()
                return;
        }
 
-       map<string, vector<Buffer::TocItem> > tmp =
-               lv_->view()->buffer()->getTocList();
-       //int type = fl_get_choice( dialog_->choice_toc_type ) - 1;
-       string type = fl_get_choice_item_text(dialog_->choice_toc_type,
-                                             fl_get_choice(dialog_->choice_toc_type));
+       Buffer::Lists tmp = lv_->view()->buffer()->getLists();
+       string const type =
+               fl_get_choice_item_text(dialog_->choice_toc_type,
+                                       fl_get_choice(dialog_->choice_toc_type));
 
-       map<string, vector<Buffer::TocItem> >::iterator it = tmp.find(type);
+       Buffer::Lists::iterator it = tmp.find(type);
 
        if (it != tmp.end()) {
                // Check if all elements are the same.
@@ -209,8 +206,8 @@ void FormToc::updateToc()
 
        fl_clear_browser(dialog_->browser_toc);
 
-       vector<Buffer::TocItem>::const_iterator cit = toclist.begin();
-       vector<Buffer::TocItem>::const_iterator end = toclist.end();
+       Buffer::SingleList::const_iterator cit = toclist.begin();
+       Buffer::SingleList::const_iterator end = toclist.end();
        
        for (; cit != end; ++cit) {
                string const line = string(4 * cit->depth, ' ') + cit->str;
index 87242c6507b7a611c83969bbc6c2cdad885d3aa1..68f8161a6551bbda46345303491684f00d6e7366 100644 (file)
@@ -50,7 +50,7 @@ private:
        /// Real GUI implementation.
        FD_form_toc * dialog_;
        ///
-       std::vector<Buffer::TocItem> toclist;
+       Buffer::SingleList toclist;
 };
 
 #endif
index 0a86334e27c07609bcf5348834803dd1e33799af..f1a66d1d35ddd237683ccdf70aaa5edf93494f60 100644 (file)
@@ -361,24 +361,21 @@ void Menubar::Pimpl::add_toc(int menu, string const & extra_label,
                 toc_list[0], 0, toc_list[0].size(), 0);
 #else
 #warning Fix Me! (Lgb)
-       map<string, vector<Buffer::TocItem> > toc_list =
-               owner_->buffer()->getTocList();
-
-       map<string, vector<Buffer::TocItem> >::const_iterator cit =
-               toc_list.begin();
-       map<string, vector<Buffer::TocItem> >::const_iterator end =
-               toc_list.end();
+       Buffer::Lists toc_list = owner_->buffer()->getLists();
+       Buffer::Lists::const_iterator cit = toc_list.begin();
+       Buffer::Lists::const_iterator end = toc_list.end();
        for (; cit != end; ++cit) {
                // Handle this elsewhere
                if (cit->first == "TOC") continue;
                
                int menu2 = get_new_submenu(smn, win);
-               vector<Buffer::TocItem>::const_iterator ccit =
-                       cit->second.begin();
-               vector<Buffer::TocItem>::const_iterator eend =
-                       cit->second.end();
+               Buffer::SingleList::const_iterator ccit = cit->second.begin();
+               Buffer::SingleList::const_iterator eend = cit->second.end();
                for (; ccit != eend; ++ccit) {
-                       int const action = lyxaction.getPseudoAction(LFUN_GOTO_PARAGRAPH, tostr(ccit->par->id()));
+                       int const action =
+                               lyxaction
+                               .getPseudoAction(LFUN_GOTO_PARAGRAPH,
+                                                tostr(ccit->par->id()));
                        string label = fixlabel(ccit->str);
                        label = limit_string_length(label);
                        label += "%x" + tostr(action + action_offset);
index 4fcccd7dceee739a67d61aab1221a125eb9ab51e..1523dcfffaa1b682f540ab641d5579e6dae09836 100644 (file)
@@ -1,3 +1,7 @@
+2001-03-12  Lars Gullik Bjønnes  <larsbj@trylle.birdstep.com>
+
+       * insettoc.C (Ascii): use the Buffer typedefs
+
 2001-03-11  Lars Gullik Bjønnes  <larsbj@trylle.birdstep.com>
 
        * insettoc.C (Ascii): implement for dynamic number of lists
index a4dd80b0055c68d977c8d4a52a9c4b02485021fe..633d522076ffd6b8ff4c0807b343f58278eba898 100644 (file)
@@ -84,15 +84,12 @@ int InsetTOC::Ascii(Buffer const * buffer, ostream & os, int) const
        else 
                type = "LOT";
 
-       map<string, vector<Buffer::TocItem> > const toc_list =
-                buffer->getTocList();
-       map<string, vector<Buffer::TocItem> >::const_iterator cit =
+       Buffer::Lists const toc_list = buffer->getLists();
+       Buffer::Lists::const_iterator cit =
                toc_list.find(type);
        if (cit != toc_list.end()) {
-               vector<Buffer::TocItem>::const_iterator ccit =
-                       cit->second.begin();
-               vector<Buffer::TocItem>::const_iterator end =
-                       cit->second.end();
+               Buffer::SingleList::const_iterator ccit = cit->second.begin();
+               Buffer::SingleList::const_iterator end = cit->second.end();
                for (; ccit != end; ++ccit)
                        os << string(4 * ccit->depth, ' ')
                           << ccit->str << endl;
index 48eeb992926cddeabebc11ad45a06585e67ed460..ffd6289c8c58cd8bc560e75a1b9cecc6d11790bc 100644 (file)
@@ -21,9 +21,7 @@
 #include "lyx_cb.h"
 #include "insets/insetlabel.h"
 #include "insets/figinset.h"
-#include "lyxfunc.h"
 #include "minibuffer.h"
-#include "combox.h"
 #include "bufferlist.h"
 #include "frontends/FileDialog.h"
 #include "lyx_gui_misc.h"
 #include "lyxrc.h"
 #include "lyxtext.h"
 
+using std::vector;
 using std::ifstream;
 using std::copy;
-using std::back_inserter;
 using std::endl;
-using std::cout;
-using std::ios;
+using std::back_inserter;
 using std::istream_iterator;
 using std::pair;
 using std::make_pair;
-using std::vector;
-using std::sort;
-using std::equal;
 
 extern BufferList bufferlist;
-extern void show_symbols_form();
 extern FD_form_figure * fd_form_figure;
 
 extern BufferView * current_view; // called too many times in this file...
 
-extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
-
-extern void MenuSendto();
-
 // this should be static, but I need it in buffer.C
 bool quitting; // flag, that we are quitting the program
 extern bool finished; // all cleanup done just let it run through now.
 
-char ascii_type; /* for selection notify callbacks */
-
-bool scrolling = false;
-
 /* 
    This is the inset locking stuff needed for mathed --------------------
 
@@ -179,15 +164,21 @@ bool WriteAs(BufferView * bv, Buffer * buffer, string const & filename)
 
        if (filename.empty()) {
 
-               FileDialog fileDlg(bv->owner(), _("Choose a filename to save document as"),
+               FileDialog fileDlg(bv->owner(),
+                                  _("Choose a filename to save document as"),
                        LFUN_WRITEAS,
-                       make_pair(string(_("Documents")), string(lyxrc.document_path)),
-                       make_pair(string(_("Templates")), string(lyxrc.template_path)));
+                       make_pair(string(_("Documents")),
+                                 string(lyxrc.document_path)),
+                       make_pair(string(_("Templates")),
+                                 string(lyxrc.template_path)));
 
                if (!IsLyXFilename(fname))
                        fname += ".lyx";
 
-               FileDialog::Result result = fileDlg.Select(OnlyPath(fname), _("*.lyx|LyX Documents (*.lyx)"), OnlyFilename(fname));
+               FileDialog::Result result =
+                       fileDlg.Select(OnlyPath(fname),
+                                      _("*.lyx|LyX Documents (*.lyx)"),
+                                      OnlyFilename(fname));
 
                if (result.first == FileDialog::Later)
                        return false;
@@ -204,7 +195,6 @@ bool WriteAs(BufferView * bv, Buffer * buffer, string const & filename)
        } else
                fname = filename;
 
-
        // Same name as we have already?
        if (!buffer->isUnnamed() && fname == oldname) {
                if (!AskQuestion(_("Same name as document already has:"),
@@ -670,13 +660,15 @@ void FigureApplyCB(FL_OBJECT *, long)
 }
 
 
-extern "C" void FigureCancelCB(FL_OBJECT *, long)
+extern "C"
+void FigureCancelCB(FL_OBJECT *, long)
 {
        fl_hide_form(fd_form_figure->form_figure);
 }
 
 
-extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
+extern "C"
+void FigureOKCB(FL_OBJECT * ob, long data)
 {
        FigureApplyCB(ob, data);
        FigureCancelCB(ob, data);
index 619d399e425ffd4ba7a4f63fe5eea3145eccb011..264204fa466a288ad154edec79303bf597ba5edc 100644 (file)
@@ -3,21 +3,13 @@
 #define LYX_CB_H
 
 #include "LString.h"
-#include "lyxfont.h"
 
-class BufferParams;
+class Buffer;
 class BufferView;
-class Combox;
 
 ///
 extern bool quitting;
-///
-extern bool toggleall;
 
-// When still false after reading lyxrc, warn user
-//about failing \bind_file command. RVDK_PATCH_5
-///
-extern bool BindFileSet;
 ///
 void ShowMessage(Buffer const * buf,
                 string const & msg1,
@@ -26,7 +18,8 @@ void ShowMessage(Buffer const * buf,
 ///
 bool MenuWrite(BufferView * bv, Buffer * buffer);
 /// write the given file, or ask if no name given
-bool WriteAs(BufferView * bv, Buffer * buffer, const string & filename = string());
+bool WriteAs(BufferView * bv, Buffer * buffer,
+            string const & filename = string());
 ///
 int MenuRunChktex(Buffer * buffer);
 ///
@@ -40,14 +33,10 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph);
 ///
 void MenuInsertLabel(BufferView * bv, string const & arg);
 ///
-void MenuLayoutCharacter();
-///
 void MenuLayoutSave(BufferView * bv);
 ///
 void Figure();
 ///
 void Reconfigure(BufferView * bv);
-
-       
 #endif