d770d7e044be60816fa42f915fc7c65ff62cc881
[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
15 SXSIStorageInterface::SXSIStorageInterface(int sf,bool iet,bool dtc)
16 {
17   tree = new XMLTree();
18   tree->OpenDocument(iet,sf,dtc);
19 }
20
21 SXSIStorageInterface::~SXSIStorageInterface()
22 {
23 }
24
25 void SXSIStorageInterface::newChild(string name)
26
27   _new_child++;
28   tree->NewOpenTag((unsigned char*) name.c_str());
29 }
30
31
32 void SXSIStorageInterface::newText(string text)
33 {
34
35   if (text.empty()) {
36     _new_empty_text++;
37     tree->NewEmptyText();
38   }
39   else {
40     _new_text++;
41     _length_text += text.size();
42     tree->NewText((unsigned char*) text.c_str());  
43   }
44 }
45
46
47 void SXSIStorageInterface::nodeFinished(string name)
48 {  
49   tree->NewClosingTag((unsigned char*) name.c_str());
50
51 }             
52               
53   void SXSIStorageInterface::parsingFinished()
54 {
55
56   tree->CloseDocument();
57         
58 }
59
60 void *SXSIStorageInterface::returnDocument(){
61 #ifdef DEBUG
62   printStats();
63 #endif
64   return ((void *) tree);
65   
66 }
67 void SXSIStorageInterface::printStats(){
68   std::cerr << "Parsing stats :  \n";
69   std::cerr << _new_child << " calls to newOpenTag/newClosingTag\n";
70   std::cerr << _new_text << " calls to newText\n";
71   std::cerr << _new_empty_text << " calls to newEmptyText\n";
72   std::cerr << _length_text << " bytes (=" << _length_text/1024 << "kb ) added to TextCollection\n";
73   return;
74 }