File: ODi_ElementStack.h

package info (click to toggle)
abiword 3.0.7~dfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 64,700 kB
  • sloc: cpp: 477,933; ansic: 16,754; makefile: 5,834; xml: 3,993; yacc: 1,818; lex: 1,104; perl: 812; python: 413; php: 183; sh: 169
file content (106 lines) | stat: -rw-r--r-- 3,122 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* AbiSource Program Utilities
 *
 * Copyright (C) 2005 Daniel d'Andrada T. de Carvalho
 * <daniel.carvalho@indt.org.br>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 */

#ifndef _ODI_ELEMENTSTACK_H_
#define _ODI_ELEMENTSTACK_H_

// AbiWord includes
#include <ut_types.h>
#include <ut_vector.h>

// Internal classes
class ODi_StartTag;


/**
 * This class stores info about the parent elements of the current element being
 * parsed.
 *
 * Example:
 *
 * If you are parsing the <style:footnote-sep/> element, this class will hold
 * info about its parents. On this case: <style:page-layout-properties>,
 * <style:page-layout> and <office:automatic-styles>.
 *
 * <office:automatic-styles>
 *    <style:page-layout>
 *        <style:page-layout-properties>
 *            <style:footnote-sep/>
 *        </style:page-layout-properties>
 *    </style:page-layout>
 * </office:automatic-styles>
 *
 *
 * When parsing a start element tag, level 0 is the parent element.
 *
 * When parsing a start element tag, level 0 is its own element, with level 1
 * being the parent and so on.
 *
 */
class ODi_ElementStack {

public:

    ODi_ElementStack();
    ~ODi_ElementStack();

    /**
     * @param level 0 is the immediate parent, 1 is the parent of the parent
     *              and so on.
     *
     * On the startElement method, level 0 is the parent start tag.
     * On the endElement method, level 0 is the corresponding start tag.
     */
    const ODi_StartTag* getStartTag(UT_sint32 level);

    bool hasElement(const gchar* pName) const;

    /**
     * Returns the level of the closest element with the given name.
     */
    UT_sint32 getElementLevel(const gchar* pName) const;

    /**
     * Returns the closest parent with the given name. It returns NULL if there
     * is no parent with the given name.
     *
     * @param pName Element name.
     * @param fromLevel The level from which the search begins.
     */
    const ODi_StartTag* getClosestElement(const gchar* pName,
                                          UT_sint32 fromLevel = 0) const;


    void startElement (const gchar* pName, const gchar** ppAtts);
    void endElement (const gchar* pName);
    bool isEmpty() const {return m_stackSize==0;}
    void clear() {m_stackSize = 0;}

    UT_sint32 getStackSize() const {return m_stackSize;}


private:

    UT_GenericVector <ODi_StartTag*>* m_pStartTags;
    UT_sint32 m_stackSize;
};

#endif //_ODI_ELEMENTSTACK_H_