Skip to content

state_populating

Dmitry Koplyarov edited this page May 17, 2016 · 7 revisions

Back to reference

A policy that defines how the populators and withdrawers work.

namespace state_populating
{
	struct populator_only;
	struct populator_and_withdrawer;
	struct none;
}

Table of contents

Supplied policies

populator_only

A signal holds a populator std::function, which is invoked when connecting to a signal.
This is a default policy because you usually need a populator in mutithreaded code and rarely need a withdrawer. It is also an acceptable choice for a single-threaded code because the overhead is not that large.

populator_and_withdrawer

A signal holds both populator and withdrawer std::functions, that are invoked when connecting to and disconnecting from a signal.

none

An empty policy. Best if you don't need state populating (e.g. in single-threaded environment) because it has no overhead.

How to implement your own policy

struct my_state_populating
{
	using tag = wigwag::state_populating::tag<wigwag::api_version<2, 0>>;

	template < typename HandlerType_ >
	struct handler_processor
	{
		bool has_populate_state() const { /*...*/ }
		void populate_state(const HandlerType_& handler) const { /*...*/ }

		bool has_withdraw_state() const { /*...*/ }
		void withdraw_state(const HandlerType_& handler) const { /*...*/ }
	};
};

Required nested types

tag

using tag = wigwag::state_populating::tag<wigwag::api_version<2, 0>>;

The policy tag. Must be a type alias for wigwag::state_populating::tag<wigwag::api_version<2, 0>>.

handler_processor

template < typename HandlerType_ >
struct handler_processor;

A handler_processor object is stored inside a signal.

Template arguments:

  • HandlerType_ - the type of a handler (std::function<Signature_> for signal, ListenerType_ for listenable)

Required methods in handler_processor nested class

has_populate_state

bool has_populate_state() const;

Used to determine whether the populate_state method should be invoked

Return value: false if the populate_state method invokation may be omitted, true otherwise

populate_state

void populate_state(const HandlerType_& handler) const;

Invoked when a handler is being connected to a signal

Arguments:

  • handler - the handler

has_withdraw_state

bool has_withdraw_state() const;

Used to determine whether the withdraw_state method should be invoked

Return value: false if the withdraw_state method invokation may be omitted, true otherwise

withdraw_state

void withdraw_state(const HandlerType_& handler) const;

Invoked when a handler is being disconnected from a signal

Arguments:

  • handler - the handler

Clone this wiki locally