public PDFXRefTableEntry this[PDFObjectRef oref]
 {
     get
     {
         for (int i = this._sections.Count - 1; i >= 0; i--)
         {
             PDFXRefTableSection section = this._sections[i];
             if (section.Start <= oref.Number && section.Start + section.Count > oref.Number)
             {
                 PDFXRefTableEntry entry = section[oref];
                 if (null != entry)
                 {
                     return(entry);
                 }
             }
         }
         if (null != this.Previous)
         {
             return(this.Previous[oref]);
         }
         else
         {
             return(null);
         }
     }
 }
        public void StartNewSection(int index)
        {
            if (this.ReadOnly)
            {
                throw new InvalidOperationException("Read Only XRef Table");
            }

            PDFXRefTableSection section = new PDFXRefTableSection(index, this.Generation);

            this._sections.Add(section);
        }
        /// <summary>
        /// Adds an indirect object, and in turn setting its number and generation
        /// </summary>
        /// <param name="obj">The object to add</param>
        /// <returns>The added objects number</returns>
        public int Append(IIndirectObject obj)
        {
            if (this.ReadOnly)
            {
                throw new InvalidOperationException("Read Only XRef Table");
            }

            int index = this._sections.Count - 1;
            PDFXRefTableSection section = this._sections[index];

            return(section.Add(obj));
        }
        public static PDFXRefTable Parse(string value, int offset, out int end)
        {
            if (value.Substring(offset, 4) != "xref")
            {
                throw new PDFNativeParserException(CommonErrors.XRefTableDoesNotStartWithXRef);
            }
            offset += 4;

            PDFXRefTable table = new PDFXRefTable(0);

            while (char.IsWhiteSpace(value, offset))
            {
                offset++;
            }

            //Force at least one subsection with at least one entry.
            if (char.IsDigit(value, offset) == false)
            {
                throw new PDFNativeParserException(CommonErrors.XRefTableSectionMustBe2Integers);
            }

            PDFXRefTableSection section = PDFXRefTableSection.Parse(value, offset, out end);

            if (section.Count == 0)
            {
                throw new PDFNativeParserException(CommonErrors.XRefTableSectionMustBe2Integers);
            }

            offset = end;

            table._sections.Clear();
            table._sections.Add(section);

            while (offset < value.Length)
            {
                if (char.IsDigit(value, offset))
                {
                    section = PDFXRefTableSection.Parse(value, offset, out end);
                    table._sections.Add(section);
                    offset = end;
                }
                else
                {
                    break;
                }
            }
            return(table);
        }
        internal static PDFXRefTableSection Parse(string value, int offset, out int end)
        {
            if (!char.IsDigit(value, offset))
            {
                throw new PDFNativeParserException(CommonErrors.XRefTableSectionMustBe2Integers);
            }

            StringBuilder buffer = new StringBuilder();
            int           index;
            int           count;

            do
            {
                buffer.Append(value[offset++]);
            }while (char.IsDigit(value, offset));

            index = int.Parse(buffer.ToString());
            buffer.Clear();

            offset++; // past the space

            do
            {
                buffer.Append(value[offset++]);
            }while (char.IsDigit(value, offset));

            count = int.Parse(buffer.ToString());
            buffer.Clear();

            while (char.IsDigit(value, offset) == false)
            {
                offset++;
            }

            PDFXRefTableSection section = new PDFXRefTableSection(index, 0);

            for (int i = 0; i < count; i++)
            {
                PDFXRefTableEntry entry = PDFXRefTableEntry.Parse(index + i, value, offset, out end);
                section._entries.Add(entry);
                offset = end;
            }

            end = offset;
            return(section);
        }
        /// <summary>
        /// Removes the current IIndirectObject and fills the space with an empty item
        /// </summary>
        /// <param name="obj"></param>
        public void Delete(IIndirectObject obj)
        {
            if (this.ReadOnly)
            {
                throw new InvalidOperationException("Read Only XRef Table");
            }

            for (int i = this._sections.Count - 1; i >= 0; i--)
            {
                PDFXRefTableSection section = this._sections[i];
                if (section.Start < obj.Number)
                {
                    section.Delete(obj);
                    break;
                }
            }
        }
 public bool Contains(IIndirectObject obj)
 {
     for (int i = this._sections.Count - 1; i >= 0; i--)
     {
         PDFXRefTableSection section = this._sections[i];
         if (section.Start < obj.Number)
         {
             return(section.Contains(obj));
         }
     }
     if (null != this.Previous)
     {
         return(this.Previous.Contains(obj));
     }
     else
     {
         return(false);
     }
 }
 public PDFXRefTableEntry this[int number]
 {
     get
     {
         for (int i = this._sections.Count - 1; i >= 0; i--)
         {
             PDFXRefTableSection section = this._sections[i];
             if (section.Start <= number && section.Start + section.Count > number)
             {
                 return(section[number - section.Start]);
             }
         }
         if (null != this.Previous)
         {
             return(this.Previous[number]);
         }
         else
         {
             return(null);
         }
     }
 }