43ea1551518b05009d74a5ac8c7f74b6a6c2be58
[SXSI/xpathcomp.git] / SXSIStorageInterface.cpp
1 /*******************************************
2  * SXSIStorageInterface.cpp
3  * ------------------------
4  *
5  * 
6  * Author: Kim Nguyen
7  * Date: 04/11/08
8  */
9
10
11 #include "SXSIStorageInterface.h"
12 #include "Utils.h"
13
14 SXSIStorageInterface::SXSIStorageInterface(int sf,bool iet,bool dtc)
15 {
16   tree = NULL;
17   tb = new XMLTreeBuilder();
18   tb ->OpenDocument(iet,sf,dtc);
19 }
20
21 SXSIStorageInterface::~SXSIStorageInterface()
22 {
23 }
24
25 void SXSIStorageInterface::newChild(string name)
26
27   _new_child++;
28   tb->NewOpenTag((unsigned char*) name.c_str());
29 }
30
31
32 void SXSIStorageInterface::newText(string text)
33 {
34
35   _new_text++;
36   _length_text += text.size();
37   tb->NewText((unsigned char*) text.c_str());
38 }
39
40
41 void SXSIStorageInterface::nodeFinished(string name)
42 {  
43   tb->NewClosingTag((unsigned char*) name.c_str());
44
45 }             
46               
47   void SXSIStorageInterface::parsingFinished()
48 {
49
50   tree = tb->CloseDocument();
51         
52 }
53
54 void *SXSIStorageInterface::returnDocument(){
55 #ifdef DEBUG
56   printStats();
57 #endif
58   return ((void *) tree);
59   
60 }
61
62 void SXSIStorageInterface::printStats(){
63   std::cerr << "Parsing stats :  \n";
64   std::cerr << _new_child << " calls to newOpenTag/newClosingTag\n";
65   std::cerr << _new_text << " calls to newText\n";
66   std::cerr << _new_empty_text << " calls to newEmptyText\n";
67   std::cerr << _length_text << " bytes (=" << _length_text/1024 << "kb ) added to TextCollection\n";
68   return;
69 }