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

Packet.hpp

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 #ifndef SFML_PACKET_HPP
00026 #define SFML_PACKET_HPP
00027 
00029 // Headers
00031 #include <SFML/Config.hpp>
00032 #include <string>
00033 #include <vector>
00034 
00035 
00036 namespace sf
00037 {
00038 class String;
00039 class TcpSocket;
00040 class UdpSocket;
00041 
00047 class SFML_API Packet
00048 {
00049     // A bool-like type that cannot be converted to integer or pointer types
00050     typedef bool (Packet::*BoolType)(std::size_t);
00051 
00052 public :
00053 
00060     Packet();
00061 
00066     virtual ~Packet();
00067 
00077     void Append(const void* data, std::size_t sizeInBytes);
00078 
00087     void Clear();
00088 
00102     const char* GetData() const;
00103 
00115     std::size_t GetDataSize() const;
00116 
00129     bool EndOfPacket() const;
00130 
00131 public:
00132 
00171     operator BoolType() const;
00172 
00177     Packet& operator >>(bool&         data);
00178     Packet& operator >>(Int8&         data);
00179     Packet& operator >>(Uint8&        data);
00180     Packet& operator >>(Int16&        data);
00181     Packet& operator >>(Uint16&       data);
00182     Packet& operator >>(Int32&        data);
00183     Packet& operator >>(Uint32&       data);
00184     Packet& operator >>(float&        data);
00185     Packet& operator >>(double&       data);
00186     Packet& operator >>(char*         data);
00187     Packet& operator >>(std::string&  data);
00188     Packet& operator >>(wchar_t*      data);
00189     Packet& operator >>(std::wstring& data);
00190     Packet& operator >>(String&       data);
00191 
00196     Packet& operator <<(bool                data);
00197     Packet& operator <<(Int8                data);
00198     Packet& operator <<(Uint8               data);
00199     Packet& operator <<(Int16               data);
00200     Packet& operator <<(Uint16              data);
00201     Packet& operator <<(Int32               data);
00202     Packet& operator <<(Uint32              data);
00203     Packet& operator <<(float               data);
00204     Packet& operator <<(double              data);
00205     Packet& operator <<(const char*         data);
00206     Packet& operator <<(const std::string&  data);
00207     Packet& operator <<(const wchar_t*      data);
00208     Packet& operator <<(const std::wstring& data);
00209     Packet& operator <<(const String&       data);
00210 
00211 private :
00212 
00213     friend class TcpSocket;
00214     friend class UdpSocket;
00215 
00220     bool operator ==(const Packet& right) const;
00221     bool operator !=(const Packet& right) const;
00222 
00233     bool CheckSize(std::size_t size);
00234 
00253     virtual const char* OnSend(std::size_t& size);
00254 
00270     virtual void OnReceive(const char* data, std::size_t size);
00271 
00273     // Member data
00275     std::vector<char> myData;    
00276     std::size_t       myReadPos; 
00277     bool              myIsValid; 
00278 };
00279 
00280 } // namespace sf
00281 
00282 
00283 #endif // SFML_PACKET_HPP
00284 
00285 

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