Z3
 
Loading...
Searching...
No Matches
Z3Object.cs
Go to the documentation of this file.
1/*++
2Copyright (c) 2012 Microsoft Corporation
3
4Module Name:
5
6 Z3Object.cs
7
8Abstract:
9
10 Z3 Managed API: Internal Z3 Objects
11
12Author:
13
14 Christoph Wintersteiger (cwinter) 2012-03-21
15
16Notes:
17
18--*/
19
20using System.Diagnostics;
21using System;
22using System.Threading;
23using System.Collections.Generic;
24using System.Linq;
25
26namespace Microsoft.Z3
27{
32 public class Z3Object : IDisposable
33 {
37 ~Z3Object()
38 {
39 Dispose();
40 }
41
45 public void Dispose()
46 {
47 if (m_n_obj != IntPtr.Zero)
48 {
49 DecRef(m_n_obj);
50 m_n_obj = IntPtr.Zero;
51 }
52
53 m_ctx = null;
54
55 GC.SuppressFinalize(this);
56 }
57
58 #region Object Invariant
59
60 private void ObjectInvariant()
61 {
62 Debug.Assert(this.m_ctx != null);
63 }
64
65 #endregion
66
67 #region Internal
68 private Context m_ctx = null;
69 private IntPtr m_n_obj = IntPtr.Zero;
70
71 internal Z3Object(Context ctx)
72 {
73 Debug.Assert(ctx != null);
74 m_ctx = ctx;
75 }
76
77 internal Z3Object(Context ctx, IntPtr obj)
78 {
79 Debug.Assert(ctx != null);
80 m_ctx = ctx;
81 m_n_obj = obj;
82 IncRef(obj);
83 }
84
85 internal virtual void IncRef(IntPtr o) { }
86 internal virtual void DecRef(IntPtr o) { }
87
88 internal virtual void CheckNativeObject(IntPtr obj) { }
89
90 internal virtual IntPtr NativeObject
91 {
92 get { return m_n_obj; }
93 set
94 {
95 if (value != IntPtr.Zero) { CheckNativeObject(value); IncRef(value); }
96 if (m_n_obj != IntPtr.Zero) { DecRef(m_n_obj); }
97 m_n_obj = value;
98 }
99 }
100
101 internal static IntPtr GetNativeObject(Z3Object s)
102 {
103 if (s == null) return IntPtr.Zero;
104 return s.NativeObject;
105 }
106
111 {
112 get
113 {
114 return m_ctx;
115 }
116 }
117
118 internal static IntPtr[] ArrayToNative(Z3Object[] a)
119 {
120
121 if (a == null) return null;
122 IntPtr[] an = new IntPtr[a.Length];
123 for (uint i = 0; i < a.Length; i++)
124 if (a[i] != null) an[i] = a[i].NativeObject;
125 return an;
126 }
127
128 internal static uint ArrayLength(Z3Object[] a)
129 {
130 return (a == null)?0:(uint)a.Length;
131 }
132#endregion
133 }
134}
The main interaction with Z3 happens via the Context.
Definition Context.cs:34
Internal base class for interfacing with native Z3 objects. Should not be used externally.
Definition Z3Object.cs:33
void Dispose()
Disposes of the underlying native Z3 object.
Definition Z3Object.cs:45
Context Context
Access Context object.
Definition Z3Object.cs:111