47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using System;
|
|
using PkmnLibSharp.FFI;
|
|
using PkmnLibSharp.Utils;
|
|
using Interface = PkmnLibSharp.FFI.StaticData.Libraries.SpeciesLibrary;
|
|
|
|
namespace PkmnLibSharp.StaticData.Libraries
|
|
{
|
|
public class SpeciesLibrary : DataLibrary<Species>
|
|
{
|
|
public SpeciesLibrary(ulong capacity) : base(Interface.species_library_new(capacity), true)
|
|
{
|
|
}
|
|
|
|
internal SpeciesLibrary(IdentifiablePointer ptr, bool isOwner) : base(ptr, isOwner)
|
|
{
|
|
}
|
|
|
|
protected override void Destructor() => Interface.species_library_drop(Ptr);
|
|
|
|
public override void Add(string key, Species value) =>
|
|
Interface.species_library_add(Ptr, key.ToPtr(), value.TakeOwnershipAndInvalidate());
|
|
|
|
public override int Count => (int)Interface.species_library_len(Ptr);
|
|
|
|
protected override Species? GetValueByKey(string key)
|
|
{
|
|
var ptr = Interface.species_library_get(Ptr, key.ToPtr());
|
|
return ptr.Ptr == IntPtr.Zero ? null : new Species(ptr);
|
|
}
|
|
|
|
public override string? GetKeyByIndex(ulong index) =>
|
|
Interface.species_library_get_key_by_index(Ptr, index).PtrString();
|
|
|
|
public override void InvalidateChildren()
|
|
{
|
|
foreach (var value in Cache.ValueCache.Values)
|
|
{
|
|
value.Invalidate();
|
|
}
|
|
}
|
|
|
|
~SpeciesLibrary()
|
|
{
|
|
Dispose();
|
|
}
|
|
}
|
|
} |