[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Runtime/Serialization
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Runtime/Serialization ObjectManager.cs,1.3,1.4 |
Date: |
Wed, 04 Jun 2003 19:32:23 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Runtime/Serialization
In directory subversions:/tmp/cvs-serv25580/runtime/System/Runtime/Serialization
Modified Files:
ObjectManager.cs
Log Message:
Make fixups more efficient in "ObjectManager"; add some test cases
for "System.Runtime.Serialization".
Index: ObjectManager.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Runtime/Serialization/ObjectManager.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** ObjectManager.cs 26 May 2003 04:41:21 -0000 1.3
--- ObjectManager.cs 4 Jun 2003 23:32:21 -0000 1.4
***************
*** 31,45 ****
public class ObjectManager
{
! // Information that is stored for a member fixup.
! private sealed class ObjectFixup
{
! public ObjectInfo obj;
! public MemberInfo member;
! public String memberName;
! public int[] arrayIndex;
public ObjectFixup nextFixup;
}; // class ObjectFixup
// Information that is stored for an object identifier.
private sealed class ObjectInfo
--- 31,163 ----
public class ObjectManager
{
! // Common information that is stored for a member fixup.
! private abstract class ObjectFixup
{
! public ObjectInfo value;
public ObjectFixup nextFixup;
+ // Constructor.
+ protected ObjectFixup(ObjectInfo value, ObjectFixup nextFixup)
+ {
+ this.value = value;
+ this.nextFixup = nextFixup;
+ }
+
+ // Apply this fixup to an object.
+ public virtual void Apply(Object obj)
+ {
+ throw new SerializationException
+ (_("Serialize_BadFixup"));
+ }
+
}; // class ObjectFixup
+ // Fixup that uses a MemberInfo.
+ private class MemberInfoFixup : ObjectFixup
+ {
+ private MemberInfo member;
+
+ // Constructor.
+ public MemberInfoFixup(ObjectInfo value, MemberInfo member,
+ ObjectFixup
nextFixup)
+ : base(value, nextFixup)
+ {
+ this.member = member;
+ }
+
+ // Apply this fixup to an object.
+ public override void Apply(Object obj)
+ {
+ if(member is FieldInfo)
+ {
+
((FieldInfo)member).SetValue(obj, value.obj);
+ }
+ else
+ {
+ throw new SerializationException
+
(_("Serialize_BadFixup"));
+ }
+ }
+
+ }; // class MemberInfoFixup
+
+ // Fixup that uses a member name.
+ private class MemberNameFixup : ObjectFixup
+ {
+ private String memberName;
+
+ // Constructor.
+ public MemberNameFixup(ObjectInfo value, String memberName,
+ ObjectFixup
nextFixup)
+ : base(value, nextFixup)
+ {
+ this.memberName = memberName;
+ }
+
+ // Apply this fixup to an object.
+ public override void Apply(Object obj)
+ {
+ MemberInfo[] member =
obj.GetType().GetMember
+ (memberName);
+ if(member == null || member.Length != 1)
+ {
+ throw new SerializationException
+
(_("Serialize_BadFixup"));
+ }
+ if(member[0] is FieldInfo)
+ {
+
((FieldInfo)(member[0])).SetValue(obj, value.obj);
+ }
+ else
+ {
+ throw new SerializationException
+
(_("Serialize_BadFixup"));
+ }
+ }
+
+ }; // class MemberNameFixup
+
+ // Fixup that uses an array index.
+ private class ArrayIndexFixup : ObjectFixup
+ {
+ private int[] indices;
+
+ // Constructor.
+ public ArrayIndexFixup(ObjectInfo value, int[] indices,
+ ObjectFixup
nextFixup)
+ : base(value, nextFixup)
+ {
+ this.indices = indices;
+ }
+
+ // Apply this fixup to an object.
+ public override void Apply(Object obj)
+ {
+ ((Array)obj).SetValue(value.obj,
indices);
+ }
+
+ }; // class ArrayIndexFixup
+
+ // Fixup that uses an index into a single-dimensional array.
+ private class SingleArrayIndexFixup : ObjectFixup
+ {
+ private int index;
+
+ // Constructor.
+ public SingleArrayIndexFixup(ObjectInfo value, int index,
+
ObjectFixup nextFixup)
+ : base(value, nextFixup)
+ {
+ this.index = index;
+ }
+
+ // Apply this fixup to an object.
+ public override void Apply(Object obj)
+ {
+ ((Array)obj).SetValue(value.obj, index);
+ }
+
+ }; // class SingleArrayIndexFixup
+
// Information that is stored for an object identifier.
private sealed class ObjectInfo
***************
*** 79,135 ****
}
- // Apply a fixup.
- private static void ApplyFixup(ObjectInfo oinfo, ObjectFixup fixup)
- {
- if(fixup.obj.obj == null)
- {
- throw new SerializationException
- (_("Serialize_MissingFixup"));
- }
- if(fixup.member != null)
- {
- if(fixup.member is FieldInfo)
- {
-
((FieldInfo)(fixup.member)).SetValue
- (oinfo.obj,
fixup.obj.obj);
- }
- else
- {
- throw new SerializationException
-
(_("Serialize_BadFixup"));
- }
- }
- else if(fixup.memberName != null)
- {
- MemberInfo[] member =
oinfo.obj.GetType().GetMember
- (fixup.memberName);
- if(member == null || member.Length != 1)
- {
- throw new SerializationException
-
(_("Serialize_BadFixup"));
- }
- if(member[0] is FieldInfo)
- {
-
((FieldInfo)(member[0])).SetValue
- (oinfo.obj,
fixup.obj.obj);
- }
- else
- {
- throw new SerializationException
-
(_("Serialize_BadFixup"));
- }
- }
- else if(fixup.arrayIndex != null)
- {
- ((Array)(oinfo.obj)).SetValue
- (fixup.obj.obj,
fixup.arrayIndex);
- }
- else
- {
- throw new SerializationException
- (_("Serialize_BadFixup"));
- }
- }
-
// Apply a contained member fixup.
private static void ApplyContained(ObjectInfo oinfo, ObjectInfo contain)
--- 197,200 ----
***************
*** 182,186 ****
while(fixup != null)
{
! ApplyFixup(contain,
fixup);
fixup = fixup.nextFixup;
}
--- 247,256 ----
while(fixup != null)
{
! if(fixup.value.obj ==
null)
! {
! throw new
SerializationException
!
(_("Serialize_MissingFixup"));
! }
!
fixup.Apply(contain.obj);
fixup = fixup.nextFixup;
}
***************
*** 221,225 ****
while(fixup != null)
{
! ApplyFixup(oinfo, fixup);
fixup = fixup.nextFixup;
}
--- 291,300 ----
while(fixup != null)
{
! if(fixup.value.obj == null)
! {
! throw new
SerializationException
!
(_("Serialize_MissingFixup"));
! }
! fixup.Apply(oinfo.obj);
fixup = fixup.nextFixup;
}
***************
*** 246,250 ****
}
! // Raise a deserialization event on all register objects that want it.
public virtual void RaiseDeserializationEvent()
{
--- 321,325 ----
}
! // Raise a deserialization event on all registered objects that want it.
public virtual void RaiseDeserializationEvent()
{
***************
*** 261,293 ****
}
! // Record a fixup.
! private void RecordFixup(long objectToBeFixed, long objectRequired,
! MemberInfo member,
String memberName,
! int[] arrayIndex)
! {
! // Find or create the containing object's
information block.
! ObjectInfo oinfo =
(ObjectInfo)(objects[objectToBeFixed]);
! if(oinfo == null)
{
! oinfo = new ObjectInfo();
! objects[objectToBeFixed] = oinfo;
}
!
! // Find or create the required object's
information block.
! ObjectInfo oinfo2 =
(ObjectInfo)(objects[objectRequired]);
! if(oinfo2 == null)
{
! oinfo2 = new ObjectInfo();
! objects[objectRequired] = oinfo2;
}
-
- // Add a fixup to the containing object.
- ObjectFixup fixup = new ObjectFixup();
- fixup.obj = oinfo2;
- fixup.member = member;
- fixup.memberName = memberName;
- fixup.arrayIndex = arrayIndex;
- fixup.nextFixup = oinfo.fixups;
- oinfo.fixups = fixup;
}
--- 336,358 ----
}
! // Get the object information for an object, or add a new one.
! private ObjectInfo GetObjectInfo(long objectID)
! {
! if(objectID <= 0)
{
! throw new ArgumentOutOfRangeException
! ("objectID",
_("Serialize_BadObjectID"));
}
! ObjectInfo oinfo =
(ObjectInfo)(objects[objectID]);
! if(oinfo != null)
{
! return oinfo;
! }
! else
! {
! oinfo = new ObjectInfo();
! objects[objectID] = oinfo;
! return oinfo;
}
}
***************
*** 296,331 ****
(long arrayToBeFixed, int index, long
objectRequired)
{
! if(arrayToBeFixed <= 0)
! {
! throw new ArgumentOutOfRangeException
! ("arrayToBeFixed",
_("Serialize_BadObjectID"));
! }
! if(objectRequired <= 0)
! {
! throw new ArgumentOutOfRangeException
! ("objectRequired",
_("Serialize_BadObjectID"));
! }
! RecordFixup(arrayToBeFixed, objectRequired,
! null, null, new int[]
{index});
}
public virtual void RecordArrayElementFixup
(long arrayToBeFixed, int[] indices, long
objectRequired)
{
! if(arrayToBeFixed <= 0)
! {
! throw new ArgumentOutOfRangeException
! ("arrayToBeFixed",
_("Serialize_BadObjectID"));
! }
! if(objectRequired <= 0)
! {
! throw new ArgumentOutOfRangeException
! ("objectRequired",
_("Serialize_BadObjectID"));
! }
if(indices == null)
{
throw new
ArgumentNullException("indices");
}
! RecordFixup(arrayToBeFixed, objectRequired,
! null, null, indices);
}
--- 361,380 ----
(long arrayToBeFixed, int index, long
objectRequired)
{
! ObjectInfo oinfo1 =
GetObjectInfo(arrayToBeFixed);
! ObjectInfo oinfo2 =
GetObjectInfo(objectRequired);
! oinfo1.fixups = new SingleArrayIndexFixup
! (oinfo2, index, oinfo1.fixups);
}
public virtual void RecordArrayElementFixup
(long arrayToBeFixed, int[] indices, long
objectRequired)
{
! ObjectInfo oinfo1 =
GetObjectInfo(arrayToBeFixed);
! ObjectInfo oinfo2 =
GetObjectInfo(objectRequired);
if(indices == null)
{
throw new
ArgumentNullException("indices");
}
! oinfo1.fixups = new ArrayIndexFixup
! (oinfo2, indices, oinfo1.fixups);
}
***************
*** 334,373 ****
(long objectToBeFixed, String memberName, long
objectRequired)
{
! if(objectToBeFixed <= 0)
! {
! throw new ArgumentOutOfRangeException
! ("objectToBeFixed",
_("Serialize_BadObjectID"));
! }
! if(objectRequired <= 0)
! {
! throw new ArgumentOutOfRangeException
! ("objectRequired",
_("Serialize_BadObjectID"));
! }
if(memberName == null)
{
throw new
ArgumentNullException("memberName");
}
! RecordFixup(objectToBeFixed, objectRequired,
! null, memberName, null);
}
public virtual void RecordFixup
(long objectToBeFixed, MemberInfo member, long
objectRequired)
{
! if(objectToBeFixed <= 0)
! {
! throw new ArgumentOutOfRangeException
! ("objectToBeFixed",
_("Serialize_BadObjectID"));
! }
! if(objectRequired <= 0)
! {
! throw new ArgumentOutOfRangeException
! ("objectRequired",
_("Serialize_BadObjectID"));
! }
if(member == null)
{
throw new
ArgumentNullException("member");
}
! RecordFixup(objectToBeFixed, objectRequired,
! member, null, null);
}
--- 383,406 ----
(long objectToBeFixed, String memberName, long
objectRequired)
{
! ObjectInfo oinfo1 =
GetObjectInfo(objectToBeFixed);
! ObjectInfo oinfo2 =
GetObjectInfo(objectRequired);
if(memberName == null)
{
throw new
ArgumentNullException("memberName");
}
! oinfo1.fixups = new MemberNameFixup
! (oinfo2, memberName, oinfo1.fixups);
}
public virtual void RecordFixup
(long objectToBeFixed, MemberInfo member, long
objectRequired)
{
! ObjectInfo oinfo1 =
GetObjectInfo(objectToBeFixed);
! ObjectInfo oinfo2 =
GetObjectInfo(objectRequired);
if(member == null)
{
throw new
ArgumentNullException("member");
}
! oinfo1.fixups = new MemberInfoFixup
! (oinfo2, member, oinfo1.fixups);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Runtime/Serialization ObjectManager.cs,1.3,1.4,
Rhys Weatherley <address@hidden> <=