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 |
using System.Runtime.InteropServices; |
---|
14 |
|
---|
15 |
namespace Softec.AprSharp |
---|
16 |
{ |
---|
17 |
public struct AprString |
---|
18 |
{ |
---|
19 |
IntPtr mString; |
---|
20 |
|
---|
21 |
#region Generic embedding functions of an IntPtr |
---|
22 |
private AprString(IntPtr ptr) |
---|
23 |
{ |
---|
24 |
mString = ptr; |
---|
25 |
} |
---|
26 |
|
---|
27 |
public bool IsNull() |
---|
28 |
{ |
---|
29 |
return( mString == IntPtr.Zero ); |
---|
30 |
} |
---|
31 |
|
---|
32 |
private void CheckPtr() |
---|
33 |
{ |
---|
34 |
if( IsNull() ) |
---|
35 |
throw new AprNullReferenceException(); |
---|
36 |
} |
---|
37 |
|
---|
38 |
public void ClearPtr() |
---|
39 |
{ |
---|
40 |
mString = IntPtr.Zero; |
---|
41 |
} |
---|
42 |
|
---|
43 |
public static implicit operator IntPtr(AprString str) |
---|
44 |
{ |
---|
45 |
return str.mString; |
---|
46 |
} |
---|
47 |
|
---|
48 |
public static implicit operator AprString(IntPtr ptr) |
---|
49 |
{ |
---|
50 |
return new AprString(ptr); |
---|
51 |
} |
---|
52 |
|
---|
53 |
public override string ToString() |
---|
54 |
{ |
---|
55 |
return(Marshal.PtrToStringAnsi(mString)); |
---|
56 |
} |
---|
57 |
#endregion |
---|
58 |
|
---|
59 |
#region Methods wrappers |
---|
60 |
public static AprString Duplicate(AprPool pool, string str) |
---|
61 |
{ |
---|
62 |
return(new AprString(Apr.apr_pstrdup(pool, str))); |
---|
63 |
} |
---|
64 |
|
---|
65 |
public static AprString Duplicate(AprPool pool, AprString str) |
---|
66 |
{ |
---|
67 |
return(new AprString(Apr.apr_pstrdup(pool, str))); |
---|
68 |
} |
---|
69 |
|
---|
70 |
public static AprString Duplicate(AprPool pool, string str, int size) |
---|
71 |
{ |
---|
72 |
return(AprString.Duplicate(pool, str, unchecked((uint)size))); |
---|
73 |
} |
---|
74 |
|
---|
75 |
[CLSCompliant(false)] |
---|
76 |
public static AprString Duplicate(AprPool pool, string str, uint size) |
---|
77 |
{ |
---|
78 |
return(new AprString(Apr.apr_pstrndup(pool, str, size))); |
---|
79 |
} |
---|
80 |
|
---|
81 |
public static AprString Duplicate(AprPool pool, AprString str, int size) |
---|
82 |
{ |
---|
83 |
return(AprString.Duplicate(pool, str, unchecked((uint)size))); |
---|
84 |
} |
---|
85 |
|
---|
86 |
[CLSCompliant(false)] |
---|
87 |
public static AprString Duplicate(AprPool pool, AprString str, uint size) |
---|
88 |
{ |
---|
89 |
return(new AprString(Apr.apr_pstrndup(pool, str, size))); |
---|
90 |
} |
---|
91 |
#endregion |
---|
92 |
} |
---|
93 |
} |
---|