| 1 |
// |
|---|
| 2 |
// Softec |
|---|
| 3 |
// |
|---|
| 4 |
// Contact: |
|---|
| 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 |
|
|---|
| 14 |
namespace Softec.AprSharp |
|---|
| 15 |
{ |
|---|
| 16 |
|
|---|
| 17 |
public struct AprPool |
|---|
| 18 |
{ |
|---|
| 19 |
IntPtr mPool; |
|---|
| 20 |
|
|---|
| 21 |
#region Generic embedding functions of an IntPtr |
|---|
| 22 |
private AprPool(IntPtr ptr) |
|---|
| 23 |
{ |
|---|
| 24 |
mPool = ptr; |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
public bool IsNull() |
|---|
| 28 |
{ |
|---|
| 29 |
return( mPool == IntPtr.Zero ); |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
private void CheckPtr() |
|---|
| 33 |
{ |
|---|
| 34 |
if( IsNull() ) |
|---|
| 35 |
throw new AprNullReferenceException(); |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
public void ClearPtr() |
|---|
| 39 |
{ |
|---|
| 40 |
mPool = IntPtr.Zero; |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
public static implicit operator IntPtr(AprPool pool) |
|---|
| 44 |
{ |
|---|
| 45 |
return pool.mPool; |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
public static implicit operator AprPool(IntPtr ptr) |
|---|
| 49 |
{ |
|---|
| 50 |
return new AprPool(ptr); |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
public override string ToString() |
|---|
| 54 |
{ |
|---|
| 55 |
return("[apr_pool_t:"+mPool.ToInt32().ToString("X")+"]"); |
|---|
| 56 |
} |
|---|
| 57 |
#endregion |
|---|
| 58 |
|
|---|
| 59 |
#region Wrapper methods |
|---|
| 60 |
public static AprPool Create() |
|---|
| 61 |
{ |
|---|
| 62 |
return(Create(IntPtr.Zero, IntPtr.Zero)); |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
public static AprPool Create(AprPool pool) |
|---|
| 66 |
{ |
|---|
| 67 |
return(Create(pool, IntPtr.Zero)); |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
public static AprPool Create(AprAllocator allocator) |
|---|
| 71 |
{ |
|---|
| 72 |
return(Create(IntPtr.Zero, allocator)); |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
public static AprPool Create(AprPool pool, AprAllocator allocator) |
|---|
| 76 |
{ |
|---|
| 77 |
IntPtr ptr; |
|---|
| 78 |
|
|---|
| 79 |
Debug.Write(String.Format("apr_pool_create_ex({0},{1})...",pool,allocator)); |
|---|
| 80 |
int res = Apr.apr_pool_create_ex(out ptr, pool, |
|---|
| 81 |
IntPtr.Zero, allocator); |
|---|
| 82 |
if(res != 0 ) |
|---|
| 83 |
throw new AprException(res); |
|---|
| 84 |
Debug.WriteLine(String.Format("Done({0:X})",((Int32)ptr))); |
|---|
| 85 |
|
|---|
| 86 |
return(ptr); |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
public void Destroy() |
|---|
| 90 |
{ |
|---|
| 91 |
CheckPtr(); |
|---|
| 92 |
Debug.Write(String.Format("apr_pool_destroy({0:X})...",((Int32)mPool))); |
|---|
| 93 |
Apr.apr_pool_destroy(mPool); |
|---|
| 94 |
Debug.WriteLine("Done"); |
|---|
| 95 |
ClearPtr(); |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
public void Clear() |
|---|
| 99 |
{ |
|---|
| 100 |
CheckPtr(); |
|---|
| 101 |
Debug.Write(String.Format("apr_pool_clear({0:X})...",((Int32)mPool))); |
|---|
| 102 |
Apr.apr_pool_clear(mPool); |
|---|
| 103 |
Debug.WriteLine("Done"); |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
public unsafe IntPtr Alloc(int size) |
|---|
| 107 |
{ |
|---|
| 108 |
return((IntPtr)Alloc(unchecked((uint)size))); |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
[CLSCompliant(false)] |
|---|
| 112 |
public unsafe byte *Alloc(uint size) |
|---|
| 113 |
{ |
|---|
| 114 |
CheckPtr(); |
|---|
| 115 |
Debug.WriteLine(String.Format("apr_palloc({0:X})",((Int32)mPool))); |
|---|
| 116 |
return((byte *)Apr.apr_palloc(mPool, size)); |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
public unsafe IntPtr CAlloc(int size) |
|---|
| 120 |
{ |
|---|
| 121 |
return((IntPtr)CAlloc(unchecked((uint)size))); |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
[CLSCompliant(false)] |
|---|
| 125 |
public unsafe byte *CAlloc(uint size) |
|---|
| 126 |
{ |
|---|
| 127 |
CheckPtr(); |
|---|
| 128 |
Debug.WriteLine(String.Format("apr_pcalloc({0:X})",((Int32)mPool))); |
|---|
| 129 |
return((byte *)Apr.apr_pcalloc(mPool, size)); |
|---|
| 130 |
} |
|---|
| 131 |
|
|---|
| 132 |
public bool IsAncestor(AprPool pool) |
|---|
| 133 |
{ |
|---|
| 134 |
CheckPtr(); |
|---|
| 135 |
Debug.WriteLine(String.Format("apr_pool_is_ancestor({0:X},{1:X})",((Int32)mPool),((Int32)pool.mPool))); |
|---|
| 136 |
return((Apr.apr_pool_is_ancestor(mPool,pool) == 0) ? false : true); |
|---|
| 137 |
} |
|---|
| 138 |
#endregion |
|---|
| 139 |
|
|---|
| 140 |
#region Wrapper properties |
|---|
| 141 |
public AprAllocator Allocator |
|---|
| 142 |
{ |
|---|
| 143 |
get { |
|---|
| 144 |
Debug.WriteLine(String.Format("apr_pool_allocator_get({0:X})",((Int32)mPool))); |
|---|
| 145 |
return(Apr.apr_pool_allocator_get(mPool)); |
|---|
| 146 |
} |
|---|
| 147 |
} |
|---|
| 148 |
|
|---|
| 149 |
public AprPool Parent |
|---|
| 150 |
{ |
|---|
| 151 |
get { |
|---|
| 152 |
Debug.WriteLine(String.Format("apr_pool_parent_get({0:X})",((Int32)mPool))); |
|---|
| 153 |
return(Apr.apr_pool_parent_get(mPool)); |
|---|
| 154 |
} |
|---|
| 155 |
} |
|---|
| 156 |
#endregion |
|---|
| 157 |
} |
|---|
| 158 |
} |
|---|