iLab Neuromorphic Robotics Toolkit  0.1
include/nrt/Probabilistic/Types/details/StateDefinitionHelpers.H
Go to the documentation of this file.
00001 /*! @file
00002     @author Randolph Voorhies (voorhies at usc dot edu)
00003     @copyright GNU Public License (GPL v3)
00004     @section License
00005     @verbatim
00006     // ////////////////////////////////////////////////////////////////////////
00007     //              The iLab Neuromorphic Robotics Toolkit (NRT)             //
00008     // Copyright 2010-2012 by the University of Southern California (USC)    //
00009     //                          and the iLab at USC.                         //
00010     //                                                                       //
00011     //                iLab - University of Southern California               //
00012     //                Hedco Neurociences Building, Room HNB-10               //
00013     //                    Los Angeles, Ca 90089-2520 - USA                   //
00014     //                                                                       //
00015     //      See http://ilab.usc.edu for information about this project.      //
00016     // ////////////////////////////////////////////////////////////////////////
00017     // This file is part of The iLab Neuromorphic Robotics Toolkit.          //
00018     //                                                                       //
00019     // The iLab Neuromorphic Robotics Toolkit is free software: you can      //
00020     // redistribute it and/or modify it under the terms of the GNU General   //
00021     // Public License as published by the Free Software Foundation, either   //
00022     // version 3 of the License, or (at your option) any later version.      //
00023     //                                                                       //
00024     // The iLab Neuromorphic Robotics Toolkit is distributed in the hope     //
00025     // that it will be useful, but WITHOUT ANY WARRANTY; without even the    //
00026     // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR       //
00027     // PURPOSE.  See the GNU General Public License for more details.        //
00028     //                                                                       //
00029     // You should have received a copy of the GNU General Public License     //
00030     // along with The iLab Neuromorphic Robotics Toolkit.  If not, see       //
00031     // <http://www.gnu.org/licenses/>.                                       //
00032     // ////////////////////////////////////////////////////////////////////////
00033     @endverbatim */
00034 
00035 
00036 #ifndef INCLUDE_NRT_PROBABILISTIC_TYPES_DETAILS_STATEDEFINITIONHELPERS_H
00037 #define INCLUDE_NRT_PROBABILISTIC_TYPES_DETAILS_STATEDEFINITIONHELPERS_H
00038 
00039 #define STATE_FIELD_GROUP_STRUCT_NAME(r, data, elem) \
00040   BOOST_PP_CAT(NRT_STATE_FIELD_GROUP_STRUCT_,BOOST_PP_CAT(data,BOOST_PP_CAT(_,elem)))
00041 
00042 #define DEF_STATE_FIELD_GROUP_STRUCT(r, data, elem) \
00043   class STATE_FIELD_GROUP_STRUCT_NAME(r, data, elem) : public nrt::StateFieldBase {};
00044 
00045 #define DEF_STATE_FIELD_GROUP(r, data, elem) \
00046   typedef STATE_FIELD_GROUP_STRUCT_NAME(r, data, elem) elem;
00047 
00048 #define NRT_CREATE_STATE_FIELD_GROUP(StateFieldGroupName, Fields)                 \
00049   BOOST_PP_SEQ_FOR_EACH(DEF_STATE_FIELD_GROUP_STRUCT,StateFieldGroupName, Fields) \
00050   class StateFieldGroupName : public nrt::StateFieldGroupBase {                   \
00051     public:                                                                       \
00052     BOOST_PP_SEQ_FOR_EACH(DEF_STATE_FIELD_GROUP, StateFieldGroupName, Fields)     \
00053     typedef boost::mpl::vector<                                                   \
00054       BOOST_PP_SEQ_ENUM(Fields)                                                   \
00055     > fields;                                                                     \
00056     static size_t const num_fields = boost::mpl::size<fields>::value;             \
00057   }
00058 
00059 namespace nrt
00060 {
00061   template <class ... StateFields> struct ConcatenateFields { };
00062   template <> struct ConcatenateFields<> 
00063   {
00064     typedef boost::mpl::vector<> fields;
00065   };
00066 
00067   template<class Head, class ... Tail>
00068     struct ConcatenateFields<Head, Tail...>
00069     {
00070       typedef Head head;
00071       typedef typename head::fields headfields;
00072       typedef typename ConcatenateFields<Tail...>::fields tailfields;
00073 
00074       typedef 
00075         typename boost::mpl::insert_range
00076         <
00077         headfields,
00078         typename boost::mpl::end<headfields>::type,
00079         tailfields
00080           >::type fields;
00081     };
00082 
00083   template<class ...FieldGroups> struct ConcatenateFieldGroups { };
00084   template <> struct ConcatenateFieldGroups<>
00085   {
00086     typedef boost::mpl::vector<> groups;
00087   };
00088 
00089   template<class Head, class ...Tail>
00090     struct ConcatenateFieldGroups<Head, Tail...>
00091     {
00092       typedef typename ConcatenateFieldGroups<Tail...>::groups tailgroups;
00093       typedef
00094         typename boost::mpl::push_front
00095         <
00096           tailgroups,
00097           Head
00098         >::type groups;
00099     };
00100 
00101   class StateDefinitionBase {};
00102   class StateFieldGroupBase {};
00103   class StateFieldBase {};
00104 
00105   template<class Field>
00106   constexpr bool is_state_field()
00107   {
00108     return std::is_base_of<StateFieldBase, Field>::value;
00109   }
00110 
00111   template<class Field1, class Field2>
00112   constexpr bool are_state_fields()
00113   {
00114     return std::is_base_of<StateFieldBase, Field1>::value && 
00115       std::is_base_of<StateFieldBase, Field2>::value;
00116   }
00117 
00118   template<class Group>
00119   constexpr bool is_state_field_group()
00120   {
00121     return std::is_base_of<StateFieldGroupBase, Group>::value;
00122   };
00123 
00124   template<class Group1, class Group2>
00125   constexpr bool are_state_field_groups()
00126   {
00127     return std::is_base_of<StateFieldGroupBase, Group1>::value &&
00128       std::is_base_of<StateFieldGroupBase, Group2>::value;
00129   };
00130 }
00131 
00132 #endif // INCLUDE_NRT_PROBABILISTIC_TYPES_DETAILS_STATEDEFINITIONHELPERS_H
00133 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines