Skip to content

Commit

Permalink
Various minor fixes/tweaks. #20
Browse files Browse the repository at this point in the history
  • Loading branch information
bero committed Dec 6, 2024
1 parent c35d7d4 commit 2858731
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 64 deletions.
36 changes: 18 additions & 18 deletions Source/BoldElements.pas
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ TBoldExternalVariableList = class(TBoldObjectArray)
function GetEnumerator: TBoldExternalVariableListTraverser;
procedure Add(Variable: TBoldExternalVariable); overload;
procedure Add(AName: string; AValue: TBoldElement); overload;
procedure Add(AName: string; AValue: string); overload;
procedure AddInteger(AName: string; AValue: integer);
procedure AddFloat(AName: string; AValue: Double);
procedure AddDateTime(AName: string; AValue: TDateTime);
procedure AddDate(AName: string; AValue: TDate);
procedure AddTime(AName: string; AValue: TTime);
procedure Add(AName: string; AValue: string; AEvaluator: TBoldEvaluator = nil); overload;
procedure AddInteger(AName: string; AValue: integer; AEvaluator: TBoldEvaluator = nil);
procedure AddFloat(AName: string; AValue: Double; AEvaluator: TBoldEvaluator = nil);
procedure AddDateTime(AName: string; AValue: TDateTime; AEvaluator: TBoldEvaluator = nil);
procedure AddDate(AName: string; AValue: TDate; AEvaluator: TBoldEvaluator = nil);
procedure AddTime(AName: string; AValue: TTime; AEvaluator: TBoldEvaluator = nil);
property Variables[index: integer]: TBoldExternalVariable read GetVariables; default;
property VariableByName[const aName: string]: TBoldExternalVariable read GetVariableByName;
property AsCommaText: string read GetAsCommaText;
Expand Down Expand Up @@ -983,39 +983,39 @@ procedure TBoldExternalVariableList.Add(Variable: TBoldExternalVariable);
inherited Add(Variable);
end;

procedure TBoldExternalVariableList.Add(AName, AValue: string);
procedure TBoldExternalVariableList.Add(AName, AValue: string; AEvaluator: TBoldEvaluator);
begin
Add(TBoldOclVariable.CreateStringVariable(AName, AValue));
Add(TBoldOclVariable.CreateStringVariable(AName, AValue, AEvaluator));
end;

procedure TBoldExternalVariableList.Add(AName: string; AValue: TBoldElement);
begin
Add(TBoldOclVariable.Create(AName, AValue));
end;

procedure TBoldExternalVariableList.AddDate(AName: string; AValue: TDate);
procedure TBoldExternalVariableList.AddDate(AName: string; AValue: TDate; AEvaluator: TBoldEvaluator);
begin
Add(TBoldOclVariable.CreateDateVariable(AName, AValue));
Add(TBoldOclVariable.CreateDateVariable(AName, AValue, AEvaluator));
end;

procedure TBoldExternalVariableList.AddDateTime(AName: string; AValue: TDateTime);
procedure TBoldExternalVariableList.AddDateTime(AName: string; AValue: TDateTime; AEvaluator: TBoldEvaluator);
begin
Add(TBoldOclVariable.CreateDateTimeVariable(AName, AValue));
Add(TBoldOclVariable.CreateDateTimeVariable(AName, AValue, AEvaluator));
end;

procedure TBoldExternalVariableList.AddFloat(AName: string; AValue: Double);
procedure TBoldExternalVariableList.AddFloat(AName: string; AValue: Double; AEvaluator: TBoldEvaluator);
begin
Add(TBoldOclVariable.CreateFloatVariable(AName, AValue));
Add(TBoldOclVariable.CreateFloatVariable(AName, AValue, AEvaluator));
end;

procedure TBoldExternalVariableList.AddInteger(AName: string; AValue: integer);
procedure TBoldExternalVariableList.AddInteger(AName: string; AValue: integer; AEvaluator: TBoldEvaluator);
begin
Add(TBoldOclVariable.CreateIntegerVariable(AName, AValue));
Add(TBoldOclVariable.CreateIntegerVariable(AName, AValue, AEvaluator));
end;

procedure TBoldExternalVariableList.AddTime(AName: string; AValue: TTime);
procedure TBoldExternalVariableList.AddTime(AName: string; AValue: TTime; AEvaluator: TBoldEvaluator);
begin
Add(TBoldOclVariable.CreateTimeVariable(AName, AValue));
Add(TBoldOclVariable.CreateTimeVariable(AName, AValue, AEvaluator));
end;

constructor TBoldExternalVariableList.Create(aOwnsVariables: boolean);
Expand Down
1 change: 1 addition & 0 deletions Source/BoldIndex.pas
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ procedure TBoldIntegerIndex.Clear(DestroyObjects: Boolean=false);
end;
end;
fCount := 0;
SetCapacity(0);
end;

constructor TBoldIntegerIndex.Create;
Expand Down
21 changes: 12 additions & 9 deletions Source/BoldIndexableList.pas
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ TBoldUnOrderedIndexableList = class(TBoldNonRefCountedObject)
function AddIndex(BoldIndex: TBoldIndex): integer;
procedure AddToAllIndexes(Item: TObject);
procedure RemoveAndFreeIndex(var BoldIndex: TBoldIndex; DestroyObjects: Boolean);
procedure RemoveFromAllIndexes(Item: TObject);
function RemoveFromAllIndexes(Item: TObject): boolean;
procedure SetIndexCapacity(NewCapacity: integer);
function TraverserClass: TBoldIndexableListTraverserClass; virtual;
property IndexCount: integer read GetIndexCount;
Expand All @@ -82,7 +82,7 @@ TBoldUnOrderedIndexableList = class(TBoldNonRefCountedObject)
procedure Add(Item: TObject);
procedure Clear;
procedure ItemChanged(Item: TObject);
procedure Remove(Item: TObject);
function Remove(Item: TObject): boolean;
function CreateTraverser: TBoldIndexableListTraverser;
function GetEnumerator: TBoldIndexableListTraverser;
property Count: integer read GetCount;
Expand Down Expand Up @@ -364,14 +364,19 @@ procedure TBoldUnOrderedIndexableList.AddToAllIndexes(Item: TObject);
Indexes[i].Add(Item);
end;

procedure TBoldUnOrderedIndexableList.RemoveFromAllIndexes(Item: TObject);
function TBoldUnOrderedIndexableList.RemoveFromAllIndexes(Item: TObject): boolean;
var
i: integer;
begin
if Assigned(Item) then
begin
result := (IndexCount > 0);
for i := 0 to IndexCount-1 do
if Assigned(Indexes[i]) then
Indexes[i].Remove(Item);
result := Indexes[i].Remove(Item) and result;
end
else
result := false;
end;

procedure TBoldUnOrderedIndexableList.Add(Item: TObject);
Expand All @@ -387,14 +392,13 @@ procedure TBoldUnOrderedIndexableList.Add(Item: TObject);
AddToAllIndexes(Item);
end;

procedure TBoldUnOrderedIndexableList.Remove(Item: TObject);
function TBoldUnOrderedIndexableList.Remove(Item: TObject): boolean;
begin
RemoveFromAllIndexes(item);
result := RemoveFromAllIndexes(item);
if OwnsEntries then
item.free;
end;


procedure TBoldUnOrderedIndexableList.ItemChanged(Item: TObject);
var
i: integer;
Expand All @@ -404,7 +408,6 @@ procedure TBoldUnOrderedIndexableList.ItemChanged(Item: TObject);
Indexes[i].ItemChanged(Item);
end;


procedure TBoldUnOrderedIndexableList.Clear;
var
i: Integer;
Expand All @@ -416,7 +419,7 @@ procedure TBoldUnOrderedIndexableList.Clear;
for i := 0 to IndexCount-1 do
if assigned(Indexes[i]) then
begin
Indexes[i].Clear(OwnsEntries and (IndicesToGo=1));
Indexes[i].Clear(OwnsEntries and (IndicesToGo=1)); // only free from one (last) index
dec(IndicesToGo);
end;
end;
Expand Down
7 changes: 4 additions & 3 deletions Source/BoldMeta.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2252,10 +2252,11 @@ procedure TMoldElement.SetBoldTVByName(const Tag, value: string);
begin
TrimmedValue := BoldTrim(Value);
Definition := DefaultBoldTVList.DefinitionForTag[Tag];
// only set tag if it differs from default
if Assigned(Definition) and (Definition.DefaultValue = TrimmedValue) then
// do Nothing
else
BoldTaggedValues.ValueByName[Tag] := TrimmedValue;
if BoldTaggedValues.ValueByName[Tag] = '' then
exit;
BoldTaggedValues.ValueByName[Tag] := TrimmedValue;
end;

function TMoldMember.GetManuallyDerived: Boolean;
Expand Down
54 changes: 25 additions & 29 deletions Source/BoldObjectListControllers.pas
Original file line number Diff line number Diff line change
Expand Up @@ -381,27 +381,19 @@ procedure TBoldObjectListController._ReceiveObjectDeleted(
{$ENDIF}
end;

procedure RemoveLocator(Locator: TBoldObjectLocator);
begin
if LocatorList.LocatorInList[Locator] then
begin
LocatorList.Remove(Locator);
Changed(beItemDeleted, [Locator]);
end;
end;

var
DeletedLocator: TBoldObjectLocator;
begin
case OriginalEvent of
beLocatorDestroying, beObjectDeleted:
begin
DeletedLocator := (Originator as TBoldObject).BoldObjectLocator;
RemoveLocator(DeletedLocator);
DeletedLocator := Args[0].vObject as TBoldObjectLocator;
if LocatorList.Remove(DeletedLocator) then
Changed(beItemDeleted, [DeletedLocator]);
end;
beDestroying:
begin
RemoveAllObjectsFromSystem(TBoldSystem(TBoldObjectList(Originator).OwningElement));
RemoveAllObjectsFromSystem(Originator as TBoldSystem);
end;
else
raise EBoldInternal.CreateFmt(sUnknownEvent, [classname]);
Expand All @@ -410,31 +402,34 @@ procedure TBoldObjectListController._ReceiveObjectDeleted(

procedure TBoldObjectListController.SubscribeToObjectDeleted(Locator: TBoldObjectLocator);
var
ClassList: TBoldObjectList;
SubscriptionSource: TBoldElement;
begin
if not (OwningObjectList.SubscribeToLocatorsInList or OwningObjectList.SubscribeToObjectsInList) then
exit;
if Assigned(FSubscriber) then // if assigned then subscriptions should already have been placed.
exit;
FSubscriber := TBoldExtendedPassthroughSubscriber.CreateWithExtendedReceive(_ReceiveObjectDeleted);

{$IFNDEF NoBoldClassLists}
if Assigned(OwningObjectList.ListElementTypeInfo) then
ClassList := Locator.BoldSystem.Classes[OwningObjectList.ListElementTypeInfo.TopSortedIndex]
SubscriptionSource := Locator.BoldSystem.Classes[OwningObjectList.ListElementTypeInfo.TopSortedIndex]
else
ClassList := Locator.BoldSystem.Classes[0];

SubscriptionSource := Locator.BoldSystem.Classes[0];
{$ELSE}
SubscriptionSource := Locator.BoldSystem;
{$ENDIF NoBoldClassLists}
if OwningObjectList.SubscribeToLocatorsInList then
begin
// Subscribe to ClassList instead of System to avoid having all subscriptions on system.
// When object is deleted, system sends beObjectDeleted, ClassList receives it and sends beItemDeleted instead
if OwningObjectList.SubscribeToObjectsInList then
ClassList.AddSmallSubscription(FSubscriber, [beLocatorDestroying, beObjectDeleted{, beDestroying}])
SubscriptionSource.AddSmallSubscription(FSubscriber, [beLocatorDestroying, beObjectDeleted{, beDestroying}])
else
ClassList.AddSmallSubscription(FSubscriber, [beLocatorDestroying]);
SubscriptionSource.AddSmallSubscription(FSubscriber, [beLocatorDestroying]);
end
else
if OwningObjectList.SubscribeToObjectsInList then
ClassList.AddSmallSubscription(FSubscriber, [beDestroying, beObjectDeleted]);
SubscriptionSource.AddSmallSubscription(FSubscriber, [beDestroying, beObjectDeleted]);
end;

procedure TBoldObjectListController.DropSubscriptions;
Expand Down Expand Up @@ -683,13 +678,11 @@ procedure TBoldClassListController.ReceiveClassEvent(BoldElement: TBoldDomainEle
beObjectDeleted:
begin
Dec(fLoadedObjectCount);
LocatorList.Remove(BoldObject.BoldObjectLocator);
if not List.BoldPersistenceStateIsInvalid then
begin
// if ClassTypeInfo.Persistent and BoldSystem.BoldPersistent then
// Assert(LocatorList.Includes(BoldObject.BoldObjectLocator));
if List.HasSubscribers then
List.Publisher.SendEvent(beValueInvalid);
if LocatorList.Remove(BoldObject.BoldObjectLocator) then
if List.HasSubscribers then
List.Publisher.SendEvent(beValueInvalid);
end;
end;
beObjectFetched:
Expand All @@ -710,7 +703,8 @@ procedure TBoldClassListController.ReceiveClassEvent(BoldElement: TBoldDomainEle
Dec(fLoadedObjectCount);
if not List.BoldPersistenceStateIsInvalid then
begin
SetPersistenceState(bvpsTransient);
if List.BoldPersistenceState <> bvpsTransient then
SetPersistenceState(bvpsTransient);
if list.HasSubscribers then
List.Publisher.SendEvent(beValueInvalid);
end;
Expand Down Expand Up @@ -837,7 +831,6 @@ procedure TBoldClassListController.SetFromIdList(
Locator := BoldSystem.EnsuredLocatorByID[ID];
if not IncludesLocator(Locator) then
begin
PreChange;
LocatorList.Add(Locator);
Changed(beItemAdded, [Locator]);
end;
Expand Down Expand Up @@ -893,7 +886,7 @@ procedure TBoldClassListController.SetFromIdList(
for I := 0 to NewList.Count - 1 do
InternalAddId(NewList[I]);
finally
NewList.Free;
NewList.Free;
end;
end;

Expand All @@ -902,8 +895,11 @@ procedure TBoldClassListController.SetPersistenceState(
begin
with OwningList do
begin
BoldPersistenceState := APersistenceState;
SendEvent(beClassListStateChanged);
if BoldPersistenceState <> APersistenceState then
begin
BoldPersistenceState := APersistenceState;
SendEvent(beClassListStateChanged);
end;
end;
end;

Expand Down
8 changes: 3 additions & 5 deletions Source/BoldSystem.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2830,7 +2830,7 @@ procedure TBoldSystem.DestroyObject(BoldObject: TBoldObject);
// If we got an exception duriung destoy, we might get an half uninitialized BoldObject without Locator next time.
if Assigned(aLocator) then //PATCH
begin
TBoldClassListController(Classes[aLocator.BoldClassTypeInfo.TopSortedIndex].ObjectListController).ReceiveClassEvent(BoldObject, beLocatorDestroying, []);
TBoldClassListController(Classes[aLocator.BoldClassTypeInfo.TopSortedIndex].ObjectListController).ReceiveClassEvent(BoldObject, beLocatorDestroying, [aLocator]);
SendExtendedEvent(beLocatorDestroying, [aLocator]);
aLocator.UnloadBoldObject;
Locators.Remove(aLocator);
Expand Down Expand Up @@ -5923,17 +5923,15 @@ procedure TBoldMember.InternalDiscard;
{$ENDIF}
case BoldPersistenceState of
bvpsModified: begin

if not OwningObject.BoldObjectLocator.BoldObjectID.IsStorable then
BoldPersistenceState := bvpsCurrent
else
BoldPersistenceState := bvpsInvalid;

FreeContent;
SendEvent(beValueInvalid);
end;
bvpsTransient: if not Derived and mutable then
DoSetInitialValue;
bvpsTransient: if not Derived and mutable and not OwningObject.Discarding then
DoSetInitialValue;
end;
end;
end;
Expand Down

0 comments on commit 2858731

Please sign in to comment.