แก้ไข

แชร์ผ่าน


transformer Class

A transformer messaging block is a single-target, multi-source, ordered propagator_block which can accept messages of one type and is capable of storing an unbounded number of messages of a different type.

Syntax

template<class _Input, class _Output>
class transformer : public propagator_block<single_link_registry<ITarget<_Output>>,
    multi_link_registry<ISource<_Input>>>;

Parameters

_Input
The payload type of the messages accepted by the buffer.

_Output
The payload type of the messages stored and propagated out by the buffer.

Members

Public Constructors

Name Description
transformer Overloaded. Constructs a transformer messaging block.
~transformer Destructor Destroys the transformer messaging block.

Protected Methods

Name Description
accept_message Accepts a message that was offered by this transformer messaging block, transferring ownership to the caller.
consume_message Consumes a message previously offered by the transformer and reserved by the target, transferring ownership to the caller.
link_target_notification A callback that notifies that a new target has been linked to this transformer messaging block.
propagate_message Asynchronously passes a message from an ISource block to this transformer messaging block. It is invoked by the propagate method, when called by a source block.
propagate_to_any_targets Executes the transformer function on the input messages.
release_message Releases a previous message reservation. (Overrides source_block::release_message.)
reserve_message Reserves a message previously offered by this transformer messaging block. (Overrides source_block::reserve_message.)
resume_propagation Resumes propagation after a reservation has been released. (Overrides source_block::resume_propagation.)
send_message Synchronously passes a message from an ISource block to this transformer messaging block. It is invoked by the send method, when called by a source block.
supports_anonymous_source Overrides the supports_anonymous_source method to indicate that this block can accept messages offered to it by a source that is not linked. (Overrides ITarget::supports_anonymous_source.)

Remarks

For more information, see Asynchronous Message Blocks.

Inheritance Hierarchy

ISource

ITarget

source_block

propagator_block

transformer

Requirements

Header: agents.h

Namespace: concurrency

accept_message

Accepts a message that was offered by this transformer messaging block, transferring ownership to the caller.

virtual message<_Output>* accept_message(runtime_object_identity _MsgId);

Parameters

_MsgId
The runtime_object_identity of the offered message object.

Return Value

A pointer to the message object that the caller now has ownership of.

consume_message

Consumes a message previously offered by the transformer and reserved by the target, transferring ownership to the caller.

virtual message<_Output>* consume_message(runtime_object_identity _MsgId);

Parameters

_MsgId
The runtime_object_identity of the message object being consumed.

Return Value

A pointer to the message object that the caller now has ownership of.

Remarks

Similar to accept, but is always preceded by a call to reserve.

A callback that notifies that a new target has been linked to this transformer messaging block.

virtual void link_target_notification(_Inout_ ITarget<_Output> *);

propagate_message

Asynchronously passes a message from an ISource block to this transformer messaging block. It is invoked by the propagate method, when called by a source block.

virtual message_status propagate_message(
    _Inout_ message<_Input>* _PMessage,
    _Inout_ ISource<_Input>* _PSource);

Parameters

_PMessage
A pointer to the message object.

_PSource
A pointer to the source block offering the message.

Return Value

A message_status indication of what the target decided to do with the message.

propagate_to_any_targets

Executes the transformer function on the input messages.

virtual void propagate_to_any_targets(_Inout_opt_ message<_Output> *);

release_message

Releases a previous message reservation.

virtual void release_message(runtime_object_identity _MsgId);

Parameters

_MsgId
The runtime_object_identity of the message object being released.

reserve_message

Reserves a message previously offered by this transformer messaging block.

virtual bool reserve_message(runtime_object_identity _MsgId);

Parameters

_MsgId
The runtime_object_identity of the message object being reserved.

Return Value

true if the message was successfully reserved, false otherwise.

Remarks

After reserve is called, if it returns true, either consume or release must be called to either take or release ownership of the message.

resume_propagation

Resumes propagation after a reservation has been released.

virtual void resume_propagation();

send_message

Synchronously passes a message from an ISource block to this transformer messaging block. It is invoked by the send method, when called by a source block.

virtual message_status send_message(
    _Inout_ message<_Input>* _PMessage,
    _Inout_ ISource<_Input>* _PSource);

Parameters

_PMessage
A pointer to the message object.

_PSource
A pointer to the source block offering the message.

Return Value

A message_status indication of what the target decided to do with the message.

supports_anonymous_source

Overrides the supports_anonymous_source method to indicate that this block can accept messages offered to it by a source that is not linked.

virtual bool supports_anonymous_source();

Return Value

true because the block does not postpone offered messages.

transformer

Constructs a transformer messaging block.

transformer(
    _Transform_method const& _Func,
    _Inout_opt_ ITarget<_Output>* _PTarget = NULL);

transformer(
    _Transform_method const& _Func,
    _Inout_opt_ ITarget<_Output>* _PTarget,
    filter_method const& _Filter);

transformer(
    Scheduler& _PScheduler,
    _Transform_method const& _Func,
    _Inout_opt_ ITarget<_Output>* _PTarget = NULL);

transformer(
    Scheduler& _PScheduler,
    _Transform_method const& _Func,
    _Inout_opt_ ITarget<_Output>* _PTarget,
    filter_method const& _Filter);

transformer(
    ScheduleGroup& _PScheduleGroup,
    _Transform_method const& _Func,
    _Inout_opt_ ITarget<_Output>* _PTarget = NULL);

transformer(
    ScheduleGroup& _PScheduleGroup,
    _Transform_method const& _Func,
    _Inout_opt_ ITarget<_Output>* _PTarget,
    filter_method const& _Filter);

Parameters

_Func
A function that will be invoked for each accepted message.

_PTarget
A pointer to a target block to link with the transformer.

_Filter
A filter function which determines whether offered messages should be accepted.

_PScheduler
The Scheduler object within which the propagation task for the transformer messaging block is scheduled.

_PScheduleGroup
The ScheduleGroup object within which the propagation task for the transformer messaging block is scheduled. The Scheduler object used is implied by the schedule group.

Remarks

The runtime uses the default scheduler if you do not specify the _PScheduler or _PScheduleGroup parameters.

The type _Transform_method is a functor with signature _Output (_Input const &) which is invoked by this transformer messaging block to process a message.

The type filter_method is a functor with signature bool (_Input const &) which is invoked by this transformer messaging block to determine whether or not it should accept an offered message.

~transformer

Destroys the transformer messaging block.

~transformer();

See also

concurrency Namespace
call Class