From 7fcd8a67185fbf965dd51937f9eead19a6aba8b0 Mon Sep 17 00:00:00 2001 From: sbund <sbund@wiback.org> Date: Thu, 13 Jul 2006 11:25:14 +0000 Subject: [PATCH] Added mimbind utility --- Utils/impl/.sconsign | 4 +++ Utils/impl/membind.hh | 63 +++++++++++++++++++++++++++++++++++++ Utils/main.test.cc | 43 ++++++++++++++++++++++++++ Utils/membind.hh | 54 ++++++++++++++++++++++++++++++++ Utils/membind.test.cc | 72 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 236 insertions(+) create mode 100644 Utils/impl/.sconsign create mode 100644 Utils/impl/membind.hh create mode 100644 Utils/main.test.cc create mode 100644 Utils/membind.hh create mode 100644 Utils/membind.test.cc diff --git a/Utils/impl/.sconsign b/Utils/impl/.sconsign new file mode 100644 index 000000000..abd844a6a --- /dev/null +++ b/Utils/impl/.sconsign @@ -0,0 +1,4 @@ +}qU +membind.hhq(cSCons.Node.FS +BuildInfo +qoq}q(U timestampqJL„ìCUcsigqU 7568d4c7a49135b8def1eae0e4f704efqubs. \ No newline at end of file diff --git a/Utils/impl/membind.hh b/Utils/impl/membind.hh new file mode 100644 index 000000000..ef1850023 --- /dev/null +++ b/Utils/impl/membind.hh @@ -0,0 +1,63 @@ +// $Id$ +// +// Copyright (C) 2006 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund <stefan.bund@fokus.fraunhofer.de> +// +// 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; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// NEVER INCLUDE DIRECTLY !! INCLUDE satcom/membind.hh + +#if !BOOST_PP_IS_ITERATING + +#include <boost/preprocessor/cat.hpp> +#include <boost/preprocessor/repetition/enum_shifted.hpp> +#include <boost/preprocessor/iteration/iterate.hpp> + +template <typename R, typename T> +boost::function<R()> membind(R (T::* fn)(),scOBTYPE ob) +{ + return boost::bind(fn,ob); +} + +// for BOOST_PP_ITERATION() in 2..9 do +#define BOOST_PP_ITERATION_PARAMS_1 (4, (2, 9, "Utils/impl/membind.hh", 1)) +#include BOOST_PP_ITERATE() +#elif BOOST_PP_ITERATION_DEPTH()==1 && BOOST_PP_ITERATION_FLAGS()==1 +// {{ + +#define scARG(z,n,d) BOOST_PP_CAT(d,n) +#define scPARAMS(d) BOOST_PP_ENUM_SHIFTED(BOOST_PP_ITERATION(),scARG,d) + +template < typename R, typename T, scPARAMS(typename A) > +boost::function<R ( scPARAMS(A) )> +membind(R (T::* fn)( scPARAMS(A) ), scOBTYPE ob) +{ + return boost::bind(fn, ob, scPARAMS(_) ); +} + +#undef scPARAMS +#undef scARG + +// } +#endif +// done + + +// Local Variables: +// mode: c++ +// End: diff --git a/Utils/main.test.cc b/Utils/main.test.cc new file mode 100644 index 000000000..fd4c97a9b --- /dev/null +++ b/Utils/main.test.cc @@ -0,0 +1,43 @@ +// $Id: main.test.cc 32 2006-03-23 16:24:56Z sbund $ +// +// Copyright (C) 2006 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund <stefan.bund@fokus.fraunhofer.de> +// +// 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; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +// Definition of non-inline non-template functions + +//#include "test.hh" +//#include "test.ih" + +// Custom includes +#define BOOST_AUTO_TEST_MAIN +#include <boost/test/auto_unit_test.hpp> +#include <boost/test/test_tools.hpp> + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// End: diff --git a/Utils/membind.hh b/Utils/membind.hh new file mode 100644 index 000000000..e624e761a --- /dev/null +++ b/Utils/membind.hh @@ -0,0 +1,54 @@ +// $Id$ +// +// Copyright (C) 2006 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund <stefan.bund@fokus.fraunhofer.de> +// +// 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; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef HH_membind_ +#define HH_membind_ 1 + +// Custom includes +#include <boost/bind.hpp> +#include <boost/function.hpp> + +///////////////////////////////hh.p//////////////////////////////////////// + +namespace satcom { +namespace lib { + +#define scOBTYPE T * +#include "Utils/impl/membind.hh" +#undef scOBTYPE + +#define scOBTYPE T & +#include "Utils/impl/membind.hh" +#undef scOBTYPE + +}} + +///////////////////////////////hh.e//////////////////////////////////////// +//#include "membind.cci" +//#include "membind.ct" +//#include "membind.cti" +#endif + + +// Local Variables: +// mode: c++ +// End: diff --git a/Utils/membind.test.cc b/Utils/membind.test.cc new file mode 100644 index 000000000..7c0595494 --- /dev/null +++ b/Utils/membind.test.cc @@ -0,0 +1,72 @@ +// $Id$ +// +// Copyright (C) 2006 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund <stefan.bund@fokus.fraunhofer.de> +// +// 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; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +// Unit tests + +//#include "membind.test.hh" +//#include "membind.test.ih" + +// Custom includes +#include <sstream> +#include <string> +#include "Utils/membind.hh" + +#include <boost/test/auto_unit_test.hpp> +#include <boost/test/test_tools.hpp> + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +namespace { + + struct Test { + char const * meth1() { + return "meth1()"; + } + + std::string meth2(int foo, int bar) { + std::stringstream s; + s << "meth2(" << foo << "," << bar << ")"; + return s.str(); + } + }; + +} + +BOOST_AUTO_UNIT_TEST(membind) +{ + Test instance; + boost::function<char const * ()> f1 (satcom::lib::membind(&Test::meth1,instance)); + boost::function<std::string (int,int)> f2 (satcom::lib::membind(&Test::meth2,instance)); + + BOOST_CHECK_EQUAL( f1(), "meth1()" ); + BOOST_CHECK_EQUAL( f2(1,2), "meth2(1,2)" ); +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// c-file-style: "satcom" +// End: -- GitLab