diff --git a/DTLib.Dtsod/DTLib.Dtsod.csproj b/DTLib.Dtsod/DTLib.Dtsod.csproj index 9fc92a5..a37ad21 100644 --- a/DTLib.Dtsod/DTLib.Dtsod.csproj +++ b/DTLib.Dtsod/DTLib.Dtsod.csproj @@ -25,7 +25,7 @@ - + Always diff --git a/DTLib.Dtsod/Dependencies/kerep.dll b/DTLib.Dtsod/Dependencies/kerep.dll deleted file mode 100644 index 0a231e7..0000000 Binary files a/DTLib.Dtsod/Dependencies/kerep.dll and /dev/null differ diff --git a/DTLib.Dtsod/Dependencies/kerep.so b/DTLib.Dtsod/Dependencies/linux/x64/kerep.so similarity index 64% rename from DTLib.Dtsod/Dependencies/kerep.so rename to DTLib.Dtsod/Dependencies/linux/x64/kerep.so index 656d2a8..c1abf1c 100644 Binary files a/DTLib.Dtsod/Dependencies/kerep.so and b/DTLib.Dtsod/Dependencies/linux/x64/kerep.so differ diff --git a/DTLib.Dtsod/Dependencies/windows/x64/kerep.dll b/DTLib.Dtsod/Dependencies/windows/x64/kerep.dll new file mode 100644 index 0000000..bdf280b Binary files /dev/null and b/DTLib.Dtsod/Dependencies/windows/x64/kerep.dll differ diff --git a/DTLib.Dtsod/Dependencies/windows/x86/kerep.dll b/DTLib.Dtsod/Dependencies/windows/x86/kerep.dll new file mode 100644 index 0000000..a760280 Binary files /dev/null and b/DTLib.Dtsod/Dependencies/windows/x86/kerep.dll differ diff --git a/DTLib.Dtsod/V24/Autoarr/Autoarr.cs b/DTLib.Dtsod/V24/Autoarr/Autoarr.cs index d105c09..ba95bb1 100644 --- a/DTLib.Dtsod/V24/Autoarr/Autoarr.cs +++ b/DTLib.Dtsod/V24/Autoarr/Autoarr.cs @@ -46,18 +46,13 @@ public class Autoarr : IEnumerable, IDisposable where T : struct public void Dispose() { - Funcs.Free(UnmanagedPtr); + if(AutoDispose) + Funcs.Free(UnmanagedPtr); } - public IEnumerator GetEnumerator() - { - return new AutoarrEnumerator(this); - } + public IEnumerator GetEnumerator() => new AutoarrEnumerator(this); - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); public void Add(T value) { @@ -79,17 +74,12 @@ public class Autoarr : IEnumerable, IDisposable where T : struct private readonly Autoarr arr; private uint index; - public AutoarrEnumerator(Autoarr ar) - { - arr = ar; - } + public AutoarrEnumerator(Autoarr ar) => arr = ar; public T Current { get; private set; } object IEnumerator.Current => Current; - public void Dispose() - { - } + public void Dispose() { } public bool MoveNext() { diff --git a/DTLib.Dtsod/V24/DependencyResolver.cs b/DTLib.Dtsod/V24/DependencyResolver.cs deleted file mode 100644 index 477d698..0000000 --- a/DTLib.Dtsod/V24/DependencyResolver.cs +++ /dev/null @@ -1,20 +0,0 @@ -using DTLib.Filesystem; - -namespace DTLib.Dtsod.V24; - -public static class DependencyResolver -{ - private static bool KerepCopied=false; - - public static void CopyLibs() - { - if(KerepCopied) return; - - string kereplib = Environment.OSVersion.Platform == PlatformID.Win32NT - ? "kerep.dll" - : "kerep.so"; - File.Copy($"Dependencies{Путь.Разд}{kereplib}",kereplib, true); - KerepCopied = true; - Log("g",$"{kereplib} copied"); - } -} \ No newline at end of file diff --git a/DTLib.Dtsod/V24/DtsodV24.cs b/DTLib.Dtsod/V24/DtsodV24.cs index 2b658e2..7ca6b41 100644 --- a/DTLib.Dtsod/V24/DtsodV24.cs +++ b/DTLib.Dtsod/V24/DtsodV24.cs @@ -4,7 +4,7 @@ using Funcs=DTLib.Dtsod.V24.DtsodV24Functions; namespace DTLib.Dtsod.V24; -public class DtsodV24 : IDtsod, IEnumerable>, IDisposable +public class DtsodV24 : IDtsod, IEnumerable, IDisposable { public DtsodVersion Version => DtsodVersion.V24; public readonly DtsodPtr UnmanagedPtr; @@ -29,7 +29,9 @@ public class DtsodV24 : IDtsod, IEnumerable>, IDisposable public IDictionary ToDictionary() { DtsodDict dict = new(); - throw new NotImplementedException(); + foreach (var p in this) + dict.Add(p.key,p.value.ToDynamic()); + return dict; } @@ -68,31 +70,41 @@ public class DtsodV24 : IDtsod, IEnumerable>, IDisposable } - public IEnumerator> GetEnumerator() => new DtsodV24Enumerator(this); + public IEnumerator GetEnumerator() => new DtsodV24Enumerator(this); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - class DtsodV24Enumerator: IEnumerator> + class DtsodV24Enumerator: IEnumerator { private readonly DtsodV24 d; private ushort h; + private IEnumerator arEnumerator; public DtsodV24Enumerator(DtsodV24 _d) => d = _d; - - public void Dispose() { } + bool NextAr() + { + if (h >= Funcs.Height(d.UnmanagedPtr)) return false; + var ar = new Autoarr(Funcs.GetRow(d.UnmanagedPtr, h), false); + arEnumerator = ar.GetEnumerator(); + h++; + return true; + } + public bool MoveNext() { - if(h >= Funcs.Height(d.UnmanagedPtr)) return false; - Current = new Autoarr(Funcs.GetRow(d.UnmanagedPtr,h), false); - h++; + if(arEnumerator==null) + NextAr(); + while(!arEnumerator.MoveNext()) + if(!NextAr()) return false; + Current = arEnumerator.Current; return true; } public void Reset() => h = 0; - - public Autoarr Current { get; private set; } - + public KVPair Current { get; private set; } object IEnumerator.Current => Current; + + public void Dispose() { } } } \ No newline at end of file diff --git a/DTLib.Dtsod/V24/DtsodV24Functions.cs b/DTLib.Dtsod/V24/DtsodV24Functions.cs index 73b08e0..16ea055 100644 --- a/DTLib.Dtsod/V24/DtsodV24Functions.cs +++ b/DTLib.Dtsod/V24/DtsodV24Functions.cs @@ -9,6 +9,8 @@ namespace DTLib.Dtsod.V24; internal static class DtsodV24Functions { + private const string kereplib = "kerep"; + static DtsodV24Functions() { DependencyResolver.CopyLibs(); @@ -24,7 +26,7 @@ internal static class DtsodV24Functions //parses text to binary values - [DllImport("kerep", CallingConvention = CallingConvention.Cdecl)] + [DllImport(kereplib, CallingConvention = CallingConvention.Cdecl)] static extern void kerep_DtsodV24_deserialize(string text, out DtsodPtr output, out CharPtr errmsg); internal static DtsodPtr Deserialize(string text) { @@ -34,7 +36,7 @@ internal static class DtsodV24Functions } //creates text representation of dtsod - [DllImport("kerep", CallingConvention = CallingConvention.Cdecl)] + [DllImport(kereplib, CallingConvention = CallingConvention.Cdecl)] static extern void kerep_DtsodV24_serialize(DtsodPtr dtsod, out CharPtr output, out CharPtr errmsg); internal static string Serialize(DtsodPtr dtsod) { @@ -43,7 +45,7 @@ internal static class DtsodV24Functions return Marshal.PtrToStringUTF8(text); } - [DllImport("kerep", CallingConvention = CallingConvention.Cdecl)] + [DllImport(kereplib, CallingConvention = CallingConvention.Cdecl)] static extern void kerep_DtsodV24_get(DtsodPtr dtsod, string key, out Unitype output); //returns value or UniNull if key not found internal static Unitype Get(DtsodPtr dtsod, string key) @@ -52,7 +54,7 @@ internal static class DtsodV24Functions return output; } - [DllImport("kerep",EntryPoint = "kerep_DtsodV24_addOrSet",CallingConvention = CallingConvention.Cdecl)] + [DllImport(kereplib,EntryPoint = "kerep_DtsodV24_addOrSet",CallingConvention = CallingConvention.Cdecl)] //adds or sets value static extern void kerep_DtsodV24_addOrSet(DtsodPtr dtsod, IntPtr key, Unitype value); @@ -62,7 +64,7 @@ internal static class DtsodV24Functions kerep_DtsodV24_addOrSet(dtsod, keyptr, value); } - [DllImport("kerep", CallingConvention = CallingConvention.Cdecl)] + [DllImport(kereplib, CallingConvention = CallingConvention.Cdecl)] //checks for dtsod contains value or dont static extern void kerep_DtsodV24_contains(DtsodPtr dtsod, string key, [MarshalAs(UnmanagedType.I1)] out bool output); internal static bool Contains(DtsodPtr dtsod, string key) @@ -71,7 +73,7 @@ internal static class DtsodV24Functions return output; } - [DllImport("kerep", CallingConvention = CallingConvention.Cdecl)] + [DllImport(kereplib, CallingConvention = CallingConvention.Cdecl)] static extern void kerep_DtsodV24_remove(DtsodPtr dtsod, string key, [MarshalAs(UnmanagedType.I1)] out bool output); //replaces value with UniNull if key exists in dtsod internal static bool Remove(DtsodPtr dtsod, string key) @@ -80,11 +82,11 @@ internal static class DtsodV24Functions return output; } - [DllImport("kerep",EntryPoint="kerep_DtsodV24_free", CallingConvention = CallingConvention.Cdecl)] + [DllImport(kereplib,EntryPoint="kerep_DtsodV24_free", CallingConvention = CallingConvention.Cdecl)] //replaces value with UniNull if key exists in dtsod internal static extern void Free(DtsodPtr dtsod); - [DllImport("kerep", CallingConvention = CallingConvention.Cdecl)] + [DllImport(kereplib, CallingConvention = CallingConvention.Cdecl)] static extern void kerep_DtsodV24_height(DtsodPtr dtsod, out ushort heigth); //returns current amounts of rows (Autoarrs of KVPairs) in hashtable internal static ushort Height(DtsodPtr ptr) @@ -93,7 +95,7 @@ internal static class DtsodV24Functions return h; } - [DllImport("kerep", CallingConvention = CallingConvention.Cdecl)] + [DllImport(kereplib, CallingConvention = CallingConvention.Cdecl)] static extern void kerep_DtsodV24_getrow(DtsodPtr dtsod, ushort h, out AutoarrKVPairPtr row); //Returns row from hashtable. //check current hashtable height before calling this. diff --git a/DTLib.Dtsod/V24/KerepTypes/Unitype.cs b/DTLib.Dtsod/V24/KerepTypes/Unitype.cs index da38370..6845e72 100644 --- a/DTLib.Dtsod/V24/KerepTypes/Unitype.cs +++ b/DTLib.Dtsod/V24/KerepTypes/Unitype.cs @@ -65,48 +65,6 @@ public struct Unitype default: throw new Exception($"can't box value of type {TypeCode}"); } } - - /*public Unitype(bool v) : this() - { - TypeCode = KerepTypeCode.Bool; - Bool = v; - } - public Unitype(int v) : this() - { - TypeCode = KerepTypeCode.Int64; - Int64 = v; - } - public Unitype(uint v) : this() - { - TypeCode = KerepTypeCode.UInt64; - UInt64 = v; - } - public Unitype(double v) : this() - { - TypeCode = KerepTypeCode.Float64; - Float64 = v; - } - public Unitype(string s) : this() - { - TypeCode = KerepTypeCode.CharPtr; - VoidPtr = s.ToHGlobalUTF8(); - } - - public Unitype(Autoarr v) : this() - { - TypeCode = KerepTypeCode.AutoarrUnitypePtr; - VoidPtr = v.UnmanagedPtr; - } - public Unitype(Autoarr v) : this() - { - TypeCode = KerepTypeCode.AutoarrKVPairPtr; - VoidPtr = v.UnmanagedPtr; - } - public Unitype(DtsodV24 v) : this() - { - TypeCode = KerepTypeCode.HashtablePtr; - VoidPtr = v.UnmanagedPtr; - }*/ public dynamic ToDynamic() { diff --git a/DTLib.Tests/DtsodV24/TestDtsodV24.cs b/DTLib.Tests/DtsodV24/TestDtsodV24.cs index a4fcf90..497214b 100644 --- a/DTLib.Tests/DtsodV24/TestDtsodV24.cs +++ b/DTLib.Tests/DtsodV24/TestDtsodV24.cs @@ -19,11 +19,8 @@ public static class TestDtsodV24 { Info.Log("c", "-----[TestDtsodV24/TestBaseTypes]-----"); DtsodV24 dtsod = new(File.ReadAllText($"DtsodV24{Путь.Разд}base_types.dtsod")); - foreach (var autoarr in dtsod) - { - foreach (KVPair pair in autoarr) - Info.LogNoTime("b", pair.ToString()); - } + foreach (var pair in dtsod) + Info.LogNoTime("b", pair.ToString()); Info.Log("g", "test completed"); } @@ -39,14 +36,24 @@ public static class TestDtsodV24 { Info.Log("c", "-------[TestDtsodV24/TestLists]-------"); DtsodV24 dtsod = new(File.ReadAllText($"DtsodV24{Путь.Разд}lists.dtsod")); - foreach (var autoarr in dtsod) - foreach (KVPair pair in autoarr) + foreach (KVPair pair in dtsod) + { + var list = new Autoarr(pair.value.VoidPtr, false); + Info.LogNoTime("b", pair.key.ToStringUTF8(), "w", $" length: {list.Length}"); + foreach (var el in list) { - var list = new Autoarr(pair.value.VoidPtr, false); - Info.LogNoTime("b", pair.key.ToStringUTF8(), "w", $" length: {list.Length}"); - foreach (var el in list) - Info.LogNoTime("h", '\t' + el.ToString()); + Info.LogNoTime("h", '\t' + el.ToString()); + if (el.TypeCode == KerepTypeCode.AutoarrUnitypePtr) + { + var ar = new Autoarr(el.VoidPtr, false); + foreach (var k in ar) + { + Info.LogNoTime($"\t\t{k.ToString()}"); + } + } } + } + Info.Log("y",dtsod.ToString()); Info.Log("g", "test completed"); } diff --git a/DTLib.Tests/DtsodV24/lists.dtsod b/DTLib.Tests/DtsodV24/lists.dtsod index 921034e..c43f109 100644 --- a/DTLib.Tests/DtsodV24/lists.dtsod +++ b/DTLib.Tests/DtsodV24/lists.dtsod @@ -12,4 +12,5 @@ $complex: { e:005; f:-1f; }; -list_of_lists: [ ["sss"]]; \ No newline at end of file +list_of_lists: [ [ "sss" ] ]; +blank_list: []; diff --git a/DTLib.Tests/Program.cs b/DTLib.Tests/Program.cs index aedf62c..f699649 100644 --- a/DTLib.Tests/Program.cs +++ b/DTLib.Tests/Program.cs @@ -28,10 +28,11 @@ public static class Program Console.Title="tester"; try { - TestPInvoke.TestAll(); + /*TestPInvoke.TestAll(); TestAutoarr.TestAll(); TestDtsodV23.TestAll(); - TestDtsodV24.TestAll(); + TestDtsodV24.TestAll();*/ + TestDtsodV24.TestLists(); } catch (Exception ex) { Info.Log("r", ex.ToString()); } diff --git a/DTLib/DependencyResolver.cs b/DTLib/DependencyResolver.cs new file mode 100644 index 0000000..560cff2 --- /dev/null +++ b/DTLib/DependencyResolver.cs @@ -0,0 +1,36 @@ +using System.Runtime.InteropServices; + +namespace DTLib; + +public static class DependencyResolver +{ + private static bool DepsCopied=false; + + public static void CopyLibs() + { + if(DepsCopied) return; + string depsdir = "Dependencies" + Путь.Разд; + depsdir += Environment.OSVersion.Platform switch + { + PlatformID.Unix => "linux", + PlatformID.Win32NT => "windows", + _=> throw new Exception($"unsupported os {Environment.OSVersion.Platform}") + }; + depsdir += Путь.Разд; + depsdir += RuntimeInformation.ProcessArchitecture switch + { + Architecture.X64 => "x64", + Architecture.X86 => "x86", + Architecture.Arm64 => "arm64", + Architecture.Arm => "arm", + _=> throw new Exception($"unsupported platform {RuntimeInformation.ProcessArchitecture}") + }; + foreach (var file in Directory.GetAllFiles(depsdir)) + { + var extracted = file.Substring(file.LastIndexOf(Путь.Разд) + 1); + File.Copy(file,extracted, true); + Log("g",$"{extracted} copied"); + } + DepsCopied = true; + } +} \ No newline at end of file diff --git a/kerep b/kerep deleted file mode 120000 index 6587f45..0000000 --- a/kerep +++ /dev/null @@ -1 +0,0 @@ -/mnt/win10-old/projects/kerep \ No newline at end of file diff --git a/kerep b/kerep new file mode 160000 index 0000000..009174e --- /dev/null +++ b/kerep @@ -0,0 +1 @@ +Subproject commit 009174ecfc3899fc615fcd2d6e9f64256b0f4e65