Skip to content
Snippets Groups Projects
Commit 7fcd8a67 authored by sbund's avatar sbund
Browse files

Added mimbind utility

parent cd2df22d
No related branches found
No related tags found
No related merge requests found
}qU
membind.hhq(cSCons.Node.FS
BuildInfo
qoq}q(U timestampqJLCUcsigqU 7568d4c7a49135b8def1eae0e4f704efqubs.
\ No newline at end of file
// $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:
// $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:
// $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:
// $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:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment