Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
packetmem.h
Go to the documentation of this file.
1 #ifndef PACKETMEM_H
2 #define PACKETMEM_H
3 
4 #include <sys/types.h>
5 #include <iostream>
6 
7 #include "vsnet_debug.h"
8 #include "networking/const.h"
9 
10 #include "boost/shared_array.hpp"
11 
12 /***********************************************************************
13  * PacketMem - declaration
14  ***********************************************************************/
15 
16 class PacketMem
17 {
19 
20 public:
21  LOCALCONST_DECL(bool,TakeOwnership,1)
22  LOCALCONST_DECL(bool,LeaveOwnership,0)
23 
24 private:
25  typedef boost::shared_array<char> ptr;
26 
27  ptr _buffer;
28  size_t _len;
29 
30 public:
31  PacketMem( );
32  PacketMem( const PacketMem& );
33  PacketMem( size_t bytesize );
34 
36  PacketMem( const void* buffer, size_t size );
37 
41  PacketMem( void* buffer, size_t size, bool own );
42 
43  ~PacketMem( );
44 
45  void set( void* buffer, size_t size, bool own );
46 
47  size_t len() const;
48  char* getVarBuf( );
49  const char* getConstBuf( ) const;
50 
54  void dump( std::ostream& ostr, size_t indent_depth ) const;
55 
56  PacketMem& operator=( const PacketMem& );
57 
58  bool operator==( const PacketMem& orig ) const;
59 
60 private:
61  void release( );
62  void inner_set( void* buffer, size_t size, bool own );
63 };
64 
65 #endif
66