Exemplo n.º 1
0
        private static int HandlePropertyChunk(IFFParser iff, object userData)
        {
            int err;

            var cn = iff.GetCurrentContext();
            var ci = new ContextInfoNode(cn.Id, cn.Type, GenericChunkIds.CI_PROPCHUNK, cn.Size, null);

            if (ci != null)
            {
                var buffer = new byte[cn.Size];
                err = iff.BufferChunk((int)cn.Size, ref buffer);
                if (err >= 0)
                {
                    ci.Data = buffer;
                    err     = iff.StoreContextInfo(ci, ContextInfoLocation.Prop);
                    if (err >= 0)
                    {
                        return(1);
                    }
                }
                ci.Dispose();
            }
            else
            {
                err = (int)ParserStatus.OutOfMemory;
            }
            return(err);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Stores the context info.
        /// </summary>
        /// <returns>The context info.</returns>
        /// <param name="contextInfoNode">Context info node.</param>
        /// <param name="location">Location.</param>
        public int StoreContextInfo(ContextInfoNode contextInfoNode, ContextInfoLocation location)
        {
            ContextNode contextNode;

            switch (location)
            {
            case ContextInfoLocation.Bottom:
                contextNode = _stack.Tail;
                break;

            case ContextInfoLocation.Top:
                contextNode = _stack.Head;
                break;

            case ContextInfoLocation.Prop:
                if ((contextNode = FindPropContext()) != null)
                {
                    break;
                }
                return((int)ParserStatus.NoScope);

            default:
                return((int)ParserStatus.BadLocation);
            }

            AttachContextInfo(contextNode, contextInfoNode);

            return(0);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Removes the context info.
 /// </summary>
 /// <param name="contextInfoNode">Context info node.</param>
 public void RemoveContextInfo(ContextInfoNode contextInfoNode)
 {
     if (contextInfoNode.Successor != null)
     {
         MinNode.Remove(contextInfoNode);
         contextInfoNode.Successor = null;
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Purges the context info node.
 /// </summary>
 /// <returns>The context info node.</returns>
 /// <param name="contextInfoNode">Context info node.</param>
 protected int PurgeContextInfoNode(ContextInfoNode contextInfoNode)
 {
     if (contextInfoNode.PurgeCallBack != null)
     {
         return(contextInfoNode.PurgeCallBack(this, contextInfoNode));
     }
     contextInfoNode.Dispose();
     return(0);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Install a handler node into the current context
        /// </summary>
        /// <returns></returns>
        private int InstallHandler(uint type, uint id, uint identifier, ContextInfoLocation position, IFFCallBack callbackHandler, object data)
        {
            int err;

            var ci = new ContextInfoNode(id, type, identifier, 0, null);

            if (ci != null)
            {
                var ch = new ChunkHandler {
                    ChunkHandlerCallBack = callbackHandler,
                    UserData             = data
                };
                ci.ChunkHandler = ch;
                err             = StoreContextInfo(ci, position);
                if (err < 0)
                {
                    ci.Dispose();
                }
                return(err);
            }
            return(0);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Attaches the context info.
        /// </summary>
        /// <param name="contextNode">Context node.</param>
        /// <param name="contextInfoNode">Context info node.</param>
        public void AttachContextInfo(ContextNode contextNode, ContextInfoNode contextInfoNode)
        {
            uint type       = contextInfoNode.Type,
                 id         = contextInfoNode.Id,
                 identifier = contextInfoNode.Identifier;

            var contextInfoNodesToDelete = new List <ContextInfoNode> ();

            foreach (var ci in contextNode.ContextInfoNodes)
            {
                if (ci.Id == id && ci.Type == type && ci.Identifier == identifier)
                {
                    contextInfoNodesToDelete.AddHead(ci);
                }
            }
            foreach (var ci in contextInfoNodesToDelete)
            {
                contextNode.ContextInfoNodes.Remove(ci);
                PurgeContextInfoNode(ci);
            }
            contextNode.ContextInfoNodes.AddHead(contextInfoNode);
        }