Panda3D

datagramIterator.h

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 &copy);
00037   INLINE void operator = (const DatagramIterator &copy);
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 float get_float32();
00051   INLINE PN_float64 get_float64();
00052 
00053   INLINE PN_int16 get_be_int16();
00054   INLINE PN_int32 get_be_int32();
00055   INLINE PN_int64 get_be_int64();
00056   INLINE PN_uint16 get_be_uint16();
00057   INLINE PN_uint32 get_be_uint32();
00058   INLINE PN_uint64 get_be_uint64();
00059   INLINE float get_be_float32();
00060   INLINE PN_float64 get_be_float64();
00061 
00062   string get_string();
00063   string get_string32();
00064   string get_z_string();
00065   string get_fixed_string(size_t size);
00066   wstring get_wstring();
00067 
00068   INLINE void skip_bytes(size_t size);
00069   string extract_bytes(size_t size);
00070 
00071   INLINE string get_remaining_bytes() const;
00072   INLINE int get_remaining_size() const;
00073 
00074   INLINE const Datagram &get_datagram() const;
00075   INLINE size_t get_current_index() const;
00076 
00077   void output(ostream &out) const;
00078   void write(ostream &out, unsigned int indent=0) const;
00079 
00080 private:
00081   const Datagram *_datagram;
00082   size_t _current_index;
00083 };
00084 
00085 // These generic functions are primarily for reading a value from a
00086 // datagram from within a template in which the actual type of the
00087 // value is not known.  If you do know the type, it's preferable to
00088 // use the explicit get_*() method from above instead.
00089 
00090 INLINE void
00091 generic_read_datagram(bool &result, DatagramIterator &source);
00092 INLINE void
00093 generic_read_datagram(int &result, DatagramIterator &source);
00094 INLINE void
00095 generic_read_datagram(float &result, DatagramIterator &source);
00096 INLINE void
00097 generic_read_datagram(double &result, DatagramIterator &source);
00098 INLINE void
00099 generic_read_datagram(string &result, DatagramIterator &source);
00100 INLINE void
00101 generic_read_datagram(wstring &result, DatagramIterator &source);
00102 
00103 #include "datagramIterator.I"
00104 
00105 #endif
 All Classes Functions Variables Enumerations