mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-27 03:23:16 +00:00
Iterator: Added integration with IEnumerable
This commit is contained in:
parent
602ea036fe
commit
cd0c436ece
2 changed files with 105 additions and 0 deletions
103
sources/custom/Iterator.cs
Normal file
103
sources/custom/Iterator.cs
Normal file
|
@ -0,0 +1,103 @@
|
|||
// Iterator.cs - Custom iterator wrapper for IEnumerable
|
||||
//
|
||||
// Author: Sebastian Dröge
|
||||
// Stephan Sundermann <stephansundermann@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2004-2009 Novell, Inc.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
namespace Gst {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using GLib;
|
||||
|
||||
public partial class Iterator : IEnumerable {
|
||||
|
||||
private class Enumerator : IEnumerator {
|
||||
Iterator iterator;
|
||||
Hashtable seen = new Hashtable ();
|
||||
|
||||
private object current = null;
|
||||
public object Current {
|
||||
get {
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext () {
|
||||
IntPtr raw_ret;
|
||||
bool retry = false;
|
||||
|
||||
if (iterator.Handle == IntPtr.Zero)
|
||||
return false;
|
||||
|
||||
do {
|
||||
GLib.Value value;
|
||||
IteratorResult ret = iterator.Next (out value);
|
||||
|
||||
switch (ret) {
|
||||
case IteratorResult.Done:
|
||||
return false;
|
||||
case IteratorResult.Ok:
|
||||
if (seen.Contains (value)) {
|
||||
retry = true;
|
||||
break;
|
||||
}
|
||||
seen.Add (value , null);
|
||||
current = value.Val;
|
||||
return true;
|
||||
case IteratorResult.Resync:
|
||||
iterator.Resync ();
|
||||
retry = true;
|
||||
break;
|
||||
default:
|
||||
case IteratorResult.Error:
|
||||
throw new Exception ("Error while iterating pads");
|
||||
}
|
||||
} while (retry);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Reset () {
|
||||
seen.Clear ();
|
||||
if (iterator.Handle != IntPtr.Zero)
|
||||
iterator.Resync ();
|
||||
}
|
||||
|
||||
public Enumerator (Iterator iterator) {
|
||||
this.iterator = iterator;
|
||||
}
|
||||
}
|
||||
|
||||
private Enumerator enumerator = null;
|
||||
|
||||
public IEnumerator GetEnumerator () {
|
||||
if (this.enumerator == null)
|
||||
this.enumerator = new Enumerator (this);
|
||||
return this.enumerator;
|
||||
}
|
||||
|
||||
~Iterator () {
|
||||
if (Raw != IntPtr.Zero)
|
||||
Free ();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -47,6 +47,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
<attr path="/api/namespace//struct[field/@cname='mini_object']" name="native">true</attr>
|
||||
<change-node-type path="/api/namespace//boxed[@cname='GstStructure']">struct</change-node-type>
|
||||
<attr path="/api/namespace/struct[@cname='GstStructure']" name="native">true</attr>
|
||||
<change-node-type path="/api/namespace//boxed[@cname='GstIterator']">struct</change-node-type>
|
||||
<attr path="/api/namespace/struct[@cname='GstIterator']" name="native">true</attr>
|
||||
<remove-node path="/api/namespace/boxed[@cname='GstStructure']/field[@cname='name']" />
|
||||
<!-- Maybe some problems with the name -->
|
||||
<remove-node path="/api/namespace/interface[@cname='GstURIHandler']/class_struct/method[@vm='get_type']" name="vm" />
|
||||
|
|
Loading…
Reference in a new issue