using System; using System.Collections; using System.Runtime.InteropServices; using System.Text; namespace Xpace { #region external struct Xpace_RefListCursor #if _WIN64 [StructLayout(LayoutKind.Explicit, Size = 8)] #else [StructLayout(LayoutKind.Explicit, Size = 4)] #endif public unsafe struct Xpace_RefListCursor { [FieldOffset(0)] public void* v; } #endregion public class RefList : IDisposable { #region DLL calls //void _stdcall Xpace_RefListCursor_Destroy // (Xpace_RefListCursor rlc); [DllImport("xpace.dll")] private static unsafe extern void Xpace_RefListCursor_Destroy (Xpace_RefListCursor rlc); //Xpace_Error _stdcall Xpace_RefListCursor_getCount // (Xpace_RefListCursor rlc, // uint64* result) [DllImport("xpace.dll")] private static unsafe extern IntPtr Xpace_RefListCursor_getCount (Xpace_RefListCursor rlc, UInt64* result); //Xpace_Error _stdcall Xpace_RefListCursor_getPosition // (Xpace_RefListCursor rlc, // uint64* result) [DllImport("xpace.dll")] private static unsafe extern IntPtr Xpace_RefListCursor_getPosition (Xpace_RefListCursor rlc, UInt64* result); //Xpace_Error _stdcall Xpace_RefListCursor_Move // (Xpace_RefListCursor rlc, // int64 distance, // bool relative, // bool* result) [DllImport("xpace.dll")] private static unsafe extern IntPtr Xpace_RefListCursor_Move (Xpace_RefListCursor rlc, Int64 distance, bool relative, bool* result); //Xpace_Error _stdcall Xpace_RefListCursor_getDocNum // (Xpace_RefListCursor rlc, // uint64* result) [DllImport("xpace.dll")] private static unsafe extern IntPtr Xpace_RefListCursor_getDocNum (Xpace_RefListCursor rlc, UInt64* result); #endregion #region private data Xpace_RefListCursor _ref_list_cursor; private bool _disposed = false; #endregion #region Constructor / Destructor internal RefList (Xpace_RefListCursor rlc) { _ref_list_cursor = rlc; //_pos = 0; } public void Dispose () { CleanUp(); GC.SuppressFinalize(this); } private void CleanUp () { if (!_disposed) { Xpace_RefListCursor_Destroy(_ref_list_cursor); _disposed = false; } } ~RefList () { CleanUp(); } #endregion #region properties public UInt64 Count { get { unsafe { UInt64 result; IntPtr err = Xpace_RefListCursor_getCount(_ref_list_cursor, &result); if (err != IntPtr.Zero) throw new XpaceException(err); return result; } } } /** public UInt64 this[int pos] { get { unsafe { if (pos != _pos) { bool res; IntPtr err = Xpace_RefListCursor_Move(_ref_list_cursor, pos, false, &res); if (err != IntPtr.Zero) throw new XpaceException(err); if (!pos) throw new IndexOutOfRangeException(); } UInt64 res; IntPtr err = Xpace_RefListCursor_getDocNum(_ref_list_cursor, &res); if (err != IntPtr.Zero) throw new XpaceException(err); return res; } } } **/ #endregion } /// /// A collection of static methods to search indexes and return results /// public class Search { #region DLL calls //XPACE_EXPORT Xpace_Error _stdcall Xpace_Search_Table // (const Xpace_Index index, // Xpace_TableCursor table, // Xpace_String query, // uint64 start, // uint64 count, // Xpace_Result* result); [DllImport("xpace.dll", CharSet = CharSet.Unicode)] private static unsafe extern IntPtr Xpace_Search_Table (Xpace_Index index, Xpace_TableCursor table, [MarshalAs(UnmanagedType.LPWStr)] string query, UInt64 start, UInt64 count, Xpace_Result* result); //XPACE_EXPORT Xpace_Error _stdcall Xpace_Search_List_Table // (const Xpace_IndexList indexList, // Xpace_TableCursor table, // Xpace_String query, // uint64 start, // uint64 count, // Xpace_Result* result); [DllImport("xpace.dll", CharSet = CharSet.Unicode)] private static unsafe extern IntPtr Xpace_Search_List_Table (Xpace_IndexList indexList, Xpace_TableCursor table, [MarshalAs(UnmanagedType.LPWStr)] string query, UInt64 start, UInt64 count, Xpace_Result* result); #endregion public static Result Table (Index index, TableCursor table, string query, UInt64 start, UInt64 count) { unsafe { Xpace_Result res; IntPtr err = Xpace_Search_Table(index._index, table._table_cursor, query, start, count, &res); if (err != IntPtr.Zero) throw new XpaceException(err); return new Result(&res); } } public static Result Table (IndexList indexList, TableCursor table, string query, UInt64 start, UInt64 count) { unsafe { Xpace_Result res; IntPtr err = Xpace_Search_List_Table(indexList._index_list, table._table_cursor, query, start, count, &res); if (err != IntPtr.Zero) throw new XpaceException(err); return new Result(&res); } } } }