Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/express/datagram.h

Go to the documentation of this file.
00001 // Filename: datagram.h
00002 // Created by:  drose (06Jun00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef DATAGRAM_H
00020 #define DATAGRAM_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "numeric_types.h"
00025 #include "typedObject.h"
00026 #include "littleEndian.h"
00027 #include "bigEndian.h"
00028 #include "pta_uchar.h"
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //       Class : Datagram
00032 // Description : An ordered list of data elements, formatted in memory
00033 //               for transmission over a socket or writing to a data
00034 //               file.
00035 //
00036 //               Data elements should be added one at a time, in
00037 //               order, to the Datagram.  The nature and contents of
00038 //               the data elements are totally up to the user.  When a
00039 //               Datagram has been transmitted and received, its data
00040 //               elements may be extracted using a DatagramIterator;
00041 //               it is up to the caller to know the correct type of
00042 //               each data element in order.
00043 //
00044 //               A Datagram is itself headerless; it is simply a
00045 //               collection of data elements.
00046 ////////////////////////////////////////////////////////////////////
00047 class EXPCL_PANDAEXPRESS Datagram : public TypedObject {
00048 PUBLISHED:
00049   INLINE Datagram();
00050   INLINE Datagram(const void *data, size_t size);
00051   INLINE Datagram(const string &data);
00052   INLINE Datagram(const Datagram &copy);
00053   INLINE void operator = (const Datagram &copy);
00054 
00055   virtual ~Datagram();
00056 
00057   virtual void clear();
00058   void dump_hex(ostream &out) const;
00059 
00060   INLINE void add_bool(bool value);
00061   INLINE void add_int8(PN_int8 value);
00062   INLINE void add_uint8(PN_uint8 value);
00063 
00064   // The default numeric packing is little-endian.
00065   INLINE void add_int16(PN_int16 value);
00066   INLINE void add_int32(PN_int32 value);
00067   INLINE void add_int64(PN_int64 value);
00068   INLINE void add_uint16(PN_uint16 value);
00069   INLINE void add_uint32(PN_uint32 value);
00070   INLINE void add_uint64(PN_uint64 value);
00071   INLINE void add_float32(float value);
00072   INLINE void add_float64(PN_float64 value);
00073 
00074   // These functions pack numbers big-endian, in case that's desired.
00075   INLINE void add_be_int16(PN_int16 value);
00076   INLINE void add_be_int32(PN_int32 value);
00077   INLINE void add_be_int64(PN_int64 value);
00078   INLINE void add_be_uint16(PN_uint16 value);
00079   INLINE void add_be_uint32(PN_uint32 value);
00080   INLINE void add_be_uint64(PN_uint64 value);
00081   INLINE void add_be_float32(float value);
00082   INLINE void add_be_float64(PN_float64 value);
00083 
00084   INLINE void add_string(const string &str);
00085   INLINE void add_z_string(string str);
00086   INLINE void add_fixed_string(const string &str, size_t size);
00087 
00088   void pad_bytes(size_t size);
00089   void append_data(const void *data, size_t size);
00090   INLINE void append_data(const string &data);
00091 
00092   INLINE string get_message() const;
00093   INLINE const void *get_data() const;
00094   INLINE size_t get_length() const;
00095 
00096   INLINE bool operator == (const Datagram &other) const;
00097   INLINE bool operator != (const Datagram &other) const;
00098   INLINE bool operator < (const Datagram &other) const;
00099 
00100 private:
00101   PTA_uchar _data;
00102 
00103 
00104 public:
00105   static TypeHandle get_class_type() {
00106     return _type_handle;
00107   }
00108   static void init_type() {
00109     TypedObject::init_type();
00110     register_type(_type_handle, "Datagram",
00111                   TypedObject::get_class_type());
00112   }
00113   virtual TypeHandle get_type() const {
00114     return get_class_type();
00115   }
00116   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00117 
00118 private:
00119   static TypeHandle _type_handle;
00120 };
00121 
00122 #include "datagram.I"
00123 
00124 #endif

Generated on Fri May 2 00:38:21 2003 for Panda by doxygen1.3