listlocked_test.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: The SourceWorks  Tue Sep 7 00:54:57 CEST 2010  listlocked_test.cpp
00003 
00004                         listlocked_test.cpp -  description
00005                            -------------------
00006     begin                : Tue September 07 2010
00007     copyright            : (C) 2010 The SourceWorks
00008     email                : peter@thesourceworks.com
00009 
00010  ***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 
00020 #include "unit.hpp"
00021 
00022 #include <internal/ListLocked.hpp>
00023 #include <boost/bind/protect.hpp>
00024 #include <rtt-detail-fwd.hpp>
00025 using namespace RTT::detail;
00026 
00027 using namespace std;
00028 using namespace RTT;
00029 using namespace boost;
00030 
00031 void foo(double d)
00032 {
00033 }
00034 
00035 
00036 struct ListTest
00037 {
00038     struct Cont :  public boost::intrusive::list_base_hook<> {
00039         double data;
00040     };
00041     typedef boost::intrusive::list<Cont> BufferType;
00042 
00043     BufferType mlist;
00044 
00045     void mfoo(double d)
00046     {}
00047 
00048     double mcfoo(Cont& c)
00049     {
00050         return c.data;
00051     }
00052 
00053     template<class Function>
00054     static void apply_item(Function func, Cont& c)
00055     {
00056         //func( c->data );
00057     }
00058 
00059     template<class Function>
00060     void apply( Function func )
00061     {
00062         //std::for_each (mlist.begin(), mlist.end(), boost::bind( &ListTest::apply_item<Function>, boost::protect(func), _1) );
00063         for (BufferType::iterator it = mlist.begin(); it != mlist.end(); ++it)
00064             func( it->data );
00065     }
00066 };
00067 
00068 void cfoo(ListTest::Cont& c)
00069 {
00070 }
00071 
00072 bool iffoo(double d)
00073 {
00074     return true;
00075 }
00076 
00077 
00078 BOOST_FIXTURE_TEST_SUITE( ListTestSuite, ListTest )
00079 
00080 BOOST_AUTO_TEST_CASE( test_instatiation )
00081 {
00082 
00083     ListLocked<double> lld(10);
00084 
00085     typedef boost::shared_ptr<double*> dsp;
00086 
00087     ListLocked<dsp> lldsp(10);
00088 }
00089 
00090 BOOST_AUTO_TEST_CASE( test_apply )
00091 {
00092 
00093     std::for_each (mlist.begin(), mlist.end(), boost::bind( &ListTestSuite::test_apply::mcfoo, this, _1) );
00094 
00095     //std::for_each (mlist.begin(), mlist.end(), boost::bind( &ListTest::apply_item, this, boost::protect(boost::bind(foo, _1)), _1) );
00096     //std::for_each (mlist.begin(), mlist.end(), boost::bind( boost::mem_fn(&ListTestSuite::test_apply::apply_item<void(double)>), this, boost::bind(foo, _1), _1) );
00097 
00098     Cont c;
00099     //boost::bind( &ListTestSuite::test_apply::apply_item, this, boost::protect( boost::bind(foo,_1)), _1)(c);
00100 
00101     apply( boost::bind(&foo,_1) );
00102 
00103 #if 1
00104     ListLocked<double> lld(10);
00105 
00106     typedef boost::shared_ptr<double*> dsp;
00107 
00108     ListLocked<dsp> lldsp(10);
00109 
00110     lld.apply( boost::bind( foo, _1 ) );
00111 #endif
00112 
00113     lld.clear();
00114 
00115     lldsp.clear();
00116 
00117     lld.find_if(&iffoo);
00118 }
00119 
00120 BOOST_AUTO_TEST_SUITE_END()
00121 


rtt
Author(s): RTT Developers
autogenerated on Sat Jun 8 2019 18:46:12