| [949953] | 1 | /*
 | 
|---|
 | 2 |  * Action_impl_python.hpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: Sep 25, 2011
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | // include config.h
 | 
|---|
 | 9 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 10 | #include <config.h>
 | 
|---|
 | 11 | #endif
 | 
|---|
 | 12 | 
 | 
|---|
 | 13 | #include <boost/preprocessor/cat.hpp>
 | 
|---|
 | 14 | #include <boost/preprocessor/comparison/equal.hpp>
 | 
|---|
 | 15 | #include <boost/preprocessor/control/if.hpp>
 | 
|---|
 | 16 | #include <boost/preprocessor/control/expr_if.hpp>
 | 
|---|
 | 17 | #include <boost/preprocessor/debug/assert.hpp>
 | 
|---|
 | 18 | #include <boost/preprocessor/facilities/expand.hpp>
 | 
|---|
 | 19 | #include <boost/preprocessor/iteration/local.hpp>
 | 
|---|
| [6ba9ba] | 20 | #include <boost/preprocessor/list/adt.hpp>
 | 
|---|
| [949953] | 21 | #include <boost/preprocessor/punctuation/comma_if.hpp>
 | 
|---|
| [6ba9ba] | 22 | #include <boost/preprocessor/punctuation/paren.hpp>
 | 
|---|
| [949953] | 23 | 
 | 
|---|
 | 24 | // some derived names: if CATEGORY is not given, we don't prefix with it
 | 
|---|
 | 25 | #ifdef CATEGORY
 | 
|---|
 | 26 | #define ACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action))
 | 
|---|
 | 27 | #define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME)
 | 
|---|
 | 28 | #define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters))
 | 
|---|
 | 29 | #else
 | 
|---|
 | 30 | #define ACTION BOOST_PP_CAT(ACTIONNAME, Action)
 | 
|---|
 | 31 | #define COMMAND ACTIONNAME
 | 
|---|
 | 32 | #define PARAMS BOOST_PP_CAT(ACTIONNAME, Parameters)
 | 
|---|
 | 33 | #endif
 | 
|---|
 | 34 | 
 | 
|---|
| [6ba9ba] | 35 | // for paramdefaults entries
 | 
|---|
 | 36 | #define PARAM_DEFAULT(x) \
 | 
|---|
 | 37 |     (x, BOOST_PP_NIL)
 | 
|---|
 | 38 | 
 | 
|---|
| [949953] | 39 | // check if no lists given
 | 
|---|
 | 40 | #ifndef paramtokens
 | 
|---|
 | 41 | #define MAXPARAMTYPES 0
 | 
|---|
 | 42 | #else
 | 
|---|
 | 43 | #define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtokens)
 | 
|---|
 | 44 | #endif
 | 
|---|
 | 45 | 
 | 
|---|
 | 46 | // calculate numbers and check whether all have same size
 | 
|---|
 | 47 | #ifdef paramtokens
 | 
|---|
 | 48 | BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramdescriptions)),\
 | 
|---|
 | 49 |   ERROR: There are not the same number of "paramtokens" and "paramdescriptions" in: __FILE__ \
 | 
|---|
 | 50 | )
 | 
|---|
 | 51 | #endif
 | 
|---|
 | 52 | 
 | 
|---|
 | 53 | // print a list of "action separator description linenend, i.e. "Action - descrption\n"
 | 
|---|
 | 54 | #define help_print(z,n,TYPELIST, VARLIST, separator, lineend) \
 | 
|---|
 | 55 |   BOOST_PP_IF(n, +, BOOST_PP_EMPTY()) \
 | 
|---|
 | 56 |   "\t" + std::string( BOOST_PP_SEQ_ELEM(n, TYPELIST) ) + \
 | 
|---|
 | 57 |   std::string( separator ) + \
 | 
|---|
 | 58 |   std::string( BOOST_PP_SEQ_ELEM(n, VARLIST) ) + \
 | 
|---|
 | 59 |   std::string( lineend )
 | 
|---|
 | 60 | 
 | 
|---|
 | 61 | // print a list of comma-separated list, i.e. (,)arg("Action")=default
 | 
|---|
 | 62 | #define stringdefault_print(z,n,STRINGLIST, DEFAULTLIST) \
 | 
|---|
 | 63 |   BOOST_PP_COMMA_IF(n) \
 | 
|---|
 | 64 |   boost::python::arg( \
 | 
|---|
 | 65 |   BOOST_PP_SEQ_ELEM(n, STRINGLIST) \
 | 
|---|
 | 66 |   ) \
 | 
|---|
| [6ba9ba] | 67 |   = \
 | 
|---|
 | 68 |   BOOST_PP_IF( \
 | 
|---|
 | 69 |       BOOST_PP_NOT( BOOST_PP_LIST_IS_NIL( BOOST_PP_SEQ_ELEM(n, paramdefaults) ) ), \
 | 
|---|
 | 70 |       toString BOOST_PP_LPAREN() \
 | 
|---|
 | 71 |           BOOST_PP_LIST_FIRST( BOOST_PP_SEQ_ELEM(n, DEFAULTLIST) ) \
 | 
|---|
 | 72 |       BOOST_PP_RPAREN(), \
 | 
|---|
 | 73 |       std::string("") \
 | 
|---|
 | 74 |   )
 | 
|---|
| [949953] | 75 | 
 | 
|---|
 | 76 | // print a list of comma-separated list, i.e. (,)arg("Action")
 | 
|---|
 | 77 | #define string_print(z,n,STRINGLIST) \
 | 
|---|
 | 78 |   BOOST_PP_COMMA_IF(n) \
 | 
|---|
 | 79 |   boost::python::arg( \
 | 
|---|
 | 80 |   BOOST_PP_SEQ_ELEM(n, STRINGLIST) \
 | 
|---|
 | 81 |   )
 | 
|---|
 | 82 | 
 | 
|---|
 | 83 | // print a list of type ref followed, i.e. "int i, double position"
 | 
|---|
 | 84 | #define type_list(z,n,TYPELIST, VARLIST) \
 | 
|---|
 | 85 |   BOOST_PP_COMMA_IF(n)\
 | 
|---|
 | 86 |   BOOST_PP_SEQ_ELEM(n, TYPELIST) \
 | 
|---|
 | 87 |   BOOST_PP_SEQ_ELEM(n, VARLIST)
 | 
|---|
 | 88 | 
 | 
|---|
 | 89 | // prints set/queryCurrentValue (command) for paramreferences and paramtokens
 | 
|---|
| [5ca6b5] | 90 | #define value_print(z, n, container, prefix) \
 | 
|---|
 | 91 |   prefix \
 | 
|---|
 | 92 |   BOOST_PP_SEQ_ELEM(n, container)\
 | 
|---|
 | 93 |   .set(\
 | 
|---|
 | 94 |   BOOST_PP_SEQ_ELEM(n, container)\
 | 
|---|
| [949953] | 95 |   );
 | 
|---|
 | 96 | 
 | 
|---|
 | 97 | #define stringtype std::string
 | 
|---|
 | 98 | 
 | 
|---|
 | 99 | #define type2string(s, data, elem) \
 | 
|---|
 | 100 |         stringtype
 | 
|---|
 | 101 | 
 | 
|---|
 | 102 | #include "Actions/Action.hpp"
 | 
|---|
 | 103 | #include "Actions/ActionRegistry.hpp"
 | 
|---|
 | 104 | 
 | 
|---|
 | 105 | namespace MoleCuilder {
 | 
|---|
| [6aa485] | 106 | #ifdef returntype
 | 
|---|
 | 107 |   returntype
 | 
|---|
 | 108 | #else
 | 
|---|
 | 109 |   void
 | 
|---|
 | 110 | #endif
 | 
|---|
 | 111 | BOOST_PP_CAT( COMMAND, _stringargs)(
 | 
|---|
| [949953] | 112 | #if defined paramtypes
 | 
|---|
 | 113 | #define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, BOOST_PP_SEQ_TRANSFORM( type2string, , paramtypes), paramreferences)
 | 
|---|
 | 114 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
 | 
|---|
 | 115 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
 | 116 | #endif
 | 
|---|
 | 117 |         );
 | 
|---|
 | 118 | }
 | 
|---|
 | 119 | 
 | 
|---|
 | 120 | void BOOST_PP_CAT(export_, COMMAND)()
 | 
|---|
 | 121 | {
 | 
|---|
 | 122 |   std::string docstring =
 | 
|---|
 | 123 |     std::string( DESCRIPTION ) + "\n\n"
 | 
|---|
 | 124 | #if defined paramtokens && defined paramdescriptions
 | 
|---|
 | 125 | #define BOOST_PP_LOCAL_MACRO(n) help_print(~, n, paramtokens, paramdescriptions, " - ", "\n")
 | 
|---|
 | 126 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
 | 
|---|
 | 127 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
 | 128 | #endif
 | 
|---|
 | 129 |   ;
 | 
|---|
 | 130 |   boost::python::def(
 | 
|---|
 | 131 |     BOOST_PP_STRINGIZE(COMMAND),
 | 
|---|
 | 132 |     MoleCuilder:: BOOST_PP_CAT( COMMAND, _stringargs)
 | 
|---|
 | 133 | #if defined paramtokens // do we have parameters at all?
 | 
|---|
 | 134 |    ,(
 | 
|---|
 | 135 | #if defined paramdefaults
 | 
|---|
 | 136 | #define BOOST_PP_LOCAL_MACRO(n) stringdefault_print(~, n, paramtokens, paramdefaults)
 | 
|---|
 | 137 | #else
 | 
|---|
 | 138 | #define BOOST_PP_LOCAL_MACRO(n) string_print(~, n, paramtokens)
 | 
|---|
 | 139 | #endif
 | 
|---|
 | 140 | #define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
 | 
|---|
 | 141 | #include BOOST_PP_LOCAL_ITERATE()
 | 
|---|
 | 142 |   ), docstring.c_str()
 | 
|---|
| [d628da] | 143 | #else
 | 
|---|
 | 144 |   , DESCRIPTION
 | 
|---|
| [949953] | 145 | #endif
 | 
|---|
 | 146 |   );
 | 
|---|
 | 147 | }
 | 
|---|
 | 148 | 
 | 
|---|
 | 149 | #undef COMMAND
 | 
|---|
 | 150 | #undef ACTION
 | 
|---|
 | 151 | #undef PARAMS
 | 
|---|
 | 152 | #undef MAXPARAMTYPES
 | 
|---|
| [6ba9ba] | 153 | #undef PARAM_DEFAULT
 | 
|---|
| [949953] | 154 | 
 | 
|---|
| [874597] | 155 | #undef help_print
 | 
|---|
| [949953] | 156 | #undef string_print
 | 
|---|
 | 157 | #undef stringdefault_print
 | 
|---|
| [874597] | 158 | #undef type_list
 | 
|---|
 | 159 | #undef value_print
 | 
|---|
 | 160 | 
 | 
|---|
 | 161 | #undef type2string
 | 
|---|
 | 162 | #undef stringtype
 | 
|---|