public void H5OvisitTest1() { Assert.IsTrue(H5G.create(m_v0_test_file, "A/B/C/D", m_lcpl) >= 0); Assert.IsTrue( H5L.create_hard(m_v0_test_file, "A/B/C/D", m_v0_test_file, "shortcut") >= 0); Assert.IsTrue(H5G.create(m_v2_test_file, "A/B/C/D", m_lcpl) >= 0); Assert.IsTrue( H5L.create_hard(m_v2_test_file, "A/B/C/D", m_v2_test_file, "shortcut") >= 0); ArrayList al = new ArrayList(); GCHandle hnd = GCHandle.Alloc(al); IntPtr op_data = (IntPtr)hnd; // the callback is defined in H5LTest.cs H5O.iterate_t cb = DelegateMethod; Assert.IsTrue(H5O.visit(m_v0_test_file, H5.index_t.NAME, H5.iter_order_t.NATIVE, cb, op_data) >= 0); // we should have 5 elements in the array list Assert.IsTrue(al.Count == 5); Assert.IsTrue(H5O.visit(m_v2_test_file, H5.index_t.NAME, H5.iter_order_t.NATIVE, cb, op_data) >= 0); // we should have 10 (5 + 5) elements in the array list Assert.IsTrue(al.Count == 10); hnd.Free(); }
public void H5OvisitTest2() { string path = String.Join("/", m_utf8strings); Assert.IsTrue(H5G.create(m_v0_test_file, Encoding.UTF8.GetBytes(path), m_lcpl_utf8) >= 0); Assert.IsTrue(H5G.create(m_v2_test_file, Encoding.UTF8.GetBytes(path), m_lcpl_utf8) >= 0); ArrayList al = new ArrayList(); GCHandle hnd = GCHandle.Alloc(al); IntPtr op_data = (IntPtr)hnd; // the callback is defined in H5LTest.cs H5O.iterate_t cb = DelegateMethod; Assert.IsTrue(H5O.visit(m_v0_test_file, H5.index_t.NAME, H5.iter_order_t.NATIVE, cb, op_data) >= 0); // we should have 6 elements in the array list Assert.IsTrue(al.Count == 6); Assert.IsTrue(H5O.visit(m_v2_test_file, H5.index_t.NAME, H5.iter_order_t.NATIVE, cb, op_data) >= 0); // we should have 12 (6 + 6) elements in the array list Assert.IsTrue(al.Count == 12); hnd.Free(); }
public static Dictionary <H5I.type_t, List <string> > IterateObject2(hid_t hid) { var objects = new Dictionary <H5I.type_t, List <string> >(); H5O.visit(hid, H5.index_t.NAME, H5.iter_order_t.INC, new H5O.iterate_t( delegate(hid_t objectId, IntPtr namePtr, ref H5O.info_t info, IntPtr data) { var objectName = Marshal.PtrToStringAnsi(namePtr); switch (H5I.get_type(objectId)) { case H5I.type_t.GROUP: if (!objects.ContainsKey(H5I.type_t.GROUP)) { objects[H5I.type_t.GROUP] = new List <string>(); } objects[H5I.type_t.GROUP].Add(objectName); break; case H5I.type_t.DATASET: if (!objects.ContainsKey(H5I.type_t.DATASET)) { objects[H5I.type_t.DATASET] = new List <string>(); } objects[H5I.type_t.DATASET].Add(objectName); break; case H5I.type_t.DATATYPE: if (!objects.ContainsKey(H5I.type_t.DATATYPE)) { objects[H5I.type_t.DATATYPE] = new List <string>(); } objects[H5I.type_t.DATATYPE].Add(objectName); break; case H5I.type_t.ATTR: if (!objects.ContainsKey(H5I.type_t.ATTR)) { objects[H5I.type_t.ATTR] = new List <string>(); } objects[H5I.type_t.ATTR].Add(objectName); break; default: break; } return(0); }), IntPtr.Zero); return(objects); }