Changeset 43

Show
Ignore:
Timestamp:
07/02/04 02:47:33 (4 years ago)
Author:
DenisG
Message:

[AprSharp] Add IAprUnmanaged and permit creation of AprArray? from ICollection

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/AprSharp/dev/src/AprAllocator.cs

    r17 r43  
    1616 
    1717    ///<summary>Embeds an opaque apr_allocator</summary> 
    18     public struct AprAllocator 
     18    public struct AprAllocator : IAprUnmanaged 
    1919    { 
    2020        private IntPtr mAllocator; 
     
    4343        { 
    4444            mAllocator = IntPtr.Zero; 
     45        } 
     46 
     47        public IntPtr ToIntPtr() 
     48        { 
     49            return mAllocator; 
    4550        } 
    4651 
  • trunk/AprSharp/dev/src/AprArray.cs

    r34 r43  
    1717namespace Softec.AprSharp 
    1818{ 
    19     public unsafe struct AprArray : IEnumerable 
     19    public unsafe struct AprArray : IEnumerable, ICollection, IAprUnmanaged 
    2020    { 
    2121        private apr_array_header_t *mArray; 
     
    7979            mArray = null; 
    8080            mEltsType = null; 
     81        } 
     82 
     83        public IntPtr ToIntPtr() 
     84        { 
     85            return new IntPtr(mArray); 
    8186        } 
    8287 
     
    141146        } 
    142147 
     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         
    143168        public AprArray Copy(AprPool pool) 
    144169        { 
     
    288313            CheckPtr(); 
    289314            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            } 
    290354        } 
    291355         
  • trunk/AprSharp/dev/src/AprFile.cs

    r37 r43  
    1414namespace Softec.AprSharp 
    1515{ 
    16     public struct AprFile 
     16    public struct AprFile : IAprUnmanaged 
    1717    { 
    1818        [Flags] 
     
    8787        } 
    8888 
     89        public IntPtr ToIntPtr() 
     90        { 
     91            return mFile; 
     92        } 
     93 
    8994        public static implicit operator IntPtr(AprFile file) 
    9095        { 
  • trunk/AprSharp/dev/src/AprHash.cs

    r39 r43  
    1616namespace Softec.AprSharp 
    1717{ 
    18     public struct AprHash : IEnumerable, ICollection 
     18    public struct AprHash : IEnumerable, ICollection, IAprUnmanaged 
    1919    { 
    2020        IntPtr mHash; 
     
    4343        { 
    4444            mHash = IntPtr.Zero; 
     45        } 
     46 
     47        public IntPtr ToIntPtr() 
     48        { 
     49            return mHash; 
    4550        } 
    4651 
  • trunk/AprSharp/dev/src/AprHashIndex.cs

    r17 r43  
    1616namespace Softec.AprSharp 
    1717{ 
    18     public struct AprHashIndex 
     18    public struct AprHashIndex : IAprUnmanaged 
    1919    { 
    2020        IntPtr mHashIndex; 
     
    4343        { 
    4444            mHashIndex = IntPtr.Zero; 
     45        } 
     46 
     47        public IntPtr ToIntPtr() 
     48        { 
     49            return mHashIndex; 
    4550        } 
    4651 
  • trunk/AprSharp/dev/src/AprMemNode.cs

    r22 r43  
    6060        } 
    6161 
     62        public IntPtr ToIntPtr() 
     63        { 
     64            return new IntPtr(mMemNode); 
     65        } 
     66 
    6267        public static implicit operator IntPtr(AprMemNode memNode) 
    6368        { 
  • trunk/AprSharp/dev/src/AprPool.cs

    r17 r43  
    1515{ 
    1616 
    17     public struct AprPool 
     17    public struct AprPool : IAprUnmanaged 
    1818    { 
    1919        IntPtr mPool; 
     
    4242        { 
    4343            mPool = IntPtr.Zero; 
     44        } 
     45 
     46        public IntPtr ToIntPtr() 
     47        { 
     48            return mPool; 
    4449        } 
    4550 
  • trunk/AprSharp/dev/src/AprSharp.prjx

    r37 r43  
    2222    <File name="./AprInvalidOperationException.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 
    2323    <File name="./AprFile.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 
     24    <File name="./IAprUnmanaged.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 
    2425  </Contents> 
    2526  <References /> 
  • trunk/AprSharp/dev/src/AprString.cs

    r39 r43  
    1515namespace Softec.AprSharp 
    1616{ 
    17     public struct AprString 
     17    public struct AprString : IAprUnmanaged 
    1818    { 
    1919        IntPtr mString; 
     
    7676        } 
    7777 
     78        public IntPtr ToIntPtr() 
     79        { 
     80            return mString; 
     81        } 
     82 
    7883        public static implicit operator IntPtr(AprString str) 
    7984        { 
  • trunk/AprSharp/dev/src/AprThreadMutex.cs

    r17 r43  
    1414namespace Softec.AprSharp 
    1515{ 
    16     public struct AprThreadMutex 
     16    public struct AprThreadMutex : IAprUnmanaged 
    1717    { 
    1818        IntPtr mThreadMutex; 
     
    4949        { 
    5050            mThreadMutex = IntPtr.Zero; 
     51        } 
     52 
     53        public IntPtr ToIntPtr() 
     54        { 
     55            return mThreadMutex; 
    5156        } 
    5257 
  • trunk/AprSharp/dev/src/AprTimeExp.cs

    r22 r43  
    1616namespace Softec.AprSharp 
    1717{ 
    18     public unsafe struct AprTimeExp 
     18    public unsafe struct AprTimeExp : IAprUnmanaged 
    1919    { 
    2020        private apr_time_exp_t *mTimeExp; 
     
    7272        } 
    7373 
     74        public IntPtr ToIntPtr() 
     75        { 
     76            return new IntPtr(mTimeExp); 
     77        } 
     78 
    7479        public static implicit operator IntPtr(AprTimeExp timeExp) 
    7580        { 
  • trunk/AprSharp/test/src/AprArrayTest.cs

    r39 r43  
    245245         
    246246        [Test] 
    247         public void CopyTo() 
     247        public void ArrayOfAprString() 
    248248        { 
    249249            AprPool p = AprPool.Create(); 
     
    274274            Assert.AreEqual("5",arr[4].ToString(),"#F12"); 
    275275             
    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"); 
    278286        } 
    279287         
     
    308316            Assert.AreEqual((IntPtr)2147483647, arr[4],"#I12"); 
    309317 
    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"); 
    312328        } 
    313329         
     
    342358            Assert.IsTrue(arr[4],"#G12"); 
    343359 
    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"); 
    346370        } 
    347371 
     
    376400            Assert.AreEqual((byte)255, arr[4],"#I12"); 
    377401 
    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"); 
    380412        } 
    381413     
     
    410442            Assert.AreEqual((sbyte)127, arr[4],"#J12"); 
    411443 
    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"); 
    414454        } 
    415455 
     
    445485            Assert.AreEqual((short)32767, arr[4],"#K12"); 
    446486 
    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"); 
    449497        } 
    450498     
     
    479527            Assert.AreEqual((ushort)65535, arr[4],"#L12"); 
    480528 
    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"); 
    483539        } 
    484540 
     
    513569            Assert.AreEqual((int)2147483647, arr[4],"#M12"); 
    514570 
    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"); 
    517581        } 
    518582     
     
    547611            Assert.AreEqual((uint)4294967295, arr[4],"#N12"); 
    548612 
    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"); 
    551623        } 
    552624         
     
    581653            Assert.AreEqual((long)9223372036854775807, arr[4],"#O12"); 
    582654 
    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"); 
    585665        } 
    586666     
     
    615695            Assert.AreEqual((ulong)18446744073709551615, arr[4],"#P12"); 
    616696 
    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"); 
    619707        } 
    620708         
     709 
    621710    } 
    622711}