From d0e02c05ba882a837d08c82cceff06106aae5b46 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Fri, 11 Oct 2013 17:00:10 +0200 Subject: [PATCH] Caps: Added indexer and IEnumerable interface --- sources/custom/Caps.cs | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 sources/custom/Caps.cs diff --git a/sources/custom/Caps.cs b/sources/custom/Caps.cs new file mode 100644 index 0000000..407c48b --- /dev/null +++ b/sources/custom/Caps.cs @@ -0,0 +1,73 @@ +// Iterator.cs - Custom iterator wrapper for IEnumerable +// +// Author: Sebastian Dröge +// Stephan Sundermann +// +// 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); + } + } +} \ No newline at end of file -- 2.7.4