[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r10700: Move generic structs to thei
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r10700: Move generic structs to their own header file so they can be used more |
Date: |
Sat, 14 Mar 2009 00:25:00 +0100 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 10700
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Sat 2009-03-14 00:25:00 +0100
message:
Move generic structs to their own header file so they can be used more
widely. Add some (respectable) template hackery to make using
boost::checked_deleter easier on containers of pointers (i.e. without
specifying the pointed-to type); and because it's done a lot add a
templated function that deletes all pointers in any standard container
of pointers.
added:
libbase/GnashAlgorithm.h
modified:
libbase/Makefile.am
libcore/MovieClip.cpp
libcore/asobj/LoadableObject.cpp
libcore/asobj/NetConnection_as.cpp
libcore/asobj/NetStream_as.cpp
libcore/movie_root.cpp
libcore/parser/SWFMovieDefinition.cpp
libcore/parser/sprite_definition.cpp
libcore/swf/DefineButtonTag.cpp
libcore/swf/DefineTextTag.cpp
libcore/swf/DefineVideoStreamTag.cpp
libcore/swf/PlaceObject2Tag.cpp
libmedia/FLVParser.cpp
------------------------------------------------------------
revno: 10694.1.2
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Fri 2009-03-13 23:11:38 +0100
message:
Move more or less generic algorithms into their own file. Extend boost's
checked_deleter so that we can pass pointers as a template argument, which
helps with generic programming (or rather with refactoring Gnash).
added:
libbase/GnashAlgorithm.h
modified:
libbase/Makefile.am
libcore/swf/DefineTextTag.cpp
libcore/swf/DefineVideoStreamTag.cpp
libcore/swf/PlaceObject2Tag.cpp
libmedia/FLVParser.cpp
------------------------------------------------------------
revno: 10694.1.3
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Fri 2009-03-13 23:46:37 +0100
message:
Use checked deleter everywhere.
modified:
libbase/GnashAlgorithm.h
libcore/MovieClip.cpp
libcore/asobj/LoadableObject.cpp
libcore/asobj/NetConnection_as.cpp
libcore/asobj/NetStream_as.cpp
libcore/movie_root.cpp
libcore/parser/SWFMovieDefinition.cpp
libcore/parser/sprite_definition.cpp
libcore/swf/DefineButtonTag.cpp
libcore/swf/DefineVideoStreamTag.cpp
libcore/swf/PlaceObject2Tag.cpp
=== added file 'libbase/GnashAlgorithm.h'
--- a/libbase/GnashAlgorithm.h 1970-01-01 00:00:00 +0000
+++ b/libbase/GnashAlgorithm.h 2009-03-13 22:46:37 +0000
@@ -0,0 +1,106 @@
+// GnashAlgorithm.h: Moderately useful functors for generic algorithms
+//
+// Copyright (C) 2007, 2008, 2009 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_ALGORITHM_H
+#define GNASH_ALGORITHM_H
+
+#include <algorithm>
+#include <boost/checked_delete.hpp>
+
+namespace gnash {
+
+/// Retrieve the second element of a container with std::pairs.
+template<typename T>
+struct SecondElement
+{
+ typedef typename T::second_type result_type;
+
+ const result_type& operator()(const T& pair) const {
+ return pair.second;
+ }
+};
+
+/// Return a pointer to a type
+template<typename T>
+struct CreatePointer
+{
+ const T* operator()(const T& t) {
+ return &t;
+ }
+};
+
+/// Recurse to the base type of a pointer.
+template<typename T>
+struct RemovePointer
+{
+ typedef T value_type;
+};
+
+template<typename T>
+struct RemovePointer<T*>
+{
+ typedef typename RemovePointer<T>::value_type value_type;
+};
+
+/// Delete a pointer safely
+//
+/// Any depth of pointers-to-pointers (up to maximum template recursion) can
+/// be passed to this struct. The type of the pointee is deduced and passed
+/// to boost::checked_deleter, which ensures that the type is fully known
+/// at the point of deletion. It does not, of course, check that the pointer
+/// was allocated with new, so this isn't completely idiot-proof.
+template<typename T>
+struct CheckedDeleter
+{
+};
+
+template<typename T>
+struct CheckedDeleter<T**>
+{
+ typedef typename CheckedDeleter<T*>::value_type value_type;
+
+ void operator()(T** p) const {
+ CheckedDeleter<T*> del;
+ dp(*p);
+ }
+};
+
+template<typename T>
+struct CheckedDeleter<T*>
+{
+ typedef T* value_type;
+ void operator()(value_type p) const {
+
+ typename boost::template checked_deleter<
+ typename RemovePointer<T>::value_type> del;
+ del(p);
+ }
+};
+
+template<typename T>
+void
+deleteAllChecked(const T& c)
+{
+ std::for_each(c.begin(), c.end(), CheckedDeleter<typename
T::value_type>());
+}
+
+} // namespace gnash
+
+#endif
+
=== modified file 'libbase/Makefile.am'
--- a/libbase/Makefile.am 2009-03-13 18:05:33 +0000
+++ b/libbase/Makefile.am 2009-03-13 23:25:00 +0000
@@ -174,6 +174,7 @@
getclocktime.hpp \
Point2d.h \
Range2d.h \
+ GnashAlgorithm.h \
snappingrange.h \
$(NULL)
=== modified file 'libcore/MovieClip.cpp'
--- a/libcore/MovieClip.cpp 2009-03-10 20:43:50 +0000
+++ b/libcore/MovieClip.cpp 2009-03-13 22:46:37 +0000
@@ -42,6 +42,7 @@
#include "VM.h"
#include "Range2d.h" // for getBounds
#include "GnashException.h"
+#include "GnashAlgorithm.h"
#include "URL.h"
#include "sound_handler.h"
#include "StreamProvider.h"
@@ -518,11 +519,7 @@
_vm.getRoot().remove_key_listener(this);
_vm.getRoot().remove_mouse_listener(this);
- for (LoadVariablesThreads::iterator it=_loadVariableRequests.begin();
- it != _loadVariableRequests.end(); ++it)
- {
- delete *it;
- }
+ deleteAllChecked(_loadVariableRequests);
}
// Execute the actions in the action list, in the given
=== modified file 'libcore/asobj/LoadableObject.cpp'
--- a/libcore/asobj/LoadableObject.cpp 2009-02-10 15:38:43 +0000
+++ b/libcore/asobj/LoadableObject.cpp 2009-03-13 22:46:37 +0000
@@ -29,6 +29,7 @@
#include "timers.h"
#include "utf8.h"
#include "fn_call.h"
+#include "GnashAlgorithm.h"
#include <sstream>
#include <map>
@@ -53,12 +54,8 @@
LoadableObject::~LoadableObject()
{
- for (LoadThreadList::iterator it = _loadThreads.begin(),
- e = _loadThreads.end(); it != e; ++it)
- {
- // Joins the thread
- delete *it;
- }
+
+ deleteAllChecked(_loadThreads);
if ( _loadCheckerTimer )
{
=== modified file 'libcore/asobj/NetConnection_as.cpp'
--- a/libcore/asobj/NetConnection_as.cpp 2009-02-10 11:33:38 +0000
+++ b/libcore/asobj/NetConnection_as.cpp 2009-03-13 22:46:37 +0000
@@ -39,18 +39,15 @@
#include "builtin_function.h"
#include "movie_root.h"
#include "Object.h" // for getObjectInterface
-
#include "StreamProvider.h"
#include "URLAccessManager.h"
#include "URL.h"
-
-// for NetConnection_as.call()
#include "VM.h"
#include "amf.h"
#include "SimpleBuffer.h"
#include "timers.h"
#include "namedStrings.h"
-
+#include "GnashAlgorithm.h"
//#define GNASH_DEBUG_REMOTING
@@ -718,12 +715,7 @@
// here to have HTTPRemotingHandler definition available
NetConnection_as::~NetConnection_as()
{
- for (std::list<ConnectionHandler*>::iterator
- i=_queuedConnections.begin(), e=_queuedConnections.end();
- i!=e; ++i)
- {
- delete *i;
- }
+ deleteAllChecked(_queuedConnections);
}
=== modified file 'libcore/asobj/NetStream_as.cpp'
--- a/libcore/asobj/NetStream_as.cpp 2009-02-11 21:58:37 +0000
+++ b/libcore/asobj/NetStream_as.cpp 2009-03-13 22:46:37 +0000
@@ -37,7 +37,7 @@
#include "VM.h"
#include "namedStrings.h"
#include "movie_root.h"
-
+#include "GnashAlgorithm.h"
#include "VirtualClock.h" // for PlayHead
#include "SystemClock.h"
@@ -1610,11 +1610,9 @@
BufferedAudioStreamer::cleanAudioQueue()
{
boost::mutex::scoped_lock lock(_audioQueueMutex);
- for (AudioQueue::iterator i=_audioQueue.begin(), e=_audioQueue.end();
- i!=e; ++i)
- {
- delete *i;
- }
+
+ deleteAllChecked(_audioQueue);
+
_audioQueue.clear();
}
=== modified file 'libcore/movie_root.cpp'
--- a/libcore/movie_root.cpp 2009-03-12 10:14:31 +0000
+++ b/libcore/movie_root.cpp 2009-03-13 22:46:37 +0000
@@ -36,6 +36,7 @@
#include "timers.h" // for Timer use
#include "GnashKey.h" // key::code
#include "gnash.h"
+#include "GnashAlgorithm.h"
#include <boost/algorithm/string/replace.hpp>
#include <utility>
@@ -149,12 +150,8 @@
for (int lvl=0; lvl<apSIZE; ++lvl)
{
ActionQueue& q = _actionQueue[lvl];
- for (ActionQueue::iterator it=q.begin(),
- itE=q.end();
- it != itE; ++it)
- {
- delete *it;
- }
+
+ deleteAllChecked(q);
q.clear();
}
}
=== modified file 'libcore/parser/SWFMovieDefinition.cpp'
--- a/libcore/parser/SWFMovieDefinition.cpp 2009-02-10 12:26:18 +0000
+++ b/libcore/parser/SWFMovieDefinition.cpp 2009-03-13 22:46:37 +0000
@@ -42,6 +42,7 @@
#include "ControlTag.h"
#include "sound_definition.h" // for sound_sample
#include "ExportableResource.h"
+#include "GnashAlgorithm.h"
#include <boost/bind.hpp>
#include <boost/version.hpp>
@@ -217,11 +218,7 @@
e = m_playlist.end(); i != e; ++i)
{
PlayList& pl = i->second;
-
- for (PlayList::iterator j = pl.begin(), je = pl.end(); j!=je;
++j)
- {
- delete *j;
- }
+ deleteAllChecked(pl);
}
// It's supposed to be cleaned up in read()
=== modified file 'libcore/parser/sprite_definition.cpp'
--- a/libcore/parser/sprite_definition.cpp 2009-03-10 20:43:50 +0000
+++ b/libcore/parser/sprite_definition.cpp 2009-03-13 22:46:37 +0000
@@ -26,6 +26,7 @@
#include "ControlTag.h" // for dtor visibility
#include "as_function.h" // for dtor visibility
#include "SWFStream.h" // for use
+#include "GnashAlgorithm.h"
#include <vector>
#include <string>
@@ -55,10 +56,7 @@
{
PlayList& pl = i->second;
- for (PlayList::iterator j=pl.begin(), je=pl.end(); j!=je; ++j)
- {
- delete *j;
- }
+ deleteAllChecked(pl);
}
}
=== modified file 'libcore/swf/DefineButtonTag.cpp'
--- a/libcore/swf/DefineButtonTag.cpp 2009-03-10 20:43:50 +0000
+++ b/libcore/swf/DefineButtonTag.cpp 2009-03-13 22:46:37 +0000
@@ -30,6 +30,7 @@
#include "action_buffer.h"
#include "filter_factory.h"
#include "GnashKey.h" // for gnash::key::codeMap
+#include "GnashAlgorithm.h"
namespace gnash {
namespace SWF {
@@ -278,12 +279,7 @@
DefineButtonTag::~DefineButtonTag()
{
- for (ButtonActions::iterator i = _buttonActions.begin(),
- ie = _buttonActions.end();
- i != ie; ++i )
- {
- delete *i;
- }
+ deleteAllChecked(_buttonActions);
}
=== modified file 'libcore/swf/DefineTextTag.cpp'
--- a/libcore/swf/DefineTextTag.cpp 2009-03-11 09:39:20 +0000
+++ b/libcore/swf/DefineTextTag.cpp 2009-03-13 22:11:38 +0000
@@ -14,6 +14,7 @@
#include "TextRecord.h"
#include "Font.h"
#include "StaticText.h"
+#include "GnashAlgorithm.h"
#include <algorithm>
#include <numeric>
@@ -38,15 +39,6 @@
m.add_character(id, t.release());
}
-template<typename T>
-struct CreatePointer
-{
- const T* operator()(const T& t) {
- return &t;
- }
-};
-
-
character*
DefineTextTag::createDisplayObject(character* parent, int id)
{
=== modified file 'libcore/swf/DefineVideoStreamTag.cpp'
--- a/libcore/swf/DefineVideoStreamTag.cpp 2009-03-10 20:43:50 +0000
+++ b/libcore/swf/DefineVideoStreamTag.cpp 2009-03-13 22:46:37 +0000
@@ -23,6 +23,7 @@
#include "VideoDecoder.h"
#include "SWFStream.h" // for read()
#include "movie_definition.h"
+#include "GnashAlgorithm.h"
namespace gnash {
namespace SWF {
@@ -52,10 +53,9 @@
}
-DefineVideoStreamTag::DefineVideoStreamTag(SWFStream& in,
- boost::uint16_t char_id)
+DefineVideoStreamTag::DefineVideoStreamTag(SWFStream& in, boost::uint16_t id)
:
- m_char_id(char_id),
+ m_char_id(id),
_width(0),
_height(0)
{
@@ -64,8 +64,7 @@
DefineVideoStreamTag::~DefineVideoStreamTag()
{
- std::for_each(_video_frames.begin(), _video_frames.end(),
- boost::checked_deleter<media::EncodedVideoFrame>());
+ deleteAllChecked(_video_frames);
}
=== modified file 'libcore/swf/PlaceObject2Tag.cpp'
--- a/libcore/swf/PlaceObject2Tag.cpp 2009-01-22 20:10:39 +0000
+++ b/libcore/swf/PlaceObject2Tag.cpp 2009-03-13 22:46:37 +0000
@@ -28,6 +28,7 @@
#include "log.h"
#include "SWFStream.h"
#include "filter_factory.h"
+#include "GnashAlgorithm.h"
namespace gnash {
namespace SWF {
@@ -476,21 +477,10 @@
}
-/// Use to delete pointers efficiently with std::for_each,
-/// making sure that the type is complete.
-template<typename T>
-static void deleterHelper(T p)
-{
- delete p;
-}
-
PlaceObject2Tag::~PlaceObject2Tag()
{
- std::for_each(_eventHandlers.begin(), _eventHandlers.end(),
- &deleterHelper<EventHandlers::value_type>);
-
- std::for_each(_actionBuffers.begin(), _actionBuffers.end(),
- &deleterHelper<ActionBuffers::value_type>);
+ deleteAllChecked(_eventHandlers);
+ deleteAllChecked(_actionBuffers);
}
/* public static */
=== modified file 'libmedia/FLVParser.cpp'
--- a/libmedia/FLVParser.cpp 2009-03-13 14:06:53 +0000
+++ b/libmedia/FLVParser.cpp 2009-03-13 22:11:38 +0000
@@ -27,7 +27,7 @@
#include "GnashException.h"
#include "IOChannel.h"
#include "SimpleBuffer.h"
-
+#include "GnashAlgorithm.h"
#include "element.h"
#include <string>
@@ -39,21 +39,6 @@
namespace gnash {
namespace media {
-namespace {
-
-/// Functor for use when transforming a map into a vector of mapped values.
-template<typename T>
-struct SecondElement
-{
- typedef typename T::second_type result_type;
-
- const result_type& operator()(const T& pair) const
- {
- return pair.second;
- }
-};
-
-}
const size_t FLVParser::paddingBytes;
const boost::uint16_t FLVParser::FLVAudioTag::flv_audio_rates [] =
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r10700: Move generic structs to their own header file so they can be used more,
Benjamin Wolsey <=