Simple and Fast Multimedia Library
Documentation for SFML 2.0
Initializing search
SFML
Home
Learn
Tutorials
Documentation
Download
Community
Development
Donate
Simple and Fast Multimedia Library
Home
Learn
Tutorials
Documentation
Documentation
SFML 3.1.0
SFML 3.0.2
SFML 3.0.1
SFML 3.0.0
SFML 2.6.2
SFML 2.6.1
SFML 2.6.0
SFML 2.5.1
SFML 2.5.0
SFML 2.4.2
SFML 2.4.1
SFML 2.4.0
SFML 2.3.2
SFML 2.3.1
SFML 2.3
SFML 2.2
SFML 2.1
SFML 2.0
SFML 1.6
Download
Community
Development
Warning
This page refers to an old version of SFML.
Click here to switch to the latest version.
Main Page
Topics
Namespaces
Classes
Files
File List
File Members
Loading...
Searching...
No Matches
SFML
include
SFML
Network
Packet.hpp
Go to the documentation of this file.
1
2
//
3
// SFML - Simple and Fast Multimedia Library
4
// Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
5
//
6
// This software is provided 'as-is', without any express or implied warranty.
7
// In no event will the authors be held liable for any damages arising from the use of this software.
8
//
9
// Permission is granted to anyone to use this software for any purpose,
10
// including commercial applications, and to alter it and redistribute it freely,
11
// subject to the following restrictions:
12
//
13
// 1. The origin of this software must not be misrepresented;
14
// you must not claim that you wrote the original software.
15
// If you use this software in a product, an acknowledgment
16
// in the product documentation would be appreciated but is not required.
17
//
18
// 2. Altered source versions must be plainly marked as such,
19
// and must not be misrepresented as being the original software.
20
//
21
// 3. This notice may not be removed or altered from any source distribution.
22
//
24
25
#ifndef SFML_PACKET_HPP
26
#define SFML_PACKET_HPP
27
29
// Headers
31
#include <
SFML/Network/Export.hpp
>
32
#include <string>
33
#include <vector>
34
35
36
namespace
sf
37
{
38
class
String
;
39
class
TcpSocket
;
40
class
UdpSocket
;
41
47
class
SFML_NETWORK_API
Packet
48
{
49
// A bool-like type that cannot be converted to integer or pointer types
50
typedef
bool (
Packet
::*BoolType)(std::size_t);
51
52
public :
53
60
Packet
();
61
66
virtual
~Packet
();
67
77
void
append
(
const
void
* data, std::size_t sizeInBytes);
78
87
void
clear
();
88
102
const
void
*
getData
()
const
;
103
115
std::size_t
getDataSize
()
const
;
116
129
bool
endOfPacket
()
const
;
130
131
public
:
132
171
operator
BoolType()
const
;
172
177
Packet
& operator >>(
bool
& data);
178
Packet
& operator >>(
Int8
& data);
179
Packet
& operator >>(
Uint8
& data);
180
Packet
& operator >>(
Int16
& data);
181
Packet
& operator >>(
Uint16
& data);
182
Packet
& operator >>(
Int32
& data);
183
Packet
& operator >>(
Uint32
& data);
184
Packet
& operator >>(
float
& data);
185
Packet
& operator >>(
double
& data);
186
Packet
& operator >>(
char
* data);
187
Packet
& operator >>(std::string& data);
188
Packet
& operator >>(
wchar_t
* data);
189
Packet
& operator >>(std::wstring& data);
190
Packet
& operator >>(
String
& data);
191
196
Packet
& operator <<(
bool
data);
197
Packet
& operator <<(
Int8
data);
198
Packet
& operator <<(
Uint8
data);
199
Packet
& operator <<(
Int16
data);
200
Packet
& operator <<(
Uint16
data);
201
Packet
& operator <<(
Int32
data);
202
Packet
& operator <<(
Uint32
data);
203
Packet
& operator <<(
float
data);
204
Packet
& operator <<(
double
data);
205
Packet
& operator <<(
const
char
* data);
206
Packet
& operator <<(
const
std::string& data);
207
Packet
& operator <<(
const
wchar_t
* data);
208
Packet
& operator <<(
const
std::wstring& data);
209
Packet
& operator <<(
const
String
& data);
210
211
protected
:
212
213
friend
class
TcpSocket
;
214
friend
class
UdpSocket
;
215
234
virtual
const
void
*
onSend
(std::size_t& size);
235
253
virtual
void
onReceive
(
const
void
* data, std::size_t size);
254
255
private :
256
261
bool
operator ==(
const
Packet
& right)
const
;
262
bool
operator !=(
const
Packet
& right)
const
;
263
274
bool
checkSize(std::size_t size);
275
277
// Member data
279
std::vector<char> m_data;
280
std::size_t m_readPos;
281
bool
m_isValid;
282
};
283
284
}
// namespace sf
285
286
287
#endif
// SFML_PACKET_HPP
288
289
Export.hpp
SFML_NETWORK_API
#define SFML_NETWORK_API
Definition
Network/Export.hpp:43
sf::Packet::getDataSize
std::size_t getDataSize() const
Get the size of the data contained in the packet.
sf::Packet::clear
void clear()
Clear the packet.
sf::Packet::endOfPacket
bool endOfPacket() const
Tell if the reading position has reached the end of the packet.
sf::Packet::Packet
Packet()
Default constructor.
sf::Packet::append
void append(const void *data, std::size_t sizeInBytes)
Append data to the end of the packet.
sf::Packet::getData
const void * getData() const
Get a pointer to the data contained in the packet.
sf::Packet::TcpSocket
friend class TcpSocket
Definition
Packet.hpp:213
sf::Packet::onReceive
virtual void onReceive(const void *data, std::size_t size)
Called after the packet is received over the network.
sf::Packet::~Packet
virtual ~Packet()
Virtual destructor.
sf::Packet::UdpSocket
friend class UdpSocket
Definition
Packet.hpp:214
sf::Packet::onSend
virtual const void * onSend(std::size_t &size)
Called before the packet is sent over the network.
sf::String
Utility string class that automatically handles conversions between types and encodings.
Definition
String.hpp:44
sf::TcpSocket
Specialized socket using the TCP protocol.
Definition
TcpSocket.hpp:47
sf::UdpSocket
Specialized socket using the UDP protocol.
Definition
UdpSocket.hpp:46
sf
Definition
Listener.hpp:36
sf::Uint16
unsigned short Uint16
Definition
Config.hpp:141
sf::Int16
signed short Int16
Definition
Config.hpp:140
sf::Uint8
unsigned char Uint8
Definition
Config.hpp:137
sf::Int8
signed char Int8
Definition
Config.hpp:136
sf::Uint32
unsigned int Uint32
Definition
Config.hpp:145
sf::Int32
signed int Int32
Definition
Config.hpp:144
Back to top