Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pointer syntax for prospective output #989

Merged
merged 4 commits into from Aug 29, 2016
Merged

Conversation

codemercenary
Copy link
Contributor

@codemercenary codemercenary commented Aug 29, 2016

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();
}

@codemercenary codemercenary added this to the v1.0.4 milestone Aug 29, 2016
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:

```C++
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:

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

  *ppOutput = std::make_shared<MyOutputType>();
  **ppOutput = PerformExpensiveCalculation();
}
```
@gittyupagain gittyupagain merged commit a67b593 into master Aug 29, 2016
@gittyupagain gittyupagain deleted the feature-ptrarg branch August 29, 2016 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants