From 4b1212acf2da860c58f1d579f74fae86e7e45a47 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Mon, 5 Jan 2004 17:33:57 +0000 Subject: [PATCH] Some more functor work. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8303 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BranchList.C | 16 ---------------- src/BranchList.h | 13 +++++++++++++ src/ChangeLog | 3 +++ src/insets/ChangeLog | 8 ++++++++ src/insets/Makefile.am | 2 +- src/insets/insetbranch.C | 21 ++++----------------- src/insets/insettabular.C | 30 ++++++++++++++---------------- 7 files changed, 43 insertions(+), 50 deletions(-) diff --git a/src/BranchList.C b/src/BranchList.C index dc09595841..1900d956c3 100644 --- a/src/BranchList.C +++ b/src/BranchList.C @@ -14,22 +14,6 @@ using std::string; -namespace { - -class BranchNamesEqual : public std::unary_function { -public: - BranchNamesEqual(string const & name) - : name_(name) {} - bool operator()(Branch const & branch) const - { - return branch.getBranch() == name_; - } -private: - string name_; -}; - -} // namespace anon - string const & Branch::getBranch() const { diff --git a/src/BranchList.h b/src/BranchList.h index 893d8f9b63..fc57d2478b 100644 --- a/src/BranchList.h +++ b/src/BranchList.h @@ -98,4 +98,17 @@ private: std::string separator_; }; + +class BranchNamesEqual : public std::unary_function { +public: + BranchNamesEqual(std::string const & name) + : name_(name) {} + bool operator()(Branch const & branch) const + { + return branch.getBranch() == name_; + } +private: + std::string name_; +}; + #endif diff --git a/src/ChangeLog b/src/ChangeLog index adb10d34f5..ecd51ccce0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,8 @@ 2004-01-05 Lars Gullik Bjonnes + * BranchList.h: move the BranchNamesEqual functor here from... + * BranchList.C: ... to here + * BranchList.C: new BranchListEqual fuctor, use it. Remove SameName and match. (add): replace a finding loop with std::find_if. diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index d8462e6c5e..9e265a198f 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,11 @@ +2004-01-05 Lars Gullik Bjonnes + + * insetbranch.C (isBranchSelected): use the BranchNamesEqual + functor + get rid of the SameName functor + + * insettabular.C: improve the functor. + 2003-12-29 Angus Leeming * insetexternal.C (setParams): update defaultTemplateName. diff --git a/src/insets/Makefile.am b/src/insets/Makefile.am index 676894d5b6..b4bcf07011 100644 --- a/src/insets/Makefile.am +++ b/src/insets/Makefile.am @@ -117,4 +117,4 @@ libinsets_la_SOURCES = \ # insetsection.h \ # insetsection.C \ # insettheorem.C \ -# insettheorem.h \ +# insettheorem.h diff --git a/src/insets/insetbranch.C b/src/insets/insetbranch.C index a2e67e0e3c..67ecbc6e0b 100644 --- a/src/insets/insetbranch.C +++ b/src/insets/insetbranch.C @@ -25,7 +25,6 @@ #include "support/std_sstream.h" - using std::string; using std::auto_ptr; using std::istringstream; @@ -140,31 +139,19 @@ InsetBranch::priv_dispatch(FuncRequest const & cmd, return DispatchResult(true); } return InsetCollapsable::priv_dispatch(cmd, idx, pos); - + default: return InsetCollapsable::priv_dispatch(cmd, idx, pos); } } -namespace { - -struct SameBranch { - SameBranch(string const & branch_name) : bn(branch_name) {} - bool operator()(Branch const & branch) const - { return bn == branch.getBranch(); } -private: - string bn; -}; - -} // namespace anon - - bool InsetBranch::isBranchSelected(BranchList const & branchlist) const { - BranchList::const_iterator it = branchlist.begin(); BranchList::const_iterator const end = branchlist.end(); - it = std::find_if(it, end, SameBranch(params_.branch)); + BranchList::const_iterator it = + std::find_if(branchlist.begin(), end, + BranchNamesEqual(params_.branch)); if (it == end) return false; return it->getSelected(); diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index e54fcf8c8b..360763d7cc 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -38,6 +38,7 @@ #include "frontends/Painter.h" #include "support/std_sstream.h" + #include using lyx::graphics::PreviewLoader; @@ -120,18 +121,15 @@ TabularFeature tabularFeature[] = { LyXTabular::LAST_ACTION, "" } }; -struct FindFeature { - /// - FindFeature(LyXTabular::Feature feature) - : feature_(feature) - {} - /// - bool operator()(TabularFeature & tf) - { + +class FeatureEqual : public std::unary_function { +public: + FeatureEqual(LyXTabular::Feature feature) + : feature_(feature) {} + bool operator()(TabularFeature const & tf) const { return tf.action == feature_; } private: - /// LyXTabular::Feature feature_; }; @@ -140,10 +138,10 @@ private: string const featureAsString(LyXTabular::Feature feature) { - TabularFeature * it = tabularFeature; - TabularFeature * end = it + + TabularFeature * end = tabularFeature + sizeof(tabularFeature) / sizeof(TabularFeature); - it = std::find_if(it, end, FindFeature(feature)); + TabularFeature * it = std::find_if(tabularFeature, end, + FeatureEqual(feature)); return (it == end) ? string() : it->feature; } @@ -282,7 +280,7 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const continue; if (first_visible_cell < 0) first_visible_cell = cell; - if (hasSelection()) + if (hasSelection()) drawCellSelection(pi.pain, nx, y, i, j, cell); int const cx = nx + tabular.getBeginningOfTextInCell(cell); @@ -507,16 +505,16 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, case LFUN_MOUSE_RELEASE: lfunMouseRelease(cmd); return DispatchResult(true, true); - + default: break; } int cell = bv->cursor().data_.back().idx_; if (cell != -1) { - + if (cell != actcell) { - lyxerr << "## ERROR ## InsetTabular::priv_dispatch: actcell: " + lyxerr << "## ERROR ## InsetTabular::priv_dispatch: actcell: " << actcell << " and cell " << cell << " should be the same " << "here" << endl; } -- 2.39.2