ndatastream.h

Go to the documentation of this file.
00001 // LICENSE: (Please see the file COPYING for details)
00002 //
00003 // NUS - Nemesis Utilities System: A C++ application development framework 
00004 // Copyright (C) 2006, 2008 Otavio Rodolfo Piske
00005 //
00006 //  This file is part of NUS
00007 //
00008 //  This library is free software; you can redistribute it and/or
00009 //  modify it under the terms of the GNU Lesser General Public
00010 //  License as published by the Free Software Foundation version 2.1
00011 //  of the License.
00012 //
00013 //  This library is distributed in the hope that it will be useful,
00014 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 //  Lesser General Public License for more details.
00017 //
00018 //  You should have received a copy of the GNU Lesser General Public
00019 //  License along with this library; if not, write to the Free Software
00020 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021 //
00022 #ifndef NDATASTREAM_H
00023 #define NDATASTREAM_H
00024 
00029 #include "ndefs.h"
00030 #include "nstring.h"
00031 #include "nbaseexceptions.h"
00032 #include "nmemutil.h"
00033 #include "noutput.h"
00034 
00038 class DllDeclSpec NDataStream {
00039       public:
00043             enum ByteOrder {
00044                   BIGENDIAN,        
00045                   LITTLEENDIAN      
00046             };
00047 
00051             NDataStream(void);
00055             NDataStream(const NDataStream &stream);
00056             
00061             NDataStream(const char *str);
00062             
00063             
00067             ~NDataStream(void);
00068 
00073             void setByteOrder(ByteOrder bo);
00074             
00079             ByteOrder getByteOrder(void) const;
00080 
00088             NDataStream &set(const void *src, nuint32 bytes) ;
00095             NDataStream &set(const char *str) ;
00102             NDataStream &set(const NString &str) ;
00108             NDataStream &set(const nint16 val);
00114             NDataStream &set(const nuint16 val);
00120             NDataStream &set(const nint32 val);
00126             NDataStream &set(const nuint32 val);
00132             NDataStream &set(const nint64 val);
00138             NDataStream &set(const nuint64 val);
00139 
00146             NDataStream &append(const char *str) ;
00153             NDataStream &append(const NString &str) ;
00161             NDataStream &append(const void *src, nuint32 bytes) ;
00167             NDataStream &append(const nint16 val);
00173             NDataStream &append(const nuint16 val);
00179             NDataStream &append(const nint32 val);
00185             NDataStream &append(const nuint32 val);
00191             NDataStream &append(const nint64 val);
00197             NDataStream &append(const nuint64 val);
00198 
00203             NString toString(void) const;
00209             NString toString(nuint32 size) const;
00216             NString toString(nuint32 start, nuint32 bytes) const ;
00217 
00222             unsigned char toChar(void) const;
00228             unsigned char toChar(nuint32 pos) const;
00229 
00234             nint16 toInt16(void) const;
00239             nint32 toInt32(void) const;
00244             nint64 toInt64(void) const;
00245             
00250             bool isNull(void) const;
00255             nuint32 size(void) const;
00256             
00261             const void *data(void) const;
00262 
00263 
00269             bool operator==(const NDataStream &rhs) const;
00270 
00276             bool operator!=(const NDataStream &rhs) const;
00277 
00283             NDataStream &operator=(const char *str) ;
00284             
00290             NDataStream &operator=(const NString &str) ;
00291             
00298             NDataStream &operator=(const NDataStream &str) ;
00304             NDataStream &operator=(const nint16 val);
00310             NDataStream &operator=(const nuint16 val);
00316             NDataStream &operator=(const nint32 val);
00322             NDataStream &operator=(const nuint32 val);
00328             NDataStream &operator=(const nint64 val);
00334             NDataStream &operator=(const nuint64 val);
00335 
00342             NDataStream &operator+=(const char *str) ;
00349             NDataStream &operator+=(const NString &str) ;
00356             NDataStream &operator+=(const NDataStream &str) ;
00362             NDataStream &operator+=(const nint16 val);
00368             NDataStream &operator+=(const nuint16 val);
00374             NDataStream &operator+=(const nint32 val);
00380             NDataStream &operator+=(const nuint32 val);
00386             NDataStream &operator+=(const nint64 val);
00392             NDataStream &operator+=(const nuint64 val);
00393 
00400             NDataStream operator+(const char *str) ;
00401 
00408             NDataStream operator+(const NString &str) ;
00415             NDataStream operator+(const NDataStream &str) ;
00421             NDataStream operator+(const nint16 val);
00427             NDataStream operator+(const nuint16 val);
00433             NDataStream operator+(const nint32 val);
00434 
00440             NDataStream operator+(const nuint32 val);
00446             NDataStream operator+(const nint64 val);
00452             NDataStream operator+(const nuint64 val);
00453 
00460             unsigned char operator[](nuint32 pos);
00461       
00462       private:
00463             ByteOrder m_bo;
00464             void *m_data;
00465             nuint32 m_used;
00466             nuint32 m_allocated;
00467 
00468             static const nuint32 ALLOC_SIZE;
00469 
00470             void realloc(nuint32 bytes);
00471 
00472             bool needsMemory(nuint32 bytes);
00473             nuint32 calculateBlocks(nuint32 bytes);
00474             nuint32 freeBytes(void) const;
00475             bool withinLimits(nuint32 start, nuint32 bytes) const;
00476             void memcopy(void *dest);
00477             
00478             template<typename T>
00479             NDataStream &set(T val);
00480 
00481             template<typename T>
00482             NDataStream &append(T val);
00483 
00484             template<typename T>
00485             T to(void) const;
00486 };
00487 
00488 #endif // NDATASTREAM_H

Generated on Wed Mar 5 23:10:35 2008 for NemesisUtilitiesSystem by  doxygen 1.5.4