aboutsummaryrefslogtreecommitdiff
path: root/libcmix-common/cmixprotofunctor.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'libcmix-common/cmixprotofunctor.hpp')
-rw-r--r--libcmix-common/cmixprotofunctor.hpp81
1 files changed, 30 insertions, 51 deletions
diff --git a/libcmix-common/cmixprotofunctor.hpp b/libcmix-common/cmixprotofunctor.hpp
index 755894e..effa8bd 100644
--- a/libcmix-common/cmixprotofunctor.hpp
+++ b/libcmix-common/cmixprotofunctor.hpp
@@ -2,6 +2,14 @@
#include "cmix.pb.h"
+#include <boost/preprocessor/repeat.hpp>
+#include <boost/preprocessor/seq/elem.hpp>
+#include <boost/preprocessor/variadic/to_seq.hpp>
+#include <boost/preprocessor/variadic/size.hpp>
+#include <boost/preprocessor/arithmetic/mul.hpp>
+#include <boost/preprocessor/arithmetic/add.hpp>
+#include <boost/preprocessor/arithmetic/div.hpp>
+
/*!
* \file
*/
@@ -25,59 +33,30 @@ struct CMixProtoFunctor {
#define MESSAGE_SETTER_DEF(TYPE, NAME) \
proto_type operator()(cmix_proto::TYPE const& v) { \
proto_type m; \
- *m.mutable_##NAME() = v; \
+ BOOST_PP_CAT(*m.mutable_, NAME)() = v; \
return m; \
} \
-
- /*!
- * #MESSAGE_SETTER_DEF(Initialization, initialization)
- */
- MESSAGE_SETTER_DEF(Initialization, initialization)
-
- /*!
- * #MESSAGE_SETTER_DEF(ImANode, imanode)
- */
- MESSAGE_SETTER_DEF(ImANode, imanode)
-
- /*!
- * #MESSAGE_SETTER_DEF(ImAClient, imaclient)
- */
- MESSAGE_SETTER_DEF(ImAClient, imaclient)
-
- /*!
- * #MESSAGE_SETTER_DEF(Bye, bye)
- */
- MESSAGE_SETTER_DEF(Bye, bye)
-
- /*!
- * #MESSAGE_SETTER_DEF(KeyExchange, keyexchange)
- */
- MESSAGE_SETTER_DEF(KeyExchange, keyexchange)
- /*!
- * #MESSAGE_SETTER_DEF(SecretKey, secretkey)
- */
- MESSAGE_SETTER_DEF(SecretKey, secretkey)
-
- /*!
- * #MESSAGE_SETTER_DEF(NodeReady, nodeready)
- */
- MESSAGE_SETTER_DEF(NodeReady, nodeready)
-
- /*!
- * #MESSAGE_SETTER_DEF(PrePre, prepre)
- */
- MESSAGE_SETTER_DEF(PrePre, prepre)
-
- /*!
- * #MESSAGE_SETTER_DEF(PreMix, premix)
- */
- MESSAGE_SETTER_DEF(PreMix, premix)
-
- /*!
- * #MESSAGE_SETTER_DEF(PrePost, prepost)
- */
- MESSAGE_SETTER_DEF(PrePost, prepost)
-
+ #define MESSAGE_SETTER_DEF_ITERATION(Z, N, DATA) \
+ MESSAGE_SETTER_DEF(BOOST_PP_SEQ_ELEM(BOOST_PP_MUL(N, 2), DATA), BOOST_PP_SEQ_ELEM(BOOST_PP_ADD(BOOST_PP_MUL(N, 2), 1), DATA))
+
+ #define MESSAGE_SETTER_DEFS(...) \
+ BOOST_PP_REPEAT(BOOST_PP_DIV(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), 2), MESSAGE_SETTER_DEF_ITERATION, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__))
+
+ MESSAGE_SETTER_DEFS(
+ Initialization, initialization,
+ ImANode, imanode,
+ ImAClient, imaclient,
+ Bye, bye,
+ KeyExchange, keyexchange,
+ SecretKey, secretkey,
+ NodeReady, nodeready,
+ UserMessage, usermessage,
+ PrePre, prepre,
+ PreMix, premix,
+ PrePost, prepost
+ )
+ #undef MESSAGE_SETTER_DEFS
+ #undef MESSAGE_SETTER_DEF_ITERATION
#undef MESSAGE_SETTER_DEF
};