El Octavio  1.0
This is a video game about adventures.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sf::ThreadLocalPtr< T > Class Template Reference

Pointer to a thread-local variable. More...

#include <ThreadLocalPtr.hpp>

+ Inheritance diagram for sf::ThreadLocalPtr< T >:
+ Collaboration diagram for sf::ThreadLocalPtr< T >:

Public Member Functions

 ThreadLocalPtr (T *value=NULL)
 Default constructor. More...
 
T & operator* () const
 Overload of unary operator *. More...
 
T * operator-> () const
 Overload of operator -> More...
 
 operator T* () const
 Conversion operator to implicitly convert the pointer to its raw pointer type (T*) More...
 
ThreadLocalPtr< T > & operator= (T *value)
 Assignment operator for a raw pointer parameter. More...
 
ThreadLocalPtr< T > & operator= (const ThreadLocalPtr< T > &right)
 Assignment operator for a ThreadLocalPtr parameter. More...
 

Detailed Description

template<typename T>
class sf::ThreadLocalPtr< T >

Pointer to a thread-local variable.

sf::ThreadLocalPtr is a type-safe wrapper for storing pointers to thread-local variables.

A thread-local variable holds a different value for each different thread, unlike normal variables that are shared.

Its usage is completely transparent, so that it is similar to manipulating the raw pointer directly (like any smart pointer).

Usage example:

MyClass object1;
MyClass object2;
void thread1()
{
objectPtr = &object1; // doesn't impact thread2
...
}
void thread2()
{
objectPtr = &object2; // doesn't impact thread1
...
}
int main()
{
// Create and launch the two threads
sf::Thread t1(&thread1);
sf::Thread t2(&thread2);
t1.launch();
t2.launch();
return 0;
}
int main()
Definition: Main.cpp:6
Utility class to manipulate threads.
Definition: Thread.hpp:49
Pointer to a thread-local variable.

ThreadLocalPtr is designed for internal use; however you can use it if you feel like it fits well your implementation.

Definition at line 41 of file ThreadLocalPtr.hpp.

Constructor & Destructor Documentation

◆ ThreadLocalPtr()

template<typename T >
sf::ThreadLocalPtr< T >::ThreadLocalPtr ( T *  value = NULL)

Default constructor.

Parameters
valueOptional value to initialize the variable

Definition at line 30 of file ThreadLocalPtr.inl.

Member Function Documentation

◆ operator T*()

template<typename T >
sf::ThreadLocalPtr< T >::operator T*

Conversion operator to implicitly convert the pointer to its raw pointer type (T*)

Returns
Pointer to the actual object

Definition at line 54 of file ThreadLocalPtr.inl.

◆ operator*()

template<typename T >
T & sf::ThreadLocalPtr< T >::operator*

Overload of unary operator *.

Like raw pointers, applying the * operator returns a reference to the pointed-to object.

Returns
Reference to the thread-local variable

Definition at line 38 of file ThreadLocalPtr.inl.

◆ operator->()

template<typename T >
T * sf::ThreadLocalPtr< T >::operator->

Overload of operator ->

Similarly to raw pointers, applying the -> operator returns the pointed-to object.

Returns
Pointer to the thread-local variable

Definition at line 46 of file ThreadLocalPtr.inl.

◆ operator=() [1/2]

template<typename T >
ThreadLocalPtr< T > & sf::ThreadLocalPtr< T >::operator= ( const ThreadLocalPtr< T > &  right)

Assignment operator for a ThreadLocalPtr parameter.

Parameters
rightThreadLocalPtr to assign
Returns
Reference to self

Definition at line 71 of file ThreadLocalPtr.inl.

◆ operator=() [2/2]

template<typename T >
ThreadLocalPtr< T > & sf::ThreadLocalPtr< T >::operator= ( T *  value)

Assignment operator for a raw pointer parameter.

Parameters
valuePointer to assign
Returns
Reference to self

Definition at line 62 of file ThreadLocalPtr.inl.


The documentation for this class was generated from the following files: