mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-19 13:55:41 +00:00
Caps: Added indexer and IEnumerable interface
This commit is contained in:
parent
86141ab5f1
commit
d0e02c05ba
1 changed files with 73 additions and 0 deletions
73
sources/custom/Caps.cs
Normal file
73
sources/custom/Caps.cs
Normal file
|
@ -0,0 +1,73 @@
|
|||
// 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.Runtime.InteropServices;
|
||||
|
||||
partial class Caps : IEnumerable
|
||||
{
|
||||
public Structure this [uint index] {
|
||||
get {
|
||||
if (index >= Size)
|
||||
throw new ArgumentOutOfRangeException ();
|
||||
|
||||
Structure structure = GetStructure ((uint) index);
|
||||
return structure;
|
||||
}
|
||||
}
|
||||
|
||||
private class StructureEnumerator : IEnumerator {
|
||||
Gst.Caps caps;
|
||||
long index;
|
||||
|
||||
public StructureEnumerator (Gst.Caps caps) {
|
||||
this.caps = caps;
|
||||
index = -1;
|
||||
}
|
||||
|
||||
public object Current {
|
||||
get {
|
||||
if (index >= caps.Size)
|
||||
throw new ArgumentOutOfRangeException ();
|
||||
if (index == -1)
|
||||
throw new ArgumentException ();
|
||||
|
||||
return caps[ (uint) index];
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext () {
|
||||
index += 1;
|
||||
return (index < caps.Size);
|
||||
}
|
||||
|
||||
public void Reset () {
|
||||
index = -1;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator() {
|
||||
return new StructureEnumerator (this);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue