Panda3D
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 class EXPCL_PANDA_EXPRESS DatagramIterator {
28 public:
29  INLINE void assign(Datagram &datagram, size_t offset = 0);
30 
31 PUBLISHED:
32  INLINE DatagramIterator();
33  INLINE DatagramIterator(const Datagram &datagram, size_t offset = 0);
34 
35  INLINE bool get_bool();
36  INLINE int8_t get_int8();
37  INLINE uint8_t get_uint8();
38 
39  INLINE int16_t get_int16();
40  INLINE int32_t get_int32();
41  INLINE int64_t get_int64();
42  INLINE uint16_t get_uint16();
43  INLINE uint32_t get_uint32();
44  INLINE uint64_t get_uint64();
45  INLINE PN_float32 get_float32();
46  INLINE PN_float64 get_float64();
47  INLINE PN_stdfloat get_stdfloat();
48 
49  INLINE int16_t get_be_int16();
50  INLINE int32_t get_be_int32();
51  INLINE int64_t get_be_int64();
52  INLINE uint16_t get_be_uint16();
53  INLINE uint32_t get_be_uint32();
54  INLINE uint64_t get_be_uint64();
55  INLINE PN_float32 get_be_float32();
56  INLINE PN_float64 get_be_float64();
57 
58  std::string get_string();
59  std::string get_string32();
60  std::string get_z_string();
61  std::string get_fixed_string(size_t size);
62  std::wstring get_wstring();
63 
64  INLINE vector_uchar get_blob();
65  INLINE vector_uchar get_blob32();
66 
67  INLINE void skip_bytes(size_t size);
68  vector_uchar extract_bytes(size_t size);
69  size_t extract_bytes(unsigned char *into, size_t size);
70 
71  INLINE vector_uchar get_remaining_bytes() const;
72  INLINE size_t get_remaining_size() const;
73 
74  INLINE const Datagram &get_datagram() const;
75  INLINE size_t get_current_index() const;
76 
77  void output(std::ostream &out) const;
78  void write(std::ostream &out, unsigned int indent=0) const;
79 
80 private:
81  const Datagram *_datagram;
82  size_t _current_index;
83 
84 public:
85  static TypeHandle get_class_type() {
86  return _type_handle;
87  }
88  static void init_type() {
89  register_type(_type_handle, "DatagramIterator");
90  }
91 
92 private:
93  static TypeHandle _type_handle;
94 };
95 
96 // These generic functions are primarily for reading a value from a datagram
97 // from within a template in which the actual type of the value is not known.
98 // If you do know the type, it's preferable to use the explicit get_*() method
99 // from above instead.
100 
101 INLINE void
102 generic_read_datagram(bool &result, DatagramIterator &source);
103 INLINE void
104 generic_read_datagram(int &result, DatagramIterator &source);
105 INLINE void
106 generic_read_datagram(float &result, DatagramIterator &source);
107 INLINE void
108 generic_read_datagram(double &result, DatagramIterator &source);
109 INLINE void
110 generic_read_datagram(std::string &result, DatagramIterator &source);
111 INLINE void
112 generic_read_datagram(std::wstring &result, DatagramIterator &source);
113 
114 #include "datagramIterator.I"
115 
116 #endif
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(),...
Definition: register_type.I:22
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.
A class to retrieve the individual data elements previously stored in a Datagram.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38