.
[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   void SXSIStorageInterface::parsingFinished()
53 {
54
55   tree->CloseDocument();
56         
57 }
58
59 void *SXSIStorageInterface::returnDocument(){
60 #ifdef DEBUG
61   printStats();
62 #endif
63   return ((void *) tree);
64   
65 }
66 void SXSIStorageInterface::printStats(){
67   std::cerr << "Parsing stats :  \n";
68   std::cerr << _new_child << " calls to newOpenTag/newClosingTag\n";
69   std::cerr << _new_text << " calls to newText\n";
70   std::cerr << _new_empty_text << " calls to newEmptyText\n";
71   std::cerr << _length_text << " bytes (=" << _length_text/1024 << "kb ) added to TextCollection\n";
72   return;
73 }