ENUt

packet.h

Go to the documentation of this file.
00001 /*
00002     
00003   This file is a part of ENUt, a library containing network
00004   programming utilities.
00005   
00006   Copyright (C) 2006-2008  Hasselt University - Expertise Centre for
00007                       Digital Media (EDM) (http://www.edm.uhasselt.be)
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  
00022   USA
00023 
00024 */
00025 
00030 #ifndef NUT_PACKET_H
00031 
00032 #define NUT_PACKET_H
00033 
00034 #include "nutconfig.h"
00035 #include "nuttypes.h"
00036 
00037 namespace nut
00038 {
00039 
00041 class ENUT_IMPORTEXPORT Packet
00042 {
00043 public:
00045         Packet()                                                                        { m_pData = 0; m_length = 0; }
00046 
00055         Packet(uint8_t *pData, size_t length)                                           { m_pData = pData; m_length = length; }
00056 
00057         ~Packet()                                                                       { if (m_pData) delete [] m_pData; }
00058 
00067         void setData(uint8_t *pData, size_t length)                                     { if (m_pData) delete [] m_pData; m_pData = pData; m_length = length; }
00068 
00070         const uint8_t *getData() const                                                  { return m_pData; }
00071 
00073         size_t getLength() const                                                        { return m_length; }
00074 
00081         uint8_t *extractData(size_t &length)                                            { uint8_t *pData = m_pData; length = m_length; m_pData = 0; m_length = 0; return pData; }
00082 private:
00083         // Make sure we don't accidentally copy such objects
00084         Packet(const Packet &p)                                                         { }
00085         Packet &operator=(const Packet &p)                                              { return *this; }
00086 
00087         uint8_t *m_pData;
00088         size_t m_length;
00089 };
00090         
00091 } // end namespace
00092 
00093 #endif // NUT_PACKET_H
00094