]> git.lyx.org Git - features.git/commitdiff
The func.diff patch. Functors work and some tiny cleanup.
authorLars Gullik Bjønnes <larsbj@gullik.org>
Sat, 31 Jan 2004 15:30:24 +0000 (15:30 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Sat, 31 Jan 2004 15:30:24 +0000 (15:30 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8377 a592a061-630c-0410-9148-cb99ea01b6c8

30 files changed:
po/POTFILES.in
src/ChangeLog
src/MenuBackend.C
src/MenuBackend.h
src/bufferlist.C
src/converter.C
src/converter.h
src/format.C
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlSpellchecker.C
src/frontends/controllers/biblio.C
src/frontends/controllers/frnt_lang.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/RadioButtonGroup.C
src/graphics/ChangeLog
src/graphics/PreviewLoader.C
src/insets/insettabular.C
src/lyxfind.C
src/lyxlex_pimpl.C
src/lyxtextclass.C
src/lyxtextclass.h
src/lyxtextclasslist.C
src/mathed/formulamacro.C
src/mathed/math_hullinset.C
src/support/ChangeLog
src/support/forkedcontr.C
src/support/lstrings.C
src/support/lstrings.h
src/support/lyxalgo.h
src/text.C

index 491c498a97aa0848920f978b2118a09e9b10c76d..c866841735534bf1f783f4a8b8bf0de72197a4cb 100644 (file)
@@ -179,7 +179,7 @@ src/lyxfont.C
 src/lyxfunc.C
 src/lyxrc.C
 src/lyxvc.C
-src/mathed/formulabase.C
+src/mathed/formula.C
 src/mathed/formulamacro.C
 src/mathed/math_hullinset.C
 src/mathed/math_macrotemplate.C
index f28aee93dec6bcfdac8acd816fec85463383f311..dd2164e0f89dd85639974b293ad2a55abd5b6a3f 100644 (file)
@@ -1,4 +1,36 @@
+2004-01-31  Lars Gullik Bjonnes  <larsbj@gullik.net>
 
+       * lyxtextclasslist.C (less_textclass_avail_desc): inherit from
+       std::binary_function 
+
+       * lyxtextclass.C (compare_name): rename to...
+       (LayoutNamesEqual): ...this
+
+       * lyxlex_pimpl.C (compare_tags): inherit from
+       std::binary_function, put back into anon namespace
+
+       * lyxfind.C (MatchString): inherig from std::binary_function
+       (findChange): use empty() istead of !size()
+
+       * format.C (FormatNamesEqual): new functor
+       (getFormat): use it
+       (getNumber): use it
+       (add): use it
+       (erase): use it
+       (setViewer): use it
+
+       * converter.C (compare_Converter): rename to...
+       (ConverterEqual): ...this, and fixup a bit.
+       (getConverter): use it, and make function const
+       (getNumber): use it, and make function const
+       (add): use it
+       (erase): use it: 
+
+       * bufferlist.C: add using boost::bind
+
+       * MenuBackend.C (MenuNamesEqual): new functor
+       (hasMenu): use it, and make function const
+       (hasSubmenu): use nested bind to get rid of compare_memfun.
 
 2004-01-30  André Pönitz  <poenitz@gmx.net>
 
index db9dbddf897b4cfce28d662492cabd3247740d9d..8c03ab0cb1acc9636f1351e23d6dfa27f3a27689 100644 (file)
 #include "frontends/LyXView.h"
 
 #include "support/filetools.h"
-#include "support/lyxfunctional.h"
 #include "support/lstrings.h"
 #include "support/tostr.h"
 
+#include <boost/bind.hpp>
+
 #include <algorithm>
 
 using lyx::support::compare_ascii_no_case;
@@ -51,8 +52,11 @@ using lyx::support::contains;
 using lyx::support::MakeDisplayPath;
 using lyx::support::token;
 
+using boost::bind;
+
 using std::auto_ptr;
 using std::endl;
+using std::equal_to;
 using std::find_if;
 using std::max;
 using std::sort;
@@ -63,6 +67,23 @@ using std::vector;
 extern BufferList bufferlist;
 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
 
+namespace {
+
+class MenuNamesEqual : public std::unary_function<Menu, bool> {
+public:
+       MenuNamesEqual(string const & name)
+               : name_(name) {}
+       bool operator()(Menu const & menu) const
+       {
+               return menu.name() == name_;
+       }
+private:
+       string name_;
+};
+
+} // namespace anon
+
+
 // This is the global menu definition
 MenuBackend menubackend;
 
@@ -539,7 +560,7 @@ void expandCharStyleInsert(Menu & tomenu, LyXView const * view)
                           view);
                return;
        }
-       CharStyles & charstyles = 
+       CharStyles & charstyles =
                view->buffer()->params().getLyXTextClass().charstyles();
        CharStyles::iterator cit = charstyles.begin();
        CharStyles::iterator end = charstyles.end();
@@ -769,9 +790,22 @@ void MenuBackend::expand(Menu const & frommenu, Menu & tomenu,
 
 bool Menu::hasSubmenu(string const & name) const
 {
+#if 1
        return find_if(begin(), end(),
-                      lyx::compare_memfun(&MenuItem::submenuname,
-                                          name)) != end();
+                      bind(std::equal_to<string>(),
+                           bind(&MenuItem::submenuname, _1),
+                           name)) != end();
+#else
+       // I would have prefered this, but I am not sure if it
+       // makes a difference. (Lgb)
+       return find_if(
+               make_transform_iterator(begin(),
+                                       bind(&MenuItem::submenuname, _1)),
+               make_transform_iterator(end(),
+                                       bind(&MenuItem::submenuname, _1)),
+               name
+               ).base() != end();
+#endif
 }
 
 
@@ -840,15 +874,13 @@ void MenuBackend::add(Menu const & menu)
 
 bool MenuBackend::hasMenu(string const & name) const
 {
-       return find_if(begin(), end(),
-                      lyx::compare_memfun(&Menu::name, name)) != end();
+       return find_if(begin(), end(), MenuNamesEqual(name)) != end();
 }
 
 
 Menu const & MenuBackend::getMenu(string const & name) const
 {
-       const_iterator cit = find_if(begin(), end(),
-                                    lyx::compare_memfun(&Menu::name, name));
+       const_iterator cit = find_if(begin(), end(), MenuNamesEqual(name));
        if (cit == end())
                lyxerr << "No submenu named " << name << endl;
        BOOST_ASSERT(cit != end());
@@ -858,10 +890,10 @@ Menu const & MenuBackend::getMenu(string const & name) const
 
 Menu & MenuBackend::getMenu(string const & name)
 {
-       MenuList::iterator it =
-               find_if(menulist_.begin(), menulist_.end(),
-                       lyx::compare_memfun(&Menu::name, name));
-       BOOST_ASSERT(it != menulist_.end());
+       iterator it = find_if(begin(), end(), MenuNamesEqual(name));
+       if (it == end())
+               lyxerr << "No submenu named " << name << endl;
+       BOOST_ASSERT(it != end());
        return (*it);
 }
 
index a8497f8e1cce80e389eebe582dc8af8d7d5c74eb..c704539eb0a600b6d738939f7e802647e33a9b6c 100644 (file)
@@ -55,7 +55,7 @@ public:
                /** This is a list of importable formats
                    typically for the File->Export menu. */
                ImportFormats,
-               /** This is the list of elements available 
+               /** This is the list of elements available
                 * for insertion into document. */
                CharStyles,
                /** This is the list of floats that we can
@@ -186,6 +186,8 @@ public:
        ///
        typedef MenuList::const_iterator const_iterator;
        ///
+       typedef MenuList::iterator iterator;
+       ///
        void read(LyXLex &);
        ///
        void add(Menu const &);
@@ -211,9 +213,17 @@ public:
                return menulist_.begin();
        }
        ///
+       iterator begin() {
+               return menulist_.begin();
+       }
+       ///
        const_iterator end() const {
                return menulist_.end();
        }
+       ///
+       iterator end() {
+               return menulist_.end();
+       }
 private:
        ///
        MenuList menulist_;
index 20a0a72e05fb429c9bfefeb33e60285b4f31a8a0..8c19a3928f1964ee365bb4087dfe25b96af19bd5 100644 (file)
@@ -39,6 +39,8 @@ using lyx::support::OnlyFilename;
 using lyx::support::removeAutosaveFile;
 using lyx::support::prefixIs;
 
+using boost::bind;
+
 using std::auto_ptr;
 using std::endl;
 using std::find;
@@ -235,7 +237,7 @@ void BufferList::updateIncludedTeXfiles(string const & mastertmpdir,
 void BufferList::emergencyWriteAll()
 {
        for_each(bstore.begin(), bstore.end(),
-                boost::bind(&BufferList::emergencyWrite, this, _1));
+                bind(&BufferList::emergencyWrite, this, _1));
 }
 
 
index 1c56579c00222d4af050e41e67d741dcc619625f..32f03719d75cf4e5a1a732e1378267d7ea60c674 100644 (file)
@@ -85,6 +85,19 @@ string const dvipdfm_options(BufferParams const & bp)
        return result;
 }
 
+
+class ConverterEqual : public std::binary_function<string, string, bool> {
+public:
+       ConverterEqual(string const & from, string const & to)
+               : from_(from), to_(to) {}
+       bool operator()(Converter const & c) const {
+               return c.from == from_ && c.to == to_;
+       }
+private:
+       string const from_;
+       string const to_;
+};
+
 } // namespace anon
 
 
@@ -138,26 +151,12 @@ bool operator<(Converter const & a, Converter const & b)
 }
 
 
-class compare_Converter {
-public:
-       compare_Converter(string const & f, string const & t)
-               : from(f), to(t) {}
-       bool operator()(Converter const & c) {
-               return c.from == from && c.to == to;
-       }
-private:
-       string const & from;
-       string const & to;
-};
-
-
-
 Converter const * Converters::getConverter(string const & from,
-                                           string const & to)
+                                           string const & to) const
 {
        ConverterList::const_iterator cit =
                find_if(converterlist_.begin(), converterlist_.end(),
-                       compare_Converter(from, to));
+                       ConverterEqual(from, to));
        if (cit != converterlist_.end())
                return &(*cit);
        else
@@ -165,13 +164,13 @@ Converter const * Converters::getConverter(string const & from,
 }
 
 
-int Converters::getNumber(string const & from, string const & to)
+int Converters::getNumber(string const & from, string const & to) const
 {
        ConverterList::const_iterator cit =
                find_if(converterlist_.begin(), converterlist_.end(),
-                       compare_Converter(from, to));
+                       ConverterEqual(from, to));
        if (cit != converterlist_.end())
-               return cit - converterlist_.begin();
+               return distance(converterlist_.begin(), cit);
        else
                return -1;
 }
@@ -184,7 +183,7 @@ void Converters::add(string const & from, string const & to,
        formats.add(to);
        ConverterList::iterator it = find_if(converterlist_.begin(),
                                             converterlist_.end(),
-                                            compare_Converter(from, to));
+                                            ConverterEqual(from , to));
 
        Converter converter(from, to, command, flags);
        if (it != converterlist_.end() && !flags.empty() && flags[0] == '*') {
@@ -214,7 +213,7 @@ void Converters::erase(string const & from, string const & to)
 {
        ConverterList::iterator it = find_if(converterlist_.begin(),
                                             converterlist_.end(),
-                                            compare_Converter(from, to));
+                                            ConverterEqual(from, to));
        if (it != converterlist_.end())
                converterlist_.erase(it);
 }
index 801b4c3cbf542a2545324cd383974dfe110ee740..6775fb0f1afacc2b2449bff06d50586753ab7b37 100644 (file)
@@ -77,9 +77,10 @@ public:
                return converterlist_[i];
        }
        ///
-       Converter const * getConverter(std::string const & from, std::string const & to);
+       Converter const * getConverter(std::string const & from,
+                                      std::string const & to) const;
        ///
-       int getNumber(std::string const & from, std::string const & to);
+       int getNumber(std::string const & from, std::string const & to) const;
        ///
        void add(std::string const & from, std::string const & to,
                 std::string const & command, std::string const & flags);
index c91ce4c05b129831ae17116c75138c8ac07b440e..e3a0b5a2af1656128070d07c6418e6c183b95d1c 100644 (file)
@@ -23,7 +23,6 @@
 #include "support/filetools.h"
 #include "support/path.h"
 #include "support/systemcall.h"
-#include "support/lyxfunctional.h"
 
 using lyx::support::bformat;
 using lyx::support::compare_ascii_no_case;
@@ -45,6 +44,19 @@ string const token_from("$$i");
 string const token_path("$$p");
 string const token_socket("$$a");
 
+
+class FormatNamesEqual : public std::unary_function<Format, bool> {
+public:
+       FormatNamesEqual(string const & name)
+               : name_(name) {}
+       bool operator()(Format const & f) const
+       {
+               return f.name() == name_;
+       }
+private:
+       string name_;
+};
+
 } //namespace anon
 
 bool operator<(Format const & a, Format const & b)
@@ -57,11 +69,8 @@ bool operator<(Format const & a, Format const & b)
 }
 
 Format::Format(string const & n, string const & e, string const & p,
-       string const & s, string const & v): name_(n),
-                                           extension_(e),
-                                           prettyname_(p),
-                                           shortcut_(s),
-                                           viewer_(v)
+              string const & s, string const & v)
+       : name_(n), extension_(e), prettyname_(p),shortcut_(s), viewer_(v)
 {}
 
 
@@ -91,7 +100,7 @@ Format const * Formats::getFormat(string const & name) const
 {
        FormatList::const_iterator cit =
                find_if(formatlist.begin(), formatlist.end(),
-                       lyx::compare_memfun(&Format::name, name));
+                       FormatNamesEqual(name));
        if (cit != formatlist.end())
                return &(*cit);
        else
@@ -103,9 +112,9 @@ int Formats::getNumber(string const & name) const
 {
        FormatList::const_iterator cit =
                find_if(formatlist.begin(), formatlist.end(),
-                       lyx::compare_memfun(&Format::name, name));
+                       FormatNamesEqual(name));
        if (cit != formatlist.end())
-               return cit - formatlist.begin();
+               return distance(formatlist.begin(), cit);
        else
                return -1;
 }
@@ -123,7 +132,7 @@ void Formats::add(string const & name, string const & extension,
 {
        FormatList::iterator it =
                find_if(formatlist.begin(), formatlist.end(),
-                       lyx::compare_memfun(&Format::name, name));
+                       FormatNamesEqual(name));
        if (it == formatlist.end())
                formatlist.push_back(Format(name, extension, prettyname,
                                            shortcut, ""));
@@ -138,7 +147,7 @@ void Formats::erase(string const & name)
 {
        FormatList::iterator it =
                find_if(formatlist.begin(), formatlist.end(),
-                       lyx::compare_memfun(&Format::name, name));
+                       FormatNamesEqual(name));
        if (it != formatlist.end())
                formatlist.erase(it);
 }
@@ -155,7 +164,7 @@ void Formats::setViewer(string const & name, string const & command)
        add(name);
        FormatList::iterator it =
                find_if(formatlist.begin(), formatlist.end(),
-                       lyx::compare_memfun(&Format::name, name));
+                       FormatNamesEqual(name));
        if (it != formatlist.end())
                it->setViewer(command);
 }
index 9f29b6f72c365e8dfd6ef707dea2a830ce83617a..e15fb3860a7085b0d36368ee5cac750741f017ec 100644 (file)
@@ -1,3 +1,11 @@
+2004-01-31  Lars Gullik Bjonnes  <larsbj@gullik.net>
+
+       * biblio.C (RegexMatch): inherit from std::unary_function, make
+       operator() const and variable regex_ mutable.
+
+       * ControlSpellchecker.C (check): use correct types for the result
+       from distance.
+
 2004-01-28  Lars Gullik Bjonnes  <larsbj@gullik.net>
 
        * ControlSpellchecker.C: add using statements for std::advance and
index f5f6c820454d84383fa8118412ecf6638ca5d49e..9aa770f043e724f4063735607e6182c86c2d4b5a 100644 (file)
@@ -197,8 +197,8 @@ void ControlSpellchecker::check()
        PosIterator const beg = buffer()->pos_iterator_begin();
        PosIterator const end = buffer()->pos_iterator_end();
 
-       int start = distance(beg, cur);
-       int const total = start + distance(cur, end);
+       PosIterator::difference_type start = distance(beg, cur);
+       PosIterator::difference_type const total = start + distance(cur, end);
 
        if (cur != buffer()->pos_iterator_begin())
                for (; cur != end && isLetter(cur); ++cur, ++start);
index caa9be2d321ba3025ebfa11ae7f8c0969aae6a0f..29213a98c3091df7968cff891f4f3a4e9d2c7a17 100644 (file)
@@ -272,14 +272,14 @@ string const escape_special_chars(string const & expr)
 
 // A functor for use with std::find_if, used to ascertain whether a
 // data entry matches the required regex_
-struct RegexMatch
+struct RegexMatch : public std::unary_function<string, bool>
 {
        // re and icase are used to construct an instance of boost::RegEx.
        // if icase is true, then matching is insensitive to case
        RegexMatch(InfoMap const & m, string const & re, bool icase)
                : map_(m), regex_(re, icase) {}
 
-       bool operator()(string const & key) {
+       bool operator()(string const & key) const {
                if (!validRE())
                        return false;
 
@@ -299,7 +299,7 @@ struct RegexMatch
 
 private:
        InfoMap const map_;
-       boost::RegEx regex_;
+       mutable boost::RegEx regex_;
 };
 
 } // namespace anon
index f6273174941cd2a51527c04554f715e111496083..76b9b9225330c840599ffb6cac175dd24bf5958f 100644 (file)
@@ -24,7 +24,10 @@ using std::vector;
 
 namespace {
 
-struct Sorter {
+struct Sorter
+       : public std::binary_function<frnt::LanguagePair,
+                                     frnt::LanguagePair, bool>
+{
        bool operator()(frnt::LanguagePair const & lhs,
                        frnt::LanguagePair const & rhs) const {
                return lhs.first < rhs.first;
index a274c1051c7c1c3daf86792e81fdd2bc1436b1fd..5c19af12b7df03185754dbe8bef9548d79d47a39 100644 (file)
@@ -1,3 +1,8 @@
+2004-01-31  Lars Gullik Bjonnes  <larsbj@gullik.net>
+
+       * RadioButtonGroup.C (is_set_button): inherit from
+       std::unary_function
+
 2004-01-28  Lars Gullik Bjonnes  <larsbj@gullik.net>
 
        * XFormsToolbar.C: add using statement for std::distance
index 7509b78378984e6af58bf8b5697dadd3a503d24a..cdaa0906aae2988ea164862c385cf8535da4af10 100644 (file)
@@ -72,8 +72,8 @@ void RadioButtonGroup::set(FL_OBJECT * ob) const
 }
 
 
-template < typename T >
-struct is_set_button {
+template <typename T>
+struct is_set_button : public std::unary_function<T, bool> {
        bool operator() (T const & item) const
        {
                return fl_get_button((item).first);
index 773d00f63f3f5ab413f5559f069c257b3e0657ad..0a18e061b2c870deddec84f0b420be74cc74f899 100644 (file)
@@ -1,3 +1,9 @@
+2004-01-31  Lars Gullik Bjonnes  <larsbj@gullik.net>
+
+       * PreviewLoader.C (FindFirst): inherit from std::unary_function
+       and make operator() const
+       (FindSnippet): inherit from unary_function, simplify slightly.
+
 2004-01-07  Lars Gullik Bjonnes  <larsbj@gullik.net>
 
        * GraphicsTypes.C: include <string>
index 140537b60c7720e08db74b87a9333f00cea41381..7e2b3ae3db4f2cc56bd82d496575eeefeda2fb4a 100644 (file)
@@ -47,6 +47,8 @@ using std::fill;
 using std::find_if;
 using std::make_pair;
 
+using boost::bind;
+
 using std::ifstream;
 using std::list;
 using std::map;
@@ -75,9 +77,10 @@ Converter const * setConverter();
 void setAscentFractions(vector<double> & ascent_fractions,
                        string const & metrics_file);
 
-struct FindFirst {
+class FindFirst : public std::unary_function<StrPair, bool> {
+public:
        FindFirst(string const & comp) : comp_(comp) {}
-       bool operator()(StrPair const & sp)
+       bool operator()(StrPair const & sp) const
        {
                return sp.first == comp_;
        }
@@ -343,19 +346,19 @@ PreviewLoader::Impl::preview(string const & latex_snippet) const
 
 namespace {
 
-struct FindSnippet {
+class FindSnippet : public std::unary_function<InProgressProcess, bool> {
+public:
        FindSnippet(string const & s) : snippet_(s) {}
-       bool operator()(InProgressProcess const & process)
+       bool operator()(InProgressProcess const & process) const
        {
                BitmapFile const & snippets = process.second.snippets;
-               BitmapFile::const_iterator it  = snippets.begin();
+               BitmapFile::const_iterator beg  = snippets.begin();
                BitmapFile::const_iterator end = snippets.end();
-               it = find_if(it, end, FindFirst(snippet_));
-               return it != end;
+               return find_if(beg, end, FindFirst(snippet_)) != end;
        }
 
 private:
-       string const snippet_;
+       string const snippet_;
 };
 
 } // namespace anon
@@ -491,8 +494,7 @@ void PreviewLoader::Impl::startLoading()
        // Initiate the conversion from LaTeX to bitmap images files.
        support::Forkedcall::SignalTypePtr
                convert_ptr(new support::Forkedcall::SignalType);
-       convert_ptr->connect(
-               boost::bind(&Impl::finishedGenerating, this, _1, _2));
+       convert_ptr->connect(bind(&Impl::finishedGenerating, this, _1, _2));
 
        support::Forkedcall call;
        int ret = call.startscript(command, convert_ptr);
index 81e20817ab457c160daa32d364353328a38bd0db..7007f10949258f0af7b07e1640af25b3213d1669 100644 (file)
@@ -503,8 +503,7 @@ InsetTabular::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
        }
 
        if (!tablemode) {
-
-               int cell = cur.idx();
+               int const cell = cur.idx();
                lyxerr << "# InsetTabular::dispatch: A " << cur << endl;
                result = tabular.getCellInset(cell).dispatch(cur, cmd);
 
index 528ca0b3ccf2a63929176282e6ef41c42d9b583c..d292505e4a6493b023e4891038c475f13ddee4d1 100644 (file)
@@ -210,7 +210,7 @@ bool findNextChange(BufferView * bv)
 
 namespace {
 
-class MatchString
+class MatchString : public std::binary_function<Paragraph, lyx::pos_type, bool>
 {
 public:
        MatchString(string const & str, bool cs, bool mw)
@@ -281,7 +281,7 @@ bool findBackwards(PosIterator & cur, PosIterator const & beg,
 bool findChange(PosIterator & cur, PosIterator const & end)
 {
        for (; cur != end; ++cur) {
-               if ((!cur.pit()->size() || !cur.at_end())
+               if ((cur.pit()->empty() || !cur.at_end())
                    && cur.pit()->lookupChange(cur.pos()) != Change::UNCHANGED)
                        return true;
        }
index e1c061d1a751ca0dd434bc0d3be8a5745d0185cd..ab910d97ba460050e198786c7bf367085038bf6e 100644 (file)
@@ -35,10 +35,10 @@ using std::ios;
 using std::istream;
 using std::ostream;
 
-// namespace {
-struct compare_tags {
+namespace {
+
+struct compare_tags : public std::binary_function<keyword_item, keyword_item, int> {
        // used by lower_bound, sort and sorted
-       inline
        int operator()(keyword_item const & a, keyword_item const & b) const {
                // we use the ascii version, because in turkish, 'i'
                // is not the lowercase version of 'I', and thus
@@ -46,7 +46,8 @@ struct compare_tags {
                return compare_ascii_no_case(a.tag, b.tag) < 0;
        }
 };
-// } // end of anon namespace
+
+} // end of anon namespace
 
 
 LyXLex::Pimpl::Pimpl(keyword_item * tab, int num)
index 14e89546a8710a4adfe40f381bc630ff0011d7f4..34e70f2c7038fc73a3e241689b3478be36509b08 100644 (file)
@@ -36,30 +36,29 @@ using std::string;
 using std::ostream;
 
 
-namespace { // anon
+namespace {
 
-struct compare_name {
-
-       compare_name(string const & name)
+class LayoutNamesEqual : public std::unary_function<LyXLayout_ptr, bool> {
+public:
+       LayoutNamesEqual(string const & name)
                : name_(name)
        {}
-
-       bool operator()(boost::shared_ptr<LyXLayout> const & c)
+       bool operator()(LyXLayout_ptr const & c) const
        {
                return c->name() == name_;
        }
-
+private:
        string name_;
-
 };
 
-} // anon
+} // namespace anon
 
 
 LyXTextClass::LyXTextClass(string const & fn, string const & cln,
                           string const & desc, bool texClassAvail )
        : name_(fn), latexname_(cln), description_(desc),
-         floatlist_(new FloatList), ctrs_(new Counters), texClassAvail_(texClassAvail)
+         floatlist_(new FloatList), ctrs_(new Counters),
+         texClassAvail_(texClassAvail)
 {
        outputType_ = LATEX;
        columns_ = 1;
@@ -551,7 +550,7 @@ void LyXTextClass::readCharStyle(LyXLex & lexrc, string const & name)
        LyXFont font(LyXFont::ALL_INHERIT);
        LyXFont labelfont(LyXFont::ALL_INHERIT);
        string preamble;
-       
+
        bool getout = false;
        while (!getout && lexrc.isOK()) {
                int le = lexrc.lex();
@@ -790,7 +789,7 @@ bool LyXTextClass::hasLayout(string const & n) const
        string const name = (n.empty() ? defaultLayoutName() : n);
 
        return find_if(layoutlist_.begin(), layoutlist_.end(),
-                      compare_name(name))
+                      LayoutNamesEqual(name))
                != layoutlist_.end();
 }
 
@@ -803,7 +802,7 @@ LyXLayout_ptr const & LyXTextClass::operator[](string const & name) const
        LayoutList::const_iterator cit =
                find_if(layoutlist_.begin(),
                        layoutlist_.end(),
-                       compare_name(name));
+                       LayoutNamesEqual(name));
 
        if (cit == layoutlist_.end()) {
                lyxerr << "We failed to find the layout '" << name
@@ -829,7 +828,7 @@ bool LyXTextClass::delete_layout(string const & name)
 
        LayoutList::iterator it =
                remove_if(layoutlist_.begin(), layoutlist_.end(),
-                         compare_name(name));
+                         LayoutNamesEqual(name));
 
        LayoutList::iterator end = layoutlist_.end();
        bool const ret = (it != end);
index fd4eeb986a07cbf0dcfb98358bd5837cd9bbb3c7..5f9ccca6908fb71eb94126feaacc0e33bf431bcf 100644 (file)
@@ -227,7 +227,7 @@ private:
        LayoutList layoutlist_;
        /// CharStyles available to this layout
        mutable CharStyles charstylelist_;
-       
+
        /// available types of float, eg. figure, algorithm.
        boost::shared_ptr<FloatList> floatlist_;
 
index 98339a046a3446cb898384a69ee1de774f4981a4..d5c2a678b82b176f435dcd02fae8a52088cce67d 100644 (file)
@@ -62,16 +62,19 @@ LyXTextClassList::operator[](textclass_type textclass) const
 
 
 // used when sorting the textclass list.
-class less_textclass_avail_desc {
-public:
-       int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
+struct less_textclass_avail_desc
+       : public std::binary_function<LyXTextClass, LyXTextClass, int>
+{
+       int operator()(LyXTextClass const & tc1,
+                      LyXTextClass const & tc2) const
+       {
                // Ordering criteria:
                //   1. Availability of text class
                //   2. Description (lexicographic)
 
                return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
-                      (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() &&
-                       tc1.description() < tc2.description());
+                       (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() &&
+                        tc1.description() < tc2.description());
        }
 };
 
index 9c373ddaeb9d0a05c512b081697c3bb9fa4d7e2b..99f32293789a0beeb6215ce1c3f600f22793e188 100644 (file)
@@ -128,8 +128,8 @@ string InsetFormulaMacro::prefix() const
 void InsetFormulaMacro::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        MathNestInset::metrics(mi);
-       dim = cell(0).dim(); 
-       dim += cell(1).dim(); 
+       dim = cell(0).dim();
+       dim += cell(1).dim();
        dim.asc += 5;
        dim.des += 5;
        dim.wid += 10 + font_metrics::width(prefix(), mi.base.font);
index 10cd59951bededbbe2bf6b70f4c0bbdcfad8f966..65a5075d875070ae236fe2c42fb2ba2063f79ad9 100644 (file)
@@ -38,7 +38,6 @@ using lyx::support::trim;
 
 using std::endl;
 using std::max;
-
 using std::string;
 using std::ostream;
 using std::auto_ptr;
index 5f0eaee7d0084f77276faeed18765d2f6261d00a..8e7e356f77861a9173dab012e35d26e11e6fc18a 100644 (file)
@@ -1,3 +1,11 @@
+2004-01-31  Lars Gullik Bjonnes  <larsbj@gullik.net>
+
+       * lyxalgo.h (eliminate_duplicates): reimplement with sort and the
+       unique-erase idom.
+
+       * lstrings.h (contains_functor): inherit from
+       std::binary_function, remove typedefs. 
+
 2004-01-28  Lars Gullik Bjonnes  <larsbj@gullik.net>
 
        * globbing.C: add using statement for std::distance, remove std::
index 99cc6c7429ba14c3d7d3ffbbdb158d5ef6ff6eb0..3795ec1925950e259d5b79ace5e53409bef17141 100644 (file)
@@ -29,6 +29,8 @@
 #include <sys/wait.h>
 
 
+using boost::bind;
+
 using std::endl;
 using std::find_if;
 using std::string;
@@ -55,7 +57,7 @@ ForkedcallsController::ForkedcallsController()
        timeout_ = new Timeout(100, Timeout::ONETIME);
 
        timeout_->timeout
-               .connect(boost::bind(&ForkedcallsController::timer, this));
+               .connect(bind(&ForkedcallsController::timer, this));
 }
 
 
index 6ca5e68f653a8e469f290055d83f1976744238dd..337b128a2d47a660320b384d9827cfdb418b50da 100644 (file)
@@ -290,10 +290,10 @@ bool prefixIs(string const & a, string const & pre)
        if (prelen > alen || a.empty())
                return false;
        else {
-#if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
-               return ::strncmp(a.c_str(), pre.c_str(), prelen) == 0;
-#else
+#if defined(STD_STRING_IS_GOOD)
                return a.compare(0, prelen, pre) == 0;
+#else
+               return ::strncmp(a.c_str(), pre.c_str(), prelen) == 0;
 #endif
        }
 }
index f70d140b5a8f6336d17a83dcd046072820167de4..7101f24a8802e2a0229e8b9671b0be8c91047b84 100644 (file)
@@ -103,13 +103,12 @@ bool contains(std::string const & a, std::string const & b);
 bool contains(std::string const & a, char b);
 
 /// This should probably we rewritten to be more general.
-class contains_functor {
-public:
-       typedef std::string first_argument_type;
-       typedef std::string second_argument_type;
-       typedef bool result_type;
-
-       bool operator()(std::string const & haystack, std::string const & needle) const {
+struct contains_functor
+       : public std::binary_function<std::string, std::string, bool>
+{
+       bool operator()(std::string const & haystack,
+                       std::string const & needle) const
+       {
                return contains(haystack, needle);
        }
 };
index 87848bb1a5d702fd86853d485765d0026ce62b13..19ed2e857d1846102cc70457b18ca49725a3cf35 100644 (file)
@@ -17,7 +17,6 @@
 #include <utility>
 #include <iterator>
 #include <algorithm>
-#include <set>
 
 
 namespace lyx {
@@ -93,16 +92,10 @@ count (Iterator first, Iterator last, T const & value)
 template<class C>
 void eliminate_duplicates(C & c)
 {
-       C unique_c;
-       std::set<typename C::value_type> s;
-
-       for (typename C::iterator p = c.begin(); p != c.end(); ++p) {
-               if (s.find(*p) == s.end()) {
-                       unique_c.push_back(*p);
-                       s.insert(*p);
-               }
-       }
-       swap(c, unique_c);
+       // It is a requirement that the container is sorted for
+       // std::unique to work properly.
+       std::sort(c.begin(), c.end());
+       c.erase(std::unique(c.begin(), c.end()), c.end());
 }
 
 } // namespace lyx
index db52a26cc5cba857bdc3e6dd653e4a1528a31372..82cd90bb996c8314c5763caddd6c5c1c075b612d 100644 (file)
@@ -1868,7 +1868,7 @@ int LyXText::cursorX(CursorSlice const & cur) const
 {
        ParagraphList::iterator pit = getPar(cur);
        if (pit->rows.empty())
-               return xo_; 
+               return xo_;
        Row const & row         = *pit->getRow(cur.pos());
        pos_type pos            = cur.pos();
        pos_type cursor_vpos    = 0;
@@ -1940,7 +1940,7 @@ int findText(LyXText const * text)
        CursorBase & cur = text->bv()->cursor().cursor_;
        //lyxerr << "findText: text: " << text << " cursor: "
        //      << text->bv()->cursor() << endl;
-       for (int i = cur.size() - 1; i > 0; --i) 
+       for (int i = cur.size() - 1; i > 0; --i)
                if (cur[i].text() == text)
                        return i;
        if (text->bv()->text() == text)