protected override void InitInSlot(MValue slot, MCollection parent, bool isMutable) { base.InitInSlot(slot, parent, isMutable); Debug.Assert(_dict == null); _dict = Native.FLValue_AsDict(slot.Value); Count = (int)Native.FLDict_Count(_dict); }
private static object ToObject(MValue mv, MCollection parent, ref bool cache) { var type = Native.FLValue_GetType(mv.Value); switch (type) { case FLValueType.Array: cache = true; return(parent?.MutableChildren == true ? new MutableArrayObject(mv, parent) : new ArrayObject(mv, parent)); case FLValueType.Dict: cache = true; var context = parent?.Context as DocContext; var flDict = Native.FLValue_AsDict(mv.Value); var subType = Native.FLValue_AsString(Native.FLDict_Get(flDict, Encoding.UTF8.GetBytes(ObjectTypeProperty))); var obj = CreateSpecialObject(subType, flDict, context); if (obj != null) { return(obj); } return(parent?.MutableChildren == true ? new MutableDictionaryObject(mv, parent) : new DictionaryObject(mv, parent)); default: return(FLSliceExtensions.ToObject(mv.Value)); } }
protected internal void SetSlot(MValue newSlot, MValue oldSlot) { if (_slot == oldSlot) { _slot = newSlot; if (newSlot == null) { Parent = null; } } }
protected virtual void InitInSlot(MValue slot, MCollection parent, bool isMutable) { Debug.Assert(slot != null); Debug.Assert(Context == MContext.Null); _slot = slot; Parent = parent; IsMutable = isMutable; MutableChildren = isMutable; IsMutated = _slot.IsMutated; if (_slot.Value != null) { Context = Parent?.Context; } }
public MValue Get([NotNull] string key) { CBDebug.MustNotBeNull(WriteLog.To.Database, Tag, nameof(key), key); if (_map.ContainsKey(key)) { return(_map[key]); } var val = Native.FLDict_Get(_dict, Encoding.UTF8.GetBytes(key)); if (val == null) { return(MValue.Empty); } var retVal = new MValue(val); SetInMap(key, retVal); return(retVal); }
public void Set(string key, MValue val) { if (!IsMutable) { throw new InvalidOperationException(CouchbaseLiteErrorMessage.CannotSetItemsInNonMutableInMDict); } if (_map.ContainsKey(key)) { var existing = _map[key]; if (val.IsEmpty && existing.IsEmpty) { return; } Mutate(); Count += Convert.ToInt32(!val.IsEmpty) - Convert.ToInt32(!existing.IsEmpty); _map[key] = val; } else { if (Native.FLDict_Get(_dict, Encoding.UTF8.GetBytes(key)) != null) { if (val.IsEmpty) { Count--; } } else { Count++; } Mutate(); SetInMap(key, val); } }
public void Set(string key, MValue val) { if (!IsMutable) { throw new InvalidOperationException("Cannot set items in a non-mutable MDict"); } if (_map.ContainsKey(key)) { var existing = _map[key]; if (val.IsEmpty && existing.IsEmpty) { return; } Mutate(); Count += Convert.ToInt32(!val.IsEmpty) - Convert.ToInt32(!existing.IsEmpty); _map[key] = val; } else { if (Native.FLDict_GetSharedKey(_dict, Encoding.UTF8.GetBytes(key), SharedKeys) != null) { if (val.IsEmpty) { Count--; } } else { Count++; } Mutate(); SetInMap(key, val); } }
public MDict(MValue mv, MCollection parent) { InitInSlot(mv, parent); }
private void SetInMap(string key, MValue val) { _newKeys.Add(key); _map[key] = val; }
public void InitInSlot(MValue mv, MCollection parent) { InitInSlot(mv, parent, parent?.MutableChildren == true); }
private void NativeChangeSlot(MValue newSlot) { var collection = CollectionFromObject(NativeObject); collection?.SetSlot(newSlot, this); }