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 */
30class EXPCL_PANDA_EXPRESS DatagramIterator {
31public:
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
83private:
84 const Datagram *_datagram;
85 size_t _current_index;
86
87public:
88 static TypeHandle get_class_type() {
89 return _type_handle;
90 }
91 static void init_type() {
92 register_type(_type_handle, "DatagramIterator");
93 }
94
95private:
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
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...