Back to index

libsfml  1.6+dfsg2
Public Member Functions | Private Types | Private Attributes
sf::Selector< Type > Class Template Reference

Selector allow reading from multiple sockets without blocking. It's a kind of multiplexer /////////////////////////////////////////////////////////. More...

#include <Selector.hpp>

Collaboration diagram for sf::Selector< Type >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void Add (Type Socket)
 Add a socket to watch.
void Remove (Type Socket)
 Remove a socket.
void Clear ()
 Remove all sockets.
unsigned int Wait (float Timeout=0.f)
 Wait and collect sockets which are ready for reading. This functions will return either when at least one socket is ready, or when the given time is out.
Type GetSocketReady (unsigned int Index)
 After a call to Wait(), get the Index-th socket which is ready for reading. The total number of sockets ready is the integer returned by the previous call to Wait()

Private Types

typedef std::map
< SocketHelper::SocketType,
Type > 
SocketTable

Private Attributes

SocketTable mySockets
 Table matching the SFML socket instances with their low-level handles.

Detailed Description

template<typename Type>
class sf::Selector< Type >

Selector allow reading from multiple sockets without blocking. It's a kind of multiplexer /////////////////////////////////////////////////////////.

Definition at line 44 of file Selector.hpp.


Member Typedef Documentation

template<typename Type >
typedef std::map<SocketHelper::SocketType, Type> sf::Selector< Type >::SocketTable [private]

Definition at line 99 of file Selector.hpp.


Member Function Documentation

template<typename Type >
void Selector::Add ( Type  Socket)

Add a socket to watch.

Add a socket to watch /////////////////////////////////////////////////////////.

Parameters:
Socket: Socket to add

/////////////////////////////////////////////////////////

Definition at line 30 of file Selector.inl.

{
    if (Socket.IsValid())
    {
        SelectorBase::Add(Socket.mySocket);
        mySockets[Socket.mySocket] = Socket;
    }
}
template<typename Type >
void Selector::Clear ( )

Remove all sockets.

Remove all sockets /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 59 of file Selector.inl.

template<typename Type >
Type Selector::GetSocketReady ( unsigned int  Index)

After a call to Wait(), get the Index-th socket which is ready for reading. The total number of sockets ready is the integer returned by the previous call to Wait()

After a call to Wait(), get the Index-th socket which is ready for reading. The total number of sockets ready is the integer returned by the previous call to Wait() /////////////////////////////////////////////////////////.

Parameters:
Index: Index of the socket to get
Returns:
The Index-th socket

/////////////////////////////////////////////////////////

Definition at line 88 of file Selector.inl.

{
    SocketHelper::SocketType Socket = SelectorBase::GetSocketReady(Index);

    typename SocketTable::const_iterator It = mySockets.find(Socket);
    if (It != mySockets.end())
        return It->second;
    else
        return Type(Socket);
}
template<typename Type >
void Selector::Remove ( Type  Socket)

Remove a socket.

Remove a socket /////////////////////////////////////////////////////////.

Parameters:
Socket: Socket to remove

/////////////////////////////////////////////////////////

Definition at line 44 of file Selector.inl.

{
    typename SocketTable::iterator It = mySockets.find(Socket.mySocket);
    if (It != mySockets.end())
    {
        SelectorBase::Remove(Socket.mySocket);
        mySockets.erase(It);
    }
}
template<typename Type >
unsigned int Selector::Wait ( float  Timeout = 0.f)

Wait and collect sockets which are ready for reading. This functions will return either when at least one socket is ready, or when the given time is out.

Wait and collect sockets which are ready for reading. This functions will return either when at least one socket is ready, or when the given time is out /////////////////////////////////////////////////////////.

Parameters:
Timeout: Timeout, in seconds (0 by default : no timeout)
Returns:
Number of sockets ready to be read

/////////////////////////////////////////////////////////

Definition at line 72 of file Selector.inl.

{
    // No socket in the selector : return 0
    if (mySockets.empty())
        return 0;

    return SelectorBase::Wait(Timeout);
}

Member Data Documentation

template<typename Type >
SocketTable sf::Selector< Type >::mySockets [private]

Table matching the SFML socket instances with their low-level handles.

Definition at line 104 of file Selector.hpp.


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