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

pf_Frag.h

Go to the documentation of this file.
00001 /* AbiWord
00002  * Copyright (C) 1998 AbiSource, Inc.
00003  * Updates by Ben Martin in 2011.
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00018  * 02110-1301 USA.
00019  */
00020 
00021 
00022 #ifndef PF_FRAG_H
00023 #define PF_FRAG_H
00024 
00025 #include <stdio.h>
00026 #include "ut_types.h"
00027 #include "pt_Types.h"
00028 #include "pf_Fragments.h"
00029 #include <string>
00030 
00031 class pt_PieceTable;
00032 class PX_ChangeRecord;
00033 class fd_Field;
00034 class pf_Frag_Strux;
00035 
00036 
00048 class ABI_EXPORT pf_Frag
00049 {
00050   friend class            pf_Fragments;
00051 public:
00052     enum PFType {
00053         PFT_Text = 0,
00054         PFT_Object,
00055         PFT_Strux,
00056         PFT_EndOfDoc,
00057         PFT_FmtMark
00058     };
00059 
00060     pf_Frag(pt_PieceTable * pPT, PFType type, UT_uint32 length);
00061     virtual ~pf_Frag();
00062 
00063     PFType          getType(void) const
00064         { return m_type; }
00065     pf_Frag *                       getNext(void) const;
00066     pf_Frag *                       getPrev(void) const;
00067     pf_Frag_Strux*          getNextStrux(PTStruxType t) const;
00068     pf_Frag_Strux*          tryDownCastStrux(PTStruxType t) const;
00069 
00070     UT_uint32       getLength(void) const
00071         { return m_length; }
00072     void                     zero(void)
00073         { m_length = 0;}
00074 
00075     pt_PieceTable *         getPieceTable(void) const
00076         { return m_pPieceTable;}
00077     fd_Field *              getField(void) const;
00078     PT_DocPosition          getPos(void) const;
00079     void                    lengthChanged(UT_sint32 delta);
00080     PT_DocPosition          getLeftTreeLength(void) const
00081         { return m_leftTreeLength; }
00082     void                    setLeftTreeLength(PT_DocPosition length) const
00083         { m_leftTreeLength = length;}
00084 
00085     /* We need the following function to accumulate left tree length */
00086     void                    accLeftTreeLength(PT_DocPosition length);
00087 
00088     inline PT_AttrPropIndex getIndexAP(void) const {return m_indexAP;}
00089     virtual void            setIndexAP(PT_AttrPropIndex indexNewAP) {m_indexAP = indexNewAP;}
00090 
00091     // createSpecialChangeRecord() constructs a change
00092     // record which describes the fragment itself and
00093     // not an actual change (editing) operation.  the
00094     // is used to initialize the listeners.
00095     virtual bool            createSpecialChangeRecord(PX_ChangeRecord ** ppcr,
00096                                                       PT_DocPosition dpos) const;
00097 
00098     // compare contents of two fragments, ignoring format
00099     bool                    isContentEqual(const pf_Frag & f2) const;
00100 
00101     UT_uint32               getXID() const {return m_iXID;}
00102     void                    setXID(UT_uint32 xid) {m_iXID = xid;}
00103 
00104     // I would much prefer if this was a pure vitual, but we do not have Eod frag
00105     virtual bool            usesXID() const {return false;}
00106 
00107     // compare contents and format of two fragments
00108     bool operator == (const pf_Frag & f2) const;
00109 
00110     std::string getXMLID() const;
00111 
00112 #ifdef PT_TEST
00113     virtual void            __dump(FILE * fp) const;
00114 #endif
00115 
00116 
00117 protected:
00139     virtual bool            _isContentEqual(const pf_Frag & /*f2*/) const {return true;}
00140 
00141     PFType                  m_type;
00142 
00143     fd_Field *              m_pField;
00144     pt_PieceTable *         m_pPieceTable;
00145     PT_AttrPropIndex        m_indexAP;
00146 
00147     /* in PT_DocPosition-space - gives length of this fragment */
00148     UT_uint32               m_length;
00149 
00150 private:
00151         void                    _setNode(pf_Fragments::Node * pNode);
00152     pf_Fragments::Node *    _getNode(void) const;
00153     /* In PT_DocPosition space - specifies size of left subtree */
00154     mutable UT_uint32       m_leftTreeLength;
00155     UT_uint32               m_iXID;
00156     pf_Fragments::Node *    m_pMyNode;
00157 };
00158 
00159 // This is like pf->tryDownCastStrux() but you can pass a null pf as arg1
00160 // safely.
00161 pf_Frag_Strux* tryDownCastStrux( pf_Frag* pf, PTStruxType t);
00162 
00163 #endif /* PF_FRAG_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1