Panda3D
|
00001 // Filename: datagramIterator.h 00002 // Created by: jns (07Feb00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef DATAGRAMITERATOR_H 00016 #define DATAGRAMITERATOR_H 00017 00018 #include "pandabase.h" 00019 00020 #include "datagram.h" 00021 #include "numeric_types.h" 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Class : DatagramIterator 00025 // Description : A class to retrieve the individual data elements 00026 // previously stored in a Datagram. Elements may be 00027 // retrieved one at a time; it is up to the caller to 00028 // know the correct type and order of each element. 00029 //////////////////////////////////////////////////////////////////// 00030 class EXPCL_PANDAEXPRESS DatagramIterator { 00031 public: 00032 INLINE void assign(Datagram &datagram, size_t offset = 0); 00033 PUBLISHED: 00034 INLINE DatagramIterator(); 00035 INLINE DatagramIterator(const Datagram &datagram, size_t offset = 0); 00036 INLINE DatagramIterator(const DatagramIterator ©); 00037 INLINE void operator = (const DatagramIterator ©); 00038 INLINE ~DatagramIterator(); 00039 00040 INLINE bool get_bool(); 00041 INLINE PN_int8 get_int8(); 00042 INLINE PN_uint8 get_uint8(); 00043 00044 INLINE PN_int16 get_int16(); 00045 INLINE PN_int32 get_int32(); 00046 INLINE PN_int64 get_int64(); 00047 INLINE PN_uint16 get_uint16(); 00048 INLINE PN_uint32 get_uint32(); 00049 INLINE PN_uint64 get_uint64(); 00050 INLINE PN_float32 get_float32(); 00051 INLINE PN_float64 get_float64(); 00052 INLINE PN_stdfloat get_stdfloat(); 00053 00054 INLINE PN_int16 get_be_int16(); 00055 INLINE PN_int32 get_be_int32(); 00056 INLINE PN_int64 get_be_int64(); 00057 INLINE PN_uint16 get_be_uint16(); 00058 INLINE PN_uint32 get_be_uint32(); 00059 INLINE PN_uint64 get_be_uint64(); 00060 INLINE PN_float32 get_be_float32(); 00061 INLINE PN_float64 get_be_float64(); 00062 00063 string get_string(); 00064 string get_string32(); 00065 string get_z_string(); 00066 string get_fixed_string(size_t size); 00067 wstring get_wstring(); 00068 00069 INLINE void skip_bytes(size_t size); 00070 string extract_bytes(size_t size); 00071 00072 INLINE string get_remaining_bytes() const; 00073 INLINE int get_remaining_size() const; 00074 00075 INLINE const Datagram &get_datagram() const; 00076 INLINE size_t get_current_index() const; 00077 00078 void output(ostream &out) const; 00079 void write(ostream &out, unsigned int indent=0) const; 00080 00081 private: 00082 const Datagram *_datagram; 00083 size_t _current_index; 00084 }; 00085 00086 // These generic functions are primarily for reading a value from a 00087 // datagram from within a template in which the actual type of the 00088 // value is not known. If you do know the type, it's preferable to 00089 // use the explicit get_*() method from above instead. 00090 00091 INLINE void 00092 generic_read_datagram(bool &result, DatagramIterator &source); 00093 INLINE void 00094 generic_read_datagram(int &result, DatagramIterator &source); 00095 INLINE void 00096 generic_read_datagram(float &result, DatagramIterator &source); 00097 INLINE void 00098 generic_read_datagram(double &result, DatagramIterator &source); 00099 INLINE void 00100 generic_read_datagram(string &result, DatagramIterator &source); 00101 INLINE void 00102 generic_read_datagram(wstring &result, DatagramIterator &source); 00103 00104 #include "datagramIterator.I" 00105 00106 #endif