Caps: Added indexer and IEnumerable interface
authorStephan Sundermann <stephansundermann@gmail.com>
Fri, 11 Oct 2013 15:00:10 +0000 (17:00 +0200)
committerStephan Sundermann <stephansundermann@gmail.com>
Sat, 21 Dec 2013 15:52:22 +0000 (16:52 +0100)
sources/custom/Caps.cs [new file with mode: 0644]

diff --git a/sources/custom/Caps.cs b/sources/custom/Caps.cs
new file mode 100644 (file)
index 0000000..407c48b
--- /dev/null
@@ -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);
+               }
+       }
+}
\ No newline at end of file