Empeld
Empeld plugin documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
pluginbase.Objects.Syncable.Watchers.ListSync< T > Class Template Reference
Inheritance diagram for pluginbase.Objects.Syncable.Watchers.ListSync< T >:
pluginbase.Objects.Syncable.SyncableBase< T > pluginbase.Objects.Syncable.INetSyncable pluginbase.Objects.Syncable.INetWatcher

Public Member Functions

 ListSync ()
 
 ListSync (IEnumerable< T > items)
 
IEnumerator< T > GetEnumerator ()
 
void Add (T item)
 
void Clear ()
 
bool Contains (T item)
 
void CopyTo (T[] array, int arrayIndex)
 
bool Remove (T item)
 

Protected Member Functions

override void ResetWatch ()
 Reset the touched state More...
 
override void TouchRecurse ()
 Touch the instance More...
 
sealed override void EncodeTo (BinaryWriter writer, EncodeContext context)
 Encode changes to binary data More...
 
sealed override void DecodeFrom (BinaryReader reader, DecodeContext context)
 Decode changes from binary data More...
 
- Protected Member Functions inherited from pluginbase.Objects.Syncable.SyncableBase< T >
void Touch ()
 Touch the instance, notifying something has changed More...
 
virtual void OnChanged ()
 Raises the changed event. More...
 
abstract void Persist (IPersistObject obj)
 Persist the instance to a persist object More...
 
abstract void Load (IReadPersistObject obj)
 Load the instance from a persist object More...
 

Properties

int Count [get]
 
bool IsReadOnly [get]
 
- Properties inherited from pluginbase.Objects.Syncable.INetSyncable
INetWatcher Watcher [get, set]
 Who is watching (who to inform of a change) More...
 
bool Modified [get]
 Gets a value indicating whether this pluginbase.Objects.Syncable.INetSyncable is modified. More...
 

Additional Inherited Members

- Events inherited from pluginbase.Objects.Syncable.SyncableBase< T >
Action< T > Changed
 Event triggered when any change occurs on this object, either locally or over the network More...
 
Action< T > NetUpdate
 Event triggered when a change occurs resulting from a change over the network More...
 
Action< T > Touched
 Event occurs only when an object is first touched. Usually the first instance of a local-change More...
 

Constructor & Destructor Documentation

pluginbase.Objects.Syncable.Watchers.ListSync< T >.ListSync ( )
27  { }
pluginbase.Objects.Syncable.Watchers.ListSync< T >.ListSync ( IEnumerable< T >  items)
30  {
31  foreach(var item in items)
32  {
33  Add(item);
34  }
35  }
void Add(T item)
Definition: ListSync.cs:61

Member Function Documentation

void pluginbase.Objects.Syncable.Watchers.ListSync< T >.Add ( item)

Attribute: id

= new ItemData

62  {
63  ushort id = GetNextId();
64  _items[id] = new ItemData
65  {
66  Val = item,
67  FQTypeName = TypeSerializer.Serialize(item.GetType())
68  };
69  item.Watcher = this;
70  item.TouchRecurse();
71  this.Touch();
72  }
void Touch()
Touch the instance, notifying something has changed
Definition: SyncableBase.cs:65
void pluginbase.Objects.Syncable.Watchers.ListSync< T >.Clear ( )
75  {
76  _items.Clear();
77  }
bool pluginbase.Objects.Syncable.Watchers.ListSync< T >.Contains ( item)
80  {
81  return _items.Values.Select(x => x.Val).Contains(item);
82  }
void pluginbase.Objects.Syncable.Watchers.ListSync< T >.CopyTo ( T[]  array,
int  arrayIndex 
)

Attribute: idx

= item.Val;

85  {
86  int idx=arrayIndex;
87  foreach(var item in _items.Values)
88  {
89  array[idx] = item.Val;
90  }
91  }
sealed override void pluginbase.Objects.Syncable.Watchers.ListSync< T >.DecodeFrom ( BinaryReader  reader,
DecodeContext  context 
)
protectedvirtual

Decode changes from binary data

Parameters
readerReader.
contextContext.

Attribute: itemId

= new ItemData{

Implements pluginbase.Objects.Syncable.SyncableBase< T >.

166  {
167  ushort decodeCount = reader.ReadUInt16();
168  for(int i=0; i<decodeCount; ++i)
169  {
170  ushort itemId = reader.ReadUInt16();
171  string itemTypeName = reader.ReadString();
172 
173  ItemData data;
174  if (_items.TryGetValue(itemId, out data))
175  {
176  data.Val.DecodeFrom(reader, context);
177  }
178  else
179  {
180  var instance = (T)Activator.CreateInstance( TypeSerializer.Deserialize(itemTypeName) );
181  instance.Watcher = this;
182  instance.DecodeFrom(reader, context);
183  _items[itemId] = new ItemData{
184  FQTypeName = itemTypeName,
185  Val = instance
186  };
187  }
188  }
sealed override void pluginbase.Objects.Syncable.Watchers.ListSync< T >.EncodeTo ( BinaryWriter  writer,
EncodeContext  context 
)
protectedvirtual

Encode changes to binary data

Parameters
writerWriter.
contextContext.

Attribute: i

;

Implements pluginbase.Objects.Syncable.SyncableBase< T >.

143  {
144  bool full = context.Mode == WatchableEncodeMode.Full;
145 
146  var toEncode = _items.Where( x => x.Value.Val.Modified || full ).ToArray();
147 
148  writer.Write((ushort)toEncode.Length);
149  for (int i=0; i<toEncode.Length; ++i)
150  {
151  var kv = toEncode[i];
152  writer.Write(kv.Key);
153  writer.Write(kv.Value.FQTypeName);
154  kv.Value.Val.EncodeTo(writer, context);
155  context.Increment();
156  }
157 
158  writer.Write((ushort)_remList.Count);
159  foreach(ushort item in _remList)
160  {
161  writer.Write(item);
162  }
163  }
WatchableEncodeMode
Under which mode is the encode context
Definition: EncodeContext.cs:9
IEnumerator<T> pluginbase.Objects.Syncable.Watchers.ListSync< T >.GetEnumerator ( )
55  {
56  return _items.Values.Select(x => x.Val).GetEnumerator();
57  }
bool pluginbase.Objects.Syncable.Watchers.ListSync< T >.Remove ( item)
94  {
95  foreach(var kv in _items)
96  {
97  if (kv.Value == item)
98  {
99  _items.Remove(kv.Key);
100  _remList.Add(kv.Key);
101  this.Touch();
102  return true;
103  }
104  }
105  return false;
106  }
void Touch()
Touch the instance, notifying something has changed
Definition: SyncableBase.cs:65
override void pluginbase.Objects.Syncable.Watchers.ListSync< T >.ResetWatch ( )
protectedvirtual

Reset the touched state

Reimplemented from pluginbase.Objects.Syncable.SyncableBase< T >.

125  {
126  base.ResetWatch();
127  foreach(var item in _items)
128  {
129  item.Value.Val.ResetWatch();
130  }
131  }
override void pluginbase.Objects.Syncable.Watchers.ListSync< T >.TouchRecurse ( )
protectedvirtual

Touch the instance

Reimplemented from pluginbase.Objects.Syncable.SyncableBase< T >.

134  {
135  base.TouchRecurse();
136  foreach(var item in _items)
137  {
138  item.Value.Val.TouchRecurse();
139  }
140  }

Property Documentation

int pluginbase.Objects.Syncable.Watchers.ListSync< T >.Count
get
bool pluginbase.Objects.Syncable.Watchers.ListSync< T >.IsReadOnly
get

The documentation for this class was generated from the following file: