Menu
Lumberyard
C++ API Reference (Version 1.10)

AZ::EBusReduceResult< T &, Aggregator > Struct Template Reference

Aggregates results returned by all handlers of an EBus event. More...

Public Member Functions

AZ_FORCE_INLINE EBusReduceResult (T &rhs, const Aggregator &aggregator=Aggregator())
 Creates an instance of the class, sets the reference to the initial value, and sets the function object to use as the aggregator. More...
 
AZ_FORCE_INLINE void operator= (const T &rhs)
 Overloads the assignment operator to aggregate a new value with the existing aggregated value. More...
 
AZ_FORCE_INLINE void operator= (T &rhs)
 Overloads the assignment operator to aggregate a new value with the existing aggregated value. More...
 
EBusReduceResultoperator= (const EBusReduceResult &)=delete
 Disallows copying an EBusReduceResult object by reference. More...
 

Public Attributes

T & value
 A reference to the current value, which new values will be aggregated with. More...
 
Aggregator unary
 The function object that aggregates a new value with an existing value. More...
 

Detailed Description

template<class T, class Aggregator>
struct AZ::EBusReduceResult< T &, Aggregator >

Aggregates results returned by all handlers of an EBus event.

Also puts the aggregated value into the input value that is passed by reference. You can use this structure to add results, apply a logical AND to results, and so on.

Template Parameters
TThe output type of the aggregator.
AggregatorA function object that aggregates results. The return type must match T. For examples of function objects that you can use as aggregators, see functional_basic.h.

The following example replaces the value returned by a handler with the sum of the value and previous handler return values.

int myExistingInt = 5;
EBusReduceResult<int&, AZStd::plus<int>> result(myExistingInt);
MyBus::BroadcastResult(result, &MyBus::Events::GetANumber);
AZ_Printf("%d", result.value); // or AZ_Printf("%d", myExistingInt);

The following example determines whether all handlers, including the latest handler, return true. Also replaces the latest handler result with the aggregated result.

bool myExistingBool = true;
EBusReduceResult<bool&, AZStd::logical_and<bool>> result(myExistingBool);
MyBus::BroadcastResult(result, &MyBus::Events::IsDoneDoingThing);
// myExistingBool is now only true if all handlers returned true.
AZ_Printf("%d", myExistingBool);

Constructor & Destructor Documentation

◆ EBusReduceResult()

template<class T , class Aggregator >
AZ_FORCE_INLINE AZ::EBusReduceResult< T &, Aggregator >::EBusReduceResult ( T &  rhs,
const Aggregator &  aggregator = Aggregator() 
)
inlineexplicit

Creates an instance of the class, sets the reference to the initial value, and sets the function object to use as the aggregator.

Parameters
rhsA reference to the initial value, which new values will be aggregated with.
aggregatorA function object to aggregate the values. For examples of function objects that you can use as aggregators, see functional_basic.h.

Member Function Documentation

◆ operator=() [1/3]

template<class T , class Aggregator >
AZ_FORCE_INLINE void AZ::EBusReduceResult< T &, Aggregator >::operator= ( const T &  rhs)
inline

Overloads the assignment operator to aggregate a new value with the existing aggregated value.

Parameters
rhsA reference to the value that will be aggregated with the existing aggregated value.

◆ operator=() [2/3]

template<class T , class Aggregator >
AZ_FORCE_INLINE void AZ::EBusReduceResult< T &, Aggregator >::operator= ( T &  rhs)
inline

Overloads the assignment operator to aggregate a new value with the existing aggregated value.

Parameters
rhsA reference to the value that will be aggregated with the existing aggregated value.

◆ operator=() [3/3]

template<class T , class Aggregator >
EBusReduceResult& AZ::EBusReduceResult< T &, Aggregator >::operator= ( const EBusReduceResult< T &, Aggregator > &  )
delete

Disallows copying an EBusReduceResult object by reference.

Member Data Documentation

◆ unary

template<class T , class Aggregator >
Aggregator AZ::EBusReduceResult< T &, Aggregator >::unary

The function object that aggregates a new value with an existing value.

◆ value

template<class T , class Aggregator >
T& AZ::EBusReduceResult< T &, Aggregator >::value

A reference to the current value, which new values will be aggregated with.


The documentation for this struct was generated from the following file:
  • C:/lumberyard-root/dev/Code/Framework/AzCore/AzCore/EBus/Results.h