SFML logo
  • Main Page
  • Namespaces
  • 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 
00043 class SFML_API Packet
00044 {
00045 public :
00046 
00051     Packet();
00052 
00057     virtual ~Packet();
00058 
00066     void Append(const void* data, std::size_t sizeInBytes);
00067 
00072     void Clear();
00073 
00082     const char* GetData() const;
00083 
00090     std::size_t GetDataSize() const;
00091 
00098     bool EndOfPacket() const;
00099 
00106     operator bool() const;
00107 
00112     Packet& operator >>(bool&         data);
00113     Packet& operator >>(Int8&         data);
00114     Packet& operator >>(Uint8&        data);
00115     Packet& operator >>(Int16&        data);
00116     Packet& operator >>(Uint16&       data);
00117     Packet& operator >>(Int32&        data);
00118     Packet& operator >>(Uint32&       data);
00119     Packet& operator >>(float&        data);
00120     Packet& operator >>(double&       data);
00121     Packet& operator >>(char*         data);
00122     Packet& operator >>(std::string&  data);
00123     Packet& operator >>(wchar_t*      data);
00124     Packet& operator >>(std::wstring& data);
00125     Packet& operator >>(String&       data);
00126 
00131     Packet& operator <<(bool                data);
00132     Packet& operator <<(Int8                data);
00133     Packet& operator <<(Uint8               data);
00134     Packet& operator <<(Int16               data);
00135     Packet& operator <<(Uint16              data);
00136     Packet& operator <<(Int32               data);
00137     Packet& operator <<(Uint32              data);
00138     Packet& operator <<(float               data);
00139     Packet& operator <<(double              data);
00140     Packet& operator <<(const char*         data);
00141     Packet& operator <<(const std::string&  data);
00142     Packet& operator <<(const wchar_t*      data);
00143     Packet& operator <<(const std::wstring& data);
00144     Packet& operator <<(const String&       data);
00145 
00146 private :
00147 
00148     friend class SocketTCP;
00149     friend class SocketUDP;
00150 
00159     bool CheckSize(std::size_t size);
00160 
00169     virtual const char* OnSend(std::size_t& dataSize);
00170 
00178     virtual void OnReceive(const char* data, std::size_t dataSize);
00179 
00181     // Member data
00183     std::vector<char> myData;    
00184     std::size_t       myReadPos; 
00185     bool              myIsValid; 
00186 };
00187 
00188 } // namespace sf
00189 
00190 
00191 #endif // SFML_PACKET_HPP

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