From: Stephan Sundermann Date: Fri, 11 Oct 2013 15:00:10 +0000 (+0200) Subject: Caps: Added indexer and IEnumerable interface X-Git-Tag: 1.19.3~483^2~280 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d0e02c05ba882a837d08c82cceff06106aae5b46;p=platform%2Fupstream%2Fgstreamer.git Caps: Added indexer and IEnumerable interface --- 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