• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

pd_Iterator.h

Go to the documentation of this file.
00001 /* AbiWord
00002  * Copyright (C) 2003 Tomas Frydrych <tomas@frydrych.uklinux.net>
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301 USA.
00018  */
00019 
00020 #ifndef PD_ITERATOR_H
00021 #define PD_ITERATOR_H
00022 
00024 //
00025 //  The following classes allow us to iterate sequentially and
00026 //  efficiently over the content of a document.
00027 //
00028 //  Tomas, Nov 9, 2003
00029 //
00030 
00031 #include "ut_TextIterator.h"
00032 #include "pt_Types.h"
00033 
00034 class PD_Document;
00035 class pt_PieceTable;
00036 class pf_Frag;
00037 class pf_Frag_Strux;
00038 
00039 /******************************************************************
00040  *
00041  * PD_DocIterator iterates over the contents of the whole document
00042  *
00043  * NB: because iterating over a document using document position
00044  * requires that the PT fragments are clean, this iterator will clean
00045  * the fragments whenever they are not clean. This has certain
00046  * performance implications for long docs: it will be preferable to
00047  * use the PD_StruxIterator below when accessing a limited portion of
00048  * the document; PD_DocIterator is more suitable when access is
00049  * required to large part of document and access is not strictly
00050  * sequential
00051  *
00052  */
00053 class ABI_EXPORT PD_DocIterator : public UT_TextIterator
00054 {
00055   public:
00056     PD_DocIterator(const PD_Document & doc, PT_DocPosition dpos = 0);
00057 
00058     virtual UT_UCS4Char  getChar(); // return character at present position
00059 
00060     virtual UT_uint32 getPosition() const {return m_pos;}
00061     virtual void setPosition(UT_uint32 pos);
00062 
00063     virtual void      setUpperLimit(UT_uint32 maxpos) {m_max_pos = maxpos;}
00064     virtual UT_uint32 getUpperLimit() const { return m_max_pos;}
00065 
00066     virtual UTIterStatus getStatus() const {return m_status;}
00067 
00068     virtual UT_uint32 find(UT_UCS4Char * what, UT_uint32 iLen, bool bForward = true);
00069     virtual UT_uint32 find(UT_TextIterator & text, UT_uint32 iLen, bool bForward = true);
00070 
00071     virtual UT_TextIterator * makeCopy() const;
00072 
00073     virtual UT_TextIterator & operator ++ ();
00074     virtual UT_TextIterator & operator -- ();
00075     virtual UT_TextIterator & operator +=  (UT_sint32 i);
00076     virtual UT_TextIterator & operator -=  (UT_sint32 i);
00077 
00078     virtual UT_UCS4Char   operator [](UT_uint32 dpos);
00079 
00080     const pf_Frag * getFrag() const {return m_frag;}
00081 
00082     void            reset() {m_pos = 0; m_frag = NULL; m_status = UTIter_OK;}
00083     void            reset(PT_DocPosition pos, const pf_Frag * pf) // use with great care
00084                      {m_pos = pos; m_frag = pf; _findFrag();}
00085 
00086 
00087   private:
00088     // private constructor
00089     PD_DocIterator(pt_PieceTable & pt):m_pt(pt){};
00090 
00091     bool _findFrag();
00092 
00093     pt_PieceTable & m_pt;
00094     PT_DocPosition  m_pos;
00095     PT_DocPosition  m_max_pos;
00096 
00097     const pf_Frag * m_frag;
00098 
00099     UTIterStatus    m_status;
00100 };
00101 
00102 /******************************************************************
00103  *
00104  * PD_StruxIterator iterates over the contents of document from a
00105  * given strux onwards; in contrast to PD_DocIterator above, it does
00106  * not rely on PT fragments being clean, but calculates offest from
00107  * the starting strux from lengths of individual fragments
00108  *
00109  */
00110 
00111 class ABI_EXPORT PD_StruxIterator : public UT_TextIterator
00112 {
00113   public:
00114     PD_StruxIterator(pf_Frag_Strux* sdh,
00115                      UT_uint32 offset = 0, UT_uint32 maxoffset = 0xffffffff);
00116 
00117     virtual UT_UCS4Char getChar(); // return character at present position
00118 
00119     virtual UT_uint32 getPosition() const {return m_offset;}
00120     virtual void setPosition(UT_uint32 pos);
00121 
00122     virtual void      setUpperLimit(UT_uint32 maxpos) {m_max_offset = maxpos;}
00123     virtual UT_uint32 getUpperLimit() const {return m_max_offset;}
00124 
00125     virtual UTIterStatus getStatus() const {return m_status;}
00126 
00127     virtual UT_uint32 find(UT_UCS4Char * what, UT_uint32 iLen, bool bForward = true);
00128     virtual UT_uint32 find(UT_TextIterator & text, UT_uint32 iLen, bool bForward = true);
00129 
00130     virtual UT_TextIterator * makeCopy() const;
00131 
00132     virtual UT_TextIterator & operator ++ ();
00133     virtual UT_TextIterator & operator -- ();
00134     virtual UT_TextIterator & operator +=  (UT_sint32 i);
00135     virtual UT_TextIterator & operator -=  (UT_sint32 i);
00136 
00137     virtual UT_UCS4Char   operator [](UT_uint32 dpos);
00138 
00139   private:
00140     // private default constructor
00141     PD_StruxIterator(){};
00142 
00143     bool _findFrag();
00144     bool _incrementPos(UT_sint32 d);
00145 
00146     pt_PieceTable *   m_pPT;
00147     UT_uint32         m_offset;
00148     UT_uint32         m_frag_offset;
00149     pf_Frag_Strux* m_sdh;
00150 
00151     const pf_Frag * m_frag;
00152 
00153     UTIterStatus    m_status;
00154     UT_uint32       m_max_offset;
00155     UT_uint32       m_strux_len;
00156 };
00157 
00158 #endif //PD_ITERATOR_H

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1