[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog libbase/Makefile.am libbase/Buf...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog libbase/Makefile.am libbase/Buf... |
Date: |
Wed, 11 Jun 2008 13:58:18 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 08/06/11 13:58:18
Modified files:
. : ChangeLog
libbase : Makefile.am
Added files:
libbase : Buffer.h
Log message:
* libbase/: Buffer.h, Makefile.am: add a generic Buffer class aimed
at unifying buffer types among the whole gnash lib.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6898&r2=1.6899
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/Makefile.am?cvsroot=gnash&r1=1.119&r2=1.120
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/Buffer.h?cvsroot=gnash&rev=1.1
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6898
retrieving revision 1.6899
diff -u -b -r1.6898 -r1.6899
--- ChangeLog 11 Jun 2008 12:10:53 -0000 1.6898
+++ ChangeLog 11 Jun 2008 13:58:16 -0000 1.6899
@@ -1,5 +1,10 @@
2008-06-11 Sandro Santilli <address@hidden>
+ * libbase/: Buffer.h, Makefile.am: add a generic Buffer class aimed
+ at unifying buffer types among the whole gnash lib.
+
+2008-06-11 Sandro Santilli <address@hidden>
+
* utilities/Makefile.am: add full AM_LDFLAGS to gprocessor, otherwise
only using the LDFLAGS explicitly put in overridden _LDFLAGS
automake variable (at least on some systems, reported on bug
Index: libbase/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/libbase/Makefile.am,v
retrieving revision 1.119
retrieving revision 1.120
diff -u -b -r1.119 -r1.120
--- libbase/Makefile.am 9 Jun 2008 20:53:49 -0000 1.119
+++ libbase/Makefile.am 11 Jun 2008 13:58:17 -0000 1.120
@@ -123,6 +123,7 @@
noinst_HEADERS = \
$(LIBLTDLHEAD) \
dlmalloc.h \
+ Buffer.h \
extension.h \
GnashException.h \
gettext.h \
Index: libbase/Buffer.h
===================================================================
RCS file: libbase/Buffer.h
diff -N libbase/Buffer.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libbase/Buffer.h 11 Jun 2008 13:58:18 -0000 1.1
@@ -0,0 +1,139 @@
+//
+// Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+#ifndef GNASH_BUFFER_H
+#define GNASH_BUFFER_H
+
+#ifdef HAVE_CONFIG_H
+#include "gnashconfig.h"
+#endif
+
+//#include "dsodefs.h" // for DSOEXPORT (not used)
+
+#include <cassert>
+#include <cstring> // for memcpy, should be changed to use std::copy
+#include <boost/scoped_array.hpp>
+
+namespace gnash {
+
+/// A simple buffer of bytes
+//
+/// This class is fully inlined and just aiming to provide RIIA
+/// and unified view of memory buffers.
+/// It is a kind of a std::vector with a reduced interface
+/// in the intentions of the author.
+///
+class Buffer {
+
+public:
+
+ /// Construct a Buffer with an optional initial size
+ Buffer(size_t size=0)
+ :
+ _data(0),
+ _size(size),
+ _capacity(size)
+ {
+ if ( _size ) _data = new boost::uint8_t[size];
+ }
+
+ ~Buffer()
+ {
+ delete _data;
+ }
+
+ /// Return true if buffer is empty
+ bool empty() const { return _size==0; }
+
+ /// Get a pointer to start of data. May be NULL if size==0.
+ boost::uint8_t* data() { return _data.get(); }
+
+ /// Get a pointer to start of data. May be NULL if size==0.
+ const boost::uint8_t* data() const { return _data; }
+
+ /// Resize the buffer
+ void resize(size_t newSize)
+ {
+ reserve(newSize); // will set capacity
+ _size = newSize;
+ }
+
+ /// Ensure at least 'newCapacity' bytes are allocated for this buffer
+ void reserve(size_t newCapacity)
+ {
+ if ( _capacity >= newCapacity ) return;
+
+ // TODO: use smalles power of 2 bigger then newCapacity
+ _capacity = std::max(newCapacity, _capacity*2);
+
+ boost::uint8_t* tmp = _data;
+ _data = new boost::uint8_t[_capacity];
+ if ( _size )
+ {
+ std::copy(_data, tmp, _size);
+ delete [] tmp;
+ }
+ }
+
+ /// Append data to the buffer
+ //
+ /// The buffer will be appropriately resized to have space for
+ /// the incoming data. The data will be copied.
+ ///
+ /// @param newData
+ /// Data to append. Will be copied.
+ ///
+ /// @param size
+ /// Size of data to append
+ ///
+ void append(const boost::uint8_t* newData, size_t size)
+ {
+ size_t curSize = _size;
+ resize(curSize+size);
+ std::copy(_data+curSize, newData, size);
+ assert(_size == curSize+size);
+ }
+
+ /// Append data to the buffer
+ //
+ /// The buffer will be appropriately resized to have space for
+ /// the incoming data. The data will be copied.
+ ///
+ /// @param newData
+ /// Buffer containing data to append
+ ///
+ void append(const Buffer& buf)
+ {
+ size_t incomingDataSize = buf.size();
+ const boost::uint8_t* incomingData = buf.data();
+ append(incomingData, incomingDataSize);
+ }
+
+private:
+
+ boost::uint8_t* _data;
+
+ size_t _size;
+ size_t _capacity;
+
+};
+
+
+} // namespace gnash
+
+#endif // GNASH_BUFFER_H
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog libbase/Makefile.am libbase/Buf...,
Sandro Santilli <=