Skip to content

Commit

Permalink
Combined List/PluginListBInaryTranslationGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Dec 23, 2023
1 parent 6908d03 commit 69d7178
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 66 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@

namespace Mutagen.Bethesda.Generation.Modules.Binary;

public class PluginListBinaryTranslationGeneration : ListBinaryTranslationGeneration
public enum ListBinaryType
{
SubTrigger,
Trigger,
CounterRecord,
PrependCount,
Frame
}

public class PluginListBinaryTranslationGeneration : BinaryTranslationGeneration
{
public virtual string TranslatorName => $"ListBinaryTranslation";
const string ThreadKey = "ListThread";
public const string CounterRecordType = "ListCounterRecordType";
public const string CounterByteLength = "CounterByteLength";
Expand All @@ -29,6 +39,11 @@ public class PluginListBinaryTranslationGeneration : ListBinaryTranslationGenera
public const string ItemStartMarker = "ItemStartMarker";
public const string ItemEndMarker = "ItemEndMarker";

public override async Task<int?> ExpectedLength(ObjectGeneration objGen, TypeGeneration typeGen)
{
return null;
}

public override void Load(ObjectGeneration obj, TypeGeneration field, XElement node)
{
var listType = field as ListType;
Expand Down Expand Up @@ -1286,4 +1301,46 @@ public void WrapSet(StructuredStringBuilder sb, Accessor accessor, ListType list
}
}
}

public override string GetTranslatorInstance(TypeGeneration typeGen, bool getter)
{
var list = typeGen as ListType;
if (!Module.TryGetTypeGeneration(list.SubTypeGeneration.GetType(), out var subTransl))
{
throw new ArgumentException("Unsupported type generator: " + list.SubTypeGeneration);
}

var subMaskStr = subTransl.MaskModule.GetMaskModule(list.SubTypeGeneration.GetType()).GetErrorMaskTypeStr(list.SubTypeGeneration);
return $"{TranslatorName}<{list.SubTypeGeneration.TypeName(getter, needsCovariance: true)}, {subMaskStr}>.Instance";
}

public override bool IsAsync(TypeGeneration gen, bool read)
{
var listType = gen as ListType;
if (this.Module.TryGetTypeGeneration(listType.SubTypeGeneration.GetType(), out var keyGen)
&& keyGen.IsAsync(listType.SubTypeGeneration, read)) return true;
return false;
}

protected virtual string GetWriteAccessor(Accessor itemAccessor)
{
return itemAccessor.Access;
}

public override void GenerateCopyInRet(
StructuredStringBuilder sb,
ObjectGeneration objGen,
TypeGeneration targetGen,
TypeGeneration typeGen,
Accessor nodeAccessor,
AsyncMode asyncMode,
Accessor retAccessor,
Accessor outItemAccessor,
Accessor errorMaskAccessor,
Accessor translationAccessor,
Accessor converterAccessor,
bool inline)
{
throw new NotImplementedException();
}
}

0 comments on commit 69d7178

Please sign in to comment.