[Aptitude-svn-commit] r3539 - in branches/aptitude-0.3/aptitude: . src/generic

Daniel Burrows dburrows@costa.debian.org
Sat, 02 Jul 2005 14:28:53 +0000


Author: dburrows
Date: Sat Jul  2 14:28:51 2005
New Revision: 3539

Added:
   branches/aptitude-0.3/aptitude/src/generic/mut_fun.h
Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/Makefile.am
Log:
Add a mutator functor.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Sat Jul  2 14:28:51 2005
@@ -1,5 +1,10 @@
 2005-07-02  Daniel Burrows  <dburrows@debian.org>
 
+	* src/generic/Makefile.am, src/generic/mut_fun.h:
+
+	  Add a functor class that assigns its argument to a fixed
+	  variable.
+
 	* src/download_screen.cc, src/download_screen.h:
 
 	  Update the download-screen class for wide characters.

Modified: branches/aptitude-0.3/aptitude/src/generic/Makefile.am
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/Makefile.am	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/Makefile.am	Sat Jul  2 14:28:51 2005
@@ -31,6 +31,7 @@
 	infer_reason.cc \
 	matchers.h	\
 	matchers.cc	\
+	mut_fun.h	\
 	pkg_acqfile.h	\
 	pkg_acqfile.cc	\
 	pkg_changelog.h	\

Added: branches/aptitude-0.3/aptitude/src/generic/mut_fun.h
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/generic/mut_fun.h	Sat Jul  2 14:28:51 2005
@@ -0,0 +1,42 @@
+// mut_fun.h                                    -*-c++-*-
+//
+//   Copyright (C) 2005 Daniel Burrows
+//
+//   This program is free software; you can redistribute it and/or
+//   modify it under the terms of the GNU General Public License as
+//   published by the Free Software Foundation; either version 2 of
+//   the License, or (at your option) any later version.
+//
+//   This program is distributed in the hope that it will be useful,
+//   but WITHOUT ANY WARRANTY; without even the implied warranty of
+//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//   General Public License for more details.
+//
+//   You should have received a copy of the GNU General Public License
+//   along with this program; see the file COPYING.  If not, write to
+//   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+//   Boston, MA 02111-1307, USA.
+
+#ifndef MUT_FUN_H
+#define MUT_FUN_H
+
+/** A functor that assigns a value to a variable when it is
+ *  triggered.
+ */
+template<class T>
+class _mut_fun_slot
+{
+  T& target;
+public:
+  _mut_fun_slot(T& _target):target(_target) {}
+
+  void operator()(const T& source) const {target=source;}
+};
+
+template<class T>
+inline _mut_fun_slot<T> mut_fun(T& target)
+{
+  return _mut_fun_slot<T>(target);
+}
+
+#endif // MUT_FUN_H