Panda3D

Loading...
Searching...
No Matches
datagramIterator.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file datagramIterator.h
10 * @author jns
11 * @date 2000-02-07
12 */
13
14#ifndef DATAGRAMITERATOR_H
15#define DATAGRAMITERATOR_H
16
17#include "pandabase.h"
18
19#include "datagram.h"
20#include "numeric_types.h"
21
22/**
23 * A class to retrieve the individual data elements previously stored in a
24 * Datagram. Elements may be retrieved one at a time; it is up to the caller
25 * to know the correct type and order of each element.
26 *
27 * Note that it is the responsibility of the caller to ensure that the datagram
28 * object is not destructed while this DatagramIterator is in use.
29 */
30 class EXPCL_PANDA_EXPRESS DatagramIterator {
31 public:
32 INLINE void assign(Datagram &datagram, size_t offset = 0);
33
34PUBLISHED:
35 INLINE DatagramIterator();
36 INLINE DatagramIterator(const Datagram &datagram, size_t offset = 0);
37
38 INLINE bool get_bool();
39 INLINE int8_t get_int8();
40 INLINE uint8_t get_uint8();
41
42 INLINE int16_t get_int16();
43 INLINE int32_t get_int32();
44 INLINE int64_t get_int64();
45 INLINE uint16_t get_uint16();
46 INLINE uint32_t get_uint32();
47 INLINE uint64_t get_uint64();
48 INLINE PN_float32 get_float32();
49 INLINE PN_float64 get_float64();
50 INLINE PN_stdfloat get_stdfloat();
51
52 INLINE int16_t get_be_int16();
53 INLINE int32_t get_be_int32();
54 INLINE int64_t get_be_int64();
55 INLINE uint16_t get_be_uint16();
56 INLINE uint32_t get_be_uint32();
57 INLINE uint64_t get_be_uint64();
58 INLINE PN_float32 get_be_float32();
59 INLINE PN_float64 get_be_float64();
60
61 std::string get_string();
62 std::string get_string32();
63 std::string get_z_string();
64 std::string get_fixed_string(size_t size);
65 std::wstring get_wstring();
66
67 INLINE vector_uchar get_blob();
68 INLINE vector_uchar get_blob32();
69
70 INLINE void skip_bytes(size_t size);
71 vector_uchar extract_bytes(size_t size);
72 size_t extract_bytes(unsigned char *into, size_t size);
73
74 INLINE vector_uchar get_remaining_bytes() const;
75 INLINE size_t get_remaining_size() const;
76
77 INLINE const Datagram &get_datagram() const;
78 INLINE size_t get_current_index() const;
79
80 void output(std::ostream &out) const;
81 void write(std::ostream &out, unsigned int indent=0) const;
82
83 private:
84 const Datagram *_datagram;
85 size_t _current_index;
86
87 public:
88 static TypeHandle get_class_type() {
89 return _type_handle;
90 }
91 static void init_type() {
92 register_type(_type_handle, "DatagramIterator");
93 }
94
95 private:
96 static TypeHandle _type_handle;
97};
98
99// These generic functions are primarily for reading a value from a datagram
100// from within a template in which the actual type of the value is not known.
101// If you do know the type, it's preferable to use the explicit get_*() method
102// from above instead.
103
104INLINE void
105generic_read_datagram(bool &result, DatagramIterator &source);
106INLINE void
107generic_read_datagram(int &result, DatagramIterator &source);
108INLINE void
109generic_read_datagram(float &result, DatagramIterator &source);
110INLINE void
111generic_read_datagram(double &result, DatagramIterator &source);
112INLINE void
113generic_read_datagram(std::string &result, DatagramIterator &source);
114INLINE void
115generic_read_datagram(std::wstring &result, DatagramIterator &source);
116
117#include "datagramIterator.I"
118
119#endif
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition datagramIterator.h:30
DatagramIterator::skip_bytes
void skip_bytes(size_t size)
Skips over the indicated number of bytes in the datagram.
Definition datagramIterator.I:423
DatagramIterator::get_uint8
uint8_t get_uint8()
Extracts an unsigned 8-bit integer.
Definition datagramIterator.I:72
DatagramIterator::get_float32
PN_float32 get_float32()
Extracts a 32-bit single-precision floating-point number.
Definition datagramIterator.I:202
DatagramIterator::assign
void assign(Datagram &datagram, size_t offset=0)
direct Assignment to a Datagram
Definition datagramIterator.I:37
DatagramIterator::get_blob32
vector_uchar get_blob32()
Extracts a variable-length binary blob with a 32-bit size field.
Definition datagramIterator.I:415
DatagramIterator::get_be_uint16
uint16_t get_be_uint16()
Extracts an unsigned 16-bit big-endian integer.
Definition datagramIterator.I:312
DatagramIterator::get_int16
int16_t get_int16()
Extracts a signed 16-bit integer.
Definition datagramIterator.I:88
DatagramIterator::get_be_uint32
uint32_t get_be_uint32()
Extracts an unsigned 32-bit big-endian integer.
Definition datagramIterator.I:331
DatagramIterator::get_be_int32
int32_t get_be_int32()
Extracts a signed 32-bit big-endian integer.
Definition datagramIterator.I:274
DatagramIterator::get_z_string
std::string get_z_string()
Extracts a variable-length string, as a NULL-terminated string.
Definition datagramIterator.cxx:64
DatagramIterator::get_uint64
uint64_t get_uint64()
Extracts an unsigned 64-bit integer.
Definition datagramIterator.I:183
DatagramIterator::get_stdfloat
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
Definition datagramIterator.I:242
DatagramIterator::get_uint16
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
Definition datagramIterator.I:145
DatagramIterator::get_be_float32
PN_float32 get_be_float32()
Extracts a 32-bit big-endian single-precision floating-point number.
Definition datagramIterator.I:369
DatagramIterator::get_int64
int64_t get_int64()
Extracts a signed 64-bit integer.
Definition datagramIterator.I:126
DatagramIterator::get_wstring
std::wstring get_wstring()
Extracts a variable-length wstring (with a 32-bit length field).
Definition datagramIterator.cxx:104
DatagramIterator::extract_bytes
vector_uchar extract_bytes(size_t size)
Extracts the indicated number of bytes in the datagram and returns them as a string.
Definition datagramIterator.cxx:126
DatagramIterator::get_uint32
uint32_t get_uint32()
Extracts an unsigned 32-bit integer.
Definition datagramIterator.I:164
DatagramIterator::get_remaining_bytes
vector_uchar get_remaining_bytes() const
Returns the remaining bytes in the datagram as a string, but does not extract them from the iterator.
Definition datagramIterator.I:442
DatagramIterator::write
void write(std::ostream &out, unsigned int indent=0) const
Write a string representation of this instance to <out>.
Definition datagramIterator.cxx:172
DatagramIterator::get_int8
int8_t get_int8()
Extracts a signed 8-bit integer.
Definition datagramIterator.I:56
DatagramIterator::get_float64
PN_float64 get_float64()
Extracts a 64-bit floating-point number.
Definition datagramIterator.I:221
DatagramIterator::get_be_uint64
uint64_t get_be_uint64()
Extracts an unsigned 64-bit big-endian integer.
Definition datagramIterator.I:350
DatagramIterator::get_bool
bool get_bool()
Extracts a boolean value.
Definition datagramIterator.I:48
DatagramIterator::get_fixed_string
std::string get_fixed_string(size_t size)
Extracts a fixed-length string.
Definition datagramIterator.cxx:87
DatagramIterator::get_string
std::string get_string()
Extracts a variable-length string.
Definition datagramIterator.cxx:26
DatagramIterator::get_be_float64
PN_float64 get_be_float64()
Extracts a 64-bit big-endian floating-point number.
Definition datagramIterator.I:388
DatagramIterator::get_be_int16
int16_t get_be_int16()
Extracts a signed 16-bit big-endian integer.
Definition datagramIterator.I:255
DatagramIterator::output
void output(std::ostream &out) const
Write a string representation of this instance to <out>.
Definition datagramIterator.cxx:162
DatagramIterator::get_datagram
const Datagram & get_datagram() const
Return the datagram of this iterator.
Definition datagramIterator.I:462
DatagramIterator::get_string32
std::string get_string32()
Extracts a variable-length string with a 32-bit length field.
Definition datagramIterator.cxx:45
DatagramIterator::get_int32
int32_t get_int32()
Extracts a signed 32-bit integer.
Definition datagramIterator.I:107
DatagramIterator::get_blob
vector_uchar get_blob()
Extracts a variable-length binary blob.
Definition datagramIterator.I:407
DatagramIterator::get_current_index
size_t get_current_index() const
Returns the current position within the datagram of the next piece of data to extract.
Definition datagramIterator.I:471
DatagramIterator::get_be_int64
int64_t get_be_int64()
Extracts a signed 64-bit big-endian integer.
Definition datagramIterator.I:293
DatagramIterator::get_remaining_size
size_t get_remaining_size() const
Return the bytes left in the datagram.
Definition datagramIterator.I:454
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
datagramIterator.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
datagram.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
indent
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
numeric_types.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition register_type.I:22