[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>
|
---|
| 20 | #include <boost/preprocessor/punctuation/comma_if.hpp>
|
---|
| 21 |
|
---|
| 22 | #define NODEFAULT ""
|
---|
| 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 |
|
---|
| 35 | // check if no lists given
|
---|
| 36 | #ifndef paramtokens
|
---|
| 37 | #define MAXPARAMTYPES 0
|
---|
| 38 | #else
|
---|
| 39 | #define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtokens)
|
---|
| 40 | #endif
|
---|
| 41 |
|
---|
| 42 | // calculate numbers and check whether all have same size
|
---|
| 43 | #ifdef paramtokens
|
---|
| 44 | BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramdescriptions)),\
|
---|
| 45 | ERROR: There are not the same number of "paramtokens" and "paramdescriptions" in: __FILE__ \
|
---|
| 46 | )
|
---|
| 47 | #endif
|
---|
| 48 |
|
---|
| 49 | // print a list of "action separator description linenend, i.e. "Action - descrption\n"
|
---|
| 50 | #define help_print(z,n,TYPELIST, VARLIST, separator, lineend) \
|
---|
| 51 | BOOST_PP_IF(n, +, BOOST_PP_EMPTY()) \
|
---|
| 52 | "\t" + std::string( BOOST_PP_SEQ_ELEM(n, TYPELIST) ) + \
|
---|
| 53 | std::string( separator ) + \
|
---|
| 54 | std::string( BOOST_PP_SEQ_ELEM(n, VARLIST) ) + \
|
---|
| 55 | std::string( lineend )
|
---|
| 56 |
|
---|
| 57 | // print a list of comma-separated list, i.e. (,)arg("Action")=default
|
---|
| 58 | #define stringdefault_print(z,n,STRINGLIST, DEFAULTLIST) \
|
---|
| 59 | BOOST_PP_COMMA_IF(n) \
|
---|
| 60 | boost::python::arg( \
|
---|
| 61 | BOOST_PP_SEQ_ELEM(n, STRINGLIST) \
|
---|
| 62 | ) \
|
---|
| 63 | = BOOST_PP_SEQ_ELEM(n, DEFAULTLIST)
|
---|
| 64 |
|
---|
| 65 | // print a list of comma-separated list, i.e. (,)arg("Action")
|
---|
| 66 | #define string_print(z,n,STRINGLIST) \
|
---|
| 67 | BOOST_PP_COMMA_IF(n) \
|
---|
| 68 | boost::python::arg( \
|
---|
| 69 | BOOST_PP_SEQ_ELEM(n, STRINGLIST) \
|
---|
| 70 | )
|
---|
| 71 |
|
---|
| 72 | // print a list of type ref followed, i.e. "int i, double position"
|
---|
| 73 | #define type_list(z,n,TYPELIST, VARLIST) \
|
---|
| 74 | BOOST_PP_COMMA_IF(n)\
|
---|
| 75 | BOOST_PP_SEQ_ELEM(n, TYPELIST) \
|
---|
| 76 | BOOST_PP_SEQ_ELEM(n, VARLIST)
|
---|
| 77 |
|
---|
| 78 | // prints set/queryCurrentValue (command) for paramreferences and paramtokens
|
---|
| 79 | #define value_print(z,n,command, prefix) \
|
---|
| 80 | ValueStorage::getInstance(). command (\
|
---|
| 81 | BOOST_PP_SEQ_ELEM(n, paramtokens)\
|
---|
| 82 | , \
|
---|
| 83 | prefix\
|
---|
| 84 | BOOST_PP_SEQ_ELEM(n, paramreferences)\
|
---|
| 85 | );
|
---|
| 86 |
|
---|
| 87 | #define stringtype std::string
|
---|
| 88 |
|
---|
| 89 | #define type2string(s, data, elem) \
|
---|
| 90 | stringtype
|
---|
| 91 |
|
---|
| 92 | #include "Actions/Action.hpp"
|
---|
| 93 | #include "Actions/ActionRegistry.hpp"
|
---|
| 94 | #include "Actions/ValueStorage.hpp"
|
---|
| 95 |
|
---|
| 96 | namespace MoleCuilder {
|
---|
[6aa485] | 97 | #ifdef returntype
|
---|
| 98 | returntype
|
---|
| 99 | #else
|
---|
| 100 | void
|
---|
| 101 | #endif
|
---|
| 102 | BOOST_PP_CAT( COMMAND, _stringargs)(
|
---|
[949953] | 103 | #if defined paramtypes
|
---|
| 104 | #define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, BOOST_PP_SEQ_TRANSFORM( type2string, , paramtypes), paramreferences)
|
---|
| 105 | #define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
|
---|
| 106 | #include BOOST_PP_LOCAL_ITERATE()
|
---|
| 107 | #endif
|
---|
| 108 | );
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | void BOOST_PP_CAT(export_, COMMAND)()
|
---|
| 112 | {
|
---|
| 113 | std::string docstring =
|
---|
| 114 | std::string( DESCRIPTION ) + "\n\n"
|
---|
| 115 | #if defined paramtokens && defined paramdescriptions
|
---|
| 116 | #define BOOST_PP_LOCAL_MACRO(n) help_print(~, n, paramtokens, paramdescriptions, " - ", "\n")
|
---|
| 117 | #define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
|
---|
| 118 | #include BOOST_PP_LOCAL_ITERATE()
|
---|
| 119 | #endif
|
---|
| 120 | ;
|
---|
| 121 | boost::python::def(
|
---|
| 122 | BOOST_PP_STRINGIZE(COMMAND),
|
---|
| 123 | MoleCuilder:: BOOST_PP_CAT( COMMAND, _stringargs)
|
---|
| 124 | #if defined paramtokens // do we have parameters at all?
|
---|
| 125 | ,(
|
---|
| 126 | #if defined paramdefaults
|
---|
| 127 | #define BOOST_PP_LOCAL_MACRO(n) stringdefault_print(~, n, paramtokens, paramdefaults)
|
---|
| 128 | #else
|
---|
| 129 | #define BOOST_PP_LOCAL_MACRO(n) string_print(~, n, paramtokens)
|
---|
| 130 | #endif
|
---|
| 131 | #define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
|
---|
| 132 | #include BOOST_PP_LOCAL_ITERATE()
|
---|
| 133 | ), docstring.c_str()
|
---|
[d628da] | 134 | #else
|
---|
| 135 | , DESCRIPTION
|
---|
[949953] | 136 | #endif
|
---|
| 137 | );
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | #undef COMMAND
|
---|
| 141 | #undef ACTION
|
---|
| 142 | #undef PARAMS
|
---|
| 143 | #undef MAXPARAMTYPES
|
---|
| 144 |
|
---|
[874597] | 145 | #undef help_print
|
---|
[949953] | 146 | #undef string_print
|
---|
| 147 | #undef stringdefault_print
|
---|
[874597] | 148 | #undef type_list
|
---|
| 149 | #undef value_print
|
---|
| 150 |
|
---|
| 151 | #undef type2string
|
---|
| 152 | #undef stringtype
|
---|