~ubuntu-branches/ubuntu/vivid/monodevelop/vivid-proposed

« back to all changes in this revision

Viewing changes to external/maccore/src/CoreFoundation/CFArray.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2014-10-09 14:09:23 UTC
  • mfrom: (10.3.5)
  • Revision ID: package-import@ubuntu.com-20141009140923-s0d22u5f9kg8jvds
Tags: 5.5.0.227-1
* [b2c8331] Imported Upstream version 5.5.0.227 (Closes: #754316)
* [d210995] Delete obsolete patches
* [1b59ae1] Clear patch fizz, via quilt refresh
* [3dd147d] Fix error in configure.in which applies for tarball builds but 
  not git builds when running autoreconf
* [21c2a57] Remove Metacity references for good
* [3331661] Ensure NUnit 2.6.3 is installed
* [fd85c88] Build-depend on NuGet
* [a1ae116] Add WebKit to build dependencies, for Xwt moduleref resolution
* [9b4cf12] Since the GDB addin is integrated now, declare it in 
  debian/control
* [6231562] Correct NUnit links
* [3d2b693] Fix NuGet addin, by copying libs locally
* [74bf9a8] Don't symlink unused Mocks NUnit assembly
* [ade52b2] Ensure IKVM.Reflection is built with default (4.5) profile

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// 
2
 
// CFArray.cs: P/Invokes for CFArray
3
 
//
4
 
// Authors:
5
 
//    Mono Team
6
 
//    Rolf Bjarne Kvinge (rolf@xamarin.com)
7
 
//
8
 
//     
9
 
// Copyright 2010 Novell, Inc
10
 
// Copyright 2012 Xamarin Inc
11
 
//
12
 
// Permission is hereby granted, free of charge, to any person obtaining
13
 
// a copy of this software and associated documentation files (the
14
 
// "Software"), to deal in the Software without restriction, including
15
 
// without limitation the rights to use, copy, modify, merge, publish,
16
 
// distribute, sublicense, and/or sell copies of the Software, and to
17
 
// permit persons to whom the Software is furnished to do so, subject to
18
 
// the following conditions:
19
 
// 
20
 
// The above copyright notice and this permission notice shall be
21
 
// included in all copies or substantial portions of the Software.
22
 
// 
23
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
 
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
 
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
 
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27
 
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28
 
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29
 
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
 
//
31
 
 
32
 
using System;
33
 
using System.Runtime.InteropServices;
34
 
using MonoMac.Foundation;
35
 
using MonoMac.ObjCRuntime;
36
 
 
37
 
using CFIndex = System.Int32;
38
 
 
39
 
namespace MonoMac.CoreFoundation {
40
 
        
41
 
        class CFArray : INativeObject, IDisposable {
42
 
 
43
 
                internal IntPtr handle;
44
 
 
45
 
                internal CFArray (IntPtr handle)
46
 
                        : this (handle, false)
47
 
                {
48
 
                }
49
 
 
50
 
                [Preserve (Conditional = true)]
51
 
                internal CFArray (IntPtr handle, bool owns)
52
 
                {
53
 
                        if (handle == IntPtr.Zero)
54
 
                                throw new ArgumentNullException ("handle");
55
 
 
56
 
                        this.handle = handle;
57
 
                        if (!owns)
58
 
                                CFObject.CFRetain (handle);
59
 
                }
60
 
                
61
 
                public IntPtr Handle {
62
 
                        get {return handle;}
63
 
                }
64
 
 
65
 
                [DllImport (Constants.CoreFoundationLibrary, EntryPoint="CFArrayGetTypeID")]
66
 
                public extern static int GetTypeID ();
67
 
 
68
 
                ~CFArray ()
69
 
                {
70
 
                        Dispose (false);
71
 
                }
72
 
                
73
 
                public void Dispose ()
74
 
                {
75
 
                        Dispose (true);
76
 
                        GC.SuppressFinalize (this);
77
 
                }
78
 
 
79
 
                protected virtual void Dispose (bool disposing)
80
 
                {
81
 
                        if (handle != IntPtr.Zero){
82
 
                                CFObject.CFRelease (handle);
83
 
                                handle = IntPtr.Zero;
84
 
                        }
85
 
                }
86
 
 
87
 
                // pointer to a const struct (REALLY APPLE?)
88
 
                static readonly IntPtr kCFTypeArrayCallbacks_ptr;
89
 
 
90
 
                static CFArray ()
91
 
                {
92
 
                        var handle = Dlfcn.dlopen (Constants.CoreFoundationLibrary, 0);
93
 
                        if (handle == IntPtr.Zero)
94
 
                                return;
95
 
                        try {
96
 
                                kCFTypeArrayCallbacks_ptr = Dlfcn.GetIndirect (handle, "kCFTypeArrayCallBacks");
97
 
                        }
98
 
                        finally {
99
 
                                Dlfcn.dlclose (handle);
100
 
                        }
101
 
                }
102
 
 
103
 
                public static CFArray FromIntPtrs (params IntPtr[] values)
104
 
                {
105
 
                        return new CFArray (Create (values), true);
106
 
                }
107
 
 
108
 
                public static CFArray FromNativeObjects (params INativeObject[] values)
109
 
                {
110
 
                        return new CFArray (Create (values), true);
111
 
                }
112
 
 
113
 
                public int Count {
114
 
                        get {return CFArrayGetCount (handle);}
115
 
                }
116
 
 
117
 
                [DllImport (Constants.CoreFoundationLibrary)]
118
 
                extern static IntPtr CFArrayCreate (IntPtr allocator, IntPtr values, CFIndex numValues, IntPtr callbacks);
119
 
 
120
 
                [DllImport (Constants.CoreFoundationLibrary)]
121
 
                extern static IntPtr CFArrayGetValueAtIndex (IntPtr theArray, IntPtr index);
122
 
 
123
 
                public IntPtr GetValue (int index)
124
 
                {
125
 
                        return CFArrayGetValueAtIndex (handle, new IntPtr (index));
126
 
                }
127
 
 
128
 
                public static unsafe IntPtr Create (params IntPtr[] values)
129
 
                {
130
 
                        if (values == null)
131
 
                                throw new ArgumentNullException ("values");
132
 
                        fixed (IntPtr* pv = values) {
133
 
                                return CFArrayCreate (IntPtr.Zero, 
134
 
                                                (IntPtr) pv,
135
 
                                                values.Length,
136
 
                                                kCFTypeArrayCallbacks_ptr);
137
 
                        }
138
 
                }
139
 
 
140
 
                public static IntPtr Create (params INativeObject[] values)
141
 
                {
142
 
                        if (values == null)
143
 
                                throw new ArgumentNullException ("values");
144
 
                        IntPtr[] _values = new IntPtr [values.Length];
145
 
                        for (int i = 0; i < _values.Length; ++i)
146
 
                                _values [i] = values [i].Handle;
147
 
                        return Create (_values);
148
 
                }
149
 
 
150
 
                [DllImport (Constants.CoreFoundationLibrary)]
151
 
                extern static CFIndex CFArrayGetCount (IntPtr theArray);
152
 
                public static int GetCount (IntPtr array)
153
 
                {
154
 
                        return CFArrayGetCount (array);
155
 
                }
156
 
        }
157
 
}
158