graphannis_capi/
update.rs

1use super::cerror::ErrorList;
2use super::{cast_mut, cstr, map_cerr};
3use graphannis::update::{GraphUpdate, UpdateEvent};
4
5/// Create a new graph (empty) update instance
6#[unsafe(no_mangle)]
7pub extern "C" fn annis_graphupdate_new() -> *mut GraphUpdate {
8    let gu = GraphUpdate::new();
9    Box::into_raw(Box::new(gu))
10}
11
12/// Add "add node" action to the graph update object.
13///
14/// - `ptr` - The graph update object.
15/// - `node_name` - Name of the new node.
16/// - `node_type` - Type of the new node, e.g. "node" or "corpus".
17/// - `err` - Pointer to a list of errors. If any error occurred, this list will be non-empty.
18#[unsafe(no_mangle)]
19pub extern "C" fn annis_graphupdate_add_node(
20    ptr: *mut GraphUpdate,
21    node_name: *const libc::c_char,
22    node_type: *const libc::c_char,
23    err: *mut *mut ErrorList,
24) {
25    let u: &mut GraphUpdate = cast_mut(ptr);
26    map_cerr(
27        u.add_event(UpdateEvent::AddNode {
28            node_name: String::from(cstr(node_name)),
29            node_type: String::from(cstr(node_type)),
30        }),
31        err,
32    );
33}
34
35/// Add "delete node" action to the graph update object.
36///
37/// - `ptr` - The graph update object.
38/// - `node_name` - Name of node to delete.
39/// - `err` - Pointer to a list of errors. If any error occurred, this list will be non-empty.
40#[unsafe(no_mangle)]
41pub extern "C" fn annis_graphupdate_delete_node(
42    ptr: *mut GraphUpdate,
43    node_name: *const libc::c_char,
44    err: *mut *mut ErrorList,
45) {
46    let cs: &mut GraphUpdate = cast_mut(ptr);
47    map_cerr(
48        cs.add_event(UpdateEvent::DeleteNode {
49            node_name: String::from(cstr(node_name)),
50        }),
51        err,
52    );
53}
54
55/// Add "add node label" action to the graph update object.
56///
57/// - `ptr` - The graph update object.
58/// - `node_name` - Name of the node the label is attached to.
59/// - `annos_ns` - Namespace of the new annotation.
60/// - `annos_name` - Name of the new annotation.
61/// - `annos_value` - Value of the new annotation.
62/// - `err` - Pointer to a list of errors. If any error occurred, this list will be non-empty.
63#[unsafe(no_mangle)]
64pub extern "C" fn annis_graphupdate_add_node_label(
65    ptr: *mut GraphUpdate,
66    node_name: *const libc::c_char,
67    anno_ns: *const libc::c_char,
68    anno_name: *const libc::c_char,
69    anno_value: *const libc::c_char,
70    err: *mut *mut ErrorList,
71) {
72    let cs: &mut GraphUpdate = cast_mut(ptr);
73    map_cerr(
74        cs.add_event(UpdateEvent::AddNodeLabel {
75            node_name: String::from(cstr(node_name)),
76            anno_ns: String::from(cstr(anno_ns)),
77            anno_name: String::from(cstr(anno_name)),
78            anno_value: String::from(cstr(anno_value)),
79        }),
80        err,
81    );
82}
83
84/// Add "delete node label" action to the graph update object.
85///
86/// - `ptr` - The graph update object.
87/// - `node_name` - Name of the node the label is attached to.
88/// - `annos_ns` - Namespace of deleted new annotation.
89/// - `annos_name` - Name of the deleted annotation.
90/// - `err` - Pointer to a list of errors. If any error occurred, this list will be non-empty.
91#[unsafe(no_mangle)]
92pub extern "C" fn annis_graphupdate_delete_node_label(
93    ptr: *mut GraphUpdate,
94    node_name: *const libc::c_char,
95    anno_ns: *const libc::c_char,
96    anno_name: *const libc::c_char,
97    err: *mut *mut ErrorList,
98) {
99    let cs: &mut GraphUpdate = cast_mut(ptr);
100    map_cerr(
101        cs.add_event(UpdateEvent::DeleteNodeLabel {
102            node_name: String::from(cstr(node_name)),
103            anno_ns: String::from(cstr(anno_ns)),
104            anno_name: String::from(cstr(anno_name)),
105        }),
106        err,
107    );
108}
109
110/// Add "add edge" action to the graph update object.
111///
112/// - `ptr` - The graph update object.
113/// - `source_node` - Name of source node of the new edge.
114/// - `target_node` - Name of target node of the new edge.
115/// - `layer` - Layer of the new edge.
116/// - `component_type` - Type of the component of the new edge.
117/// - `component_name` - Name of the component of the new edge.
118/// - `err` - Pointer to a list of errors. If any error occurred, this list will be non-empty.
119#[unsafe(no_mangle)]
120pub extern "C" fn annis_graphupdate_add_edge(
121    ptr: *mut GraphUpdate,
122    source_node: *const libc::c_char,
123    target_node: *const libc::c_char,
124    layer: *const libc::c_char,
125    component_type: *const libc::c_char,
126    component_name: *const libc::c_char,
127    err: *mut *mut ErrorList,
128) {
129    let cs: &mut GraphUpdate = cast_mut(ptr);
130
131    map_cerr(
132        cs.add_event(UpdateEvent::AddEdge {
133            source_node: String::from(cstr(source_node)),
134            target_node: String::from(cstr(target_node)),
135            layer: String::from(cstr(layer)),
136            component_type: String::from(cstr(component_type)),
137            component_name: String::from(cstr(component_name)),
138        }),
139        err,
140    );
141}
142
143/// Add "delete edge" action to the graph update object.
144///
145/// - `ptr` - The graph update object.
146/// - `source_node` - Name of source node of the edge to delete.
147/// - `target_node` - Name of target node of the edge to delete.
148/// - `layer` - Layer of the edge to delete.
149/// - `component_type` - Type of the component of the edge to delete.
150/// - `component_name` - Name of the component of the edge to delete.
151/// - `err` - Pointer to a list of errors. If any error occurred, this list will be non-empty.
152#[unsafe(no_mangle)]
153pub extern "C" fn annis_graphupdate_delete_edge(
154    ptr: *mut GraphUpdate,
155    source_node: *const libc::c_char,
156    target_node: *const libc::c_char,
157    layer: *const libc::c_char,
158    component_type: *const libc::c_char,
159    component_name: *const libc::c_char,
160    err: *mut *mut ErrorList,
161) {
162    let cs: &mut GraphUpdate = cast_mut(ptr);
163    map_cerr(
164        cs.add_event(UpdateEvent::DeleteEdge {
165            source_node: String::from(cstr(source_node)),
166            target_node: String::from(cstr(target_node)),
167            layer: String::from(cstr(layer)),
168            component_type: String::from(cstr(component_type)),
169            component_name: String::from(cstr(component_name)),
170        }),
171        err,
172    );
173}
174
175/// Add "add edge label" action to the graph update object.
176///
177/// - `ptr` - The graph update object.
178/// - `source_node` - Name of source node of the edge.
179/// - `target_node` - Name of target node of the edge.
180/// - `layer` - Layer of the edge.
181/// - `component_type` - Type of the component of the edge.
182/// - `component_name` - Name of the component of the edge.
183/// - `annos_ns` - Namespace of the new annotation.
184/// - `annos_name` - Name of the new annotation.
185/// - `annos_value` - Value of the new annotation.
186/// - `err` - Pointer to a list of errors. If any error occurred, this list will be non-empty.
187#[unsafe(no_mangle)]
188pub extern "C" fn annis_graphupdate_add_edge_label(
189    ptr: *mut GraphUpdate,
190    source_node: *const libc::c_char,
191    target_node: *const libc::c_char,
192    layer: *const libc::c_char,
193    component_type: *const libc::c_char,
194    component_name: *const libc::c_char,
195    anno_ns: *const libc::c_char,
196    anno_name: *const libc::c_char,
197    anno_value: *const libc::c_char,
198    err: *mut *mut ErrorList,
199) {
200    let cs: &mut GraphUpdate = cast_mut(ptr);
201
202    map_cerr(
203        cs.add_event(UpdateEvent::AddEdgeLabel {
204            source_node: String::from(cstr(source_node)),
205            target_node: String::from(cstr(target_node)),
206            layer: String::from(cstr(layer)),
207            component_type: String::from(cstr(component_type)),
208            component_name: String::from(cstr(component_name)),
209            anno_ns: String::from(cstr(anno_ns)),
210            anno_name: String::from(cstr(anno_name)),
211            anno_value: String::from(cstr(anno_value)),
212        }),
213        err,
214    );
215}
216
217/// Add "delete edge label" action to the graph update object.
218///
219/// - `ptr` - The graph update object.
220/// - `source_node` - Name of source node of the edge.
221/// - `target_node` - Name of target node of the edge.
222/// - `layer` - Layer of the edge.
223/// - `component_type` - Type of the component of the edge.
224/// - `component_name` - Name of the component of the edge.
225/// - `annos_ns` - Namespace of the annotation to delete.
226/// - `annos_name` - Name of the annotation to delete.
227/// - `err` - Pointer to a list of errors. If any error occurred, this list will be non-empty.
228#[unsafe(no_mangle)]
229pub extern "C" fn annis_graphupdate_delete_edge_label(
230    ptr: *mut GraphUpdate,
231    source_node: *const libc::c_char,
232    target_node: *const libc::c_char,
233    layer: *const libc::c_char,
234    component_type: *const libc::c_char,
235    component_name: *const libc::c_char,
236    anno_ns: *const libc::c_char,
237    anno_name: *const libc::c_char,
238    err: *mut *mut ErrorList,
239) {
240    let cs: &mut GraphUpdate = cast_mut(ptr);
241
242    map_cerr(
243        cs.add_event(UpdateEvent::DeleteEdgeLabel {
244            source_node: String::from(cstr(source_node)),
245            target_node: String::from(cstr(target_node)),
246            layer: String::from(cstr(layer)),
247            component_type: String::from(cstr(component_type)),
248            component_name: String::from(cstr(component_name)),
249            anno_ns: String::from(cstr(anno_ns)),
250            anno_name: String::from(cstr(anno_name)),
251        }),
252        err,
253    );
254}