Changeset 43
- Timestamp:
- 07/02/04 02:47:33 (4 years ago)
- Files:
-
- trunk/AprSharp/dev/src/AprAllocator.cs (modified) (2 diffs)
- trunk/AprSharp/dev/src/AprArray.cs (modified) (4 diffs)
- trunk/AprSharp/dev/src/AprFile.cs (modified) (2 diffs)
- trunk/AprSharp/dev/src/AprHash.cs (modified) (2 diffs)
- trunk/AprSharp/dev/src/AprHashIndex.cs (modified) (2 diffs)
- trunk/AprSharp/dev/src/AprMemNode.cs (modified) (1 diff)
- trunk/AprSharp/dev/src/AprPool.cs (modified) (2 diffs)
- trunk/AprSharp/dev/src/AprSharp.prjx (modified) (1 diff)
- trunk/AprSharp/dev/src/AprString.cs (modified) (2 diffs)
- trunk/AprSharp/dev/src/AprThreadMutex.cs (modified) (2 diffs)
- trunk/AprSharp/dev/src/AprTimeExp.cs (modified) (2 diffs)
- trunk/AprSharp/dev/src/IAprUnmanaged.cs (added)
- trunk/AprSharp/test/src/AprArrayTest.cs (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/AprSharp/dev/src/AprAllocator.cs
r17 r43 16 16 17 17 ///<summary>Embeds an opaque apr_allocator</summary> 18 public struct AprAllocator 18 public struct AprAllocator : IAprUnmanaged 19 19 { 20 20 private IntPtr mAllocator; … … 43 43 { 44 44 mAllocator = IntPtr.Zero; 45 } 46 47 public IntPtr ToIntPtr() 48 { 49 return mAllocator; 45 50 } 46 51 trunk/AprSharp/dev/src/AprArray.cs
r34 r43 17 17 namespace Softec.AprSharp 18 18 { 19 public unsafe struct AprArray : IEnumerable 19 public unsafe struct AprArray : IEnumerable, ICollection, IAprUnmanaged 20 20 { 21 21 private apr_array_header_t *mArray; … … 79 79 mArray = null; 80 80 mEltsType = null; 81 } 82 83 public IntPtr ToIntPtr() 84 { 85 return new IntPtr(mArray); 81 86 } 82 87 … … 141 146 } 142 147 148 public static AprArray Make(AprPool pool, ICollection list ) 149 { 150 if(list is AprArray) 151 //return(((AprArray)list).Copy(pool)); 152 return (AprArray)list; 153 else 154 { 155 IEnumerator it = list.GetEnumerator(); 156 it.MoveNext(); 157 158 AprArray a = Make(pool, list.Count, it.Current.GetType()); 159 it.Reset(); 160 161 while(it.MoveNext()) { 162 a.Push(it.Current); 163 } 164 return(a); 165 } 166 } 167 143 168 public AprArray Copy(AprPool pool) 144 169 { … … 288 313 CheckPtr(); 289 314 Marshal.WriteIntPtr(Push(),ptr); 315 } 316 317 public void Push(object o) 318 { 319 if(mEltsType.IsPrimitive) 320 { 321 if(mEltsType == typeof(bool)) 322 Push((bool)o); 323 else if(mEltsType == typeof(byte)) 324 Push((byte)o); 325 else if(mEltsType == typeof(sbyte)) 326 Push((sbyte)o); 327 else if(mEltsType == typeof(short)) 328 Push((short)o); 329 else if(mEltsType == typeof(ushort)) 330 Push((ushort)o); 331 else if(mEltsType == typeof(int)) 332 Push((int)o); 333 else if(mEltsType == typeof(uint)) 334 Push((uint)o); 335 else if(mEltsType == typeof(long)) 336 Push((long)o); 337 else if(mEltsType == typeof(ulong)) 338 Push((ulong)o); 339 else 340 throw new AprInvalidOperationException("Array type not supported."); 341 } 342 else 343 { 344 if(mEltsType == typeof(IntPtr)) 345 Push((IntPtr)o); 346 else 347 { 348 IAprUnmanaged obj = o as IAprUnmanaged; 349 if( o == null ) 350 throw new AprInvalidOperationException("Array type should implement IAprUnmanaged."); 351 Push(obj.ToIntPtr()); 352 } 353 } 290 354 } 291 355 trunk/AprSharp/dev/src/AprFile.cs
r37 r43 14 14 namespace Softec.AprSharp 15 15 { 16 public struct AprFile 16 public struct AprFile : IAprUnmanaged 17 17 { 18 18 [Flags] … … 87 87 } 88 88 89 public IntPtr ToIntPtr() 90 { 91 return mFile; 92 } 93 89 94 public static implicit operator IntPtr(AprFile file) 90 95 { trunk/AprSharp/dev/src/AprHash.cs
r39 r43 16 16 namespace Softec.AprSharp 17 17 { 18 public struct AprHash : IEnumerable, ICollection 18 public struct AprHash : IEnumerable, ICollection, IAprUnmanaged 19 19 { 20 20 IntPtr mHash; … … 43 43 { 44 44 mHash = IntPtr.Zero; 45 } 46 47 public IntPtr ToIntPtr() 48 { 49 return mHash; 45 50 } 46 51 trunk/AprSharp/dev/src/AprHashIndex.cs
r17 r43 16 16 namespace Softec.AprSharp 17 17 { 18 public struct AprHashIndex 18 public struct AprHashIndex : IAprUnmanaged 19 19 { 20 20 IntPtr mHashIndex; … … 43 43 { 44 44 mHashIndex = IntPtr.Zero; 45 } 46 47 public IntPtr ToIntPtr() 48 { 49 return mHashIndex; 45 50 } 46 51 trunk/AprSharp/dev/src/AprMemNode.cs
r22 r43 60 60 } 61 61 62 public IntPtr ToIntPtr() 63 { 64 return new IntPtr(mMemNode); 65 } 66 62 67 public static implicit operator IntPtr(AprMemNode memNode) 63 68 { trunk/AprSharp/dev/src/AprPool.cs
r17 r43 15 15 { 16 16 17 public struct AprPool 17 public struct AprPool : IAprUnmanaged 18 18 { 19 19 IntPtr mPool; … … 42 42 { 43 43 mPool = IntPtr.Zero; 44 } 45 46 public IntPtr ToIntPtr() 47 { 48 return mPool; 44 49 } 45 50 trunk/AprSharp/dev/src/AprSharp.prjx
r37 r43 22 22 <File name="./AprInvalidOperationException.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 23 23 <File name="./AprFile.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 24 <File name="./IAprUnmanaged.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 24 25 </Contents> 25 26 <References /> trunk/AprSharp/dev/src/AprString.cs
r39 r43 15 15 namespace Softec.AprSharp 16 16 { 17 public struct AprString 17 public struct AprString : IAprUnmanaged 18 18 { 19 19 IntPtr mString; … … 76 76 } 77 77 78 public IntPtr ToIntPtr() 79 { 80 return mString; 81 } 82 78 83 public static implicit operator IntPtr(AprString str) 79 84 { trunk/AprSharp/dev/src/AprThreadMutex.cs
r17 r43 14 14 namespace Softec.AprSharp 15 15 { 16 public struct AprThreadMutex 16 public struct AprThreadMutex : IAprUnmanaged 17 17 { 18 18 IntPtr mThreadMutex; … … 49 49 { 50 50 mThreadMutex = IntPtr.Zero; 51 } 52 53 public IntPtr ToIntPtr() 54 { 55 return mThreadMutex; 51 56 } 52 57 trunk/AprSharp/dev/src/AprTimeExp.cs
r22 r43 16 16 namespace Softec.AprSharp 17 17 { 18 public unsafe struct AprTimeExp 18 public unsafe struct AprTimeExp : IAprUnmanaged 19 19 { 20 20 private apr_time_exp_t *mTimeExp; … … 72 72 } 73 73 74 public IntPtr ToIntPtr() 75 { 76 return new IntPtr(mTimeExp); 77 } 78 74 79 public static implicit operator IntPtr(AprTimeExp timeExp) 75 80 { trunk/AprSharp/test/src/AprArrayTest.cs
r39 r43 245 245 246 246 [Test] 247 public void CopyTo()247 public void ArrayOfAprString() 248 248 { 249 249 AprPool p = AprPool.Create(); … … 274 274 Assert.AreEqual("5",arr[4].ToString(),"#F12"); 275 275 276 p.Destroy(); 277 Assert.IsTrue(p.IsNull,"#F13"); 276 a = AprArray.Make(p,arr); 277 278 Assert.AreEqual("5",a.PopObject().ToString(),"#F13"); 279 Assert.AreEqual("4",a.PopObject().ToString(),"#F14"); 280 Assert.AreEqual("3",a.PopObject().ToString(),"#F15"); 281 Assert.AreEqual("2",a.PopObject().ToString(),"#F16"); 282 Assert.AreEqual("1",a.PopObject().ToString(),"#F17"); 283 284 p.Destroy(); 285 Assert.IsTrue(p.IsNull,"#F18"); 278 286 } 279 287 … … 308 316 Assert.AreEqual((IntPtr)2147483647, arr[4],"#I12"); 309 317 310 p.Destroy(); 311 Assert.IsTrue(p.IsNull,"#I13"); 318 a = AprArray.Make(p,arr); 319 320 Assert.AreEqual((IntPtr)2147483647, a.PopObject(),"#G13"); 321 Assert.AreEqual((IntPtr)1000000, a.PopObject(),"#G14"); 322 Assert.AreEqual((IntPtr)1000, a.PopObject(),"#G15"); 323 Assert.AreEqual((IntPtr)1, a.PopObject(),"#G16"); 324 Assert.AreEqual((IntPtr)0, a.PopObject(),"#G17"); 325 326 p.Destroy(); 327 Assert.IsTrue(p.IsNull,"#I18"); 312 328 } 313 329 … … 342 358 Assert.IsTrue(arr[4],"#G12"); 343 359 344 p.Destroy(); 345 Assert.IsTrue(p.IsNull,"#G13"); 360 a = AprArray.Make(p,arr); 361 362 Assert.IsTrue((bool)a.PopObject(),"#G13"); 363 Assert.IsFalse((bool)a.PopObject(),"#G14"); 364 Assert.IsTrue((bool)a.PopObject(),"#G15"); 365 Assert.IsFalse((bool)a.PopObject(),"#G16"); 366 Assert.IsTrue((bool)a.PopObject(),"#G17"); 367 368 p.Destroy(); 369 Assert.IsTrue(p.IsNull,"#G18"); 346 370 } 347 371 … … 376 400 Assert.AreEqual((byte)255, arr[4],"#I12"); 377 401 378 p.Destroy(); 379 Assert.IsTrue(p.IsNull,"#I13"); 402 a = AprArray.Make(p,arr); 403 404 Assert.AreEqual((byte)255, a.PopObject(),"#I13"); 405 Assert.AreEqual((byte)100, a.PopObject(),"#I14"); 406 Assert.AreEqual((byte)10, a.PopObject(),"#I15"); 407 Assert.AreEqual((byte)1, a.PopObject(),"#I16"); 408 Assert.AreEqual((byte)0, a.PopObject(),"#I17"); 409 410 p.Destroy(); 411 Assert.IsTrue(p.IsNull,"#I18"); 380 412 } 381 413 … … 410 442 Assert.AreEqual((sbyte)127, arr[4],"#J12"); 411 443 412 p.Destroy(); 413 Assert.IsTrue(p.IsNull,"#J13"); 444 a = AprArray.Make(p,arr); 445 446 Assert.AreEqual((sbyte)127, a.PopObject(),"#J13"); 447 Assert.AreEqual((sbyte)-100, a.PopObject(),"#J14"); 448 Assert.AreEqual((sbyte)10, a.PopObject(),"#J15"); 449 Assert.AreEqual((sbyte)-1, a.PopObject(),"#J16"); 450 Assert.AreEqual((sbyte)0, a.PopObject(),"#J17"); 451 452 p.Destroy(); 453 Assert.IsTrue(p.IsNull,"#J18"); 414 454 } 415 455 … … 445 485 Assert.AreEqual((short)32767, arr[4],"#K12"); 446 486 447 p.Destroy(); 448 Assert.IsTrue(p.IsNull,"#K13"); 487 a = AprArray.Make(p,arr); 488 489 Assert.AreEqual((short)32767, a.PopObject(),"#K13"); 490 Assert.AreEqual((short)-1000, a.PopObject(),"#K14"); 491 Assert.AreEqual((short)100, a.PopObject(),"#K15"); 492 Assert.AreEqual((short)-1, a.PopObject(),"#K16"); 493 Assert.AreEqual((short)0, a.PopObject(),"#K17"); 494 495 p.Destroy(); 496 Assert.IsTrue(p.IsNull,"#K18"); 449 497 } 450 498 … … 479 527 Assert.AreEqual((ushort)65535, arr[4],"#L12"); 480 528 481 p.Destroy(); 482 Assert.IsTrue(p.IsNull,"#L13"); 529 a = AprArray.Make(p,arr); 530 531 Assert.AreEqual((ushort)65535, a.PopObject(),"#L13"); 532 Assert.AreEqual((ushort)1000, a.PopObject(),"#L14"); 533 Assert.AreEqual((ushort)100, a.PopObject(),"#L15"); 534 Assert.AreEqual((ushort)1, a.PopObject(),"#L16"); 535 Assert.AreEqual((ushort)0, a.PopObject(),"#L17"); 536 537 p.Destroy(); 538 Assert.IsTrue(p.IsNull,"#L18"); 483 539 } 484 540 … … 513 569 Assert.AreEqual((int)2147483647, arr[4],"#M12"); 514 570 515 p.Destroy(); 516 Assert.IsTrue(p.IsNull,"#M13"); 571 a = AprArray.Make(p,arr); 572 573 Assert.AreEqual((int)2147483647, a.PopObject(),"#M13"); 574 Assert.AreEqual((int)-1000000, a.PopObject(),"#M14"); 575 Assert.AreEqual((int)10000, a.PopObject(),"#M15"); 576 Assert.AreEqual((int)-1, a.PopObject(),"#M16"); 577 Assert.AreEqual((int)0, a.PopObject(),"#M17"); 578 579 p.Destroy(); 580 Assert.IsTrue(p.IsNull,"#M18"); 517 581 } 518 582 … … 547 611 Assert.AreEqual((uint)4294967295, arr[4],"#N12"); 548 612 549 p.Destroy(); 550 Assert.IsTrue(p.IsNull,"#N13"); 613 a = AprArray.Make(p,arr); 614 615 Assert.AreEqual((uint)4294967295, a.PopObject(),"#N13"); 616 Assert.AreEqual((uint)1000000, a.PopObject(),"#N14"); 617 Assert.AreEqual((uint)10000, a.PopObject(),"#N15"); 618 Assert.AreEqual((uint)1, a.PopObject(),"#N16"); 619 Assert.AreEqual((uint)0, a.PopObject(),"#N17"); 620 621 p.Destroy(); 622 Assert.IsTrue(p.IsNull,"#N18"); 551 623 } 552 624 … … 581 653 Assert.AreEqual((long)9223372036854775807, arr[4],"#O12"); 582 654 583 p.Destroy(); 584 Assert.IsTrue(p.IsNull,"#O13"); 655 a = AprArray.Make(p,arr); 656 657 Assert.AreEqual((long)9223372036854775807, a.PopObject(),"#O13"); 658 Assert.AreEqual((long)-1000000000, a.PopObject(),"#O14"); 659 Assert.AreEqual((long)100000, a.PopObject(),"#O15"); 660 Assert.AreEqual((long)-1, a.PopObject(),"#O16"); 661 Assert.AreEqual((long)0, a.PopObject(),"#O17"); 662 663 p.Destroy(); 664 Assert.IsTrue(p.IsNull,"#O18"); 585 665 } 586 666 … … 615 695 Assert.AreEqual((ulong)18446744073709551615, arr[4],"#P12"); 616 696 617 p.Destroy(); 618 Assert.IsTrue(p.IsNull,"#P13"); 697 a = AprArray.Make(p,arr); 698 699 Assert.AreEqual((ulong)18446744073709551615, a.PopObject(),"#P13"); 700 Assert.AreEqual((ulong)1000000000, a.PopObject(),"#P14"); 701 Assert.AreEqual((ulong)100000, a.PopObject(),"#P15"); 702 Assert.AreEqual((ulong)1, a.PopObject(),"#P16"); 703 Assert.AreEqual((ulong)0, a.PopObject(),"#P17"); 704 705 p.Destroy(); 706 Assert.IsTrue(p.IsNull,"#P18"); 619 707 } 620 708 709 621 710 } 622 711 }