diff options
author | George Kiagiadakis <george.kiagiadakis@collabora.co.uk> | 2011-01-21 16:17:20 +0200 |
---|---|---|
committer | George Kiagiadakis <george.kiagiadakis@collabora.co.uk> | 2011-01-21 16:17:20 +0200 |
commit | fd62e23f6ffcd7cf3e13d71ca3c301f45d3aa567 (patch) | |
tree | 20eda7840904a08cfe4ed783d760a4915319f41d | |
parent | 713af1465298803b4a37950b66380e90e5b89813 (diff) |
Add variadic Bin::add implementation.
-rw-r--r-- | src/QGst/bin.h | 46 | ||||
-rw-r--r-- | tests/compilation/CompilationTests.cmake | 35 |
2 files changed, 81 insertions, 0 deletions
diff --git a/src/QGst/bin.h b/src/QGst/bin.h index f65631b..9fa6c4e 100644 --- a/src/QGst/bin.h +++ b/src/QGst/bin.h @@ -27,6 +27,10 @@ # pragma warning(disable:4250) //Bin inherits QGst::Object::ref/unref via dominance #endif +#if !QGLIB_HAVE_CXX0X +# include <boost/preprocessor.hpp> +#endif + namespace QGst { /*! \headerfile bin.h <QGst/Bin> @@ -73,6 +77,48 @@ public: */ bool add(const ElementPtr & element); +#if QGLIB_HAVE_CXX0X + +# ifndef DOXYGEN_RUN +private: + inline void add() {} //terminate condition for the variadic template recursion +public: +# endif + + /*! Adds two or more elements to the bin. This function is equivalent to calling + * add() for each of the elements. The return value of each add() is ignored. + * \note This function makes use of C++0x features. If your compiler doesn't support + * this, a different version will be compiled. That version supports up to + * QGST_BIN_ADD_MAX_ARGS arguments, which defaults to 10. If you need more, define + * this to a greater value before including any QtGStreamer headers. + */ + template <typename First, typename Second, typename... Rest> + inline void add(const First & first, const Second & second, const Rest & ... rest) + { + add(first); + add(second); + add(rest...); + } + +#else //QGLIB_HAVE_CXX0X + +# ifndef QGST_BIN_ADD_MAX_ARGS +# define QGST_BIN_ADD_MAX_ARGS 10 +# endif + +# define QGST_BIN_ADD_DECLARATION(z, n, data) \ + inline void add(BOOST_PP_ENUM_PARAMS(n, const ElementPtr & e)) \ + { \ + add(e0); \ + add(BOOST_PP_ENUM_SHIFTED_PARAMS(n, e)); \ + }; + + BOOST_PP_REPEAT_FROM_TO(2, BOOST_PP_INC(QGST_BIN_ADD_MAX_ARGS), QGST_BIN_ADD_DECLARATION, dummy) + +# undef QGST_BIN_ADD_DECLARATION + +#endif //QGLIB_HAVE_CXX0X + /*! Removes the element from the bin, unparenting it as well. * * If the element's pads are linked to other pads, the pads will be diff --git a/tests/compilation/CompilationTests.cmake b/tests/compilation/CompilationTests.cmake index b774af0..ea63bd5 100644 --- a/tests/compilation/CompilationTests.cmake +++ b/tests/compilation/CompilationTests.cmake @@ -164,3 +164,38 @@ int main() ") ######### END disconnect tests ######## +######### BEGIN bin add() tests ######## + +cxx_compilation_test(bin_add_test_1 SHOULD_COMPILE " +#include <QGst/Bin> + +int main() +{ + QGst::ElementPtr tee; + QGst::BinPtr bin; + + bool b = bin->add(tee); + bin->add(tee, tee); + bin->add(tee, tee, tee); + bin->add(tee, tee, tee, tee); + bin->add(tee, tee, tee, tee, tee); + bin->add(tee, tee, tee, tee, tee, tee); + bin->add(tee, tee, tee, tee, tee, tee, tee); + bin->add(tee, tee, tee, tee, tee, tee, tee, tee); + bin->add(tee, tee, tee, tee, tee, tee, tee, tee, tee); + bin->add(tee, tee, tee, tee, tee, tee, tee, tee, tee, tee); +} +") + +cxx_compilation_test(bin_add_test_2 SHOULD_COMPILE " +#define QGST_BIN_ADD_MAX_ARGS 12 +#include <QGst/Bin> + +int main() +{ + QGst::ElementPtr tee; + QGst::BinPtr bin; + bin->add(tee, tee, tee, tee, tee, tee, tee, tee, tee, tee, tee, tee); +} +") +######### END bin add() tests ######## |