Added filename to Save() and Load()
[SXSI/XMLTree.git] / XMLTreeBuilder.h
1 \r
2 /******************************************************************************\r
3  *   Copyright (C) 2009 by Diego Arroyuelo                                    *\r
4  *   Builder class for the in-memory XQuery/XPath engine                      *\r
5  *                                                                            *\r
6  *   This program is free software; you can redistribute it and/or modify     *\r
7  *   it under the terms of the GNU Lesser General Public License as published *\r
8  *   by the Free Software Foundation; either version 2 of the License, or     *\r
9  *   (at your option) any later version.                                      *\r
10  *                                                                            *\r
11  *   This program is distributed in the hope that it will be useful,          *\r
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *\r
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *\r
14  *   GNU Lesser General Public License for more details.                      *\r
15  *                                                                            *\r
16  *   You should have received a copy of the GNU Lesser General Public License *\r
17  *   along with this program; if not, write to the                            *\r
18  *   Free Software Foundation, Inc.,                                          *\r
19  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.                *\r
20  ******************************************************************************/ \r
21 \r
22 #ifndef XMLTREEBUILDER_H_\r
23 #define XMLTREEBUILDER_H_\r
24 \r
25 #include "TextCollection/TextCollectionBuilder.h"\r
26 #undef W\r
27 #undef WW\r
28 #undef Wminusone\r
29 \r
30 \r
31 #include "XMLTree.h"\r
32 \r
33 using SXSI::TextCollection;\r
34 using SXSI::TextCollectionBuilder;\r
35 \r
36 #define NULLT -1\r
37 \r
38         // sets bit p in e\r
39 #define bitset(e,p) ((e)[(p)/W] |= (1<<((p)%W)))\r
40         // cleans bit p in e\r
41 #define bitclean(e,p) ((e)[(p)/W] &= ~(1<<((p)%W)))\r
42 \r
43 \r
44 \r
45 class XMLTreeBuilder {\r
46   \r
47    /** Array containing the balanced parentheses sequence */\r
48    pb *par_aux;\r
49    int parArraySize;\r
50    int npar;\r
51 \r
52    /** Mapping from tag identifer to tag name */  \r
53    std::vector<std::string> *TagName;\r
54    TagIdMap * tIdMap;\r
55    /** Array containing the sequence of tags */\r
56    TagType *tags_aux;\r
57    \r
58    /** The texts in the XML document */\r
59    TextCollectionBuilder *TextBuilder;\r
60    TextCollection *Text;\r
61    \r
62    /** The texts in the XML document (cached for faster display) */\r
63 \r
64    std::vector<std::string> *CachedText;\r
65 \r
66    unsigned int *empty_texts_aux;\r
67    int eta_size;\r
68    // Allows to disable the TextCollection for benchmarkin purposes\r
69    bool disable_tc;\r
70 \r
71 public:\r
72 \r
73    XMLTreeBuilder() {;};\r
74 \r
75    ~XMLTreeBuilder();\r
76    \r
77    /** OpenDocument(sample_rate_text,dtc): initilizes the construction\r
78     * of the data structure for the XML document.  Parameter \r
79     * sample_rate_text indicates the sampling rate for the text searching data\r
80     * structures (small values get faster searching but a bigger space \r
81     * requirement). dtc disable the use of the TextCollection\r
82     * (i.e. everything is considered an empty text *)\r
83     * Returns a non-zero value upon success, NULLT in case of \r
84     * error. */\r
85    int OpenDocument(bool empty_texts, int sample_rate_text, bool dtc);\r
86 \r
87    /** CloseDocument(): finishes the construction of the data structure for \r
88     * the XML document. Tree and tags are represented in the final form, \r
89     * dynamic data structures are made static, returning the resulting\r
90     * XMLTree. After that, the XMLTree data structure can be queried. */\r
91    XMLTree *CloseDocument();\r
92 \r
93    /** NewOpenTag(tagname): indicates the event of finding a new opening tag \r
94     * in the document. Tag name is given. Returns a non-zero value upon \r
95     * success, and returns NULLT in case of error. */\r
96    int NewOpenTag(std::string tagname);\r
97    \r
98    /** NewClosingTag(tagname): indicates the event of finding a new closing tag\r
99     *  in the document. Tag name is given. Returns a non-zero value upon \r
100     *  success, and returns NULLT in case of error. */\r
101    int NewClosingTag(std::string tagname);\r
102  \r
103    /** NewText(s): indicates the event of finding a new text s in \r
104     * the document. The new text is inserted within the text collection. \r
105     * Returns a non-zero value upon success, NULLT in case of error. \r
106     * If the string is empty, which is legal in attributes, then\r
107     * the string the sequence '\0x01\0x00' is inserted in the TextCollection\r
108     * It is ok to do so since a non printable character cannot occur in an XML document\r
109     */\r
110    int NewText(std::string text);\r
111 \r
112 \r
113 };\r
114 #endif\r
115 \r