Beispiel #1
0
        public ItemRef(Decoder decoder, ID id, byte info)
        {
            this.decoder = decoder;
            this.id      = id;
            missing      = new List <ID>();
            left         = (info & Encoder.Bit8) != 0 ? decoder.ReadID() : null;
            right        = (info & Encoder.Bit7) != 0 ? decoder.ReadID() : null;
            bool canCopyParentInfo = (info & (Encoder.Bit8 | Encoder.Bit7)) == 0;
            bool hasParentDocKey   = canCopyParentInfo && decoder.ReadByte() == 1;

            parentDocKey = hasParentDocKey ? decoder.ReadString() : null;
            parent       = canCopyParentInfo && !hasParentDocKey?decoder.ReadID() : null;

            parentKey = canCopyParentInfo && (info & Encoder.Bit6) != 0 ? decoder.ReadString() : null;
            int lastClock = decoder.doc.store.GetState(id.client);

            if (left != null && left.clock >= lastClock)
            {
                missing.Add(left);
            }
            if (right != null && right.clock >= lastClock)
            {
                missing.Add(right);
            }
            if (parent != null && parent.clock >= lastClock)
            {
                missing.Add(parent);
            }

            content = decoder.ReadContent(info);
            length  = content.Length;
        }
Beispiel #2
0
 public void Insert(int index, AbstractContent content)
 {
     if (doc != null)
     {
         doc.Transact((transaction) =>
         {
             InsertFunc(index, content, transaction);
         });
     }
 }
Beispiel #3
0
 public void Set(string key, AbstractContent content)
 {
     if (doc != null)
     {
         doc.Transact((transaction) =>
         {
             SetFunc(key, content, transaction);
         });
     }
 }
Beispiel #4
0
 public Item(ID id, Item left, ID leftOrigin, Item right, ID rightOrigin, AbstractStruct parent, string parentKey, AbstractContent content)
 {
     this.id          = id;
     this.left        = left;
     this.leftOrigin  = leftOrigin;
     this.right       = right;
     this.rightOrigin = rightOrigin;
     this.parent      = parent;
     this.content     = content;
     this.parentKey   = parentKey;
     this.deleted     = false;
     this.countable   = content.Countable;
     this.length      = content.Length;
     this.redone      = null;
 }
Beispiel #5
0
        public Item ToItem(Transaction transaction, Store store, int offset = 0)
        {
            if (offset > 0)
            {
                id.clock += offset;
                this.left = new ID(id.client, id.clock - 1);
                content   = content.Splice(offset);
                length   -= offset;
            }

            Item left = this.left != null?store.GetItemCleanEnd(transaction, this.left) : null;

            Item right = this.right != null?store.GetItemCleanStart(transaction, this.right) : null;

            AbstractStruct parent    = null;
            string         parentKey = this.parentKey;

            if (this.parent != null)
            {
                Item parentItem = store.FindItem(this.parent);
                if (!parentItem.deleted && left == null && right == null)
                {
                    parent = parentItem.content as AbstractStruct;
                }
            }
            else if (parentDocKey != null)
            {
                transaction.doc.share.TryGetValue(parentDocKey, out parent);
            }
            else if (left != null)
            {
                parent    = left.parent;
                parentKey = left.parentKey;
            }
            else if (right != null)
            {
                parent    = right.parent;
                parentKey = right.parentKey;
            }
            else
            {
                throw new Exception("could not convert to item");
            }

            return(parent != null ? new Item(id, left, this.left, right, this.right, parent, parentKey, content) : null);
        }
Beispiel #6
0
        public void InsertFunc(int index, AbstractContent content, Transaction transaction)
        {
            Item left = null;

            // find insert position

            if (index != 0)
            {
                left = start;

                for (; left != null && index > 0; left = left.right)
                {
                    if (!left.deleted && left.countable)
                    {
                        if (index <= left.length)
                        {
                            // split item
                            if (index < left.length)
                            {
                                transaction.doc.store.GetItemCleanStart(transaction, new ID(left.id.client, left.id.clock + index));
                            }

                            break;
                        }

                        index -= left.length;
                    }
                }
            }

            Item right = left?.right ?? start;

            Item newItem = new Item(
                transaction.NextID(),
                left,
                left != null ? new ID(left.id.client, left.id.clock + left.length - 1) : null,
                right,
                right?.id,
                this,
                null,
                content
                );

            newItem.Integrate(transaction);
        }
Beispiel #7
0
        public void SetFunc(string key, AbstractContent content, Transaction transaction)
        {
            Item left = null;

            map.TryGetValue(key, out left);

            Item newItem = new Item(
                transaction.NextID(),
                left,
                left != null ? new ID(left.id.client, left.id.clock + left.length - 1) : null,
                null,
                null,
                this,
                key,
                content
                );

            newItem.Integrate(transaction);
        }
 public StandardMeasureContent(AbstractAttributes attributes, AbstractContent content) : base(attributes, content)
 {
 }