diff options
author | Christian Kamm <christian.d.kamm@nokia.com> | 2010-03-22 17:34:13 +0100 |
---|---|---|
committer | Christian Kamm <christian.d.kamm@nokia.com> | 2010-03-26 13:05:02 +0100 |
commit | 9a87cb5347a888a104cab47c17f05f1f0aa7a133 (patch) | |
tree | 4c247ab28ab0d067a55f90fde1061ad88d05a90f | |
parent | 883dee678eca4f55faf3848a248253d4b4b8a40e (diff) |
Use function binding generator from QtConcurrent.
* Copy tools/codegenerator and tools/generatebuild from QtConcurrent
and adapt for Coroutines. This allows coroutines from various callables
to be created with a call to build(...).
* Add initial tests.
* Fix incorrect use of QThreadStorage.
* Fix severe typo in Coroutine::yieldHelper.
-rw-r--r-- | coroutine.pro | 5 | ||||
-rw-r--r-- | src/coroutine.cpp | 36 | ||||
-rw-r--r-- | src/coroutine.h | 12 | ||||
-rw-r--r-- | src/coroutinebuild.h | 243 | ||||
-rw-r--r-- | src/coroutinestoredfunctioncall.h | 536 | ||||
-rw-r--r-- | src/src.pro | 7 | ||||
-rw-r--r-- | tests/auto/auto.pro | 2 | ||||
-rw-r--r-- | tests/auto/basic/basic.pro | 3 | ||||
-rw-r--r-- | tests/auto/basic/tst_basic.cpp | 37 | ||||
-rw-r--r-- | tests/auto/build/build.pro | 3 | ||||
-rw-r--r-- | tests/auto/build/tst_build.cpp | 58 | ||||
-rw-r--r-- | tests/tests.pro | 2 | ||||
-rw-r--r-- | tools/codegenerator/codegenerator.pri | 5 | ||||
-rw-r--r-- | tools/codegenerator/src/codegenerator.cpp | 140 | ||||
-rw-r--r-- | tools/codegenerator/src/codegenerator.h | 204 | ||||
-rw-r--r-- | tools/generatebuild/main.cpp | 359 | ||||
-rw-r--r-- | tools/generatebuild/run.pro | 9 |
17 files changed, 1635 insertions, 26 deletions
diff --git a/coroutine.pro b/coroutine.pro index 65d9262..f7f039f 100644 --- a/coroutine.pro +++ b/coroutine.pro @@ -1,2 +1,7 @@ TEMPLATE = subdirs SUBDIRS = src + +system(echo "INCLUDEPATH *= $$PWD/src" > use_coroutine.pri) +system(echo "LIBS *= -L$$OUT_PWD/lib" >> use_coroutine.pri) +system(echo "LIBS *= -l$$qtLibraryTarget(coroutine)" >> use_coroutine.pri) +system(echo "unix:LIBS *= -Wl,-rpath,$$OUT_PWD/lib" >> use_coroutine.pri) diff --git a/src/coroutine.cpp b/src/coroutine.cpp index eb6ebc5..03cb618 100644 --- a/src/coroutine.cpp +++ b/src/coroutine.cpp @@ -42,9 +42,8 @@ void initializeStack(void *data, int size, void (*entry)(), void **stackPointer) void switchStack(void* to, void** from) { _switchStackInternal(to, from); } #endif -Coroutine::Coroutine(StartFunction startFunction, int stackSize) - : _startFunction(startFunction) - , _stackData(0) +Coroutine::Coroutine(int stackSize) + : _stackData(0) , _stackPointer(0) , _previousCoroutine(0) , _status(NotStarted) @@ -56,9 +55,8 @@ Coroutine::Coroutine(StartFunction startFunction, int stackSize) initializeStack(_stackData, stackSize, &entryPoint, &_stackPointer); } -Coroutine::Coroutine() - : _startFunction(0) - , _stackData(0) +Coroutine::Coroutine(bool) + : _stackData(0) , _stackPointer(0) , _previousCoroutine(0) , _status(Running) @@ -71,23 +69,23 @@ Coroutine::~Coroutine() free(_stackData); } -static QThreadStorage<Coroutine *> qt_currentCoroutine; +static QThreadStorage<Coroutine **> qt_currentCoroutine; Coroutine *Coroutine::currentCoroutine() { - Coroutine *current = qt_currentCoroutine.localData(); - if (current) + // establish a context for the starting coroutine + if (!qt_currentCoroutine.hasLocalData()) { + Coroutine *current = new Coroutine(true); + qt_currentCoroutine.setLocalData(new Coroutine*(current)); return current; + } - // establish a context for the starting coroutine - current = new Coroutine; - qt_currentCoroutine.setLocalData(current); - return current; + return *qt_currentCoroutine.localData(); } void Coroutine::entryPoint() { - qt_currentCoroutine.localData()->_startFunction(); + (*qt_currentCoroutine.localData())->run(); yieldHelper(Terminated); Q_ASSERT(0); // unreachable } @@ -100,8 +98,8 @@ bool Coroutine::cont() _status = Running; - _previousCoroutine = qt_currentCoroutine.localData(); - qt_currentCoroutine.setLocalData(this); + _previousCoroutine = *qt_currentCoroutine.localData(); + *qt_currentCoroutine.localData() = this; switchStack(_stackPointer, &_previousCoroutine->_stackPointer); return _status != Terminated; } @@ -113,7 +111,7 @@ void Coroutine::yield() void Coroutine::yieldHelper(Status stopStatus) { - Coroutine *stoppingCoroutine = qt_currentCoroutine.localData(); + Coroutine *stoppingCoroutine = *qt_currentCoroutine.localData(); Q_ASSERT(stoppingCoroutine); Q_ASSERT(stoppingCoroutine->_status == Running); stoppingCoroutine->_status = stopStatus; @@ -122,6 +120,6 @@ void Coroutine::yieldHelper(Status stopStatus) Q_ASSERT(continuingCoroutine); stoppingCoroutine->_previousCoroutine = 0; - qt_currentCoroutine.setLocalData(continuingCoroutine); - switchStack(continuingCoroutine, &stoppingCoroutine->_stackPointer); + *qt_currentCoroutine.localData() = continuingCoroutine; + switchStack(continuingCoroutine->_stackPointer, &stoppingCoroutine->_stackPointer); } diff --git a/src/coroutine.h b/src/coroutine.h index ca47e77..7a7cd1c 100644 --- a/src/coroutine.h +++ b/src/coroutine.h @@ -4,8 +4,6 @@ class Coroutine { public: - typedef void(*StartFunction)(); - enum Status { NotStarted, @@ -15,8 +13,8 @@ public: }; public: - explicit Coroutine(StartFunction startFunction, int stackSize = 32768); - ~Coroutine(); + explicit Coroutine(int stackSize = 32768); + virtual ~Coroutine(); bool cont(); static void yield(); @@ -26,14 +24,16 @@ public: static Coroutine *currentCoroutine(); +protected: + virtual void run() {} + private: // for the original coroutine - Coroutine(); + Coroutine(bool); static void yieldHelper(Status stopStatus); static void entryPoint(); - StartFunction _startFunction; void *_stackData; void *_stackPointer; Coroutine *_previousCoroutine; diff --git a/src/coroutinebuild.h b/src/coroutinebuild.h new file mode 100644 index 0000000..ddff983 --- /dev/null +++ b/src/coroutinebuild.h @@ -0,0 +1,243 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +****************************************************************************/ + +// Generated code, do not edit! Use generator at tools/generatebuild/ +#ifndef COROUTINE_MAKE_H +#define COROUTINE_MAKE_H + +#include "coroutine.h" +#include "coroutinestoredfunctioncall.h" + +#ifdef qdoc + + Coroutine* build(Function function, ...); + +#else + + +Coroutine* build(int stackSize, void (*functionPointer)()) +{ + return new StoredFunctorCall0<void (*)()>(stackSize, functionPointer); +} +template <typename Param1, typename Arg1> +Coroutine* build(int stackSize, void (*functionPointer)(Param1), const Arg1 &arg1) +{ + return new StoredFunctorCall1<void (*)(Param1), Arg1>(stackSize, functionPointer, arg1); +} +template <typename Param1, typename Arg1, typename Param2, typename Arg2> +Coroutine* build(int stackSize, void (*functionPointer)(Param1, Param2), const Arg1 &arg1, const Arg2 &arg2) +{ + return new StoredFunctorCall2<void (*)(Param1, Param2), Arg1, Arg2>(stackSize, functionPointer, arg1, arg2); +} +template <typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> +Coroutine* build(int stackSize, void (*functionPointer)(Param1, Param2, Param3), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) +{ + return new StoredFunctorCall3<void (*)(Param1, Param2, Param3), Arg1, Arg2, Arg3>(stackSize, functionPointer, arg1, arg2, arg3); +} +template <typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> +Coroutine* build(int stackSize, void (*functionPointer)(Param1, Param2, Param3, Param4), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) +{ + return new StoredFunctorCall4<void (*)(Param1, Param2, Param3, Param4), Arg1, Arg2, Arg3, Arg4>(stackSize, functionPointer, arg1, arg2, arg3, arg4); +} +template <typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> +Coroutine* build(int stackSize, void (*functionPointer)(Param1, Param2, Param3, Param4, Param5), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) +{ + return new StoredFunctorCall5<void (*)(Param1, Param2, Param3, Param4, Param5), Arg1, Arg2, Arg3, Arg4, Arg5>(stackSize, functionPointer, arg1, arg2, arg3, arg4, arg5); +} + +template <typename FunctionObject> +Coroutine* build(int stackSize, FunctionObject functionObject) +{ + return new StoredFunctorCall0<FunctionObject>(stackSize, functionObject); +} +template <typename FunctionObject, typename Arg1> +Coroutine* build(int stackSize, FunctionObject functionObject, const Arg1 &arg1) +{ + return new StoredFunctorCall1<FunctionObject, Arg1>(stackSize, functionObject, arg1); +} +template <typename FunctionObject, typename Arg1, typename Arg2> +Coroutine* build(int stackSize, FunctionObject functionObject, const Arg1 &arg1, const Arg2 &arg2) +{ + return new StoredFunctorCall2<FunctionObject, Arg1, Arg2>(stackSize, functionObject, arg1, arg2); +} +template <typename FunctionObject, typename Arg1, typename Arg2, typename Arg3> +Coroutine* build(int stackSize, FunctionObject functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) +{ + return new StoredFunctorCall3<FunctionObject, Arg1, Arg2, Arg3>(stackSize, functionObject, arg1, arg2, arg3); +} +template <typename FunctionObject, typename Arg1, typename Arg2, typename Arg3, typename Arg4> +Coroutine* build(int stackSize, FunctionObject functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) +{ + return new StoredFunctorCall4<FunctionObject, Arg1, Arg2, Arg3, Arg4>(stackSize, functionObject, arg1, arg2, arg3, arg4); +} +template <typename FunctionObject, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> +Coroutine* build(int stackSize, FunctionObject functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) +{ + return new StoredFunctorCall5<FunctionObject, Arg1, Arg2, Arg3, Arg4, Arg5>(stackSize, functionObject, arg1, arg2, arg3, arg4, arg5); +} + +template <typename FunctionObject> +Coroutine* build(int stackSize, FunctionObject *functionObject) +{ + return new StoredFunctorPointerCall0<FunctionObject>(stackSize, functionObject); +} +template <typename FunctionObject, typename Arg1> +Coroutine* build(int stackSize, FunctionObject *functionObject, const Arg1 &arg1) +{ + return new StoredFunctorPointerCall1<FunctionObject, Arg1>(stackSize, functionObject, arg1); +} +template <typename FunctionObject, typename Arg1, typename Arg2> +Coroutine* build(int stackSize, FunctionObject *functionObject, const Arg1 &arg1, const Arg2 &arg2) +{ + return new StoredFunctorPointerCall2<FunctionObject, Arg1, Arg2>(stackSize, functionObject, arg1, arg2); +} +template <typename FunctionObject, typename Arg1, typename Arg2, typename Arg3> +Coroutine* build(int stackSize, FunctionObject *functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) +{ + return new StoredFunctorPointerCall3<FunctionObject, Arg1, Arg2, Arg3>(stackSize, functionObject, arg1, arg2, arg3); +} +template <typename FunctionObject, typename Arg1, typename Arg2, typename Arg3, typename Arg4> +Coroutine* build(int stackSize, FunctionObject *functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) +{ + return new StoredFunctorPointerCall4<FunctionObject, Arg1, Arg2, Arg3, Arg4>(stackSize, functionObject, arg1, arg2, arg3, arg4); +} +template <typename FunctionObject, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> +Coroutine* build(int stackSize, FunctionObject *functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) +{ + return new StoredFunctorPointerCall5<FunctionObject, Arg1, Arg2, Arg3, Arg4, Arg5>(stackSize, functionObject, arg1, arg2, arg3, arg4, arg5); +} + +template <typename Class> +Coroutine* build(int stackSize, const Class &object, void (Class::*fn)()) +{ + return new StoredMemberFunctionCall0<Class>(stackSize, fn, object); +} +template <typename Class, typename Param1, typename Arg1> +Coroutine* build(int stackSize, const Class &object, void (Class::*fn)(Param1), const Arg1 &arg1) +{ + return new StoredMemberFunctionCall1<Class, Param1, Arg1>(stackSize, fn, object, arg1); +} +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> +Coroutine* build(int stackSize, const Class &object, void (Class::*fn)(Param1, Param2), const Arg1 &arg1, const Arg2 &arg2) +{ + return new StoredMemberFunctionCall2<Class, Param1, Arg1, Param2, Arg2>(stackSize, fn, object, arg1, arg2); +} +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> +Coroutine* build(int stackSize, const Class &object, void (Class::*fn)(Param1, Param2, Param3), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) +{ + return new StoredMemberFunctionCall3<Class, Param1, Arg1, Param2, Arg2, Param3, Arg3>(stackSize, fn, object, arg1, arg2, arg3); +} +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> +Coroutine* build(int stackSize, const Class &object, void (Class::*fn)(Param1, Param2, Param3, Param4), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) +{ + return new StoredMemberFunctionCall4<Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4>(stackSize, fn, object, arg1, arg2, arg3, arg4); +} +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> +Coroutine* build(int stackSize, const Class &object, void (Class::*fn)(Param1, Param2, Param3, Param4, Param5), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) +{ + return new StoredMemberFunctionCall5<Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4, Param5, Arg5>(stackSize, fn, object, arg1, arg2, arg3, arg4, arg5); +} + +template <typename Class> +Coroutine *build(int stackSize, const Class &object, void (Class::*fn)() const) +{ + return new StoredConstMemberFunctionCall0<Class>(stackSize, fn, object); +} +template <typename Class, typename Param1, typename Arg1> +Coroutine *build(int stackSize, const Class &object, void (Class::*fn)(Param1) const, const Arg1 &arg1) +{ + return new StoredConstMemberFunctionCall1<Class, Param1, Arg1>(stackSize, fn, object, arg1); +} +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> +Coroutine *build(int stackSize, const Class &object, void (Class::*fn)(Param1, Param2) const, const Arg1 &arg1, const Arg2 &arg2) +{ + return new StoredConstMemberFunctionCall2<Class, Param1, Arg1, Param2, Arg2>(stackSize, fn, object, arg1, arg2); +} +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> +Coroutine *build(int stackSize, const Class &object, void (Class::*fn)(Param1, Param2, Param3) const, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) +{ + return new StoredConstMemberFunctionCall3<Class, Param1, Arg1, Param2, Arg2, Param3, Arg3>(stackSize, fn, object, arg1, arg2, arg3); +} +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> +Coroutine *build(int stackSize, const Class &object, void (Class::*fn)(Param1, Param2, Param3, Param4) const, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) +{ + return new StoredConstMemberFunctionCall4<Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4>(stackSize, fn, object, arg1, arg2, arg3, arg4); +} +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> +Coroutine *build(int stackSize, const Class &object, void (Class::*fn)(Param1, Param2, Param3, Param4, Param5) const, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) +{ + return new StoredConstMemberFunctionCall5<Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4, Param5, Arg5>(stackSize, fn, object, arg1, arg2, arg3, arg4, arg5); +} + +template <typename Class> +Coroutine* build(int stackSize, Class *object, void (Class::*fn)()) +{ + return new StoredMemberFunctionPointerCall0<Class>(stackSize, fn, object); +} +template <typename Class, typename Param1, typename Arg1> +Coroutine* build(int stackSize, Class *object, void (Class::*fn)(Param1), const Arg1 &arg1) +{ + return new StoredMemberFunctionPointerCall1<Class, Param1, Arg1>(stackSize, fn, object, arg1); +} +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> +Coroutine* build(int stackSize, Class *object, void (Class::*fn)(Param1, Param2), const Arg1 &arg1, const Arg2 &arg2) +{ + return new StoredMemberFunctionPointerCall2<Class, Param1, Arg1, Param2, Arg2>(stackSize, fn, object, arg1, arg2); +} +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> +Coroutine* build(int stackSize, Class *object, void (Class::*fn)(Param1, Param2, Param3), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) +{ + return new StoredMemberFunctionPointerCall3<Class, Param1, Arg1, Param2, Arg2, Param3, Arg3>(stackSize, fn, object, arg1, arg2, arg3); +} +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> +Coroutine* build(int stackSize, Class *object, void (Class::*fn)(Param1, Param2, Param3, Param4), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) +{ + return new StoredMemberFunctionPointerCall4<Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4>(stackSize, fn, object, arg1, arg2, arg3, arg4); +} +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> +Coroutine* build(int stackSize, Class *object, void (Class::*fn)(Param1, Param2, Param3, Param4, Param5), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) +{ + return new StoredMemberFunctionPointerCall5<Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4, Param5, Arg5>(stackSize, fn, object, arg1, arg2, arg3, arg4, arg5); +} + +template <typename Class> +Coroutine* build(int stackSize, const Class *object, void (Class::*fn)() const) +{ + return new StoredConstMemberFunctionPointerCall0<Class>(stackSize, fn, object); +} +template <typename Class, typename Param1, typename Arg1> +Coroutine* build(int stackSize, const Class *object, void (Class::*fn)(Param1) const, const Arg1 &arg1) +{ + return new StoredConstMemberFunctionPointerCall1<Class, Param1, Arg1>(stackSize, fn, object, arg1); +} +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> +Coroutine* build(int stackSize, const Class *object, void (Class::*fn)(Param1, Param2) const, const Arg1 &arg1, const Arg2 &arg2) +{ + return new StoredConstMemberFunctionPointerCall2<Class, Param1, Arg1, Param2, Arg2>(stackSize, fn, object, arg1, arg2); +} +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> +Coroutine* build(int stackSize, const Class *object, void (Class::*fn)(Param1, Param2, Param3) const, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) +{ + return new StoredConstMemberFunctionPointerCall3<Class, Param1, Arg1, Param2, Arg2, Param3, Arg3>(stackSize, fn, object, arg1, arg2, arg3); +} +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> +Coroutine* build(int stackSize, const Class *object, void (Class::*fn)(Param1, Param2, Param3, Param4) const, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) +{ + return new StoredConstMemberFunctionPointerCall4<Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4>(stackSize, fn, object, arg1, arg2, arg3, arg4); +} +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> +Coroutine* build(int stackSize, const Class *object, void (Class::*fn)(Param1, Param2, Param3, Param4, Param5) const, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) +{ + return new StoredConstMemberFunctionPointerCall5<Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4, Param5, Arg5>(stackSize, fn, object, arg1, arg2, arg3, arg4, arg5); +} + + +#endif // qdoc + +#endif diff --git a/src/coroutinestoredfunctioncall.h b/src/coroutinestoredfunctioncall.h new file mode 100644 index 0000000..bdcc329 --- /dev/null +++ b/src/coroutinestoredfunctioncall.h @@ -0,0 +1,536 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +****************************************************************************/ + +// Generated code, do not edit! Use generator at tools/generatebuild/ +#ifndef COROUTINE_STOREDFUNCTIONCALL_H +#define COROUTINE_STOREDFUNCTIONCALL_H + +#include "coroutine.h" +#ifndef qdoc + +template <typename FunctionPointer> +struct StoredFunctorCall0: public Coroutine +{ + inline StoredFunctorCall0(int stackSize, FunctionPointer function) + : Coroutine(stackSize), function(function) {} +protected: + virtual void run() { function(); } + FunctionPointer function; + +}; + +template <typename FunctionPointer> +struct StoredFunctorPointerCall0: public Coroutine +{ + inline StoredFunctorPointerCall0(int stackSize, FunctionPointer * function) + : Coroutine(stackSize), function(function) {} +protected: + virtual void run() { (*function)(); } + FunctionPointer * function; + +}; + +template <typename Class> +class StoredMemberFunctionCall0 : public Coroutine +{ +public: + StoredMemberFunctionCall0(int stackSize, void (Class::*fn)() , const Class &object) + : Coroutine(stackSize), fn(fn), object(object){ } +protected: + virtual void run() + { + (object.*fn)(); + } +private: + void (Class::*fn)(); + Class object; + +}; +template <typename Class> +class StoredConstMemberFunctionCall0 : public Coroutine +{ +public: + StoredConstMemberFunctionCall0(int stackSize, void (Class::*fn)() const, const Class &object) + : Coroutine(stackSize), fn(fn), object(object){ } +protected: + virtual void run() + { + (object.*fn)(); + } +private: + void (Class::*fn)()const; + const Class object; + +}; +template <typename Class> +class StoredMemberFunctionPointerCall0 : public Coroutine +{ +public: + StoredMemberFunctionPointerCall0(int stackSize, void (Class::*fn)() , Class *object) + : Coroutine(stackSize), fn(fn), object(object){ } +protected: + virtual void run() + { + (object->*fn)(); + } +private: + void (Class::*fn)(); + Class *object; + +}; +template <typename Class> +class StoredConstMemberFunctionPointerCall0 : public Coroutine +{ +public: + StoredConstMemberFunctionPointerCall0(int stackSize, void (Class::*fn)() const, Class const *object) + : Coroutine(stackSize), fn(fn), object(object){ } +protected: + virtual void run() + { + (object->*fn)(); + } +private: + void (Class::*fn)()const; + Class const *object; + +}; +template <typename FunctionPointer, typename Arg1> +struct StoredFunctorCall1: public Coroutine +{ + inline StoredFunctorCall1(int stackSize, FunctionPointer function, const Arg1 &arg1) + : Coroutine(stackSize), function(function), arg1(arg1) {} +protected: + virtual void run() { function(arg1); } + FunctionPointer function; + Arg1 arg1; +}; + +template <typename FunctionPointer, typename Arg1> +struct StoredFunctorPointerCall1: public Coroutine +{ + inline StoredFunctorPointerCall1(int stackSize, FunctionPointer * function, const Arg1 &arg1) + : Coroutine(stackSize), function(function), arg1(arg1) {} +protected: + virtual void run() { (*function)(arg1); } + FunctionPointer * function; + Arg1 arg1; +}; + +template <typename Class, typename Param1, typename Arg1> +class StoredMemberFunctionCall1 : public Coroutine +{ +public: + StoredMemberFunctionCall1(int stackSize, void (Class::*fn)(Param1) , const Class &object, const Arg1 &arg1) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1){ } +protected: + virtual void run() + { + (object.*fn)(arg1); + } +private: + void (Class::*fn)(Param1); + Class object; + Arg1 arg1; +}; +template <typename Class, typename Param1, typename Arg1> +class StoredConstMemberFunctionCall1 : public Coroutine +{ +public: + StoredConstMemberFunctionCall1(int stackSize, void (Class::*fn)(Param1) const, const Class &object, const Arg1 &arg1) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1){ } +protected: + virtual void run() + { + (object.*fn)(arg1); + } +private: + void (Class::*fn)(Param1)const; + const Class object; + Arg1 arg1; +}; +template <typename Class, typename Param1, typename Arg1> +class StoredMemberFunctionPointerCall1 : public Coroutine +{ +public: + StoredMemberFunctionPointerCall1(int stackSize, void (Class::*fn)(Param1) , Class *object, const Arg1 &arg1) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1){ } +protected: + virtual void run() + { + (object->*fn)(arg1); + } +private: + void (Class::*fn)(Param1); + Class *object; + Arg1 arg1; +}; +template <typename Class, typename Param1, typename Arg1> +class StoredConstMemberFunctionPointerCall1 : public Coroutine +{ +public: + StoredConstMemberFunctionPointerCall1(int stackSize, void (Class::*fn)(Param1) const, Class const *object, const Arg1 &arg1) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1){ } +protected: + virtual void run() + { + (object->*fn)(arg1); + } +private: + void (Class::*fn)(Param1)const; + Class const *object; + Arg1 arg1; +}; +template <typename FunctionPointer, typename Arg1, typename Arg2> +struct StoredFunctorCall2: public Coroutine +{ + inline StoredFunctorCall2(int stackSize, FunctionPointer function, const Arg1 &arg1, const Arg2 &arg2) + : Coroutine(stackSize), function(function), arg1(arg1), arg2(arg2) {} +protected: + virtual void run() { function(arg1, arg2); } + FunctionPointer function; + Arg1 arg1; Arg2 arg2; +}; + +template <typename FunctionPointer, typename Arg1, typename Arg2> +struct StoredFunctorPointerCall2: public Coroutine +{ + inline StoredFunctorPointerCall2(int stackSize, FunctionPointer * function, const Arg1 &arg1, const Arg2 &arg2) + : Coroutine(stackSize), function(function), arg1(arg1), arg2(arg2) {} +protected: + virtual void run() { (*function)(arg1, arg2); } + FunctionPointer * function; + Arg1 arg1; Arg2 arg2; +}; + +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> +class StoredMemberFunctionCall2 : public Coroutine +{ +public: + StoredMemberFunctionCall2(int stackSize, void (Class::*fn)(Param1, Param2) , const Class &object, const Arg1 &arg1, const Arg2 &arg2) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1), arg2(arg2){ } +protected: + virtual void run() + { + (object.*fn)(arg1, arg2); + } +private: + void (Class::*fn)(Param1, Param2); + Class object; + Arg1 arg1; Arg2 arg2; +}; +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> +class StoredConstMemberFunctionCall2 : public Coroutine +{ +public: + StoredConstMemberFunctionCall2(int stackSize, void (Class::*fn)(Param1, Param2) const, const Class &object, const Arg1 &arg1, const Arg2 &arg2) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1), arg2(arg2){ } +protected: + virtual void run() + { + (object.*fn)(arg1, arg2); + } +private: + void (Class::*fn)(Param1, Param2)const; + const Class object; + Arg1 arg1; Arg2 arg2; +}; +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> +class StoredMemberFunctionPointerCall2 : public Coroutine +{ +public: + StoredMemberFunctionPointerCall2(int stackSize, void (Class::*fn)(Param1, Param2) , Class *object, const Arg1 &arg1, const Arg2 &arg2) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1), arg2(arg2){ } +protected: + virtual void run() + { + (object->*fn)(arg1, arg2); + } +private: + void (Class::*fn)(Param1, Param2); + Class *object; + Arg1 arg1; Arg2 arg2; +}; +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> +class StoredConstMemberFunctionPointerCall2 : public Coroutine +{ +public: + StoredConstMemberFunctionPointerCall2(int stackSize, void (Class::*fn)(Param1, Param2) const, Class const *object, const Arg1 &arg1, const Arg2 &arg2) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1), arg2(arg2){ } +protected: + virtual void run() + { + (object->*fn)(arg1, arg2); + } +private: + void (Class::*fn)(Param1, Param2)const; + Class const *object; + Arg1 arg1; Arg2 arg2; +}; +template <typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3> +struct StoredFunctorCall3: public Coroutine +{ + inline StoredFunctorCall3(int stackSize, FunctionPointer function, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) + : Coroutine(stackSize), function(function), arg1(arg1), arg2(arg2), arg3(arg3) {} +protected: + virtual void run() { function(arg1, arg2, arg3); } + FunctionPointer function; + Arg1 arg1; Arg2 arg2; Arg3 arg3; +}; + +template <typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3> +struct StoredFunctorPointerCall3: public Coroutine +{ + inline StoredFunctorPointerCall3(int stackSize, FunctionPointer * function, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) + : Coroutine(stackSize), function(function), arg1(arg1), arg2(arg2), arg3(arg3) {} +protected: + virtual void run() { (*function)(arg1, arg2, arg3); } + FunctionPointer * function; + Arg1 arg1; Arg2 arg2; Arg3 arg3; +}; + +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> +class StoredMemberFunctionCall3 : public Coroutine +{ +public: + StoredMemberFunctionCall3(int stackSize, void (Class::*fn)(Param1, Param2, Param3) , const Class &object, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3){ } +protected: + virtual void run() + { + (object.*fn)(arg1, arg2, arg3); + } +private: + void (Class::*fn)(Param1, Param2, Param3); + Class object; + Arg1 arg1; Arg2 arg2; Arg3 arg3; +}; +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> +class StoredConstMemberFunctionCall3 : public Coroutine +{ +public: + StoredConstMemberFunctionCall3(int stackSize, void (Class::*fn)(Param1, Param2, Param3) const, const Class &object, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3){ } +protected: + virtual void run() + { + (object.*fn)(arg1, arg2, arg3); + } +private: + void (Class::*fn)(Param1, Param2, Param3)const; + const Class object; + Arg1 arg1; Arg2 arg2; Arg3 arg3; +}; +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> +class StoredMemberFunctionPointerCall3 : public Coroutine +{ +public: + StoredMemberFunctionPointerCall3(int stackSize, void (Class::*fn)(Param1, Param2, Param3) , Class *object, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3){ } +protected: + virtual void run() + { + (object->*fn)(arg1, arg2, arg3); + } +private: + void (Class::*fn)(Param1, Param2, Param3); + Class *object; + Arg1 arg1; Arg2 arg2; Arg3 arg3; +}; +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> +class StoredConstMemberFunctionPointerCall3 : public Coroutine +{ +public: + StoredConstMemberFunctionPointerCall3(int stackSize, void (Class::*fn)(Param1, Param2, Param3) const, Class const *object, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3){ } +protected: + virtual void run() + { + (object->*fn)(arg1, arg2, arg3); + } +private: + void (Class::*fn)(Param1, Param2, Param3)const; + Class const *object; + Arg1 arg1; Arg2 arg2; Arg3 arg3; +}; +template <typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4> +struct StoredFunctorCall4: public Coroutine +{ + inline StoredFunctorCall4(int stackSize, FunctionPointer function, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) + : Coroutine(stackSize), function(function), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4) {} +protected: + virtual void run() { function(arg1, arg2, arg3, arg4); } + FunctionPointer function; + Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; +}; + +template <typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4> +struct StoredFunctorPointerCall4: public Coroutine +{ + inline StoredFunctorPointerCall4(int stackSize, FunctionPointer * function, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) + : Coroutine(stackSize), function(function), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4) {} +protected: + virtual void run() { (*function)(arg1, arg2, arg3, arg4); } + FunctionPointer * function; + Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; +}; + +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> +class StoredMemberFunctionCall4 : public Coroutine +{ +public: + StoredMemberFunctionCall4(int stackSize, void (Class::*fn)(Param1, Param2, Param3, Param4) , const Class &object, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4){ } +protected: + virtual void run() + { + (object.*fn)(arg1, arg2, arg3, arg4); + } +private: + void (Class::*fn)(Param1, Param2, Param3, Param4); + Class object; + Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; +}; +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> +class StoredConstMemberFunctionCall4 : public Coroutine +{ +public: + StoredConstMemberFunctionCall4(int stackSize, void (Class::*fn)(Param1, Param2, Param3, Param4) const, const Class &object, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4){ } +protected: + virtual void run() + { + (object.*fn)(arg1, arg2, arg3, arg4); + } +private: + void (Class::*fn)(Param1, Param2, Param3, Param4)const; + const Class object; + Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; +}; +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> +class StoredMemberFunctionPointerCall4 : public Coroutine +{ +public: + StoredMemberFunctionPointerCall4(int stackSize, void (Class::*fn)(Param1, Param2, Param3, Param4) , Class *object, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4){ } +protected: + virtual void run() + { + (object->*fn)(arg1, arg2, arg3, arg4); + } +private: + void (Class::*fn)(Param1, Param2, Param3, Param4); + Class *object; + Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; +}; +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> +class StoredConstMemberFunctionPointerCall4 : public Coroutine +{ +public: + StoredConstMemberFunctionPointerCall4(int stackSize, void (Class::*fn)(Param1, Param2, Param3, Param4) const, Class const *object, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4){ } +protected: + virtual void run() + { + (object->*fn)(arg1, arg2, arg3, arg4); + } +private: + void (Class::*fn)(Param1, Param2, Param3, Param4)const; + Class const *object; + Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; +}; +template <typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> +struct StoredFunctorCall5: public Coroutine +{ + inline StoredFunctorCall5(int stackSize, FunctionPointer function, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) + : Coroutine(stackSize), function(function), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4), arg5(arg5) {} +protected: + virtual void run() { function(arg1, arg2, arg3, arg4, arg5); } + FunctionPointer function; + Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; +}; + +template <typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> +struct StoredFunctorPointerCall5: public Coroutine +{ + inline StoredFunctorPointerCall5(int stackSize, FunctionPointer * function, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) + : Coroutine(stackSize), function(function), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4), arg5(arg5) {} +protected: + virtual void run() { (*function)(arg1, arg2, arg3, arg4, arg5); } + FunctionPointer * function; + Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; +}; + +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> +class StoredMemberFunctionCall5 : public Coroutine +{ +public: + StoredMemberFunctionCall5(int stackSize, void (Class::*fn)(Param1, Param2, Param3, Param4, Param5) , const Class &object, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4), arg5(arg5){ } +protected: + virtual void run() + { + (object.*fn)(arg1, arg2, arg3, arg4, arg5); + } +private: + void (Class::*fn)(Param1, Param2, Param3, Param4, Param5); + Class object; + Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; +}; +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> +class StoredConstMemberFunctionCall5 : public Coroutine +{ +public: + StoredConstMemberFunctionCall5(int stackSize, void (Class::*fn)(Param1, Param2, Param3, Param4, Param5) const, const Class &object, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4), arg5(arg5){ } +protected: + virtual void run() + { + (object.*fn)(arg1, arg2, arg3, arg4, arg5); + } +private: + void (Class::*fn)(Param1, Param2, Param3, Param4, Param5)const; + const Class object; + Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; +}; +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> +class StoredMemberFunctionPointerCall5 : public Coroutine +{ +public: + StoredMemberFunctionPointerCall5(int stackSize, void (Class::*fn)(Param1, Param2, Param3, Param4, Param5) , Class *object, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4), arg5(arg5){ } +protected: + virtual void run() + { + (object->*fn)(arg1, arg2, arg3, arg4, arg5); + } +private: + void (Class::*fn)(Param1, Param2, Param3, Param4, Param5); + Class *object; + Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; +}; +template <typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> +class StoredConstMemberFunctionPointerCall5 : public Coroutine +{ +public: + StoredConstMemberFunctionPointerCall5(int stackSize, void (Class::*fn)(Param1, Param2, Param3, Param4, Param5) const, Class const *object, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) + : Coroutine(stackSize), fn(fn), object(object), arg1(arg1), arg2(arg2), arg3(arg3), arg4(arg4), arg5(arg5){ } +protected: + virtual void run() + { + (object->*fn)(arg1, arg2, arg3, arg4, arg5); + } +private: + void (Class::*fn)(Param1, Param2, Param3, Param4, Param5)const; + Class const *object; + Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; +}; + +#endif // qdoc + +#endif diff --git a/src/src.pro b/src/src.pro index 6fe0bd2..1bc6de1 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,7 +1,12 @@ TEMPLATE = lib +DESTDIR = ../lib TARGET = coroutine -HEADERS += coroutine.h +HEADERS += \ + coroutine.h \ + coroutinebuild.h \ + coroutinestoredfunctioncall.h + SOURCES += coroutine.cpp INCLUDEPATH += . diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro new file mode 100644 index 0000000..675ee12 --- /dev/null +++ b/tests/auto/auto.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = basic build diff --git a/tests/auto/basic/basic.pro b/tests/auto/basic/basic.pro new file mode 100644 index 0000000..c0d2002 --- /dev/null +++ b/tests/auto/basic/basic.pro @@ -0,0 +1,3 @@ +QT += testlib +SOURCES += tst_basic.cpp +include(../../../use_coroutine.pri) diff --git a/tests/auto/basic/tst_basic.cpp b/tests/auto/basic/tst_basic.cpp new file mode 100644 index 0000000..c33ef40 --- /dev/null +++ b/tests/auto/basic/tst_basic.cpp @@ -0,0 +1,37 @@ +#include <QtTest/QtTest> +#include <coroutine.h> + +class tst_basic : public QObject +{ +Q_OBJECT + +private slots: + void noYield(); +}; + +class NoYieldCoro : public Coroutine +{ +public: + virtual void run() + { + i++; + QCOMPARE(status(), Running); + QCOMPARE(currentCoroutine(), this); + } + + int i; +}; + +void tst_basic::noYield() +{ + NoYieldCoro coro; + coro.i = 0; + QCOMPARE(coro.status(), Coroutine::NotStarted); + QCOMPARE(coro.cont(), false); + QCOMPARE(coro.i, 1); + QCOMPARE(coro.status(), Coroutine::Terminated); + Q_ASSERT(Coroutine::currentCoroutine() != &coro); +} + +QTEST_MAIN(tst_basic) +#include "tst_basic.moc" diff --git a/tests/auto/build/build.pro b/tests/auto/build/build.pro new file mode 100644 index 0000000..9b60fc4 --- /dev/null +++ b/tests/auto/build/build.pro @@ -0,0 +1,3 @@ +QT += testlib +SOURCES += tst_build.cpp +include(../../../use_coroutine.pri) diff --git a/tests/auto/build/tst_build.cpp b/tests/auto/build/tst_build.cpp new file mode 100644 index 0000000..c557d34 --- /dev/null +++ b/tests/auto/build/tst_build.cpp @@ -0,0 +1,58 @@ +#include <QtTest/QtTest> +#include <coroutine.h> +#include <coroutinebuild.h> + +class tst_build: public QObject +{ +Q_OBJECT + +private slots: + void staticFn(); +}; + +static int fnCounter = -99; +static void fnNoArg() +{ + fnCounter = 0; + Coroutine::yield(); + fnCounter++; + Coroutine::yield(); + fnCounter++; + +} + +static void fnArg(int start) +{ + fnCounter = start; + Coroutine::yield(); + fnCounter++; + Coroutine::yield(); + fnCounter++; +} + + +void tst_build::staticFn() +{ + Coroutine* c1 = build(32000, &fnNoArg); + QCOMPARE(fnCounter, -99); + QCOMPARE(c1->cont(), true); + QCOMPARE(fnCounter, 0); + QCOMPARE(c1->cont(), true); + QCOMPARE(fnCounter, 1); + QCOMPARE(c1->cont(), false); + QCOMPARE(fnCounter, 2); + delete c1; + + Coroutine* c2 = build(32000, &fnArg, 40); + QCOMPARE(c2->cont(), true); + QCOMPARE(fnCounter, 40); + QCOMPARE(c2->cont(), true); + QCOMPARE(fnCounter, 41); + QCOMPARE(c2->cont(), false); + QCOMPARE(fnCounter, 42); + delete c2; +} + + +QTEST_MAIN(tst_build) +#include "tst_build.moc" diff --git a/tests/tests.pro b/tests/tests.pro new file mode 100644 index 0000000..7fbc8a9 --- /dev/null +++ b/tests/tests.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = auto diff --git a/tools/codegenerator/codegenerator.pri b/tools/codegenerator/codegenerator.pri new file mode 100644 index 0000000..0aeabab --- /dev/null +++ b/tools/codegenerator/codegenerator.pri @@ -0,0 +1,5 @@ +SOURCES += $$PWD/src/codegenerator.cpp +HEADERS += $$PWD/src/codegenerator.h +INCLUDEPATH += $$PWD/src +DEPENDPATH += $$PWD/src + diff --git a/tools/codegenerator/src/codegenerator.cpp b/tools/codegenerator/src/codegenerator.cpp new file mode 100644 index 0000000..31902ae --- /dev/null +++ b/tools/codegenerator/src/codegenerator.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "codegenerator.h" +#include <qdebug.h> +namespace CodeGenerator +{ + +//Convenience constructor so you can say Item("foo") +Item::Item(const char * const text) : generator(Text(QByteArray(text)).generator) {} + +int BaseGenerator::currentCount(GeneratorStack * const stack) const +{ + const int stackSize = stack->count(); + for (int i = stackSize - 1; i >= 0; --i) { + BaseGenerator const * const generator = stack->at(i); + switch (generator->type) { + case RepeaterType: { + RepeaterGenerator const * const repeater = static_cast<RepeaterGenerator const * const>(generator); + return repeater->currentRepeat; + } break; + case GroupType: { + GroupGenerator const * const group = static_cast<GroupGenerator const * const>(generator); + return group->currentRepeat; + } break; + default: + break; + } + } + return -1; +} + +int BaseGenerator::repeatCount(GeneratorStack * const stack) const +{ + const int stackSize = stack->count(); + for (int i = stackSize - 1; i >= 0; --i) { + BaseGenerator const * const generator = stack->at(i); + switch (generator->type) { + case RepeaterType: { + RepeaterGenerator const * const repeater = static_cast<RepeaterGenerator const * const>(generator); + return repeater->currentRepeat; + } break; +/* case GroupType: { + GroupGenerator const * const group = static_cast<GroupGenerator const * const>(generator); + return group->currentRepeat; + } break; +*/ + default: + break; + } + } + return -1; +} + +QByteArray RepeaterGenerator::generate(GeneratorStack * const stack) +{ + GeneratorStacker stacker(stack, this); + QByteArray generated; + for (int i = repeatOffset; i < repeatCount + repeatOffset; ++i) { + currentRepeat = i; + generated += childGenerator->generate(stack); + } + return generated; +}; + +QByteArray GroupGenerator::generate(GeneratorStack * const stack) +{ + const int repeatCount = currentCount(stack); + GeneratorStacker stacker(stack, this); + QByteArray generated; + + if (repeatCount > 0) + generated += prefix->generate(stack); + + for (int i = 1; i <= repeatCount; ++i) { + currentRepeat = i; + generated += childGenerator->generate(stack); + if (i != repeatCount) + generated += separator->generate(stack); + } + + if (repeatCount > 0) + generated += postfix->generate(stack); + + return generated; +}; + +const Compound operator+(const Item &a, const Item &b) +{ + return Compound(a, b); +} + +const Compound operator+(const Item &a, const char * const text) +{ + return Compound(a, Text(text)); +} + +const Compound operator+(const char * const text, const Item &b) +{ + return Compound(Text(text), b); +} + +}
\ No newline at end of file diff --git a/tools/codegenerator/src/codegenerator.h b/tools/codegenerator/src/codegenerator.h new file mode 100644 index 0000000..c1aefe9 --- /dev/null +++ b/tools/codegenerator/src/codegenerator.h @@ -0,0 +1,204 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef CODEGENERATOR_H +#define CODEGENERATOR_H + +#include <QByteArray> +#include <QString> +#include <QList> +#include <QStack> + +namespace CodeGenerator +{ + enum GeneratorType {NoopType, CompoundType, TextType, RepeaterType, CounterType, GroupType}; + class BaseGenerator; + typedef QStack<BaseGenerator *> GeneratorStack; + + template <typename ValueType> + class Stacker { + public: + Stacker(QStack<ValueType> *stack, ValueType value) : stack(stack) { stack->push(value); } + ~Stacker() { stack->pop();} + private: + QStack<ValueType> *stack; + }; + typedef Stacker<BaseGenerator *> GeneratorStacker; + + class BaseGenerator + { + public: + BaseGenerator(GeneratorType type = NoopType) : type(type) {} + virtual ~BaseGenerator() {}; + virtual QByteArray generate(GeneratorStack *stack) { Q_UNUSED(stack); return QByteArray(); }; + int currentCount(GeneratorStack *stack) const; + int repeatCount(GeneratorStack *stack) const; + GeneratorType type; + }; + + class Item + { + public: + Item(BaseGenerator * const base) : generator(base) {} + Item(const char * const text); + QByteArray generate() const + { GeneratorStack stack; return generator->generate(&stack); } + // ### TODO: Fix memory leak! + // QExplicitlySharedDataPointer<BaseGenerator> generator; + BaseGenerator * const generator; + }; + + class CompoundGenerator : public BaseGenerator + { + public: + CompoundGenerator(BaseGenerator * const a, BaseGenerator * const b) + : BaseGenerator(CompoundType), a(a), b(b) {} + virtual QByteArray generate(GeneratorStack *stack) + { return a->generate(stack) + b->generate(stack); }; + protected: + BaseGenerator * const a; + BaseGenerator * const b; + }; + + class Compound : public Item + { + public: + Compound(const Item &a, const Item &b) : Item(new CompoundGenerator(a.generator, b.generator)) {} + }; + + class TextGenerator : public BaseGenerator + { + public: + TextGenerator(const QByteArray &text) : BaseGenerator(TextType), text(text) {} + virtual QByteArray generate(GeneratorStack *) { return text; }; + protected: + QByteArray text; + }; + + class Text : public Item { + public: + Text(const QByteArray &text) : Item(new TextGenerator(text)) {} + Text(const char * const text) : Item(new TextGenerator(QByteArray(text))) {} + }; + + class RepeaterGenerator : public BaseGenerator + { + public: + RepeaterGenerator(BaseGenerator * const childGenerator) + : BaseGenerator(RepeaterType), repeatCount(1), repeatOffset(0), childGenerator(childGenerator) {} + virtual QByteArray generate(GeneratorStack *stack); + + int repeatCount; + int repeatOffset; + int currentRepeat; + BaseGenerator * const childGenerator; + }; + + class Repeater : public Item { + public: + Repeater(const Item &item) : Item(new RepeaterGenerator(item.generator)) {} + void setRepeatCount(int count) + { static_cast<RepeaterGenerator * const>(generator)->repeatCount = count; } + void setRepeatOffset(int offset) + { static_cast<RepeaterGenerator * const>(generator)->repeatOffset = offset; } + }; + + class CounterGenerator : public BaseGenerator + { + public: + CounterGenerator() : BaseGenerator(CounterType), offset(0), increment(1), reverse(false) {} + QByteArray generate(GeneratorStack *stack) + { + if (reverse) + return QByteArray::number(repeatCount(stack) - (currentCount(stack) * increment) + offset + 1); + else + return QByteArray::number((currentCount(stack) * increment) + offset); + } + int offset; + int increment; + bool reverse; + }; + + class Counter : public Item { + public: + Counter() : Item(new CounterGenerator()) {} + Counter(int offset) : Item(new CounterGenerator()) { setOffset(offset); } + void setOffset(int offset) + { static_cast<CounterGenerator *>(generator)->offset = offset; } + void setIncrement(int increment) + { static_cast<CounterGenerator *>(generator)->increment = increment; } + void setReverse(bool reverse) + { static_cast<CounterGenerator *>(generator)->reverse = reverse; } + + }; + + class GroupGenerator : public BaseGenerator + { + public: + GroupGenerator(BaseGenerator * const childGenerator) + : BaseGenerator(GroupType), currentRepeat(0), childGenerator(childGenerator), + separator(new BaseGenerator()), prefix(new BaseGenerator()), postfix(new BaseGenerator()) { } + virtual QByteArray generate(GeneratorStack *stack); + int currentRepeat; + BaseGenerator * const childGenerator; + BaseGenerator *separator; + BaseGenerator *prefix; + BaseGenerator *postfix; + }; + + class Group : public Item + { + public: + Group(const Item &item) : Item(new GroupGenerator(item.generator)) { setSeparator(", "); } + void setSeparator(const Item &separator) + { static_cast<GroupGenerator *>(generator)->separator = separator.generator; } + void setPrefix(const Item &prefix) + { static_cast<GroupGenerator *>(generator)->prefix = prefix.generator; } + void setPostfix(const Item &postfix) + { static_cast<GroupGenerator *>(generator)->postfix = postfix.generator; } + }; + + const Compound operator+(const Item &a, const Item &b); + const Compound operator+(const Item &a, const char * const text); + const Compound operator+(const char * const text, const Item &b); + +} //namespace CodeGenerator + +#endif diff --git a/tools/generatebuild/main.cpp b/tools/generatebuild/main.cpp new file mode 100644 index 0000000..9a87938 --- /dev/null +++ b/tools/generatebuild/main.cpp @@ -0,0 +1,359 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QApplication> +#include <QDebug> +#include <QFile> + +#include "codegenerator.h" +using namespace CodeGenerator; + +const Item argument = "arg" + Counter(); +const Item argumentRef = "&arg" + Counter(); +const Item argumentType = "Arg" + Counter(); +const Item constArgumentType = "const Arg" + Counter(); +const Item parameterType = "Param" + Counter(); + +Group argumentTypes(argumentType); // expands to ",Arg1, Arg2, ..." +Group argumentTypesNoPrefix(argumentType); // expands to "Arg1, Arg2, ..." +Group arguments(argument); // expands to ",arg1, arg2, ..." +Group argumentsNoPrefix(argument); // expands to "arg1, arg2, ..." +Group parameterTypes(parameterType); // expands to ",Param1, Param2, ..." +Group parameterTypesNoPrefix(parameterType); // expands to "Param1, Param2, ..." +Group typenameTypes("typename " + parameterType + ", typename " + argumentType); // expands to " ,typename Param1, typename Arg1, ..." +Group typenameTypesWithTemplate("typename " + parameterType + ", typename " + argumentType); // expands to "typename Param1, typename Arg1, ..." +Group types(parameterType + ", " + argumentType); // expands to ", Param1, Arg1, ..." +Group functionParameters(constArgumentType + " " + argumentRef); +Group typenameArgumentTypes("typename " + argumentType); + +Group initializers(argument + "(" + argument + ")"); +Group classData(argumentType +" " + argument + ";"); +Group arglist(argument); +Group typeList(argumentTypes); + +void init() +{ + argumentTypes.setPrefix(", "); + arguments.setPrefix(", "); + parameterTypes.setPrefix(", "); + typenameTypes.setPrefix(", "); + typenameTypesWithTemplate.setPrefix("template <"); + typenameTypesWithTemplate.setPostfix(">"); + types.setPrefix(", "); + functionParameters.setPrefix(", "); + typenameArgumentTypes.setPrefix(", "); + + initializers.setPrefix(", "); + classData.setSeparator(" "); + classData.setPrefix(" "); + arglist.setPrefix(", "); + typeList.setPrefix(", "); +} + + +Item Line(Item item) +{ + return item + "\n"; +} + +Item generateBuildFunctions(int repeats) +{ + Item functionPointerType = "void (*)(" + parameterTypesNoPrefix + ")"; + + Item functionPointerParameter = "void (*functionPointer)(" + parameterTypesNoPrefix + ")"; + + Item stackSizeParameter = "int stackSize, "; + Item stackSizeArgument = "stackSize, "; + + + + // plain functions + Repeater functions = Line (typenameTypesWithTemplate) + + Line ("Coroutine* build(" + stackSizeParameter + functionPointerParameter + functionParameters + ")") + + Line("{") + + Line(" return new StoredFunctorCall" + Counter() + "<" + + functionPointerType + argumentTypes + ">(" + stackSizeArgument + "functionPointer" + arguments + ");") + + Line("}"); + functions.setRepeatCount(repeats); + + // function objects by value + Repeater functionObjects = Line ("template <typename FunctionObject" + typenameArgumentTypes + ">") + + Line ("Coroutine* build(" + stackSizeParameter + "FunctionObject functionObject" + functionParameters + ")") + + Line("{") + + Line(" return new StoredFunctorCall" + Counter() + + "<FunctionObject" + + argumentTypes + ">(" + stackSizeArgument + "functionObject" + arguments + ");") + + Line("}"); + functionObjects.setRepeatCount(repeats); + + // function objects by pointer + Repeater functionObjectsPointer = Line ("template <typename FunctionObject" + typenameArgumentTypes + ">") + + Line ("Coroutine* build(" + stackSizeParameter + "FunctionObject *functionObject" + functionParameters + ")") + + Line("{") + + Line(" return new StoredFunctorPointerCall" + Counter() + + "<FunctionObject" + + argumentTypes + ">(" + stackSizeArgument + "functionObject" + arguments + ");") + + Line("}"); + functionObjectsPointer.setRepeatCount(repeats); + + // member functions by value + Repeater memberFunction = Line ("template <typename Class" + typenameTypes + ">") + + Line ("Coroutine* build(" + stackSizeParameter + "const Class &object, void (Class::*fn)(" + parameterTypesNoPrefix + ")" + functionParameters + ")") + + Line("{") + + Line(" return new StoredMemberFunctionCall" + Counter() + + "<Class" + + types + ">(" + stackSizeArgument + "fn, object" + arguments + ");") + + Line("}"); + memberFunction.setRepeatCount(repeats); + + // const member functions by value + Repeater constMemberFunction = Line ("template <typename Class" + typenameTypes + ">") + + Line ("Coroutine *build(" + stackSizeParameter + "const Class &object, void (Class::*fn)(" + parameterTypesNoPrefix + ") const" + functionParameters + ")") + + Line("{") + + Line(" return new StoredConstMemberFunctionCall" + Counter() + + "<Class" + + types + ">(" + stackSizeArgument + "fn, object" + arguments + ");") + + Line("}"); + constMemberFunction.setRepeatCount(repeats); + + // member functions by class pointer + Repeater memberFunctionPointer = Line ("template <typename Class" + typenameTypes + ">") + + Line ("Coroutine* build(" + stackSizeParameter + "Class *object, void (Class::*fn)(" + parameterTypesNoPrefix + ")" + functionParameters + ")") + + Line("{") + + Line(" return new StoredMemberFunctionPointerCall" + Counter() + + "<Class" + + types + ">(" + stackSizeArgument + "fn, object" + arguments + ");") + + Line("}"); + memberFunctionPointer.setRepeatCount(repeats); + + // const member functions by class pointer + Repeater constMemberFunctionPointer = Line ("template <typename Class" + typenameTypes + ">") + + Line ("Coroutine* build(" + stackSizeParameter + "const Class *object, void (Class::*fn)(" + parameterTypesNoPrefix + ") const" + functionParameters + ")") + + Line("{") + + Line(" return new StoredConstMemberFunctionPointerCall" + Counter() + + "<Class" + + types + ">(" + stackSizeArgument + "fn, object" + arguments + ");") + + Line("}"); + constMemberFunctionPointer.setRepeatCount(repeats); + + + return functions + Line("") + functionObjects + Line("") + functionObjectsPointer + Line("") + + memberFunction + Line("") + constMemberFunction + Line("") + + memberFunctionPointer + Line("") + constMemberFunctionPointer + Line("") + ; +} + + +Item functions(Item className, Item functorType, Item callLine) +{ + return + Line("template <typename FunctionPointer" + typenameArgumentTypes + ">") + + Line("struct " + className + Counter() +": public Coroutine") + + Line("{") + + Line(" inline " + className + Counter() + "(int stackSize, " + functorType + " function" + functionParameters +")") + + Line(" : Coroutine(stackSize), function(function)" + initializers + " {}") + + Line("protected:") + + Line(" virtual void run() { " + callLine + argumentsNoPrefix + "); }") + + Line(" " + functorType + " function;") + + Line( classData) + + Line("};") + + Line(""); +} + +Item memberFunctions(Item className, Item constFunction, Item objectArgument, Item objectMember, Item callLine) +{ + return + Line("template <typename Class" + typenameTypes + ">") + + Line("class " + className + Counter() + " : public Coroutine") + + Line("{") + + Line("public:")+ + Line(" " + className + Counter() + "(int stackSize, void (Class::*fn)(" + parameterTypesNoPrefix + ") " + constFunction + ", " + objectArgument + functionParameters + ")") + + Line(" : Coroutine(stackSize), fn(fn), object(object)" + initializers + "{ }" ) + + Line("protected:") + + Line(" virtual void run()")+ + Line(" {")+ + Line(" " + callLine + argumentsNoPrefix + ");")+ + Line(" }")+ + Line("private:")+ + Line(" void (Class::*fn)(" + parameterTypesNoPrefix + ")" + constFunction + ";")+ + Line(" " + objectMember + ";") + + Line( classData) + + Line("};"); +} + +Item generateSFCs(int repeats) +{ + + Item functionPointerTypedef = "typedef void (*FunctionPointer)(" + argumentTypesNoPrefix + ");"; + + Repeater dataStructures = + + // Function objects by value + functions(Item("StoredFunctorCall"), Item("FunctionPointer"), Item("function(")) + + + // Function objects by pointer + functions(Item("StoredFunctorPointerCall"), Item("FunctionPointer *"), Item("(*function)(")) + + + // Member functions by value + memberFunctions(Item("StoredMemberFunctionCall"), Item(""), Item("const Class &object"), Item("Class object"), Item("(object.*fn)(")) + + + // Const Member functions by value + memberFunctions(Item("StoredConstMemberFunctionCall"), Item("const"), Item("const Class &object"), Item("const Class object"), Item("(object.*fn)(")) + + + // Member functions by pointer + memberFunctions(Item("StoredMemberFunctionPointerCall"), Item(""), Item("Class *object"), Item("Class *object"), Item("(object->*fn)(")) + + + // const member functions by pointer + memberFunctions(Item("StoredConstMemberFunctionPointerCall"), Item("const"), Item("Class const *object"), Item("Class const *object"), Item("(object->*fn)(")); + + dataStructures.setRepeatCount(repeats); + return dataStructures; +} + +void writeFile(QString fileName, QByteArray contents) +{ + QFile runFile(fileName); + if (runFile.open(QIODevice::WriteOnly) == false) { + qDebug() << "Write to" << fileName << "failed"; + return; + } + + runFile.write(contents); + runFile.close(); + qDebug() << "Write to" << fileName << "Ok"; +} + +Item dollarQuote(Item item) +{ + return Item("$") + item + Item("$"); +} + +int main() +{ + const int repeats = 6; + init(); + Item run = ( + Line("/****************************************************************************") + + Line("**") + + Line("** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).") + + Line("** Contact: Nokia Corporation (qt-info@nokia.com)") + + Line("**") + + Line("** This file is part of the Qt Toolkit.") + + Line("**") + + Line("****************************************************************************/") + + Line("") + + Line("// Generated code, do not edit! Use generator at tools/generatebuild/") + + Line("#ifndef COROUTINE_MAKE_H") + + Line("#define COROUTINE_MAKE_H") + + Line("") + + Line("#include \"coroutine.h\"") + + Line("#include \"coroutinestoredfunctioncall.h\"") + +// Line("") + +// Line("QT_BEGIN_HEADER") + +// Line("QT_BEGIN_NAMESPACE") + +// Line("") + +// Line("QT_MODULE(Core)") + + Line("") + + Line("#ifdef qdoc") + +// Line("") + +// Line("namespace Coroutine {") + + Line("") + + Line(" Coroutine* build(Function function, ...);") + +// Line("") + +// Line("} // namespace Coroutine") + + Line("") + + Line("#else") + +// Line("") + +// Line("namespace Coroutine {") + + Line("") + + generateBuildFunctions(repeats) + +// Line("") + +// Line("} //namespace Coroutine") + + Line("") + + Line("#endif // qdoc") + + Line("") + +// Line("QT_END_NAMESPACE") + +// Line("QT_END_HEADER") + +// Line("") + + Line("#endif") + ); + + writeFile("../../src/coroutinebuild.h", run.generate()); + + Item storedFunctionCall = ( + Line("/****************************************************************************") + + Line("**") + + Line("** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).") + + Line("** Contact: Nokia Corporation (qt-info@nokia.com)") + + Line("**") + + Line("** This file is part of the Qt Toolkit.") + + Line("**") + + Line("****************************************************************************/") + + Line("") + + Line("// Generated code, do not edit! Use generator at tools/generatebuild/") + + Line("#ifndef COROUTINE_STOREDFUNCTIONCALL_H") + + Line("#define COROUTINE_STOREDFUNCTIONCALL_H") + + Line("") + + Line("#include \"coroutine.h\"") + +// Line("#include <QtCore/qtconcurrentrunbase.h>") + +// Line("") + +// Line("QT_BEGIN_HEADER") + +// Line("QT_BEGIN_NAMESPACE") + +// Line("") + +// Line("QT_MODULE(Core)") + +// Line("") + + Line("#ifndef qdoc") + + Line("") + +// Line("namespace Coroutine {") + + generateSFCs(repeats) + +// Line("} //namespace Coroutine") + + Line("") + + Line("#endif // qdoc") + + Line("") + +// Line("QT_END_NAMESPACE") + +// Line("QT_END_HEADER") + +// Line("") + + Line("#endif") + ); + + writeFile("../../src/coroutinestoredfunctioncall.h", storedFunctionCall.generate()); +} + + diff --git a/tools/generatebuild/run.pro b/tools/generatebuild/run.pro new file mode 100644 index 0000000..76bc661 --- /dev/null +++ b/tools/generatebuild/run.pro @@ -0,0 +1,9 @@ +TEMPLATE = app +TARGET += +DEPENDPATH += . +INCLUDEPATH += . + +include(../codegenerator/codegenerator.pri) + +# Input +SOURCES += main.cpp |