Empeld
Empeld plugin documentation.
ArraySync.cs File Reference

Classes

class  pluginbase.Objects.Syncable.Watchers.ArraySync< T >
 Syncable class that can synchronize other syncables that it can contain More...
 

Namespaces

namespace  pluginbase.Objects.Syncable.Watchers
 

Functions

int pluginbase.Objects.Syncable.Watchers.Find (Func< T, bool > predicate)
 Find the index of an element in the array given the predicate otherwise returns -1 More...
 
int pluginbase.Objects.Syncable.Watchers.FindNull ()
 Find the index of the first available null spot Returns -1 if none exists More...
 
bool pluginbase.Objects.Syncable.Watchers.AddToNullSlot (T item)
 Add an element to first available null slot. Returns true on success. More...
 
bool pluginbase.Objects.Syncable.Watchers.Remove (T item)
 Remove the first occurance of an element in the array. Returns true on success. More...
 
void pluginbase.Objects.Syncable.Watchers.Sort< TKey > (Func< T, TKey > expression)
 Sorts the array with a given expression More...
 
override void TouchRecurse ()
 
override void ResetWatch ()
 
sealed override void EncodeTo (System.IO.BinaryWriter writer, EncodeContext context)
 
sealed override void DecodeFrom (System.IO.BinaryReader reader, DecodeContext context)
 
sealed override void Persist (pluginbase.Objects.Libs.Persist.IPersistObject obj)
 
sealed override void Load (pluginbase.Objects.Libs.Persist.IReadPersistObject obj)
 
IEnumerator< T > GetEnumerator ()
 Gets the enumerator. More...
 

Function Documentation

◆ DecodeFrom()

sealed override void DecodeFrom ( System.IO.BinaryReader  reader,
DecodeContext  context 
)
protected
323  {
324  int arrLen = reader.ReadInt32();
325  if (_items == null || _items.Length != arrLen)
326  this.Resize(arrLen);
327 
328  while(true)
329  {
330  int idx = reader.ReadInt32();
331  if (idx < 0)
332  break;
333  ReadItem(reader, idx, context);
334  OnItemChange(idx);
335  }
336  }

◆ EncodeTo()

sealed override void EncodeTo ( System.IO.BinaryWriter  writer,
EncodeContext  context 
)
protected

Attribute: i

.ArrModified

Attribute: i].Value != null && _items[i

.Value.Modified))

285  {
286  if (_items == null)
287  {
288  writer.Write(0);
289  }
290  else
291  {
292  writer.Write(_items.Length);
293 
294  for (int i=0; i<_items.Length; ++i)
295  {
296  if (context.Mode == WatchableEncodeMode.Full
297  || _items[i].ArrModified
298  || (_items[i].Value != null && _items[i].Value.Modified))
299  {
300  EncodeItem(writer, i, context);
301  }
302  }
303 
304  writer.Write(-1); //Terminator
305  }
306  }
WatchableEncodeMode
Under which mode is the encode context
Definition: EncodeContext.cs:9

◆ GetEnumerator()

IEnumerator IEnumerable GetEnumerator ( )

Gets the enumerator.

Returns
The enumerator.
428  {
429  return _items.Select(x => x.Value).Where(x => x != null).GetEnumerator();
430  }

◆ Load()

sealed override void Load ( pluginbase.Objects.Libs.Persist.IReadPersistObject  obj)
protected

Attribute: idx

.TypeString = typeString;

Attribute: idx

.Value = null;

Attribute: idx

.TypeString = null;

Attribute: idx

.TypeString = typeString;

Attribute: idx

.Value = inst;

Attribute: idx

.Value.Load(item.GetObject("_"));

382  {
383  int len = obj.Get<int>("length");
384  this.Resize(len);
385 
386  foreach(var item in obj.EnumerateList("items"))
387  {
388  try
389  {
390  int idx = item.Get<int>("idx");
391  string typeString = item.Get<string>("__type");
392  _items[idx].TypeString = typeString;
393 
394  Type type = TypeSerializer.Deserialize(typeString);
395  if (type == null)
396  {
397  _items [idx].Value = null;
398  _items [idx].TypeString = null;
399  }
400  else
401  {
402  var inst = (T)Activator.CreateInstance(type);
403  inst.Watcher = this;
404 
405  _items [idx].TypeString = typeString;
406  _items [idx].Value = inst;
407  _items [idx].Value.Load(item.GetObject("_"));
408  }
409  }
410  catch
411  {
412 #if DEBUG
413  throw;
414 #endif
415  }
416  }
417  }

◆ Persist()

sealed override void Persist ( pluginbase.Objects.Libs.Persist.IPersistObject  obj)
protected

Attribute: i

.TypeString ?? string.Empty);

Attribute: i

.Value != null)

Attribute: i

.Value.Persist(item.GetOrCreateObject("_"));

367  {
368  obj.Set("length", _items.Length);
369  for(int i=0; i<_items.Length; ++i)
370  {
371  var item = obj.CreateListItem("items");
372  item.Set("idx", i);
373  item.Set("__type", _items[i].TypeString ?? string.Empty);
374  if (_items[i].Value != null)
375  {
376  _items [i].Value.Persist(item.GetOrCreateObject("_"));
377  }
378  }
379  }

◆ ResetWatch()

override void ResetWatch ( )
protected

Attribute: i

.ArrModified = false;

Attribute: i

.Value != null)

Attribute: i

.Value.ResetWatch();

270  {
271  base.ResetWatch();
272  for (int i=0; i<_items.Length; ++i)
273  {
274  _items[i].ArrModified = false;
275  if (_items[i].Value != null)
276  _items[i].Value.ResetWatch();
277  }
278  }

◆ TouchRecurse()

override void TouchRecurse ( )
protected

Attribute: i

.Value != null)

Attribute: i

.Value.TouchRecurse();

260  {
261  base.TouchRecurse();
262  for (int i=0; i<_items.Length; ++i)
263  {
264  if (_items[i].Value != null)
265  _items[i].Value.TouchRecurse();
266  }
267  }