Пример #1
0
        // Tools

        internal void PutObj(RopObject obj, int tag)
        {
            int otag = (tag != 0? tag : tags[tags.Count - 1]);

            if (!t2objs.TryGetValue(otag, out SortedDictionary <RopObject, int> objs) || objs == null)
            {
                t2objs.Add(otag, objs = new SortedDictionary <RopObject, int>());
            }
            this.cnt++;
            objs.Add(obj, this.cnt);
        }
Пример #2
0
        /**
         * Deletes tagged / specified objects
         */
        public void drop(int tag, object _object, object[] objects, object from)
        {
            int ret = ROPE.RNP_SUCCESS;

            // collect tags to delete
            List <int>       dtags    = new List <int>();
            LinkedList <int> tags2del = new LinkedList <int>();

            if (from != null)
            {
                int idx = tags.IndexOf((int)from);
                if (!(idx < 0))
                {
                    dtags = tags.GetRange(idx, tags.Count - idx);
                }
            }
            else if (tag == 0 && tags.Count > 0)
            {
                dtags.Add(tags[tags.Count - 1]);
            }
            else
            {
                dtags.Add(tag);
            }

            // collect objects to delete
            var objset = new SortedSet <RopObject>();

            if (objects != null)
            {
                foreach (object obj in objects)
                {
                    if (typeof(RopObject).IsInstanceOfType(obj))
                    {
                        objset.Add((RopObject)obj);
                    }
                }
            }
            if (_object != null && typeof(RopObject).IsInstanceOfType(_object))
            {
                objset.Add((RopObject)_object);
            }

            // delete the dtags and objset conjuction
            SortedDictionary <int, RopObject> sorted = new SortedDictionary <int, RopObject>();

            foreach (int tg in (tag >= 0? dtags : tags))
            {
                SortedDictionary <RopObject, int> objs = null;
                if (t2objs.TryGetValue(tg, out objs) && objs != null)
                {
                    var dellist = new SortedSet <RopObject>(objs.Keys);
                    if (objset.Count > 0)
                    {
                        dellist.IntersectWith(objset);
                    }
                    sorted.Clear();
                    foreach (RopObject obj in dellist)
                    {
                        sorted.Add(objs[obj], obj);
                    }
                    var rkeys = new List <int>(sorted.Keys);
                    rkeys.Reverse();
                    foreach (int nn in rkeys)
                    {
                        RopObject obj = sorted[nn];
                        int       err = obj.Close();
                        ret = (ret == ROPE.RNP_SUCCESS? err : ret);
                        objs.Remove(obj);
                    }
                    if (objs.Count == 0)
                    {
                        t2objs.Remove(tg);
                    }
                }

                // delete obsolete tags
                if (_object == null && objects == null && !t2objs.ContainsKey(tg))
                {
                    tags2del.AddFirst(tg);
                }
            }
            foreach (int tg in tags2del)
            {
                tags.Remove(tg);
            }
            if (tags.Count == 0)
            {
                tags.Add(1);
            }
            if (tags.Count == 1)
            {
                this.cnt = tags[tags.Count - 1];
            }

            if (ret != ROPE.RNP_SUCCESS)
            {
                throw new RopError(ret);
            }
        }