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 |
using System.Collections; |
---|
32 |
|
---|
33 |
namespace Softec.AprSharp |
---|
34 |
{ |
---|
35 |
public struct AprHashIndex : IAprUnmanaged |
---|
36 |
{ |
---|
37 |
IntPtr mHashIndex; |
---|
38 |
|
---|
39 |
#region Generic embedding functions of an IntPtr |
---|
40 |
public AprHashIndex(IntPtr ptr) |
---|
41 |
{ |
---|
42 |
mHashIndex = ptr; |
---|
43 |
} |
---|
44 |
|
---|
45 |
public bool IsNull |
---|
46 |
{ |
---|
47 |
get |
---|
48 |
{ |
---|
49 |
return( mHashIndex == IntPtr.Zero ); |
---|
50 |
} |
---|
51 |
} |
---|
52 |
|
---|
53 |
private void CheckPtr() |
---|
54 |
{ |
---|
55 |
if( IsNull ) |
---|
56 |
throw new AprNullReferenceException(); |
---|
57 |
} |
---|
58 |
|
---|
59 |
public void ClearPtr() |
---|
60 |
{ |
---|
61 |
mHashIndex = IntPtr.Zero; |
---|
62 |
} |
---|
63 |
|
---|
64 |
public IntPtr ToIntPtr() |
---|
65 |
{ |
---|
66 |
return mHashIndex; |
---|
67 |
} |
---|
68 |
|
---|
69 |
public bool ReferenceEquals(IAprUnmanaged obj) |
---|
70 |
{ |
---|
71 |
return(obj.ToIntPtr() == ToIntPtr()); |
---|
72 |
} |
---|
73 |
|
---|
74 |
public static implicit operator IntPtr(AprHashIndex hashIndex) |
---|
75 |
{ |
---|
76 |
return hashIndex.mHashIndex; |
---|
77 |
} |
---|
78 |
|
---|
79 |
public static implicit operator AprHashIndex(IntPtr ptr) |
---|
80 |
{ |
---|
81 |
return new AprHashIndex(ptr); |
---|
82 |
} |
---|
83 |
|
---|
84 |
public override string ToString() |
---|
85 |
{ |
---|
86 |
return("[apr_hash_index_t:"+mHashIndex.ToInt32().ToString("X")+"]"); |
---|
87 |
} |
---|
88 |
#endregion |
---|
89 |
|
---|
90 |
#region Methods wrappers |
---|
91 |
public static AprHashIndex First(AprPool pool, AprHash h) |
---|
92 |
{ |
---|
93 |
IntPtr ptr; |
---|
94 |
|
---|
95 |
Debug.Write(String.Format("apr_hash_first({0},{1})...",pool,h)); |
---|
96 |
ptr = Apr.apr_hash_first(pool,h); |
---|
97 |
Debug.WriteLine(String.Format("Done({0:X})",((Int32)ptr))); |
---|
98 |
|
---|
99 |
return(ptr); |
---|
100 |
} |
---|
101 |
|
---|
102 |
public void Next() |
---|
103 |
{ |
---|
104 |
IntPtr ptr; |
---|
105 |
|
---|
106 |
CheckPtr(); |
---|
107 |
Debug.Write(String.Format("apr_hash_next({0})...",this)); |
---|
108 |
ptr = Apr.apr_hash_next(mHashIndex); |
---|
109 |
Debug.WriteLine(String.Format("Done({0:X})",((Int32)ptr))); |
---|
110 |
mHashIndex = ptr; |
---|
111 |
} |
---|
112 |
|
---|
113 |
public void This(out string key, out string value) |
---|
114 |
{ |
---|
115 |
IntPtr v; |
---|
116 |
|
---|
117 |
This(out key, out v); |
---|
118 |
value = Marshal.PtrToStringAnsi(v); |
---|
119 |
} |
---|
120 |
|
---|
121 |
public void This(out string key, out IntPtr value) |
---|
122 |
{ |
---|
123 |
IntPtr k; |
---|
124 |
int size; |
---|
125 |
|
---|
126 |
This(out k, out size, out value); |
---|
127 |
key = Marshal.PtrToStringAnsi(k); |
---|
128 |
} |
---|
129 |
|
---|
130 |
public void This(out IntPtr key, out int size, out IntPtr value) |
---|
131 |
{ |
---|
132 |
CheckPtr(); |
---|
133 |
Debug.Write(String.Format("apr_hash_this({0})...",this)); |
---|
134 |
Apr.apr_hash_this(mHashIndex, out key, out size, out value); |
---|
135 |
Debug.WriteLine(String.Format("Done({0:X},{1},{2:X})",key.ToInt32(),size,value.ToInt32())); |
---|
136 |
} |
---|
137 |
#endregion |
---|
138 |
} |
---|
139 |
} |
---|