The func.diff patch. Functors work and some tiny cleanup.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8377 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2004-01-31 15:30:24 +00:00
parent 99aacdad5c
commit 3420904448
30 changed files with 235 additions and 123 deletions

View 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

View 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>

View File

@ -40,10 +40,11 @@
#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;
@ -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,
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);
}

View File

@ -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_;

View 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));
}

View 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);
}

View 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);

View 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);
}

View 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

View 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);

View 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

View 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;

View 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

View 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);

View 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>

View 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);

View 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);

View 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;
}

View 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)

View 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;
@ -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);

View File

@ -62,9 +62,12 @@ 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)

View 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;

View 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::

View 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));
}

View 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
}
}

View 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);
}
};

View 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