root/trunk/AprSharp/dev/src/AprMemNode.cs

Revision 1, 4.4 kB (checked in by DenisG, 3 years ago)

Initial import

  • Property svn:eol-style set to native
Line 
1 //
2 // Softec
3 //
4 // Contact: Support@softec.st
5 //
6 // Designed by Denis Gervalle and Olivier Desaive
7 // Written by Denis Gervalle
8 //
9 // Copyright 2004 by SOFTEC. All rights reserved.
10 //
11 using System;
12 using System.Diagnostics;
13 using System.Runtime.InteropServices;
14
15 namespace Softec.AprSharp
16 {
17     public unsafe struct AprMemNode
18     {
19         private apr_memnode_t *mMemNode;
20
21         [StructLayout( LayoutKind.Sequential )]
22         private struct apr_memnode_t
23         {
24             public apr_memnode_t *next;
25             public apr_memnode_t **selfref;
26             public UInt32 index;
27             public UInt32 free_index;
28             public byte *first_avail;
29             public byte *endp;
30         }
31
32         #region Generic embedding functions of an IntPtr
33         private AprMemNode(apr_memnode_t *ptr)
34         {
35             mMemNode = ptr;
36         }
37
38         public AprMemNode(IntPtr ptr)
39         {
40             mMemNode = ptr.ToPointer();
41         }
42        
43         public bool IsNull()
44         {
45             return( mMemNode == null );
46         }
47
48         private void CheckPtr()
49         {
50             if( mMemNode == null )
51                 throw new AprNullReferenceException();
52         }
53
54         public void ClearPtr()
55         {
56             mMemNode = null;
57         }
58
59         public static implicit operator IntPtr(AprMemNode memNode)
60         {
61             return new IntPtr(memNode.mMemNode);
62         }
63        
64         public static implicit operator AprMemNode(IntPtr ptr)
65         {
66             return new AprMemNode(ptr);
67         }
68        
69         public override string ToString()
70         {
71             return("[apr_memnode_t:"+(new IntPtr(mMemNode)).ToInt32().ToString("X")+"]");
72         }
73         #endregion
74        
75         #region Structure members wrapper (Properties)
76          
77         public AprMemNode Next
78         {
79             get
80             {
81                 CheckPtr();
82                 return(new AprMemNode(mMemNode->next));
83             }
84             set
85             {
86                 CheckPtr();
87                 mMemNode->next=value.mMemNode;
88             }
89         }
90
91         public AprMemNode Ref
92         {
93             get
94             {
95                 CheckPtr();
96                 return((mMemNode->selfref != null)
97                         ? new AprMemNode(*(mMemNode->selfref))
98                         : new AprMemNode(null));
99             }
100         }
101
102         public IntPtr NativeRef
103         {
104             get
105             {
106                 CheckPtr();
107                 return((IntPtr)mMemNode->selfref);
108             }
109             set
110             {
111                 CheckPtr();
112                 mMemNode->selfref=value.ToPointer();
113             }
114         }
115
116         public int Index
117         {
118             get
119             {
120                 CheckPtr();
121                 return(unchecked((int)NativeIndex));
122             }
123         }
124
125             [CLSCompliant(false)]
126         public uint NativeIndex
127         {
128             get
129             {
130                 CheckPtr();
131                 return(mMemNode->index);
132             }
133         }
134
135         public int FreeIndex
136         {
137             get
138             {
139                 CheckPtr();
140                 return(unchecked((int)NativeFreeIndex));
141             }
142         }
143
144             [CLSCompliant(false)]
145         public uint NativeFreeIndex
146         {
147             get
148             {
149                 CheckPtr();
150                 return(mMemNode->free_index);
151             }
152         }
153        
154         public IntPtr FirstAvail
155         {
156             get
157             {
158                 CheckPtr();
159                 return((IntPtr)mMemNode->first_avail);
160             }
161             set
162             {
163                 CheckPtr();
164                 mMemNode->first_avail=value.ToPointer();
165             }
166         }
167
168             [CLSCompliant(false)]
169         public byte *NativeFirstAvail
170         {
171             get
172             {
173                 CheckPtr();
174                 return(mMemNode->first_avail);
175             }
176             set
177             {
178                 CheckPtr();
179                 mMemNode->first_avail=value;
180             }
181         }
182
183         public IntPtr EndP
184         {
185             get
186             {
187                 CheckPtr();
188                 return((IntPtr)mMemNode->endp);
189             }
190         }
191
192             [CLSCompliant(false)]
193         public byte *NativeEndP
194         {
195             get
196             {
197                 CheckPtr();
198                 return(mMemNode->endp);
199             }
200         }
201         #endregion
202     }
203 }
Note: See TracBrowser for help on using the browser.