Skip to content

Commit b1cbb32

Browse files
committed
Refactor, improve style
1 parent dc0d861 commit b1cbb32

File tree

4 files changed

+155
-177
lines changed

4 files changed

+155
-177
lines changed

solution/GraphicalDebugging/ExpressionLoader.cs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,12 @@ class Loaders
424424

425425
public Loaders()
426426
{
427-
lists = new List<LoaderCreator>[KindsCount];
427+
lists = new List<ILoaderCreator>[KindsCount];
428428
for (int i = 0; i < KindsCount; ++i)
429-
lists[i] = new List<LoaderCreator>();
429+
lists[i] = new List<ILoaderCreator>();
430430
}
431431

432-
public void Add(LoaderCreator loaderCreator)
432+
public void Add(ILoaderCreator loaderCreator)
433433
{
434434
int i = (int)loaderCreator.Kind();
435435
System.Diagnostics.Debug.Assert(0 <= i && i < KindsCount);
@@ -484,7 +484,7 @@ public Loader FindByType(IKindConstraint kindConstraint, string name, string typ
484484
// Single kind required, check only one list
485485
Kind kind = (kindConstraint as KindConstraint).Kind;
486486
int kindIndex = (int)kind;
487-
foreach (LoaderCreator creator in lists[kindIndex])
487+
foreach (ILoaderCreator creator in lists[kindIndex])
488488
{
489489
Loader loader = creator.Create(this, Instance.debugger, name, type, id);
490490
if (loader != null)
@@ -502,7 +502,7 @@ public Loader FindByType(IKindConstraint kindConstraint, string name, string typ
502502
Kind kind = (Kind)i;
503503
if (kindConstraint.Check(kind))
504504
{
505-
foreach (LoaderCreator creator in lists[i])
505+
foreach (ILoaderCreator creator in lists[i])
506506
{
507507
Loader loader = creator.Create(this, Instance.debugger, name, type, id);
508508
if (loader != null)
@@ -519,21 +519,21 @@ public Loader FindByType(IKindConstraint kindConstraint, string name, string typ
519519

520520
public void RemoveUserDefined()
521521
{
522-
foreach (List<LoaderCreator> li in lists)
522+
foreach (List<ILoaderCreator> li in lists)
523523
{
524524
for (int i = li.Count - 1; i >= 0; --i)
525525
if (li[i].IsUserDefined())
526526
li.RemoveAt(i);
527527
}
528528
}
529529

530-
private readonly List<LoaderCreator>[] lists;
530+
private readonly List<ILoaderCreator>[] lists;
531531
}
532532

533533
/// <summary>
534534
/// The interface of a loader creator.
535535
/// </summary>
536-
interface LoaderCreator
536+
interface ILoaderCreator
537537
{
538538
/// <summary>
539539
/// Returns true for user-defined Loaders which has to be reloaded
@@ -841,7 +841,7 @@ MemoryReader.Converter<double> arrayConverter
841841

842842
class BGPoint : BXPoint
843843
{
844-
public class LoaderCreator : ExpressionLoader.LoaderCreator
844+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
845845
{
846846
public bool IsUserDefined() { return false; }
847847
public Kind Kind() { return ExpressionLoader.Kind.Point; }
@@ -898,7 +898,7 @@ protected static void ParseCSAndUnit(string cs_type, out Geometry.CoordinateSyst
898898

899899
class BGPointXY : BGPoint
900900
{
901-
public new class LoaderCreator : ExpressionLoader.LoaderCreator
901+
public new class LoaderCreator : ExpressionLoader.ILoaderCreator
902902
{
903903
public bool IsUserDefined() { return false; }
904904
public Kind Kind() { return ExpressionLoader.Kind.Point; }
@@ -925,7 +925,7 @@ public BGPointXY(string coordType, Geometry.Traits traits)
925925

926926
class BGBox : BoxLoader
927927
{
928-
public class LoaderCreator : ExpressionLoader.LoaderCreator
928+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
929929
{
930930
public bool IsUserDefined() { return false; }
931931
public Kind Kind() { return ExpressionLoader.Kind.Box; }
@@ -1016,7 +1016,7 @@ public override MemoryReader.Converter<double> GetMemoryConverter(MemoryReader m
10161016

10171017
class BGSegment : SegmentLoader
10181018
{
1019-
public class LoaderCreator : ExpressionLoader.LoaderCreator
1019+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
10201020
{
10211021
public bool IsUserDefined() { return false; }
10221022
public Kind Kind() { return ExpressionLoader.Kind.Segment; }
@@ -1112,7 +1112,7 @@ public override MemoryReader.Converter<double> GetMemoryConverter(MemoryReader m
11121112

11131113
class BGReferringSegment : BGSegment
11141114
{
1115-
public new class LoaderCreator : ExpressionLoader.LoaderCreator
1115+
public new class LoaderCreator : ExpressionLoader.ILoaderCreator
11161116
{
11171117
public bool IsUserDefined() { return false; }
11181118
public Kind Kind() { return ExpressionLoader.Kind.Segment; }
@@ -1142,7 +1142,7 @@ private BGReferringSegment(PointLoader pointLoader, string pointType)
11421142

11431143
class BGNSphere : NSphereLoader
11441144
{
1145-
public class LoaderCreator : ExpressionLoader.LoaderCreator
1145+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
11461146
{
11471147
public bool IsUserDefined() { return false; }
11481148
public Kind Kind() { return ExpressionLoader.Kind.NSphere; }
@@ -1278,7 +1278,7 @@ class BGRange<ResultType> : PointRange<ResultType>
12781278
, Geometry.IContainer<Geometry.Point>
12791279
, new()
12801280
{
1281-
public class LoaderCreator : ExpressionLoader.LoaderCreator
1281+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
12821282
{
12831283
public delegate Loader DerivedConstructor(ContainerLoader containerLoader, string containerType,
12841284
PointLoader pointLoader, string pointType);
@@ -1400,7 +1400,7 @@ private BGLinestring(ContainerLoader containerLoader, string containerType,
14001400

14011401
class BGMultiLinestring : RangeLoader<ExpressionDrawer.MultiLinestring>
14021402
{
1403-
public class LoaderCreator : ExpressionLoader.LoaderCreator
1403+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
14041404
{
14051405
public bool IsUserDefined() { return false; }
14061406
public Kind Kind() { return ExpressionLoader.Kind.MultiLinestring; }
@@ -1517,7 +1517,7 @@ private BGMultiPoint(ContainerLoader containerLoader, string containerType,
15171517

15181518
class BGPolygon : PolygonLoader
15191519
{
1520-
public class LoaderCreator : ExpressionLoader.LoaderCreator
1520+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
15211521
{
15221522
public bool IsUserDefined() { return false; }
15231523
public Kind Kind() { return ExpressionLoader.Kind.Polygon; }
@@ -1602,7 +1602,7 @@ public override ExpressionDrawer.IDrawable Load(MemoryReader mreader, Debugger d
16021602

16031603
class BGMultiPolygon : RangeLoader<ExpressionDrawer.MultiPolygon>
16041604
{
1605-
public class LoaderCreator : ExpressionLoader.LoaderCreator
1605+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
16061606
{
16071607
public bool IsUserDefined() { return false; }
16081608
public Kind Kind() { return ExpressionLoader.Kind.MultiPolygon; }
@@ -1672,7 +1672,7 @@ public override ExpressionDrawer.IDrawable Load(MemoryReader mreader, Debugger d
16721672

16731673
class BGBufferedRing : RangeLoader<ExpressionDrawer.Ring>
16741674
{
1675-
public class LoaderCreator : ExpressionLoader.LoaderCreator
1675+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
16761676
{
16771677
public bool IsUserDefined() { return false; }
16781678
public Kind Kind() { return ExpressionLoader.Kind.Ring; }
@@ -1724,7 +1724,7 @@ public override ExpressionDrawer.IDrawable Load(MemoryReader mreader, Debugger d
17241724
// NOTE: There is no MultiRing concept so use MultiPolygon for now
17251725
class BGBufferedRingCollection : RangeLoader<ExpressionDrawer.MultiPolygon>
17261726
{
1727-
public class LoaderCreator : ExpressionLoader.LoaderCreator
1727+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
17281728
{
17291729
public bool IsUserDefined() { return false; }
17301730
public Kind Kind() { return ExpressionLoader.Kind.MultiPolygon; } // Or MultiGeometry
@@ -1803,7 +1803,7 @@ public override ExpressionDrawer.IDrawable Load(MemoryReader mreader, Debugger d
18031803

18041804
class BGIRtree : GeometryLoader<ExpressionDrawer.DrawablesContainer>
18051805
{
1806-
public class LoaderCreator : ExpressionLoader.LoaderCreator
1806+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
18071807
{
18081808
public bool IsUserDefined() { return false; }
18091809
public Kind Kind() { return ExpressionLoader.Kind.OtherGeometry; }
@@ -2275,7 +2275,7 @@ static bool IsLeaf(Debugger debugger, string nodePtrName, out bool result)
22752275

22762276
class BPPoint : BXPoint
22772277
{
2278-
public class LoaderCreator : ExpressionLoader.LoaderCreator
2278+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
22792279
{
22802280
public bool IsUserDefined() { return false; }
22812281
public Kind Kind() { return ExpressionLoader.Kind.Point; }
@@ -2302,7 +2302,7 @@ private BPPoint(string coordType)
23022302

23032303
class BPSegment : SegmentLoader
23042304
{
2305-
public class LoaderCreator : ExpressionLoader.LoaderCreator
2305+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
23062306
{
23072307
public bool IsUserDefined() { return false; }
23082308
public Kind Kind() { return ExpressionLoader.Kind.Segment; }
@@ -2340,7 +2340,7 @@ public override ExpressionDrawer.IDrawable Load(MemoryReader mreader, Debugger d
23402340

23412341
class BPBox : BoxLoader
23422342
{
2343-
public class LoaderCreator : ExpressionLoader.LoaderCreator
2343+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
23442344
{
23452345
public bool IsUserDefined() { return false; }
23462346
public Kind Kind() { return ExpressionLoader.Kind.Box; }
@@ -2378,7 +2378,7 @@ public override ExpressionDrawer.IDrawable Load(MemoryReader mreader, Debugger d
23782378

23792379
class BPRing : PointRange<ExpressionDrawer.Ring>
23802380
{
2381-
public class LoaderCreator : ExpressionLoader.LoaderCreator
2381+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
23822382
{
23832383
public bool IsUserDefined() { return false; }
23842384
public Kind Kind() { return ExpressionLoader.Kind.Ring; }
@@ -2463,7 +2463,7 @@ public override ExpressionDrawer.IDrawable Load(MemoryReader mreader, Debugger d
24632463

24642464
class BPPolygon : PolygonLoader
24652465
{
2466-
public class LoaderCreator : ExpressionLoader.LoaderCreator
2466+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
24672467
{
24682468
public bool IsUserDefined() { return false; }
24692469
public Kind Kind() { return ExpressionLoader.Kind.Polygon; }
@@ -2552,7 +2552,7 @@ public override ExpressionDrawer.IDrawable Load(MemoryReader mreader, Debugger d
25522552

25532553
class BVariant : DrawableLoader
25542554
{
2555-
public class LoaderCreator : ExpressionLoader.LoaderCreator
2555+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
25562556
{
25572557
public bool IsUserDefined() { return false; }
25582558
public Kind Kind() { return ExpressionLoader.Kind.Variant; }
@@ -2624,7 +2624,7 @@ public override ExpressionDrawer.IDrawable Load(MemoryReader mreader, Debugger d
26242624

26252625
class StdPairPoint : PointLoader
26262626
{
2627-
public class LoaderCreator : ExpressionLoader.LoaderCreator
2627+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
26282628
{
26292629
public bool IsUserDefined() { return false; }
26302630
public Kind Kind() { return ExpressionLoader.Kind.Point; }
@@ -2718,7 +2718,7 @@ public override MemoryReader.Converter<double> GetMemoryConverter(MemoryReader m
27182718

27192719
class StdComplexPoint : BXPoint
27202720
{
2721-
public class LoaderCreator : ExpressionLoader.LoaderCreator
2721+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
27222722
{
27232723
public bool IsUserDefined() { return false; }
27242724
public Kind Kind() { return ExpressionLoader.Kind.Point; }
@@ -2743,7 +2743,7 @@ private StdComplexPoint(string coordType)
27432743

27442744
class BGTurn : GeometryLoader<ExpressionDrawer.Turn>
27452745
{
2746-
public class LoaderCreator : ExpressionLoader.LoaderCreator
2746+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
27472747
{
27482748
public LoaderCreator(string id)
27492749
{
@@ -2852,7 +2852,7 @@ private static char OperationChar(string operation)
28522852

28532853
class BGTurnContainer : GeometryLoader<ExpressionDrawer.TurnsContainer>
28542854
{
2855-
public class LoaderCreator : ExpressionLoader.LoaderCreator
2855+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
28562856
{
28572857
public bool IsUserDefined() { return false; }
28582858
public Kind Kind() { return ExpressionLoader.Kind.TurnsContainer; }
@@ -2922,7 +2922,7 @@ public override ExpressionDrawer.IDrawable Load(MemoryReader mreader, Debugger d
29222922
// including User-Defined ones, so if possible unify all of them
29232923
class GeometryContainer : GeometryLoader<ExpressionDrawer.DrawablesContainer>
29242924
{
2925-
public class LoaderCreator : ExpressionLoader.LoaderCreator
2925+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
29262926
{
29272927
public bool IsUserDefined() { return false; }
29282928
public Kind Kind() { return ExpressionLoader.Kind.GeometriesContainer; }
@@ -3060,7 +3060,7 @@ private ExpressionDrawer.DrawablesContainer LoadParsed(MemoryReader mreader, Deb
30603060

30613061
class PointContainer : PointRange<ExpressionDrawer.MultiPoint>
30623062
{
3063-
public class LoaderCreator : ExpressionLoader.LoaderCreator
3063+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
30643064
{
30653065
public bool IsUserDefined() { return false; }
30663066
public Kind Kind() { return ExpressionLoader.Kind.MultiPoint; }
@@ -3135,7 +3135,7 @@ public override ExpressionDrawer.IDrawable Load(MemoryReader mreader, Debugger d
31353135

31363136
class ValuesContainer : LoaderR<ExpressionDrawer.ValuesContainer>
31373137
{
3138-
public class LoaderCreator : ExpressionLoader.LoaderCreator
3138+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
31393139
{
31403140
public bool IsUserDefined() { return false; }
31413141
public Kind Kind() { return ExpressionLoader.Kind.ValuesContainer; }

solution/GraphicalDebugging/ExpressionLoader_BoostGil.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ partial class ExpressionLoader
2121
{
2222
class BoostGilImage : LoaderR<ExpressionDrawer.Image>
2323
{
24-
public class LoaderCreator : ExpressionLoader.LoaderCreator
24+
public class LoaderCreator : ExpressionLoader.ILoaderCreator
2525
{
2626
public bool IsUserDefined() { return false; }
2727
public Kind Kind() { return ExpressionLoader.Kind.Image; }
@@ -54,8 +54,7 @@ public override ExpressionDrawer.IDrawable Load(MemoryReader mreader, Debugger d
5454
if (width < 1 || height < 1)
5555
return null;
5656

57-
string pixelType, isPlanarStr;
58-
if (! Util.Tparams(type, out pixelType, out isPlanarStr))
57+
if (! Util.Tparams(type, out string pixelType, out string isPlanarStr))
5958
return null;
6059

6160
string pixelId = Util.TypeId(pixelType);
@@ -64,25 +63,21 @@ public override ExpressionDrawer.IDrawable Load(MemoryReader mreader, Debugger d
6463

6564
bool isPlanar = (isPlanarStr == "1");
6665

67-
string channelValueType, layoutType;
68-
if (! Util.Tparams(pixelType, out channelValueType, out layoutType))
66+
if (! Util.Tparams(pixelType, out string channelValueType, out string layoutType))
6967
return null;
7068

7169
string layoutId = Util.TypeId(layoutType);
7270
if (layoutId != "boost::gil::layout")
7371
return null;
7472

75-
string colorSpaceType, channelMappingType;
76-
if (! Util.Tparams(layoutType, out colorSpaceType, out channelMappingType))
73+
if (! Util.Tparams(layoutType, out string colorSpaceType, out string channelMappingType))
7774
return null;
7875

79-
ChannelValueKind channelValueKind = ChannelValueKind.Unknown;
80-
int channelValueSize = 0;
81-
ParseChannelValue(debugger, channelValueType, out channelValueKind, out channelValueSize);
76+
ParseChannelValue(debugger, channelValueType, out ChannelValueKind channelValueKind, out int channelValueSize);
8277
if (channelValueKind == ChannelValueKind.Unknown || channelValueSize == 0)
8378
return null;
8479

85-
string colorSpaceId = Util.TypeId(colorSpaceType);
80+
//string colorSpaceId = Util.TypeId(colorSpaceType);
8681
ColorSpace colorSpace = ParseColorSpace(colorSpaceType);
8782
int colorSpaceSize = ColorSpaceSize(colorSpace);
8883

@@ -169,8 +164,7 @@ private void ParseChannelValue(Debugger debugger, string type,
169164
out int channelValueSize)
170165
{
171166
channelValueKind = ChannelValueKind.Unknown;
172-
channelValueSize = 0;
173-
167+
174168
string rawType = type;
175169

176170
if (type == "unsigned char"
@@ -223,7 +217,7 @@ enum ColorSpace { Unknown, Rgb, Rgba, Cmyk, Gray, GrayAlpha };
223217

224218
ColorSpace ParseColorSpace(string colorSpaceType)
225219
{
226-
string colorSpaceId = Util.TypeId(colorSpaceType);
220+
//string colorSpaceId = Util.TypeId(colorSpaceType);
227221
List<string> tparams = Util.Tparams(colorSpaceType);
228222
// NOTE: Do not check the Util.BaseType(colorSpaceType)
229223
// to avoid checking all MPL and MP11 vectors and lists

0 commit comments

Comments
 (0)