GroupItem Class

class Tasking::GroupItem

GroupItem represents the basic element that may be a part of any Group. More...

Header: #include <solutions/tasking/tasktree.h>
Inherited By:

Tasking::ExecutableItem

Note: All functions in this class are reentrant.

Public Functions

GroupItem(const QList<Tasking::GroupItem> &items)
GroupItem(const Tasking::Storage<StorageStruct> &storage)
GroupItem(std::initializer_list<Tasking::GroupItem> items)

Detailed Description

GroupItem is a basic element that may be a part of any Group. It encapsulates the functionality provided by any GroupItem's subclass. It is a value type and it is safe to copy the GroupItem instance, even when it is originally created via the subclass' constructor.

There are four main kinds of GroupItem:

GroupItem KindBrief Description
CustomTaskDefines asynchronous task type and task's start, done, and error handlers. Aliased with a unique task name, such as, ConcurrentCallTask<ResultType> or NetworkQueryTask. Asynchronous tasks are the main reason for using a task tree.
GroupA container for other group items. Since the group is of the GroupItem type, it's possible to nest it inside another group. The group is seen by its parent as a single asynchronous task.
GroupItem containing StorageEnables the child tasks of a group to exchange data. When GroupItem containing Storage is placed inside a group, the task tree instantiates the storage's data object just before the group is entered, and destroys it just after the group is left.
Other group control itemsThe items returned by parallelLimit() or workflowPolicy() influence the group's behavior. The items returned by onGroupSetup() or onGroupDone() define custom handlers called when the group starts or ends execution.

Member Function Documentation

GroupItem::GroupItem(const QList<Tasking::GroupItem> &items)

Constructs a GroupItem element with a given list of items.

When this GroupItem element is parsed by the TaskTree, it is simply replaced with its items.

This constructor is useful when constructing a Group element with lists of GroupItem elements:

 static QList<GroupItems> getItems();

 ...

 const Group root {
     parallel,
     finishAllAndSuccess,
     getItems(), // OK, getItems() list is wrapped into a single GroupItem element
     onGroupSetup(...),
     onGroupDone(...)
 };

If you want to create a subtree, use Group instead.

Note: Don't confuse this GroupItem with the Group element, as Group keeps its children nested after being parsed by the task tree, while this GroupItem does not.

See also Group.

template <typename StorageStruct> GroupItem::GroupItem(const Tasking::Storage<StorageStruct> &storage)

Constructs a GroupItem element holding the storage object.

When the Group element containing this GroupItem is entered by the running task tree, an instance of the StorageStruct is created dynamically.

When that group is about to be left after its execution, the previously instantiated StorageStruct is deleted.

The dynamically created instance of StorageStruct is accessible from inside any handler body of the parent Group element, including nested groups and its tasks, via the Storage::operator->(), Storage::operator*(), or Storage::activeStorage() method.

See also Storage.

GroupItem::GroupItem(std::initializer_list<Tasking::GroupItem> items)

This is an overloaded function.

See also GroupItem(const QList<Tasking::GroupItem> &items).