SFML logo
  • Main Page
  • Namespaces
  • Classes
  • Files
  • File List

Selector.inl

00001 
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024 
00025 
00029 template <typename Type>
00030 void Selector<Type>::Add(Type socket)
00031 {
00032     if (socket.IsValid())
00033     {
00034         SelectorBase::Add(socket.mySocket);
00035         mySockets[socket.mySocket] = socket;
00036     }
00037 }
00038 
00039 
00043 template <typename Type>
00044 void Selector<Type>::Remove(Type socket)
00045 {
00046     typename SocketTable::iterator it = mySockets.find(socket.mySocket);
00047     if (it != mySockets.end())
00048     {
00049         SelectorBase::Remove(socket.mySocket);
00050         mySockets.erase(it);
00051     }
00052 }
00053 
00054 
00058 template <typename Type>
00059 void Selector<Type>::Clear()
00060 {
00061     SelectorBase::Clear();
00062     mySockets.clear();
00063 }
00064 
00065 
00071 template <typename Type>
00072 unsigned int Selector<Type>::Wait(float timeout)
00073 {
00074     // No socket in the selector : return 0
00075     if (mySockets.empty())
00076         return 0;
00077 
00078     return SelectorBase::Wait(timeout);
00079 }
00080 
00081 
00087 template <typename Type>
00088 Type Selector<Type>::GetSocketReady(unsigned int index) const
00089 {
00090     SocketHelper::SocketType socket = SelectorBase::GetSocketReady(index);
00091 
00092     typename SocketTable::const_iterator it = mySockets.find(socket);
00093     if (it != mySockets.end())
00094         return it->second;
00095     else
00096         return Type(socket);
00097 }

 ::  Copyright © 2007-2008 Laurent Gomila, all rights reserved  ::  Documentation generated by doxygen 1.5.2  ::