Initial commit
[SXSI/xpathcomp.git] / OCamlDriver.cpp
1 /**************************************
2  * OCamlDriver.cpp
3  * -------------------
4  * A Test Ocaml Driver which calls the C++ methods and
5  * adds a C wrapper interface with OCaml code.
6  * 
7  * Author: Kim Nguyen
8  * Date: 04/11/08
9  */
10
11 /* OCaml memory managment */
12 extern "C" {
13 #include <caml/mlvalues.h>
14 #include <caml/alloc.h>
15 #include <caml/memory.h>
16 #include <caml/callback.h>
17 #include <caml/fail.h>
18 } //extern C
19
20 #include "XMLDocShredder.h"
21 #define CAMLRAISECPP(e) (caml_failwith( ((e).what())))
22 #define NOT_IMPLEMENTED  (caml_failwith("Not Implemented!!!"))
23
24 extern "C" CAMLprim value caml_call_shredder_uri(value uri){
25   CAMLparam1(uri);
26   CAMLlocal1(doc);
27   char *fn = String_val(uri);
28   try {
29   XMLDocShredder shredder(fn);  
30   shredder.processStartDocument(fn);  
31   shredder.parse();  
32   shredder.processEndDocument();
33   doc = (value) shredder.storageIfc_->returnDocument();
34
35   CAMLreturn(doc);
36   }
37   catch (const std::exception& e){
38     CAMLRAISECPP(e);
39   };
40   
41 }
42
43 extern "C" CAMLprim value caml_call_shredder_string(value data){
44   CAMLparam1(data);
45   CAMLlocal1(doc);
46   unsigned int ln = string_length(data);
47   unsigned char *fn = (unsigned char*) String_val(data);
48   
49   try {
50     XMLDocShredder shredder(fn,ln);  
51     shredder.processStartDocument("");  
52     shredder.parse();  
53     shredder.processEndDocument();
54     doc = (value) shredder.storageIfc_->returnDocument();
55     
56     CAMLreturn(doc);
57   }
58   catch (const std::exception& e) {
59     CAMLRAISECPP(e);
60   };
61 }
62
63 extern "C" CAMLprim value caml_text_collection_get_text(value tree, value id){
64   CAMLparam2(tree,id);
65
66   NOT_IMPLEMENTED;
67   CAMLreturn (Val_unit);
68 }
69 extern "C" CAMLprim value caml_xml_tree_root(value tree){
70   CAMLparam1(tree);
71
72   NOT_IMPLEMENTED;
73   CAMLreturn (Val_unit);
74 }
75 extern "C" CAMLprim value caml_xml_tree_text_collection(value tree, value id){
76   CAMLparam2(tree,id);
77
78   NOT_IMPLEMENTED;
79   CAMLreturn (Val_unit);
80 }
81 extern "C" CAMLprim value caml_xml_tree_next_sibling(value tree, value id){
82   CAMLparam2(tree,id);
83
84   NOT_IMPLEMENTED;
85   CAMLreturn (Val_unit);
86 }
87 extern "C" CAMLprim value caml_xml_tree_first_child(value tree, value id){
88   CAMLparam2(tree,id);
89
90   NOT_IMPLEMENTED;
91   CAMLreturn (Val_unit);
92 }
93 extern "C" CAMLprim value caml_xml_tree_prev_text(value tree, value id){
94   CAMLparam2(tree,id);
95
96   NOT_IMPLEMENTED;
97   CAMLreturn (Val_unit);
98 }
99 extern "C" CAMLprim value caml_xml_tree_next_text(value tree, value id){
100   CAMLparam2(tree,id);
101
102   NOT_IMPLEMENTED;
103   CAMLreturn (Val_unit);
104 }
105 extern "C" CAMLprim value caml_xml_tree_my_text(value tree, value id){
106   CAMLparam2(tree,id);
107
108   NOT_IMPLEMENTED;
109   CAMLreturn (Val_unit);
110 }
111
112 extern "C" CAMLprim value caml_xml_tree_text_xml_id(value tree, value id){
113   CAMLparam2(tree,id);
114
115   NOT_IMPLEMENTED;
116   CAMLreturn (Val_unit);
117 }
118 extern "C" CAMLprim value caml_xml_tree_node_xml_id(value tree, value id){
119   CAMLparam2(tree,id);
120
121   NOT_IMPLEMENTED;
122   CAMLreturn (Val_unit);
123 }
124 extern "C" CAMLprim value caml_xml_tree_tag(value tree, value id){
125   CAMLparam2(tree,id);
126
127   NOT_IMPLEMENTED;
128   CAMLreturn (Val_unit);
129 }
130 extern "C" CAMLprim value caml_xml_tree_nullt(value unit){
131   CAMLparam1(unit);
132   CAMLreturn (Val_int(-1));
133
134 }