From: Steven M. <sr...@us...> - 2006-01-04 04:42:25
|
Update of /cvsroot/instantobjects/Source/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6891 Modified Files: InstantPersistence.pas Log Message: Changes: 1. Refactored the TInstantReferences class to use the new TInstantObjectReferenceList class. 2. Fixed a bug in the TInstantObjectReferenceList.Add method and added more functionality to support the list's use in TInstantReferences. Index: InstantPersistence.pas =================================================================== RCS file: /cvsroot/instantobjects/Source/Core/InstantPersistence.pas,v retrieving revision 1.80 retrieving revision 1.81 diff -C2 -d -r1.80 -r1.81 *** InstantPersistence.pas 31 Dec 2005 10:53:57 -0000 1.80 --- InstantPersistence.pas 4 Jan 2006 04:42:12 -0000 1.81 *************** *** 82,85 **** --- 82,86 ---- TInstantAttribute = class; TInstantAttributeClass = class of TInstantAttribute; + TInstantObjectReferenceList = class; TInstantStorageKind = (skEmbedded, skExternal); *************** *** 1080,1090 **** FAllowOwned: Boolean; FConnector: TInstantConnector; ! FObjectReferenceList: TObjectList; ! function CreateObjectReference(AObject: TInstantObject): TInstantObjectReference; ! function GetObjectReferenceList: TObjectList; ! function GetObjectReferences(Index: Integer): TInstantObjectReference; ! procedure SetObjectReferences(Index: Integer; Value: TInstantObjectReference); ! property ObjectReferenceList: TObjectList read GetObjectReferenceList; ! property ObjectReferences[Index: Integer]: TInstantObjectReference read GetObjectReferences write SetObjectReferences; protected class function AttributeType: TInstantAttributeType; override; --- 1081,1088 ---- FAllowOwned: Boolean; FConnector: TInstantConnector; ! FObjectReferenceList: TInstantObjectReferenceList; ! function GetObjectReferenceList: TInstantObjectReferenceList; ! property ObjectReferenceList: TInstantObjectReferenceList read ! GetObjectReferenceList; protected class function AttributeType: TInstantAttributeType; override; *************** *** 1752,1757 **** end; - TInstantObjectReferenceList = class; - TInstantQuery = class(TPersistent) private --- 1750,1753 ---- *************** *** 2604,2609 **** --- 2600,2607 ---- procedure Clear; procedure Delete(Index: Integer); + procedure Exchange(Index1, Index2: Integer); function IndexOf(Item: TInstantObject): Integer; procedure Insert(Index: Integer; Item: TInstantObject); + procedure Move(CurIndex, NewIndex: Integer); function Remove(Item: TInstantObject): Integer; property Capacity: Integer read GetCapacity write SetCapacity; *************** *** 7138,7147 **** end; - function TInstantReferences.CreateObjectReference( - AObject: TInstantObject): TInstantObjectReference; - begin - Result := TInstantObjectReference.Create(AObject, True, Self); - end; - destructor TInstantReferences.Destroy; begin --- 7136,7139 ---- *************** *** 7152,7156 **** procedure TInstantReferences.DestroyObject(Index: Integer); begin ! ObjectReferences[Index].DestroyInstance; end; --- 7144,7148 ---- procedure TInstantReferences.DestroyObject(Index: Integer); begin ! ObjectReferenceList.RefItems[Index].DestroyInstance; end; *************** *** 7175,7206 **** function TInstantReferences.GetInstances(Index: Integer): TInstantObject; begin ! Result := ObjectReferences[Index].Instance; end; ! function TInstantReferences.GetObjectReferenceList: TObjectList; begin if not Assigned(FObjectReferenceList) then ! FObjectReferenceList := TObjectList.Create; Result := FObjectReferenceList; end; ! function TInstantReferences.GetObjectReferences( ! Index: Integer): TInstantObjectReference; ! begin ! Result := TInstantObjectReference(ObjectReferenceList[Index]); ! end; ! ! function TInstantReferences.InternalAdd( ! AObject: TInstantObject): Integer; ! var ! Ref: TInstantObjectReference; begin ! Ref := CreateObjectReference(AObject); ! try ! Result := ObjectReferenceList.Add(Ref); ! except ! Ref.Free; ! raise; ! end; end; --- 7167,7184 ---- function TInstantReferences.GetInstances(Index: Integer): TInstantObject; begin ! Result := ObjectReferenceList[Index]; end; ! function TInstantReferences.GetObjectReferenceList: TInstantObjectReferenceList; begin if not Assigned(FObjectReferenceList) then ! FObjectReferenceList := TInstantObjectReferenceList.Create( ! True, Connector, Self); Result := FObjectReferenceList; end; ! function TInstantReferences.InternalAdd(AObject: TInstantObject): Integer; begin ! Result := ObjectReferenceList.Add(AObject); end; *************** *** 7221,7274 **** function TInstantReferences.InternalGetItems(Index: Integer): TInstantObject; - var - Ref: TInstantObjectReference; begin ! Ref := ObjectReferences[Index]; ! if not Assigned(Ref.Instance) then ! Result := Ref.Dereference(Connector) ! else ! Result := Ref.Instance; end; function TInstantReferences.InternalIndexOf( AObject: TInstantObject): Integer; - var - Ref: TInstantObjectReference; begin ! for Result := 0 to Pred(Count) do ! begin ! Ref := ObjectReferences[Result]; ! if Ref.Equals(AObject) then ! Exit; ! end; ! Result := -1; end; function TInstantReferences.InternalIndexOfInstance( Instance: Pointer): Integer; - var - Ref: TInstantObjectReference; begin ! for Result := 0 to Pred(Count) do ! begin ! Ref := ObjectReferences[Result]; ! if Ref.Instance = Instance then ! Exit; ! end; ! Result := -1; end; procedure TInstantReferences.InternalInsert(Index: Integer; AObject: TInstantObject); - var - Ref: TInstantObjectReference; begin ! Ref := CreateObjectReference(AObject); ! try ! ObjectReferenceList.Insert(Index, Ref); ! except ! Ref.Free; ! raise; ! end; end; --- 7199,7222 ---- function TInstantReferences.InternalGetItems(Index: Integer): TInstantObject; begin ! Result := ObjectReferenceList[Index]; end; function TInstantReferences.InternalIndexOf( AObject: TInstantObject): Integer; begin ! Result := ObjectReferenceList.IndexOf(AObject); end; function TInstantReferences.InternalIndexOfInstance( Instance: Pointer): Integer; begin ! Result := ObjectReferenceList.IndexOf(TInstantObject(Instance)); end; procedure TInstantReferences.InternalInsert(Index: Integer; AObject: TInstantObject); begin ! ObjectReferenceList.Insert(Index, AObject); end; *************** *** 7281,7285 **** AValue: TInstantObject); begin ! ObjectReferences[Index].Instance := AValue; end; --- 7229,7233 ---- AValue: TInstantObject); begin ! ObjectReferenceList[Index] := AValue; end; *************** *** 7312,7323 **** Obj := InstantReadObjectFromStream(AStream); try ! ObjReference := TInstantObjectReference.Create(nil, True, Self); try ObjReference.ReferenceObject( TInstantObjectReference(Obj).ObjectClassName, TInstantObjectReference(Obj).ObjectId); - ObjectReferenceList.Add(ObjReference); except ! ObjReference.Free; raise; end; --- 7260,7270 ---- Obj := InstantReadObjectFromStream(AStream); try ! ObjReference := ObjectReferenceList.Add; try ObjReference.ReferenceObject( TInstantObjectReference(Obj).ObjectClassName, TInstantObjectReference(Obj).ObjectId); except ! ObjectReferenceList.Delete(Pred(Count)); raise; end; *************** *** 7341,7350 **** ObjId := Processor.ReadData; //Data = ObjectId Processor.ReadTag; //closing tag ! ObjReference := TInstantObjectReference.Create(nil, True, Self); try ObjReference.ReferenceObject(ObjClassName, ObjId); - ObjectReferenceList.Add(ObjReference); except ! ObjReference.Free; end; end; --- 7288,7297 ---- ObjId := Processor.ReadData; //Data = ObjectId Processor.ReadTag; //closing tag ! ObjReference := ObjectReferenceList.Add; try ObjReference.ReferenceObject(ObjClassName, ObjId); except ! ObjectReferenceList.Delete(Pred(Count)); ! raise; end; end; *************** *** 7365,7374 **** while not Reader.EndOfList do begin ! Ref := CreateObjectReference(nil); try Ref.ReadAsObject(Reader); - ObjectReferenceList.Add(Ref); except ! Ref.Free; raise; end; --- 7312,7320 ---- while not Reader.EndOfList do begin ! Ref := ObjectReferenceList.Add; try Ref.ReadAsObject(Reader); except ! ObjectReferenceList.Delete(Pred(Count)); raise; end; *************** *** 7389,7393 **** begin for I := 0 to Pred(Count) do ! InstantWriteObjectToStream(AStream, ObjectReferences[I]); end else --- 7335,7339 ---- begin for I := 0 to Pred(Count) do ! InstantWriteObjectToStream(AStream, ObjectReferenceList.RefItems[I]); end else *************** *** 7401,7406 **** for I := 0 to Pred(Count) do begin ! InstantXMLProducer.WriteStartTag(ObjectReferences[I].ObjectClassName); ! InstantXMLProducer.WriteData(ObjectReferences[I].ObjectId); InstantXMLProducer.WriteEndTag; end; --- 7347,7353 ---- for I := 0 to Pred(Count) do begin ! InstantXMLProducer.WriteStartTag( ! ObjectReferenceList.RefItems[I].ObjectClassName); ! InstantXMLProducer.WriteData(ObjectReferenceList.RefItems[I].ObjectId); InstantXMLProducer.WriteEndTag; end; *************** *** 7417,7426 **** end; - procedure TInstantReferences.SetObjectReferences(Index: Integer; - Value: TInstantObjectReference); - begin - ObjectReferenceList[Index] := Value; - end; - procedure TInstantReferences.ValidateObject(AObject: TInstantObject); begin --- 7364,7367 ---- *************** *** 7437,7441 **** Writer.WriteValue(vaCollection); for I := 0 to Pred(Count) do ! ObjectReferences[I].WriteAsObject(Writer); Writer.WriteListEnd; end; --- 7378,7382 ---- Writer.WriteValue(vaCollection); for I := 0 to Pred(Count) do ! ObjectReferenceList.RefItems[I].WriteAsObject(Writer); Writer.WriteListEnd; end; *************** *** 14472,14479 **** while not DataSet.Eof do begin ! RefObject := TInstantObjectReference.Create(nil, True, ! Attribute as TInstantReferences); RefObject.ReferenceObject(Metadata.ObjectClass, DataSet.Fields[1].AsString); - (Attribute as TInstantReferences).ObjectReferenceList.Add(RefObject); DataSet.Next; end; --- 14413,14419 ---- while not DataSet.Eof do begin ! RefObject := ! (Attribute as TInstantReferences).ObjectReferenceList.Add; RefObject.ReferenceObject(Metadata.ObjectClass, DataSet.Fields[1].AsString); DataSet.Next; end; *************** *** 15581,15588 **** begin Result := TInstantObjectReference.Create(nil, FRefOwnsInstance, FRefOwner); ! if Assigned(AObject) and FRefOwnsInstance then ! Result.Instance := AObject ! else ! Result.ReferenceObject(AObject.ClassName, AObject.Id); end; --- 15521,15531 ---- begin Result := TInstantObjectReference.Create(nil, FRefOwnsInstance, FRefOwner); ! if Assigned(AObject) then ! begin ! if FRefOwnsInstance then ! Result.Instance := AObject ! else ! Result.ReferenceObject(AObject.ClassName, AObject.Id); ! end; end; *************** *** 15592,15595 **** --- 15535,15543 ---- end; + procedure TInstantObjectReferenceList.Exchange(Index1, Index2: Integer); + begin + FList.Exchange(Index1, Index2); + end; + function TInstantObjectReferenceList.GetCapacity: Integer; begin *************** *** 15642,15645 **** --- 15590,15598 ---- end; + procedure TInstantObjectReferenceList.Move(CurIndex, NewIndex: Integer); + begin + FList.Move(CurIndex, NewIndex); + end; + function TInstantObjectReferenceList.Remove(Item: TInstantObject): Integer; begin |