Skip to content

Commit

Permalink
Minor improvements (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serg-Norseman committed Dec 3, 2024
1 parent d3ea54b commit 9657f1c
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 171 deletions.
17 changes: 6 additions & 11 deletions projects/GKCore/GDModel/GDMList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,15 @@ public sealed class GDMList<T> : IGDMList<T>

private struct GEDCOMListEnumerator : IGDMListEnumerator<T>
{
private readonly GDMList<T> fOwnList;
private readonly IList<T> fDataList;
private int fIndex;
private int fSize;

public GEDCOMListEnumerator(GDMList<T> list)
{
fOwnList = list;

fDataList = list.fDataList;
fIndex = -1;

List<T> dataList = list.fDataList;
fSize = ((dataList == null) ? 0 : dataList.Count);
fSize = (fDataList == null) ? 0 : fDataList.Count;
}

void IDisposable.Dispose()
Expand All @@ -54,9 +51,7 @@ void IDisposable.Dispose()
void IEnumerator.Reset()
{
fIndex = -1;

List<T> dataList = fOwnList.fDataList;
fSize = ((dataList == null) ? 0 : dataList.Count);
fSize = (fDataList == null) ? 0 : fDataList.Count;
}

bool IEnumerator.MoveNext()
Expand All @@ -67,12 +62,12 @@ bool IEnumerator.MoveNext()

object IEnumerator.Current
{
get { return fOwnList.fDataList[fIndex]; }
get { return fDataList[fIndex]; }
}

T IEnumerator<T>.Current
{
get { return fOwnList.fDataList[fIndex]; }
get { return fDataList[fIndex]; }
}
}

Expand Down
20 changes: 10 additions & 10 deletions projects/GKCore/GDModel/GDMTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ public sealed class GDMTree : GDMObject

private struct TreeEnumerator : IGDMTreeEnumerator
{
private readonly GDMTree fTree;
private readonly IList<GDMRecord> fTreeRecords;
private readonly GDMRecordType fRecType;
private readonly int fEndIndex;
private int fIndex;

public TreeEnumerator(GDMTree tree, GDMRecordType recType)
{
fTree = tree;
fTreeRecords = tree.fRecords.GetList();
fIndex = -1;
fEndIndex = tree.RecordsCount - 1;
fEndIndex = ((fTreeRecords == null) ? 0 : fTreeRecords.Count) - 1;
fRecType = recType;
}

Expand All @@ -61,13 +61,13 @@ public bool MoveNext(out GDMRecord current)
if (fRecType == GDMRecordType.rtNone) {
if (fIndex < fEndIndex) {
fIndex++;
current = fTree[fIndex];
current = fTreeRecords[fIndex];
return true;
}
} else {
while (fIndex < fEndIndex) {
fIndex++;
GDMRecord rec = fTree[fIndex];
GDMRecord rec = fTreeRecords[fIndex];
if (rec.RecordType == fRecType) {
current = rec;
return true;
Expand All @@ -88,22 +88,22 @@ public void Reset()

private struct TreeEnumerator<T> : IGDMTreeEnumerator<T> where T : GDMRecord
{
private readonly GDMTree fTree;
private readonly IList<GDMRecord> fTreeRecords;
private readonly int fEndIndex;
private int fIndex;

public TreeEnumerator(GDMTree tree)
{
fTree = tree;
fTreeRecords = tree.fRecords.GetList();
fIndex = -1;
fEndIndex = tree.RecordsCount - 1;
fEndIndex = ((fTreeRecords == null) ? 0 : fTreeRecords.Count) - 1;
}

public bool MoveNext(out T current)
{
while (fIndex < fEndIndex) {
fIndex++;
T rec = fTree[fIndex] as T;
T rec = fTreeRecords[fIndex] as T;
if (rec != null) {
current = rec;
return true;
Expand All @@ -119,7 +119,7 @@ public bool MoveNext(out GDMRecord current)
{
while (fIndex < fEndIndex) {
fIndex++;
var rec = fTree[fIndex];
var rec = fTreeRecords[fIndex];
if (rec != null) {
current = rec;
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2023 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -303,10 +303,9 @@ private GDMFamilyRecord GetParentsFamily(GDMIndividualRecord father, GDMIndividu
string fatherXRef = (father == null) ? string.Empty : father.XRef;
string motherXRef = (mother == null) ? string.Empty : mother.XRef;

var famEnum = fTree.GetEnumerator(GDMRecordType.rtFamily);
GDMRecord record;
while (famEnum.MoveNext(out record)) {
var famRec = record as GDMFamilyRecord;
var famEnum = fTree.GetEnumerator<GDMFamilyRecord>();
GDMFamilyRecord famRec;
while (famEnum.MoveNext(out famRec)) {
if (famRec.Husband.XRef == fatherXRef && famRec.Wife.XRef == motherXRef) {
result = famRec;
break;
Expand Down
64 changes: 12 additions & 52 deletions projects/GKCore/GKCore/BaseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -592,61 +592,21 @@ public void CollectTips(StringList tipsList)

try {
bool firstTip = true;
int num = fTree.RecordsCount;
for (int i = 0; i < num; i++) {
GDMRecord rec = fTree[i];
if (rec.RecordType != GDMRecordType.rtIndividual) continue;

GDMIndividualRecord iRec = (GDMIndividualRecord)rec;

int days = GKUtils.GetDaysForBirth(iRec);
if (days >= 0 && days < 3) {
if (firstTip) {
tipsList.Add("#" + LangMan.LS(LSID.BirthDays));
firstTip = false;
}

string nm = Culture.GetPossessiveName(iRec);

string tip;
switch (days) {
case 0:
tip = string.Format(LangMan.LS(LSID.BirthdayToday), nm);
break;
case 1:
tip = string.Format(LangMan.LS(LSID.BirthdayTomorrow), nm);
break;
default:
tip = string.Format(LangMan.LS(LSID.DaysRemained), nm, days);
break;
}
tipsList.Add(tip);
}

var indiEnum = fTree.GetEnumerator<GDMIndividualRecord>();
GDMIndividualRecord iRec;
while (indiEnum.MoveNext(out iRec)) {
int years;
days = GKUtils.GetDaysForBirthAnniversary(iRec, out years);
if (days >= 0 && days < 3) {
if (firstTip) {
tipsList.Add("#" + LangMan.LS(LSID.BirthDays));
firstTip = false;
}
bool anniversary;
int days = GKUtils.GetDaysForBirth(iRec, true, out years, out anniversary);
if (days < 0 || days >= 3) continue;

string nm = Culture.GetPossessiveName(iRec);

string tip;
switch (days) {
case 0:
tip = string.Format(LangMan.LS(LSID.AnniversaryToday), nm);
break;
case 1:
tip = string.Format(LangMan.LS(LSID.AnniversaryTomorrow), nm);
break;
default:
tip = string.Format(LangMan.LS(LSID.AnniversaryDaysRemained), nm, days);
break;
}
tipsList.Add(tip);
if (firstTip) {
tipsList.Add("#" + LangMan.LS(LSID.BirthDays));
firstTip = false;
}

string tip = GKUtils.GetBirthTipMessage(Culture, iRec, days, years, anniversary);
tipsList.Add(tip);
}
} catch (Exception ex) {
Logger.WriteError("BaseContext.CollectTips()", ex);
Expand Down
9 changes: 4 additions & 5 deletions projects/GKCore/GKCore/Controllers/SlideshowController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2023 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -87,10 +87,9 @@ private void Timer1Tick(object sender, EventArgs e)

public void LoadList()
{
GDMRecord record;
var enumerator = fBase.Context.Tree.GetEnumerator(GDMRecordType.rtMultimedia);
while (enumerator.MoveNext(out record)) {
GDMMultimediaRecord mediaRec = (GDMMultimediaRecord)record;
GDMMultimediaRecord mediaRec;
var enumerator = fBase.Context.Tree.GetEnumerator<GDMMultimediaRecord>();
while (enumerator.MoveNext(out mediaRec)) {
GDMFileReferenceWithTitle fileRef = mediaRec.FileReferences[0];

MultimediaKind mmKind = GKUtils.GetMultimediaKind(fileRef.GetMultimediaFormat());
Expand Down
8 changes: 3 additions & 5 deletions projects/GKCore/GKCore/Export/FamilyBookExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,9 @@ private void PrepareData()
reliIndex = new StringList();
sourcesIndex = new StringList();

GDMRecord rec;

var iEnum = fTree.GetEnumerator(GDMRecordType.rtIndividual);
while (iEnum.MoveNext(out rec)) {
GDMIndividualRecord iRec = (GDMIndividualRecord)rec;
var iEnum = fTree.GetEnumerator<GDMIndividualRecord>();
GDMIndividualRecord iRec;
while (iEnum.MoveNext(out iRec)) {
string text = GKUtils.GetNameString(iRec, true, false);
string st;

Expand Down
Loading

0 comments on commit 9657f1c

Please sign in to comment.