Libbarrett
1.2.4
|
00001 /* 00002 Copyright 2009, 2010 Barrett Technology <support@barrett.com> 00003 00004 This file is part of libbarrett. 00005 00006 This version of libbarrett is free software: you can redistribute it 00007 and/or modify it under the terms of the GNU General Public License as 00008 published by the Free Software Foundation, either version 3 of the 00009 License, or (at your option) any later version. 00010 00011 This version of libbarrett is distributed in the hope that it will be 00012 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License along 00017 with this version of libbarrett. If not, see 00018 <http://www.gnu.org/licenses/>. 00019 00020 Further, non-binding information about licensing is available at: 00021 <http://wiki.barrett.com/libbarrett/wiki/LicenseNotes> 00022 */ 00023 00024 /* 00025 * tuple_splitter-helper.h 00026 * 00027 * Created on: Nov 16, 2009 00028 * Author: dc 00029 */ 00030 00031 00032 #include <boost/static_assert.hpp> 00033 #include <boost/tuple/tuple.hpp> 00034 00035 #include <barrett/systems/abstract/system.h> 00036 00037 00038 namespace barrett { 00039 namespace systems { 00040 00041 00042 template< 00043 typename T0, typename T1, typename T2, typename T3, typename T4, 00044 typename T5, typename T6, typename T7, typename T8, typename T9> 00045 class TupleSplitter; 00046 00047 00048 // doxygen can't handle OutputHolder's recursive inheritance. 00049 #ifndef BARRETT_PARSED_BY_DOXYGEN 00050 namespace detail { 00051 00052 00053 template<size_t N, 00054 typename T0, typename T1, typename T2, typename T3, typename T4, 00055 typename T5, typename T6, typename T7, typename T8, typename T9> 00056 struct OutputHolder : 00057 public OutputHolder<N-1, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> { 00058 00059 typedef OutputHolder<N-1, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> 00060 inherited_type; 00061 typedef TupleSplitter<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> ts_type; 00062 typedef typename ts_type::tuple_type tuple_type; 00063 typedef typename boost::tuples::element<N-1, tuple_type>::type data_type; 00064 00065 explicit OutputHolder(ts_type* parent) : 00066 inherited_type(parent), output(parent, &outputValue) {} 00067 00068 template<size_t Index> 00069 System::Output<typename boost::tuples::element<Index, tuple_type>::type>& 00070 getOutput() { 00071 BOOST_STATIC_ASSERT(Index < N); 00072 return ( static_cast<OutputHolder< //NOLINT: lint doesn't know that these are templates 00073 Index+1, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>*>(this) )->output; 00074 } 00075 00076 void setData(const tuple_type* t) { 00077 inherited_type::setData(t); 00078 outputValue->setData( &(boost::get<N-1>(*t)) ); 00079 } 00080 00081 System::Output<data_type> output; 00082 00083 protected: 00084 typename System::Output<data_type>::Value* outputValue; 00085 }; 00086 00087 template< 00088 typename T0, typename T1, typename T2, typename T3, typename T4, 00089 typename T5, typename T6, typename T7, typename T8, typename T9> 00090 struct OutputHolder<1, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> { 00091 00092 typedef TupleSplitter<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> ts_type; 00093 typedef typename ts_type::tuple_type tuple_type; 00094 typedef T0 data_type; 00095 00096 explicit OutputHolder(ts_type* parent) : 00097 output(parent, &outputValue) {} 00098 00099 template<size_t Index> 00100 System::Output<data_type>& getOutput() { 00101 return output; 00102 } 00103 00104 void setData(const tuple_type* t) { 00105 outputValue->setData( &(boost::get<0>(*t)) ); 00106 } 00107 00108 System::Output<data_type> output; 00109 00110 protected: 00111 typename System::Output<data_type>::Value* outputValue; 00112 }; 00113 00114 00115 00116 } 00117 #endif // BARRETT_PARSED_BY_DOXYGEN 00118 } 00119 }