Skip to content

Commit bfcfc93

Browse files
More cleanup
1 parent 910a25d commit bfcfc93

30 files changed

+196
-547
lines changed

src/cs/vim/Vim.Format.Core/AssetInfo.cs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public enum AssetType
1818
/// </summary>
1919
public class AssetInfo
2020
{
21-
public const char Separator = '/';
21+
private const char Separator = '/';
2222

2323
public readonly string Name;
2424

@@ -27,7 +27,7 @@ public class AssetInfo
2727
public AssetInfo(string name, AssetType assetType)
2828
=> (Name, AssetType) = (name, assetType);
2929

30-
public static string[] SplitAssetBufferName(string assetBufferName)
30+
private static string[] SplitAssetBufferName(string assetBufferName)
3131
=> assetBufferName?.Split(Separator);
3232

3333
public static AssetInfo Parse(string assetBufferName)
@@ -63,10 +63,10 @@ public static bool TryParse(string assetBufferName, out AssetInfo assetInfo)
6363
}
6464
}
6565

66-
public static string AssetTypeToString(AssetType assetType)
66+
private static string AssetTypeToString(AssetType assetType)
6767
=> assetType.ToString("G").ToLowerInvariant();
6868

69-
public string AssetTypeString
69+
private string AssetTypeString
7070
=> AssetTypeToString(AssetType);
7171

7272
public override string ToString()
@@ -81,19 +81,13 @@ public string GetDefaultAssetFilePathInDirectory(DirectoryInfo directoryInfo)
8181

8282
public static class AssetInfoExtensions
8383
{
84-
public static bool IsTexture(this INamedBuffer buffer)
85-
=> AssetInfo.TryParse(buffer.Name, out var assetInfo) && assetInfo.AssetType == AssetType.Texture;
86-
87-
public static INamedBuffer GetAssetBuffer(this Document doc, string assetBufferName)
84+
private static INamedBuffer GetAssetBuffer(this Document doc, string assetBufferName)
8885
=> doc.Assets.GetOrDefault(assetBufferName);
8986

90-
public static IEnumerable<INamedBuffer> GetTextures(this Document d)
91-
=> d.Assets.Values.Where(IsTexture);
92-
9387
/// <summary>
9488
/// Extracts the asset buffer to the file designated by the given FileInfo.
9589
/// </summary>
96-
public static FileInfo ExtractAsset(this INamedBuffer assetBuffer, FileInfo fileInfo)
90+
private static FileInfo ExtractAsset(this INamedBuffer assetBuffer, FileInfo fileInfo)
9791
{
9892
Util.IO.CreateFileDirectory(fileInfo.FullName);
9993
using (var stream = fileInfo.Create())
@@ -105,7 +99,7 @@ public static FileInfo ExtractAsset(this INamedBuffer assetBuffer, FileInfo file
10599
/// Extracts the asset and returns a FileInfo representing the extracted asset on disk.<br/>
106100
/// Returns null if the asset could not be extracted.
107101
/// </summary>
108-
public static FileInfo ExtractAsset(this INamedBuffer assetBuffer, DirectoryInfo directoryInfo)
102+
private static FileInfo ExtractAsset(this INamedBuffer assetBuffer, DirectoryInfo directoryInfo)
109103
=> !AssetInfo.TryParse(assetBuffer.Name, out var assetInfo)
110104
? null
111105
: assetBuffer.ExtractAsset(new FileInfo(assetInfo.GetDefaultAssetFilePathInDirectory(directoryInfo)));
@@ -135,7 +129,7 @@ public static FileInfo ExtractAsset(this Document doc, string assetBufferName, F
135129
/// <summary>
136130
/// Gets the byte array which defines the given asset. Returns false if the asset was not found or if the byte array is empty or null.
137131
/// </summary>
138-
public static bool TryGetAssetBytes(this Document doc, string assetBufferName, out byte[] bytes)
132+
private static bool TryGetAssetBytes(this Document doc, string assetBufferName, out byte[] bytes)
139133
{
140134
bytes = null;
141135

@@ -151,7 +145,7 @@ public static bool TryGetAssetBytes(this Document doc, string assetBufferName, o
151145
/// <summary>
152146
/// Gets the byte array which defines the given asset. Returns false if the asset was not found or if the byte array is empty or null.
153147
/// </summary>
154-
public static bool TryGetAssetBytes(this Document doc, AssetType assetType, string assetName, out byte[] bytes)
148+
private static bool TryGetAssetBytes(this Document doc, AssetType assetType, string assetName, out byte[] bytes)
155149
=> doc.TryGetAssetBytes(new AssetInfo(assetName, assetType).ToString(), out bytes);
156150

157151
/// <summary>

src/cs/vim/Vim.Format.Core/ColumnExtensions.Buffer.cs

Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,15 @@ public static SerializableEntityTable ValidateColumnRowsAreAligned(this Serializ
3030
return et;
3131
}
3232

33-
public static string ValidateCanConcatBuffers(this INamedBuffer thisBuffer, INamedBuffer otherBuffer)
34-
{
35-
var thisPrefix = SerializableEntityTable.GetTypeFromName(thisBuffer.Name);
36-
if (string.IsNullOrEmpty(thisPrefix))
37-
throw new Exception("NamedBuffer prefix not found");
38-
39-
var otherPrefix = SerializableEntityTable.GetTypeFromName(otherBuffer.Name);
40-
if (string.IsNullOrEmpty(otherPrefix))
41-
throw new Exception("NamedBuffer prefix not found");
42-
43-
if (thisPrefix != otherPrefix)
44-
throw new Exception("NamedBuffer prefixes are not equal");
45-
46-
return thisPrefix;
47-
}
48-
4933
public static T[] RemapData<T>(this T[] self, List<int> remapping = null)
5034
=> remapping?.Select(x => self[x])?.ToArray() ?? self;
5135

5236
public static IBuffer ToBuffer<T>(this T[] array) where T : unmanaged
5337
=> new Buffer<T>(array);
5438

55-
public const string UnknownNamedBufferPrefix = "Unknown NamedBuffer prefix";
39+
private const string UnknownNamedBufferPrefix = "Unknown NamedBuffer prefix";
5640

57-
public static object GetDataColumnValue(this IBuffer dataColumn, string typePrefix, int rowIndex)
41+
private static object GetDataColumnValue(this IBuffer dataColumn, string typePrefix, int rowIndex)
5842
{
5943
switch (typePrefix)
6044
{
@@ -123,7 +107,7 @@ public static INamedBuffer CopyDataColumn(this INamedBuffer dataColumn, List<int
123107
return new NamedBuffer(dataColumn.CopyDataColumn(typePrefix, remapping), dataColumn.Name);
124108
}
125109

126-
public static IBuffer Concat<T>(this IBuffer thisBuffer, IBuffer otherBuffer) where T : unmanaged
110+
private static IBuffer Concat<T>(this IBuffer thisBuffer, IBuffer otherBuffer) where T : unmanaged
127111
=> thisBuffer.AsArray<T>().Concat(otherBuffer.AsArray<T>()).ToArray().ToBuffer();
128112

129113
public static IBuffer ConcatDataColumnBuffers(this IBuffer thisBuffer, IBuffer otherBuffer, string typePrefix)
@@ -145,60 +129,6 @@ public static IBuffer ConcatDataColumnBuffers(this IBuffer thisBuffer, IBuffer o
145129
}
146130
}
147131

148-
public static INamedBuffer ConcatDataColumns(this INamedBuffer thisColumn, INamedBuffer otherColumn)
149-
{
150-
var typePrefix = thisColumn.ValidateCanConcatBuffers(otherColumn);
151-
var combinedBuffer = thisColumn.ConcatDataColumnBuffers(otherColumn, typePrefix);
152-
return new NamedBuffer(combinedBuffer, thisColumn.Name);
153-
}
154-
155-
public static List<T> ConcatColumns<T>(
156-
this IReadOnlyList<T> thisColumnList,
157-
IReadOnlyList<T> otherColumnList,
158-
Func<T, T, T> concatFunc) where T : INamedBuffer
159-
{
160-
var mergedColumns = new List<T>();
161-
162-
foreach (var thisColumn in thisColumnList)
163-
{
164-
var otherColumn = otherColumnList.FirstOrDefault(c => c.Name == thisColumn.Name);
165-
if (otherColumn == null)
166-
continue;
167-
168-
var newNamedBuffer = concatFunc(thisColumn, otherColumn);
169-
170-
mergedColumns.Add(newNamedBuffer);
171-
}
172-
173-
return mergedColumns;
174-
}
175-
176-
public static List<INamedBuffer> ConcatDataColumns(this IReadOnlyList<INamedBuffer> thisColumnList, IReadOnlyList<INamedBuffer> otherColumnList)
177-
=> thisColumnList.ConcatColumns(otherColumnList,
178-
(a, b) => a.ConcatDataColumns(b));
179-
180-
public static List<NamedBuffer<int>> ConcatIntColumns(this IReadOnlyList<NamedBuffer<int>> thisColumnList, IReadOnlyList<NamedBuffer<int>> otherColumnList)
181-
=> thisColumnList.ConcatColumns(otherColumnList,
182-
(a, b) => new NamedBuffer<int>(a.GetTypedData().Concat(b.GetTypedData()).ToArray(), a.Name));
183-
184-
/// <summary>
185-
/// Returns a concatenated SerializableEntityTable based on the column names of thisTable.
186-
/// </summary>
187-
public static SerializableEntityTable Concat(
188-
this SerializableEntityTable thisTable,
189-
SerializableEntityTable otherTable)
190-
{
191-
var concatenated = new SerializableEntityTable
192-
{
193-
Name = thisTable.Name,
194-
IndexColumns = thisTable.IndexColumns.ConcatIntColumns(otherTable.IndexColumns),
195-
StringColumns = thisTable.StringColumns.ConcatIntColumns(otherTable.StringColumns),
196-
DataColumns = thisTable.DataColumns.ConcatDataColumns(otherTable.DataColumns),
197-
};
198-
concatenated.ValidateColumnRowsAreAligned();
199-
return concatenated;
200-
}
201-
202132
public static T[] GetColumnValues<T>(this INamedBuffer nb) where T : unmanaged
203133
=> nb.AsArray<T>();
204134

src/cs/vim/Vim.Format.Core/ColumnExtensions.Reflection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public static string GetDataColumnNameTypePrefix(this Type type)
1616
throw new Exception($"{nameof(GetDataColumnNameTypePrefix)} error: no matching data column name prefix for {type}");
1717
}
1818

19-
public static bool CanSerializeAsStringColumn(this Type type)
19+
private static bool CanSerializeAsStringColumn(this Type type)
2020
=> type == typeof(string);
2121

22-
public static bool CanSerializeAsDataColumn(this Type type)
22+
private static bool CanSerializeAsDataColumn(this Type type)
2323
=> DataColumnTypes.Contains(type);
2424

2525
public static ValueSerializationStrategy GetValueSerializationStrategy(this Type type)
@@ -60,7 +60,7 @@ public static string GetSerializedValueColumnName(this FieldInfo fieldInfo)
6060
return $"{typePrefix}{fieldInfo.GetSerializedValueName()}";
6161
}
6262

63-
public static bool IsRelationType(this Type t)
63+
private static bool IsRelationType(this Type t)
6464
=> t.Name == "Relation`1";
6565

6666
public static Type RelationTypeParameter(this Type t)

src/cs/vim/Vim.Format.Core/ColumnExtensions.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Vim.Format
77
{
88
public static partial class ColumnExtensions
99
{
10-
public static readonly IReadOnlyCollection<ColumnInfo> AllColumnInfos
10+
private static readonly IReadOnlyCollection<ColumnInfo> AllColumnInfos
1111
= new[]
1212
{
1313
new ColumnInfo(ColumnType.IndexColumn, VimConstants.IndexColumnNameTypePrefix, typeof(int)),
@@ -19,7 +19,7 @@ public static readonly IReadOnlyCollection<ColumnInfo> AllColumnInfos
1919
new ColumnInfo(ColumnType.DataColumn, VimConstants.FloatColumnNameTypePrefix, typeof(float)),
2020
};
2121

22-
public static readonly IReadOnlyDictionary<Type, string> DataColumnTypeToPrefixMap
22+
private static readonly IReadOnlyDictionary<Type, string> DataColumnTypeToPrefixMap
2323
= AllColumnInfos
2424
.Where(t => t.ColumnType == ColumnType.DataColumn)
2525
.SelectMany(t => t.RelatedTypes.Select(type => (Type: type, t.TypePrefix)))
@@ -28,27 +28,25 @@ public static readonly IReadOnlyDictionary<Type, string> DataColumnTypeToPrefixM
2828
public static readonly ISet<Type> DataColumnTypes
2929
= new HashSet<Type>(AllColumnInfos.Where(t => t.ColumnType == ColumnType.DataColumn).SelectMany(t => t.RelatedTypes));
3030

31-
public static readonly ISet<string> DataColumnNameTypePrefixes
31+
private static readonly ISet<string> DataColumnNameTypePrefixes
3232
= new HashSet<string>(AllColumnInfos.Where(t => t.ColumnType == ColumnType.DataColumn).Select(t => t.TypePrefix));
3333

34-
public static readonly Regex DataColumnTypePrefixRegex
34+
private static readonly Regex DataColumnTypePrefixRegex
3535
= new Regex($@"^(?:{string.Join("|", DataColumnNameTypePrefixes)})");
3636

37-
public static bool TryGetDataColumnNameTypePrefix(string columnName, out string typePrefix)
37+
private static bool TryGetDataColumnNameTypePrefix(string columnName)
3838
{
39-
typePrefix = null;
4039
if (string.IsNullOrEmpty(columnName))
4140
return false;
4241

4342
var match = DataColumnTypePrefixRegex.Match(columnName);
44-
typePrefix = match.Value;
4543
return match.Success;
4644
}
4745

4846
public static bool IsDataColumnName(string columnName)
49-
=> TryGetDataColumnNameTypePrefix(columnName, out _);
47+
=> TryGetDataColumnNameTypePrefix(columnName);
5048

51-
public const string RelatedTableNameFieldNameSeparator = ":";
49+
private const string RelatedTableNameFieldNameSeparator = ":";
5250

5351
public static string GetIndexColumnName(string relatedTableName, string localFieldName)
5452
=> VimConstants.IndexColumnNameTypePrefix + relatedTableName + RelatedTableNameFieldNameSeparator + localFieldName;

src/cs/vim/Vim.Format.Core/Document.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ public Document(SerializableDocument document)
3030
var tables = document.EntityTables.ToDictionary(
3131
et => et.Name,
3232
et => new EntityTable(this, et));
33-
_bim = new Bim(tables, _Document.StringTable);
33+
_bim = new Bim(tables);
3434
}
3535

36-
Bim _bim;
37-
38-
public int TableCount => _bim.TableCount;
36+
private readonly Bim _bim;
3937

4038
public EntityTable GetTable(string name)
4139
=> _bim.GetTable(name);
@@ -44,8 +42,7 @@ public EntityTable GetTable(string name)
4442
public IEnumerable<EntityTable> Tables => _bim.Tables;
4543
public VimSchema GetSchema() => VimSchema.Create(_Document);
4644

47-
public string FileName => _Document.FileName;
48-
public SerializableDocument _Document { get; }
45+
private SerializableDocument _Document { get; }
4946
public SerializableHeader Header { get; }
5047
public Dictionary<string, EntityTable> EntityTables { get; }
5148
public Dictionary<string, INamedBuffer> Assets { get; }
@@ -57,17 +54,13 @@ public EntityTable GetTable(string name)
5754

5855
public class Bim
5956
{
60-
private string[] _strings;
61-
private Dictionary<string, EntityTable> _tables { get; }
57+
private readonly Dictionary<string, EntityTable> _tables;
6258

63-
public Bim(Dictionary<string, EntityTable> tables, string[] strings)
59+
public Bim(Dictionary<string, EntityTable> tables)
6460
{
6561
_tables = tables;
66-
_strings = strings;
6762
}
6863

69-
public int TableCount => Tables.Count();
70-
7164
public EntityTable GetTable(string name)
7265
=> _tables.GetOrDefault(name);
7366

src/cs/vim/Vim.Format.Core/DocumentBuilder.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public partial class DocumentBuilder
1717
public readonly Dictionary<string, byte[]> Assets = new Dictionary<string, byte[]>();
1818
public readonly G3dBuilder Geometry = new G3dBuilder();
1919

20-
public bool UseColors { get; set; }
2120

2221
public DocumentBuilder(
2322
string generator,
@@ -128,13 +127,13 @@ public StringLookupInfo(IEnumerable<string> allStrings, int indexOffset = 0)
128127
}
129128
}
130129

131-
public static StringLookupInfo GetStringLookupInfo(IEnumerable<EntityTableBuilder> tableBuilders, int indexOffset = 0)
130+
private static StringLookupInfo GetStringLookupInfo(IEnumerable<EntityTableBuilder> tableBuilders, int indexOffset = 0)
132131
=> new StringLookupInfo(tableBuilders.SelectMany(tb => tb.GetAllStrings()), indexOffset);
133132

134-
public StringLookupInfo GetStringLookupInfo()
133+
private StringLookupInfo GetStringLookupInfo()
135134
=> GetStringLookupInfo(Tables.Values);
136135

137-
public List<SerializableEntityTable> ComputeEntityTables(IReadOnlyDictionary<string, int> stringLookup)
136+
private List<SerializableEntityTable> ComputeEntityTables(IReadOnlyDictionary<string, int> stringLookup)
138137
{
139138
// Create the new Entity tables
140139
var tableList = new List<SerializableEntityTable>();

src/cs/vim/Vim.Format.Core/DocumentBuilderExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
using Vim.BFastLib;
43

54
namespace Vim.Format
65
{
76
public static class DocumentBuilderExtensions
87
{
9-
public static EntityTableBuilder CreateTableCopy(this DocumentBuilder db, EntityTable table, List<int> nodeIndexRemapping = null)
8+
private static EntityTableBuilder CreateTableCopy(this DocumentBuilder db, EntityTable table, List<int> nodeIndexRemapping = null)
109
{
1110
var name = table.Name;
1211
var tb = db.CreateTableBuilder(name);

0 commit comments

Comments
 (0)