~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/monomac/src/ObjCRuntime/Selector.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//
2
2
// Copyright 2010, Novell, Inc.
 
3
// Copyright 2013, Xamarin Inc.
3
4
//
4
5
// Permission is hereby granted, free of charge, to any person obtaining
5
6
// a copy of this software and associated documentation files (the
25
26
 
26
27
namespace MonoMac.ObjCRuntime {
27
28
        [StructLayout(LayoutKind.Sequential)]
28
 
        public class Selector {
29
 
                public static IntPtr Init = Selector.GetHandle ("init");
30
 
                public static IntPtr InitWithCoder = Selector.GetHandle ("initWithCoder:");
 
29
        public class Selector : IEquatable<Selector>{
 
30
                public static readonly IntPtr Init = Selector.GetHandle ("init");
 
31
                public static readonly IntPtr InitWithCoder = Selector.GetHandle ("initWithCoder:");
31
32
                static IntPtr MethodSignatureForSelector = Selector.GetHandle ("methodSignatureForSelector:");
32
33
                static IntPtr FrameLength = Selector.GetHandle ("frameLength");
33
 
                internal static IntPtr Alloc = Selector.GetHandle ("alloc");
34
 
                internal static IntPtr Release = Selector.GetHandle ("release");
 
34
                internal static IntPtr RetainCount = Selector.GetHandle ("retainCount");
 
35
                internal const string Alloc = "alloc";
 
36
                internal const string Release = "release";
 
37
                internal const string Retain = "retain";
 
38
                internal const string DoesNotRecognizeSelector = "doesNotRecognizeSelector:";
 
39
                internal const string PerformSelectorOnMainThreadWithObjectWaitUntilDone = "performSelectorOnMainThread:withObject:waitUntilDone:";
 
40
                internal const string PerformSelectorWithObjectAfterDelay = "performSelector:withObject:afterDelay:";
 
41
 
 
42
                internal static IntPtr AllocHandle = Selector.GetHandle (Alloc);
 
43
                internal static IntPtr ReleaseHandle = Selector.GetHandle (Release);
 
44
                internal static IntPtr RetainHandle = Selector.GetHandle (Retain);
 
45
                internal static IntPtr DoesNotRecognizeSelectorHandle = Selector.GetHandle (DoesNotRecognizeSelector);
 
46
                internal static IntPtr PerformSelectorOnMainThreadWithObjectWaitUntilDoneHandle = GetHandle (PerformSelectorOnMainThreadWithObjectWaitUntilDone);
 
47
                internal static IntPtr PerformSelectorWithObjectAfterDelayHandle = GetHandle (PerformSelectorWithObjectAfterDelay);
35
48
 
36
49
                internal IntPtr handle;
37
50
 
43
56
                }
44
57
 
45
58
                public Selector (string name, bool alloc) {
46
 
                        if (alloc) {
47
 
                                IntPtr selstr_ptr = Marshal.StringToHGlobalAuto (name);
48
 
                                handle = sel_registerName (selstr_ptr);
49
 
 
50
 
                                if (selstr_ptr != sel_getName (handle))
51
 
                                        Marshal.FreeHGlobal (selstr_ptr);
52
 
                        } else {
53
 
                                handle = sel_registerName (name);
54
 
                        }
 
59
                        handle = GetHandle (name);
55
60
                }
56
61
 
57
62
                public Selector (string name) : this (name, false) {}
58
63
 
 
64
                [MonoNativeFunctionWrapper]
 
65
                delegate int getFrameLengthDelegate (IntPtr @this, IntPtr sel);
 
66
 
 
67
                [MonoPInvokeCallbackAttribute(typeof(getFrameLengthDelegate))]
59
68
                public static int GetFrameLength (IntPtr @this, IntPtr sel)
60
69
                {
61
70
                        IntPtr sig = Messaging.IntPtr_objc_msgSend_IntPtr (@this, MethodSignatureForSelector, sel);
75
84
                }
76
85
 
77
86
                public static bool operator!= (Selector left, Selector right) {
78
 
                        if (((object)left) == null)
79
 
                                return (((object)right) != null);
80
 
                        if (((object)right) == null)
81
 
                                return true;
82
 
 
83
 
                        return !sel_isEqual (left.handle, right.handle);
 
87
                        return !(left == right);
84
88
                }
85
89
 
86
90
                public static bool operator== (Selector left, Selector right) {
89
93
                        if (((object)right) == null)
90
94
                                return false;
91
95
 
92
 
                        return sel_isEqual (left.handle, right.handle);
 
96
                        return left.handle == right.handle;
93
97
                }
94
98
 
95
99
                public override bool Equals (object right) {
 
100
                        return Equals (right as Selector);
 
101
                }
 
102
 
 
103
                public bool Equals (Selector right) {
96
104
                        if (right == null)
97
105
                                return false;
98
106
 
99
 
                        if (right is Selector)
100
 
                                return sel_isEqual (handle, ((Selector) right).handle);
101
 
 
102
 
                        return false;
 
107
                        return handle == right.handle;
103
108
                }
104
109
 
105
110
                public override int GetHashCode () {
108
113
                
109
114
                [DllImport ("/usr/lib/libobjc.dylib")]
110
115
                extern static IntPtr sel_getName (IntPtr sel);
111
 
                [DllImport ("/usr/lib/libobjc.dylib")]
112
 
                extern static IntPtr sel_registerName (IntPtr name);
113
 
                [DllImport ("/usr/lib/libobjc.dylib")]
114
 
                internal extern static IntPtr sel_registerName (string name);
115
116
                [DllImport ("/usr/lib/libobjc.dylib", EntryPoint="sel_registerName")]
116
117
                public extern static IntPtr GetHandle (string name);
117
118
                [DllImport ("/usr/lib/libobjc.dylib")]
118
119
                extern static bool sel_isMapped (IntPtr sel);
119
 
                [DllImport ("/usr/lib/libobjc.dylib")]
120
 
                extern static bool sel_isEqual (IntPtr lhs, IntPtr rhs);
121
120
        }
122
121
}