| 1 |
// AprSharp, a wrapper library around the Apache Portable Runtime Library |
|---|
| 2 |
#region Copyright (C) 2004 SOFTEC sa. |
|---|
| 3 |
// |
|---|
| 4 |
// This library is free software; you can redistribute it and/or |
|---|
| 5 |
// modify it under the terms of the GNU Lesser General Public |
|---|
| 6 |
// License as published by the Free Software Foundation; either |
|---|
| 7 |
// version 2.1 of the License, or (at your option) any later version. |
|---|
| 8 |
// |
|---|
| 9 |
// This library is distributed in the hope that it will be useful, |
|---|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 12 |
// Lesser General Public License for more details. |
|---|
| 13 |
// |
|---|
| 14 |
// You should have received a copy of the GNU Lesser General Public |
|---|
| 15 |
// License along with this library; if not, write to the Free Software |
|---|
| 16 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 17 |
// |
|---|
| 18 |
// Sources, support options and lastest version of the complete library |
|---|
| 19 |
// is available from: |
|---|
| 20 |
// http://www.softec.st/AprSharp |
|---|
| 21 |
// |
|---|
| 22 |
// |
|---|
| 23 |
// Initial authors : |
|---|
| 24 |
// Denis Gervalle |
|---|
| 25 |
// Olivier Desaive |
|---|
| 26 |
#endregion |
|---|
| 27 |
// |
|---|
| 28 |
using System; |
|---|
| 29 |
using System.Diagnostics; |
|---|
| 30 |
using System.Runtime.InteropServices; |
|---|
| 31 |
|
|---|
| 32 |
namespace Softec.AprSharp |
|---|
| 33 |
{ |
|---|
| 34 |
public unsafe struct AprMemNode |
|---|
| 35 |
{ |
|---|
| 36 |
private apr_memnode_t *mMemNode; |
|---|
| 37 |
|
|---|
| 38 |
[StructLayout( LayoutKind.Sequential, Pack=4 )] |
|---|
| 39 |
private struct apr_memnode_t |
|---|
| 40 |
{ |
|---|
| 41 |
public apr_memnode_t *next; |
|---|
| 42 |
public apr_memnode_t **selfref; |
|---|
| 43 |
public UInt32 index; |
|---|
| 44 |
public UInt32 free_index; |
|---|
| 45 |
public byte *first_avail; |
|---|
| 46 |
public byte *endp; |
|---|
| 47 |
} |
|---|
| 48 |
|
|---|
| 49 |
#region Generic embedding functions of an IntPtr |
|---|
| 50 |
private AprMemNode(apr_memnode_t *ptr) |
|---|
| 51 |
{ |
|---|
| 52 |
mMemNode = ptr; |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
public AprMemNode(IntPtr ptr) |
|---|
| 56 |
{ |
|---|
| 57 |
mMemNode = (apr_memnode_t *)ptr.ToPointer(); |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
public bool IsNull |
|---|
| 61 |
{ |
|---|
| 62 |
get |
|---|
| 63 |
{ |
|---|
| 64 |
return( mMemNode == null ); |
|---|
| 65 |
} |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
private void CheckPtr() |
|---|
| 69 |
{ |
|---|
| 70 |
if( mMemNode == null ) |
|---|
| 71 |
throw new AprNullReferenceException(); |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
public void ClearPtr() |
|---|
| 75 |
{ |
|---|
| 76 |
mMemNode = null; |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
public IntPtr ToIntPtr() |
|---|
| 80 |
{ |
|---|
| 81 |
return new IntPtr(mMemNode); |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
public bool ReferenceEquals(IAprUnmanaged obj) |
|---|
| 85 |
{ |
|---|
| 86 |
return(obj.ToIntPtr() == ToIntPtr()); |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
public static implicit operator IntPtr(AprMemNode memNode) |
|---|
| 90 |
{ |
|---|
| 91 |
return new IntPtr(memNode.mMemNode); |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
public static implicit operator AprMemNode(IntPtr ptr) |
|---|
| 95 |
{ |
|---|
| 96 |
return new AprMemNode(ptr); |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
public override string ToString() |
|---|
| 100 |
{ |
|---|
| 101 |
return("[apr_memnode_t:"+(new IntPtr(mMemNode)).ToInt32().ToString("X")+"]"); |
|---|
| 102 |
} |
|---|
| 103 |
#endregion |
|---|
| 104 |
|
|---|
| 105 |
#region Structure members wrapper (Properties) |
|---|
| 106 |
|
|---|
| 107 |
public AprMemNode Next |
|---|
| 108 |
{ |
|---|
| 109 |
get |
|---|
| 110 |
{ |
|---|
| 111 |
CheckPtr(); |
|---|
| 112 |
return(new AprMemNode(mMemNode->next)); |
|---|
| 113 |
} |
|---|
| 114 |
set |
|---|
| 115 |
{ |
|---|
| 116 |
CheckPtr(); |
|---|
| 117 |
mMemNode->next=value.mMemNode; |
|---|
| 118 |
} |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
public AprMemNode Ref |
|---|
| 122 |
{ |
|---|
| 123 |
get |
|---|
| 124 |
{ |
|---|
| 125 |
CheckPtr(); |
|---|
| 126 |
return((mMemNode->selfref != null) |
|---|
| 127 |
? new AprMemNode(*(mMemNode->selfref)) |
|---|
| 128 |
: new AprMemNode(null)); |
|---|
| 129 |
} |
|---|
| 130 |
} |
|---|
| 131 |
|
|---|
| 132 |
public IntPtr NativeRef |
|---|
| 133 |
{ |
|---|
| 134 |
get |
|---|
| 135 |
{ |
|---|
| 136 |
CheckPtr(); |
|---|
| 137 |
return((IntPtr)mMemNode->selfref); |
|---|
| 138 |
} |
|---|
| 139 |
set |
|---|
| 140 |
{ |
|---|
| 141 |
CheckPtr(); |
|---|
| 142 |
mMemNode->selfref=(apr_memnode_t **)value.ToPointer(); |
|---|
| 143 |
} |
|---|
| 144 |
} |
|---|
| 145 |
|
|---|
| 146 |
public int Index |
|---|
| 147 |
{ |
|---|
| 148 |
get |
|---|
| 149 |
{ |
|---|
| 150 |
CheckPtr(); |
|---|
| 151 |
return(unchecked((int)NativeIndex)); |
|---|
| 152 |
} |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|
| 155 |
[CLSCompliant(false)] |
|---|
| 156 |
public uint NativeIndex |
|---|
| 157 |
{ |
|---|
| 158 |
get |
|---|
| 159 |
{ |
|---|
| 160 |
CheckPtr(); |
|---|
| 161 |
return(mMemNode->index); |
|---|
| 162 |
} |
|---|
| 163 |
} |
|---|
| 164 |
|
|---|
| 165 |
public int FreeIndex |
|---|
| 166 |
{ |
|---|
| 167 |
get |
|---|
| 168 |
{ |
|---|
| 169 |
CheckPtr(); |
|---|
| 170 |
return(unchecked((int)NativeFreeIndex)); |
|---|
| 171 |
} |
|---|
| 172 |
} |
|---|
| 173 |
|
|---|
| 174 |
[CLSCompliant(false)] |
|---|
| 175 |
public uint NativeFreeIndex |
|---|
| 176 |
{ |
|---|
| 177 |
get |
|---|
| 178 |
{ |
|---|
| 179 |
CheckPtr(); |
|---|
| 180 |
return(mMemNode->free_index); |
|---|
| 181 |
} |
|---|
| 182 |
} |
|---|
| 183 |
|
|---|
| 184 |
public IntPtr FirstAvail |
|---|
| 185 |
{ |
|---|
| 186 |
get |
|---|
| 187 |
{ |
|---|
| 188 |
CheckPtr(); |
|---|
| 189 |
return((IntPtr)mMemNode->first_avail); |
|---|
| 190 |
} |
|---|
| 191 |
set |
|---|
| 192 |
{ |
|---|
| 193 |
CheckPtr(); |
|---|
| 194 |
mMemNode->first_avail=(byte *)value.ToPointer(); |
|---|
| 195 |
} |
|---|
| 196 |
} |
|---|
| 197 |
|
|---|
| 198 |
[CLSCompliant(false)] |
|---|
| 199 |
public byte *NativeFirstAvail |
|---|
| 200 |
{ |
|---|
| 201 |
get |
|---|
| 202 |
{ |
|---|
| 203 |
CheckPtr(); |
|---|
| 204 |
return(mMemNode->first_avail); |
|---|
| 205 |
} |
|---|
| 206 |
set |
|---|
| 207 |
{ |
|---|
| 208 |
CheckPtr(); |
|---|
| 209 |
mMemNode->first_avail=value; |
|---|
| 210 |
} |
|---|
| 211 |
} |
|---|
| 212 |
|
|---|
| 213 |
public IntPtr EndP |
|---|
| 214 |
{ |
|---|
| 215 |
get |
|---|
| 216 |
{ |
|---|
| 217 |
CheckPtr(); |
|---|
| 218 |
return((IntPtr)mMemNode->endp); |
|---|
| 219 |
} |
|---|
| 220 |
} |
|---|
| 221 |
|
|---|
| 222 |
[CLSCompliant(false)] |
|---|
| 223 |
public byte *NativeEndP |
|---|
| 224 |
{ |
|---|
| 225 |
get |
|---|
| 226 |
{ |
|---|
| 227 |
CheckPtr(); |
|---|
| 228 |
return(mMemNode->endp); |
|---|
| 229 |
} |
|---|
| 230 |
} |
|---|
| 231 |
#endregion |
|---|
| 232 |
} |
|---|
| 233 |
} |
|---|