hl7parse
node.h
Go to the documentation of this file.
1 
10 #ifndef NODE_H
11 #define NODE_H
12 
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include "meta.h"
16 #include "address.h"
17 #include "message_state.h"
18 #include "logging.h"
19 
21 #define NODE_PREALLOC_CHILDREN 5
22 
24 #define MESSAGE_PREALLOC_CHILDREN 10
25 
27 #define MAX_FIELDS 1000
28 
46 typedef struct raw_field_t {
48  unsigned char *field;
50  unsigned char delim[MAX_FIELDS];
52  unsigned int pos[MAX_FIELDS];
54  unsigned int delim_l;
56  size_t length;
57 } raw_field_t;
58 
62 typedef enum node_type_t {
64  MESSAGE = 1,
66  SEGMENT = 2,
68  FIELDLIST = 4,
70  FIELD = 8,
72  COMP = 16,
74  SUBCOMP = 32,
76  LEAF = 64
77 } node_type_t;
78 
188 typedef struct node_t {
192  int id;
193 
195  struct node_t *parent;
197  struct node_t **children;
198 
203 
205  unsigned char *data;
207  size_t length;
209  int pos;
210 } node_t;
211 
243 typedef struct message_state_t message_state_t; // forward declaration
244 typedef struct message_t {
248  int id;
249 
251  struct node_t *parent;
253  struct node_t **segments;
254 
259 
262 
265 } message_t;
266 
267 #ifdef __cplusplus
268 extern "C" {
269 #endif
270 
277 
281 void free_raw_field(raw_field_t* raw_e);
282 
299 node_t* create_node_t(node_type_t type, unsigned char *data, size_t length, int pos);
300 
312 void free_node_t(node_t *node);
313 
325 int node_append(node_t** parent, node_t *node) ;
326 
334 int node_parent_child_pos(node_t *node);
335 
354 node_t *process_node(raw_field_t* raw_e, hl7_meta_t *meta, int start_pos);
355 
367 void disply_raw_node(raw_field_t* raw_e);
368 
376 node_t *node_in_segment(node_t *segment, hl7_addr_t *addr);
377 
378 /*
379  * denormalize node structure into string
380  *
381  * @param node node and children to turn into string representation
382  * @param meta hl7 metadata for delimiters
383  * @param length returns the length of the allocated buffer
384  * @returns allocated buffer
385  */
386 //char* node_to_string(node_t *node, hl7_meta_t* meta, int *length);
387 
394 const char *node_type_to_string(node_type_t type);
395 
408 
420 void free_message_t(message_t *message);
421 
432 int message_append(message_t **parent, node_t *node);
433 
447 
448 #ifdef __cplusplus
449 }
450 #endif
451 
452 #endif // end NODE_H
int id
Definition: node.h:192
void free_node_t(node_t *node)
cleanup all memory of a node
Definition: node.c:269
Definition: node.h:66
const char * node_type_to_string(node_type_t type)
string representation of node_type_t
Definition: node.c:40
hl7 meta data structures for message_t
primary storage type of a delimited element
Definition: node.h:188
size_t length
Definition: node.h:56
struct raw_field_t raw_field_t
structure to track delmiter fields in a fieldset
int num_children
Definition: node.h:256
int message_append(message_t **parent, node_t *node)
append a segment to the message
Definition: node.c:383
Definition: node.h:72
void disply_raw_node(raw_field_t *raw_e)
dump raw_e structure to stdout
Definition: node.c:23
int node_parent_child_pos(node_t *node)
find the position in parent&#39;s children struct
Definition: node.c:69
hl7_meta_t * meta
Definition: node.h:261
struct node_t ** segments
Definition: node.h:253
unsigned char * data
Definition: node.h:205
Definition: node.h:70
void free_raw_field(raw_field_t *raw_e)
free raw fiel structure
Definition: node.c:14
private message structures
hl7_addr_t * addr_from_node(node_t *node)
generate an addr from any node in a message
Definition: node.c:468
logging functioins and macros
unsigned char * field
Definition: node.h:48
struct node_t ** children
Definition: node.h:197
HL7 Seperator configuration.
Definition: meta.h:33
message_state_t * state
Definition: node.h:264
int _num_children_allocated
Definition: node.h:258
raw_field_t * create_raw_field_t(void)
create raw fied structure
Definition: node.c:3
hl7 element address
Definition: address.h:49
int num_children
Definition: node.h:200
hl7 address structures and utilities
int pos
Definition: node.h:209
int id
Definition: node.h:248
struct node_t node_t
primary storage type of a delimited element
struct node_t * parent
Definition: node.h:195
node_type_t
Node types.
Definition: node.h:62
node_t * process_node(raw_field_t *raw_e, hl7_meta_t *meta, int start_pos)
Definition: node.c:82
Definition: node.h:64
int _num_children_allocated
Definition: node.h:202
unsigned int pos[MAX_FIELDS]
Definition: node.h:52
holds callbacks and associated variables
Definition: message_state.h:84
unsigned char delim[MAX_FIELDS]
Definition: node.h:50
Definition: node.h:68
message_t * create_message_t(hl7_meta_t *meta)
initialize an empty messagte_t struct
Definition: node.c:335
node_t * node_in_segment(node_t *segment, hl7_addr_t *addr)
check if a node with given addres exists
Definition: node.c:403
unsigned int delim_l
Definition: node.h:54
Definition: node.h:244
Definition: node.h:76
node_type_t type
Definition: node.h:190
Definition: node.h:74
node_type_t type
Definition: node.h:246
structure to track delmiter fields in a fieldset
Definition: node.h:46
size_t length
Definition: node.h:207
void free_message_t(message_t *message)
free message_t an all it&#39;s child objects
Definition: node.c:357
struct node_t * parent
Definition: node.h:251
int node_append(node_t **parent, node_t *node)
append a child node
Definition: node.c:298
node_t * create_node_t(node_type_t type, unsigned char *data, size_t length, int pos)
create a new node
Definition: node.c:242
#define MAX_FIELDS
maximum number of temporary elements to allocate in the parser buffer
Definition: node.h:27