xref: /php-src/ext/dom/lexbor/lexbor/core/plog.h (revision bffab33a)
1 /*
2  * Copyright (C) 2019 Alexander Borisov
3  *
4  * Author: Alexander Borisov <borisov@lexbor.com>
5  */
6 
7 #ifndef LEXBOR_PLOG_H
8 #define LEXBOR_PLOG_H
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #include "lexbor/core/array_obj.h"
15 
16 
17 typedef struct {
18     const lxb_char_t *data;
19     void             *context;
20     unsigned         id;
21 }
22 lexbor_plog_entry_t;
23 
24 typedef struct {
25     lexbor_array_obj_t list;
26 }
27 lexbor_plog_t;
28 
29 
30 LXB_API lxb_status_t
31 lexbor_plog_init(lexbor_plog_t *plog, size_t init_size, size_t struct_size);
32 
33 LXB_API lexbor_plog_t *
34 lexbor_plog_destroy(lexbor_plog_t *plog, bool self_destroy);
35 
36 
37 /*
38  * Inline functions
39  */
40 lxb_inline lexbor_plog_t *
lexbor_plog_create(void)41 lexbor_plog_create(void)
42 {
43     return (lexbor_plog_t *) lexbor_calloc(1, sizeof(lexbor_plog_t));
44 }
45 
46 lxb_inline void
lexbor_plog_clean(lexbor_plog_t * plog)47 lexbor_plog_clean(lexbor_plog_t *plog)
48 {
49     lexbor_array_obj_clean(&plog->list);
50 }
51 
52 lxb_inline void *
lexbor_plog_push(lexbor_plog_t * plog,const lxb_char_t * data,void * ctx,unsigned id)53 lexbor_plog_push(lexbor_plog_t *plog, const lxb_char_t *data, void *ctx,
54                  unsigned id)
55 {
56     lexbor_plog_entry_t *entry;
57 
58     if (plog == NULL) {
59         return NULL;
60     }
61 
62     entry = (lexbor_plog_entry_t *) lexbor_array_obj_push(&plog->list);
63     if (entry == NULL) {
64         return NULL;
65     }
66 
67     entry->data = data;
68     entry->context = ctx;
69     entry->id = id;
70 
71     return (void *) entry;
72 }
73 
74 lxb_inline size_t
lexbor_plog_length(lexbor_plog_t * plog)75 lexbor_plog_length(lexbor_plog_t *plog)
76 {
77     return lexbor_array_obj_length(&plog->list);
78 }
79 
80 /*
81  * No inline functions for ABI.
82  */
83 LXB_API lexbor_plog_t *
84 lexbor_plog_create_noi(void);
85 
86 LXB_API void
87 lexbor_plog_clean_noi(lexbor_plog_t *plog);
88 
89 LXB_API void *
90 lexbor_plog_push_noi(lexbor_plog_t *plog, const lxb_char_t *data, void *ctx,
91                      unsigned id);
92 
93 LXB_API size_t
94 lexbor_plog_length_noi(lexbor_plog_t *plog);
95 
96 
97 #ifdef __cplusplus
98 } /* extern "C" */
99 #endif
100 
101 #endif /* LEXBOR_PLOG_H */
102 
103