Serialization support for HashSet<T> where T : Item/Mobile/BaseGuild
This commit is contained in:
parent
22557eef9f
commit
12fe97babd
1 changed files with 355 additions and 23 deletions
|
|
@ -84,6 +84,15 @@ namespace Server
|
|||
public abstract List<BaseGuild> ReadStrongGuildList();
|
||||
public abstract List<T> ReadStrongGuildList<T>() where T : BaseGuild;
|
||||
|
||||
public abstract HashSet<Item> ReadItemSet();
|
||||
public abstract HashSet<T> ReadItemSet<T>() where T: Item;
|
||||
|
||||
public abstract HashSet<Mobile> ReadMobileSet();
|
||||
public abstract HashSet<T> ReadMobileSet<T>() where T : Mobile;
|
||||
|
||||
public abstract HashSet<BaseGuild> ReadGuildSet();
|
||||
public abstract HashSet<T> ReadGuildSet<T>() where T : BaseGuild;
|
||||
|
||||
public abstract Race ReadRace();
|
||||
|
||||
public abstract bool End();
|
||||
|
|
@ -150,18 +159,36 @@ namespace Server
|
|||
public abstract void WriteItemList<T>( List<T> list ) where T : Item;
|
||||
public abstract void WriteItemList<T>( List<T> list, bool tidy ) where T : Item;
|
||||
|
||||
public abstract void Write( HashSet<Item> list );
|
||||
public abstract void Write( HashSet<Item> list, bool tidy );
|
||||
|
||||
public abstract void WriteItemSet<T>( HashSet<T> set ) where T : Item;
|
||||
public abstract void WriteItemSet<T>( HashSet<T> set, bool tidy ) where T : Item;
|
||||
|
||||
public abstract void Write( List<Mobile> list );
|
||||
public abstract void Write( List<Mobile> list, bool tidy );
|
||||
|
||||
public abstract void WriteMobileList<T>( List<T> list ) where T : Mobile;
|
||||
public abstract void WriteMobileList<T>( List<T> list, bool tidy ) where T : Mobile;
|
||||
|
||||
public abstract void Write( HashSet<Mobile> list );
|
||||
public abstract void Write( HashSet<Mobile> list, bool tidy );
|
||||
|
||||
public abstract void WriteMobileSet<T>( HashSet<T> set ) where T : Mobile;
|
||||
public abstract void WriteMobileSet<T>( HashSet<T> set, bool tidy ) where T : Mobile;
|
||||
|
||||
public abstract void Write( List<BaseGuild> list );
|
||||
public abstract void Write( List<BaseGuild> list, bool tidy );
|
||||
|
||||
public abstract void WriteGuildList<T>( List<T> list ) where T : BaseGuild;
|
||||
public abstract void WriteGuildList<T>( List<T> list, bool tidy ) where T : BaseGuild;
|
||||
|
||||
public abstract void Write( HashSet<BaseGuild> list );
|
||||
public abstract void Write( HashSet<BaseGuild> list, bool tidy );
|
||||
|
||||
public abstract void WriteGuildSet<T>( HashSet<T> set ) where T : BaseGuild;
|
||||
public abstract void WriteGuildSet<T>( HashSet<T> set, bool tidy ) where T : BaseGuild;
|
||||
|
||||
//Stupid compiler won't notice there 'where' to differentiate the generic methods.
|
||||
}
|
||||
|
||||
|
|
@ -544,6 +571,14 @@ namespace Server
|
|||
Write( (byte)0xFF );
|
||||
}
|
||||
|
||||
public override void Write( Race value )
|
||||
{
|
||||
if( value != null )
|
||||
Write( (byte)value.RaceIndex );
|
||||
else
|
||||
Write( (byte)0xFF );
|
||||
}
|
||||
|
||||
public override void Write( Item value )
|
||||
{
|
||||
if( value == null || value.Deleted )
|
||||
|
|
@ -587,7 +622,6 @@ namespace Server
|
|||
{
|
||||
WriteMobileList( list, false );
|
||||
}
|
||||
|
||||
public override void WriteMobileList( ArrayList list, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
|
|
@ -611,7 +645,6 @@ namespace Server
|
|||
{
|
||||
WriteItemList( list, false );
|
||||
}
|
||||
|
||||
public override void WriteItemList( ArrayList list, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
|
|
@ -635,7 +668,6 @@ namespace Server
|
|||
{
|
||||
WriteGuildList( list, false );
|
||||
}
|
||||
|
||||
public override void WriteGuildList( ArrayList list, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
|
|
@ -659,7 +691,6 @@ namespace Server
|
|||
{
|
||||
Write( list, false );
|
||||
}
|
||||
|
||||
public override void Write( List<Item> list, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
|
|
@ -702,11 +733,48 @@ namespace Server
|
|||
Write( list[i] );
|
||||
}
|
||||
|
||||
public override void Write( HashSet<Item> set )
|
||||
{
|
||||
Write( set, false );
|
||||
}
|
||||
public override void Write( HashSet<Item> set, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
{
|
||||
set.RemoveWhere( item => item.Deleted );
|
||||
}
|
||||
|
||||
Write( set.Count );
|
||||
|
||||
foreach( Item item in set )
|
||||
{
|
||||
Write( item );
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteItemSet<T>( HashSet<T> set )
|
||||
{
|
||||
WriteItemSet( set, false );
|
||||
}
|
||||
public override void WriteItemSet<T>( HashSet<T> set, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
{
|
||||
set.RemoveWhere( item => item.Deleted );
|
||||
}
|
||||
|
||||
Write( set.Count );
|
||||
|
||||
foreach( Item item in set )
|
||||
{
|
||||
Write( item );
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write( List<Mobile> list )
|
||||
{
|
||||
Write( list, false );
|
||||
}
|
||||
|
||||
public override void Write( List<Mobile> list, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
|
|
@ -730,7 +798,6 @@ namespace Server
|
|||
{
|
||||
WriteMobileList<T>( list, false );
|
||||
}
|
||||
|
||||
public override void WriteMobileList<T>( List<T> list, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
|
|
@ -749,12 +816,49 @@ namespace Server
|
|||
for( int i = 0; i < list.Count; ++i )
|
||||
Write( list[i] );
|
||||
}
|
||||
|
||||
public override void Write( HashSet<Mobile> set )
|
||||
{
|
||||
Write( set, false );
|
||||
}
|
||||
public override void Write( HashSet<Mobile> set, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
{
|
||||
set.RemoveWhere( mobile => mobile.Deleted );
|
||||
}
|
||||
|
||||
Write( set.Count );
|
||||
|
||||
foreach( Mobile mob in set )
|
||||
{
|
||||
Write( mob );
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteMobileSet<T>( HashSet<T> set )
|
||||
{
|
||||
WriteMobileSet( set, false );
|
||||
}
|
||||
public override void WriteMobileSet<T>( HashSet<T> set, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
{
|
||||
set.RemoveWhere( mob => mob.Deleted );
|
||||
}
|
||||
|
||||
Write( set.Count );
|
||||
|
||||
foreach( Mobile mob in set )
|
||||
{
|
||||
Write( mob );
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write( List<BaseGuild> list )
|
||||
{
|
||||
Write( list, false );
|
||||
}
|
||||
|
||||
public override void Write( List<BaseGuild> list, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
|
|
@ -778,7 +882,6 @@ namespace Server
|
|||
{
|
||||
WriteGuildList<T>( list, false );
|
||||
}
|
||||
|
||||
public override void WriteGuildList<T>( List<T> list, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
|
|
@ -798,12 +901,42 @@ namespace Server
|
|||
Write( list[i] );
|
||||
}
|
||||
|
||||
public override void Write( Race value )
|
||||
public override void Write( HashSet<BaseGuild> set )
|
||||
{
|
||||
if( value != null )
|
||||
Write( (byte)value.RaceIndex );
|
||||
else
|
||||
Write( (byte)0xFF );
|
||||
Write( set, false );
|
||||
}
|
||||
public override void Write( HashSet<BaseGuild> set, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
{
|
||||
set.RemoveWhere( guild => guild.Disbanded );
|
||||
}
|
||||
|
||||
Write( set.Count );
|
||||
|
||||
foreach( BaseGuild guild in set )
|
||||
{
|
||||
Write( guild );
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteGuildSet<T>( HashSet<T> set )
|
||||
{
|
||||
WriteGuildSet( set, false );
|
||||
}
|
||||
public override void WriteGuildSet<T>( HashSet<T> set, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
{
|
||||
set.RemoveWhere( guild => guild.Disbanded );
|
||||
}
|
||||
|
||||
Write( set.Count );
|
||||
|
||||
foreach( BaseGuild guild in set )
|
||||
{
|
||||
Write( guild );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1100,6 +1233,37 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
public override HashSet<Item> ReadItemSet()
|
||||
{
|
||||
return ReadItemSet<Item>();
|
||||
}
|
||||
|
||||
public override HashSet<T> ReadItemSet<T>()
|
||||
{
|
||||
int count = ReadInt();
|
||||
|
||||
if( count > 0 )
|
||||
{
|
||||
HashSet<T> set = new HashSet<T>();
|
||||
|
||||
for( int i = 0; i < count; ++i )
|
||||
{
|
||||
T item = ReadItem() as T;
|
||||
|
||||
if( item != null )
|
||||
{
|
||||
set.Add( item );
|
||||
}
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new HashSet<T>();
|
||||
}
|
||||
}
|
||||
|
||||
public override List<Mobile> ReadStrongMobileList()
|
||||
{
|
||||
return ReadStrongMobileList<Mobile>();
|
||||
|
|
@ -1126,6 +1290,37 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
public override HashSet<Mobile> ReadMobileSet()
|
||||
{
|
||||
return ReadMobileSet<Mobile>();
|
||||
}
|
||||
|
||||
public override HashSet<T> ReadMobileSet<T>()
|
||||
{
|
||||
int count = ReadInt();
|
||||
|
||||
if( count > 0 )
|
||||
{
|
||||
HashSet<T> set = new HashSet<T>();
|
||||
|
||||
for( int i = 0; i < count; ++i )
|
||||
{
|
||||
T item = ReadMobile() as T;
|
||||
|
||||
if( item != null )
|
||||
{
|
||||
set.Add( item );
|
||||
}
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new HashSet<T>();
|
||||
}
|
||||
}
|
||||
|
||||
public override List<BaseGuild> ReadStrongGuildList()
|
||||
{
|
||||
return ReadStrongGuildList<BaseGuild>();
|
||||
|
|
@ -1152,15 +1347,46 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
public override bool End()
|
||||
public override HashSet<BaseGuild> ReadGuildSet()
|
||||
{
|
||||
return m_File.PeekChar() == -1;
|
||||
return ReadGuildSet<BaseGuild>();
|
||||
}
|
||||
|
||||
public override HashSet<T> ReadGuildSet<T>()
|
||||
{
|
||||
int count = ReadInt();
|
||||
|
||||
if( count > 0 )
|
||||
{
|
||||
HashSet<T> set = new HashSet<T>();
|
||||
|
||||
for( int i = 0; i < count; ++i )
|
||||
{
|
||||
T item = ReadGuild() as T;
|
||||
|
||||
if( item != null )
|
||||
{
|
||||
set.Add( item );
|
||||
}
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new HashSet<T>();
|
||||
}
|
||||
}
|
||||
|
||||
public override Race ReadRace()
|
||||
{
|
||||
return Race.Races[ReadByte()];
|
||||
}
|
||||
|
||||
public override bool End()
|
||||
{
|
||||
return m_File.PeekChar() == -1;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AsyncWriter : GenericWriter
|
||||
|
|
@ -1523,7 +1749,6 @@ namespace Server
|
|||
{
|
||||
WriteMobileList( list, false );
|
||||
}
|
||||
|
||||
public override void WriteMobileList( ArrayList list, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
|
|
@ -1547,7 +1772,6 @@ namespace Server
|
|||
{
|
||||
WriteItemList( list, false );
|
||||
}
|
||||
|
||||
public override void WriteItemList( ArrayList list, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
|
|
@ -1571,7 +1795,6 @@ namespace Server
|
|||
{
|
||||
WriteGuildList( list, false );
|
||||
}
|
||||
|
||||
public override void WriteGuildList( ArrayList list, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
|
|
@ -1595,7 +1818,6 @@ namespace Server
|
|||
{
|
||||
Write( list, false );
|
||||
}
|
||||
|
||||
public override void Write( List<Item> list, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
|
|
@ -1638,11 +1860,48 @@ namespace Server
|
|||
Write( list[i] );
|
||||
}
|
||||
|
||||
public override void Write( HashSet<Item> set )
|
||||
{
|
||||
Write( set, false );
|
||||
}
|
||||
public override void Write( HashSet<Item> set, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
{
|
||||
set.RemoveWhere( item => item.Deleted );
|
||||
}
|
||||
|
||||
Write( set.Count );
|
||||
|
||||
foreach( Item item in set )
|
||||
{
|
||||
Write( item );
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteItemSet<T>( HashSet<T> set )
|
||||
{
|
||||
WriteItemSet( set, false );
|
||||
}
|
||||
public override void WriteItemSet<T>( HashSet<T> set, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
{
|
||||
set.RemoveWhere( item => item.Deleted );
|
||||
}
|
||||
|
||||
Write( set.Count );
|
||||
|
||||
foreach( Item item in set )
|
||||
{
|
||||
Write( item );
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write( List<Mobile> list )
|
||||
{
|
||||
Write( list, false );
|
||||
}
|
||||
|
||||
public override void Write( List<Mobile> list, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
|
|
@ -1666,7 +1925,6 @@ namespace Server
|
|||
{
|
||||
WriteMobileList<T>( list, false );
|
||||
}
|
||||
|
||||
public override void WriteMobileList<T>( List<T> list, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
|
|
@ -1686,11 +1944,48 @@ namespace Server
|
|||
Write( list[i] );
|
||||
}
|
||||
|
||||
public override void Write( HashSet<Mobile> set )
|
||||
{
|
||||
Write( set, false );
|
||||
}
|
||||
public override void Write( HashSet<Mobile> set, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
{
|
||||
set.RemoveWhere( mobile => mobile.Deleted );
|
||||
}
|
||||
|
||||
Write( set.Count );
|
||||
|
||||
foreach( Mobile mob in set )
|
||||
{
|
||||
Write( mob );
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteMobileSet<T>( HashSet<T> set )
|
||||
{
|
||||
WriteMobileSet( set, false );
|
||||
}
|
||||
public override void WriteMobileSet<T>( HashSet<T> set, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
{
|
||||
set.RemoveWhere( mob => mob.Deleted );
|
||||
}
|
||||
|
||||
Write( set.Count );
|
||||
|
||||
foreach( Mobile mob in set )
|
||||
{
|
||||
Write( mob );
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write( List<BaseGuild> list )
|
||||
{
|
||||
Write( list, false );
|
||||
}
|
||||
|
||||
public override void Write( List<BaseGuild> list, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
|
|
@ -1714,7 +2009,6 @@ namespace Server
|
|||
{
|
||||
WriteGuildList<T>( list, false );
|
||||
}
|
||||
|
||||
public override void WriteGuildList<T>( List<T> list, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
|
|
@ -1733,6 +2027,44 @@ namespace Server
|
|||
for( int i = 0; i < list.Count; ++i )
|
||||
Write( list[i] );
|
||||
}
|
||||
|
||||
public override void Write( HashSet<BaseGuild> set )
|
||||
{
|
||||
Write( set, false );
|
||||
}
|
||||
public override void Write( HashSet<BaseGuild> set, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
{
|
||||
set.RemoveWhere( guild => guild.Disbanded );
|
||||
}
|
||||
|
||||
Write( set.Count );
|
||||
|
||||
foreach( BaseGuild guild in set )
|
||||
{
|
||||
Write( guild );
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteGuildSet<T>( HashSet<T> set )
|
||||
{
|
||||
WriteGuildSet( set, false );
|
||||
}
|
||||
public override void WriteGuildSet<T>( HashSet<T> set, bool tidy )
|
||||
{
|
||||
if( tidy )
|
||||
{
|
||||
set.RemoveWhere( guild => guild.Disbanded );
|
||||
}
|
||||
|
||||
Write( set.Count );
|
||||
|
||||
foreach( BaseGuild guild in set )
|
||||
{
|
||||
Write( guild );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface ISerializable
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue