1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2009 Oracle. All rights reserved. 5 * 6 */ 7using System; 8using System.Collections; 9using System.Collections.Generic; 10using System.Text; 11 12namespace BerkeleyDB { 13 /// <summary> 14 /// A class providing access to multiple <see cref="DatabaseEntry"/> 15 /// objects. 16 /// </summary> 17 public class MultipleDatabaseEntry : IEnumerable<DatabaseEntry> { 18 private byte[] data; 19 private uint ulen; 20 21 internal MultipleDatabaseEntry(DatabaseEntry dbt) { 22 data = dbt.UserData; 23 ulen = dbt.ulen; 24 } 25 26 IEnumerator IEnumerable.GetEnumerator() { 27 return GetEnumerator(); 28 } 29 30 /// <summary> 31 /// Return an enumerator which iterates over all 32 /// <see cref="DatabaseEntry"/> objects represented by the 33 /// <see cref="MultipleDatabaseEntry"/>. 34 /// </summary> 35 /// <returns> 36 /// An enumerator for the <see cref="MultipleDatabaseEntry"/> 37 /// </returns> 38 public IEnumerator<DatabaseEntry> GetEnumerator() { 39 uint pos = ulen - 4; 40 int off = BitConverter.ToInt32(data, (int)pos); 41 for (int i = 0; 42 off >= 0; off = BitConverter.ToInt32(data, (int)pos), i++) { 43 pos -= 4; 44 int sz = BitConverter.ToInt32(data, (int)pos); 45 byte[] arr = new byte[sz]; 46 Array.Copy(data, off, arr, 0, sz); 47 pos -= 4; 48 yield return new DatabaseEntry(arr); 49 } 50 } 51 52 // public byte[][] Data; 53 /* No Public Constructor */ 54 //internal MultipleDatabaseEntry(DatabaseEntry dbt) { 55 // byte[] dat = dbt.UserData; 56 // List<byte[]> tmp = new List<byte[]>(); 57 // uint pos = dbt.ulen - 4; 58 // int off = BitConverter.ToInt32(dat, (int)pos); 59 // for (int i = 0; off > 0; off = BitConverter.ToInt32(dat, (int)pos), i++) { 60 // pos -= 4; 61 // int sz = BitConverter.ToInt32(dat, (int)pos); 62 // tmp.Add(new byte[sz]); 63 // Array.Copy(dat, off, tmp[i], 0, sz); 64 // pos -= 4; 65 // } 66 // Data = tmp.ToArray(); 67 //} 68 69 70 } 71} 72