コード例 #1
0
 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);
 }
コード例 #2
0
        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));
            }
        }
コード例 #3
0
 protected internal void SetSlot(MValue newSlot, MValue oldSlot)
 {
     if (_slot == oldSlot)
     {
         _slot = newSlot;
         if (newSlot == null)
         {
             Parent = null;
         }
     }
 }
コード例 #4
0
 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;
     }
 }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
 public MDict(MValue mv, MCollection parent)
 {
     InitInSlot(mv, parent);
 }
コード例 #9
0
 private void SetInMap(string key, MValue val)
 {
     _newKeys.Add(key);
     _map[key] = val;
 }
コード例 #10
0
 public void InitInSlot(MValue mv, MCollection parent)
 {
     InitInSlot(mv, parent, parent?.MutableChildren == true);
 }
コード例 #11
0
        private void NativeChangeSlot(MValue newSlot)
        {
            var collection = CollectionFromObject(NativeObject);

            collection?.SetSlot(newSlot, this);
        }