Skip to content
Dmitry Koplyarov edited this page Apr 9, 2017 · 14 revisions

Back to reference

A RAII class for managing generic resource ownership. Used for holding signal/listenable connections in wigwag library.
Here is the tutorial section.

Defined in wigwag/token.hpp

class token
{
public:
	token(token&& other);
	~token();

	token& operator = (token&& other);

	token(const token&) = delete;
	token& operator = (const token&) = delete;

	void reset();
};

Table of contents

Constructors and destructors

move constructor

token(token&& other);

Just an ordinary move constructor. Nothing special.

copy constructor

token(const token&) = delete;

The copy constructor is prohibited.

destructor

~token();

Resets a token object if it hasn't been reset before.
Releases the associated resource (e.g. signal connection).

Methods

reset

void reset();

Resets a token object if it hasn't been reset before.
Releases the associated resource (e.g. signal connection).

Thread safety: This is NOT a thread-safe method. If you assign to a token from one thread, and reset it from another, you should guard the token with a mutex or something else.

Operators

operator =

(1)
token& operator = (const token&) = delete;

(2)
token& operator = (token&&);

(1)
The copy assignment operator is prohibited

(2)
The move assignment operator resets the token object, and then moves the resource ownership from another one

Thread safety: (2) is NOT a thread-safe method. If you assign to a token from different threads, you should guard the token with a mutex or something else.

Clone this wiki locally