leapmotion / autowiring

A C++ Inversion of Control Framework
http://autowiring.io/
Apache License 2.0
148 stars 17 forks source link

Add pointer syntax for prospective output #989

Closed codemercenary closed 8 years ago

codemercenary commented 8 years ago

Now filters can detect whether there is at least one subscriber downstream to consume a produced decoration. This is done by accepting the argument as a pointer, and performing a simple null check. An example filter is as follows:

void MyType::AutoFilter(MyOutputType* pOutput) {
  if(!pOutput)
    return;

  *pOutput = PerformExpensiveCalculation();
}

The pointer will be specified as null if there are no filters downstream. The filter can choose to return early if the input argument is null, satisfy other output arguments, or to update local members as needed.

If a shared pointer or control over allocation is desired, the pointer-to-shared-pointer syntax may be used instead:

void MyType::AutoFilter(std::shared_ptr<MyOutputType>* ppOutput) {
  if (!ppOutput)
    return;

  *ppOutput = std::make_shared<MyOutputType>();
  **ppOutput = PerformExpensiveCalculation();
}