Libbarrett  1.2.4
include/barrett/systems/detail/tuple_grouper-helper.h
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_grouper-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 TupleGrouper;
00046 
00047 
00048 // doxygen can't handle InputHolder'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 InputHolder :
00057                 public InputHolder<N-1, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> {
00058 
00059         typedef InputHolder<N-1, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>
00060                         inherited_type;
00061         typedef TupleGrouper<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> tg_type;
00062         typedef typename tg_type::tuple_type tuple_type;
00063 
00064         explicit InputHolder(tg_type* parent) :
00065                 inherited_type(parent), input(parent) {}
00066 
00067         template<size_t Index>
00068         System::Input<typename boost::tuples::element<Index, tuple_type>::type>&
00069         getInput() {
00070                 BOOST_STATIC_ASSERT(Index < N);
00071                 return ( static_cast<InputHolder<  //NOLINT: lint doesn't know that these are templates
00072                         Index+1, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>*>(this) )->input;
00073         }
00074 
00075         bool valuesDefined() const {
00076                 return input.valueDefined()  &&  inherited_type::valuesDefined();
00077         }
00078 
00079         const tuple_type& getValues() {
00080                 collectValues();
00081                 return this->values;
00082         }
00083 
00084         System::Input<typename boost::tuples::element<N-1, tuple_type>::type> input;
00085 
00086 protected:
00087         void collectValues() {
00088                 inherited_type::collectValues();
00089                 boost::tuples::get<N-1>(this->values) = input.getValue();
00090         }
00091 };
00092 
00093 template<
00094         typename T0, typename T1, typename T2, typename T3, typename T4,
00095         typename T5, typename T6, typename T7, typename T8, typename T9>
00096 struct InputHolder<1, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> {
00097 
00098         typedef TupleGrouper<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> tg_type;
00099         typedef typename tg_type::tuple_type tuple_type;
00100 
00101         explicit InputHolder(tg_type* parent) :
00102                 input(parent), values() {}
00103 
00104         template<size_t InputIndex>
00105         System::Input<typename boost::tuples::element<InputIndex, tuple_type>::type >& getInput() {  //NOLINT: line length is for clarity
00106                 return input;
00107         }
00108 
00109         bool valuesDefined() const {
00110                 return input.valueDefined();
00111         }
00112 
00113         const tuple_type& getValues() {
00114                 collectValues();
00115                 return values;
00116         }
00117 
00118         System::Input<typename boost::tuples::element<0, tuple_type>::type> input;
00119         tuple_type values;
00120 
00121 protected:
00122         void collectValues() {
00123                 boost::tuples::get<0>(values) = input.getValue();
00124         }
00125 };
00126 
00127 
00128 
00129 }
00130 #endif // BARRETT_PARSED_BY_DOXYGEN
00131 }
00132 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines