More fixing in the printing code
[SXSI/XMLTree.git] / XMLTree.h
index a3ac2ed..d0a5c73 100644 (file)
--- a/XMLTree.h
+++ b/XMLTree.h
 \r
 #ifndef XMLTREE_H_\r
 #define XMLTREE_H_\r
+extern "C" {\r
+#define CAML_NAME_SPACE\r
+#include <caml/mlvalues.h>\r
+#include <caml/custom.h>\r
+#define XMLTREE(x) ((XMLTree *)(* (XMLTree**) Data_custom_val(x)))\r
+  //#define XMLTREE(x) ((XMLTree*) (x))\r
+}\r
 #include <unordered_set>\r
 #include <unordered_map>\r
+#include <sstream>\r
 #include "TextCollection/TextCollectionBuilder.h"\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
+\r
+#include <cstdio>\r
+#include <cstdlib>\r
 #include <cstring>\r
 \r
 \r
@@ -41,6 +50,7 @@ using SXSI::TextCollection;
 using SXSI::TextCollectionBuilder;\r
 \r
 \r
+\r
 // this constant is used to efficiently compute the child operation in the tree\r
 #define OPTD 10\r
 \r
@@ -77,6 +87,8 @@ typedef struct {
 #define PCDATA_TAG_ID 2\r
 #define ATTRIBUTE_DATA_OPEN_TAG "<@$>"\r
 #define ATTRIBUTE_DATA_TAG_ID 3\r
+#define CLOSING_TAG   "</>"\r
+#define CLOSING_TAG_ID 4\r
 #define DOCUMENT_CLOSE_TAG "/"\r
 #define ATTRIBUTE_CLOSE_TAG "/<@>"\r
 #define PCDATA_CLOSE_TAG "/<$>"\r
@@ -95,6 +107,10 @@ typedef TagIdMap::const_iterator TagIdMapIT;
 #define NULLT_IF(x)  do { if (x) return NULLT; } while (0)\r
 \r
 \r
+\r
+\r
+\r
+\r
 class XMLTreeBuilder;\r
 \r
 class XMLTree {\r
@@ -125,10 +141,29 @@ class XMLTree {
    bool disable_tc;\r
    \r
    FILE* stream;\r
-   int   stream_fd;\r
+   int   stream_fd; \r
+   string * buffer;\r
+   void myfputs(const char* s, FILE * fp){\r
+     buffer->append(s);\r
+     if (buffer->size() >= 100000){\r
+       fputs(buffer->c_str(),fp);\r
+       buffer->clear();\r
+     };\r
 \r
+   }\r
+   void myfputc(const char c, FILE*fp){\r
+     buffer->append(1,c);\r
+     if (buffer->size() >= 100000){\r
+       fputs(buffer->c_str(),fp);\r
+       buffer->clear();\r
+     };\r
+   }\r
+   void mybufferflush(FILE* fp){\r
+     fputs(buffer->c_str(), fp);\r
+     buffer->clear();\r
+   }\r
    /** Data structure constructors */\r
-   XMLTree(){;};\r
+   XMLTree(){ buffer = 0;};\r
 \r
    // non const pointer are freed by this method.\r
   XMLTree( pb * const par, uint npar,  vector<string> * const TN,  TagIdMap * const tim, uint *empty_texts_bmp, TagType *tags,\r
@@ -139,7 +174,7 @@ public:
    ~XMLTree();\r
    \r
    /** root(): returns the tree root. */\r
-   treeNode Root();\r
+   treeNode Root() { return 0; }\r
 \r
    /** Size() :  Number of parenthesis */\r
    unsigned int Size(){\r
@@ -221,7 +256,7 @@ public:
     *    if none.\r
     */\r
    treeNode FirstElement(treeNode x);\r
-\r
+   value CamlFirstElement(value x);\r
    /** LastChild(x): returns the last child of node x.  */\r
    treeNode LastChild(treeNode x);\r
    \r
@@ -234,7 +269,7 @@ public:
     *    if none.\r
     */\r
    treeNode NextElement(treeNode x);\r
-   \r
+   value CamlNextElement(value x);\r
    /** PrevSibling(x): returns the previous sibling of node x, assuming it \r
     * exists. */\r
 \r
@@ -456,8 +491,15 @@ public:
 \r
 \r
    /** Print procedure */\r
-   void Print(int fd,treeNode x);\r
+   void Print(int fd,treeNode x, bool no_text);\r
+   void Print(int fd,treeNode x) { Print(fd,x,false); }\r
 \r
 };\r
+\r
+extern "C" value caml_cpp_fast_first_element(value xmltree, value node);\r
+extern "C" value caml_cpp_fast_next_element(value xmltree, value node);\r
+\r
+\r
+\r
 #endif\r
 \r