C AMQP Protocol Engine API  0.7
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
object.h
Go to the documentation of this file.
1 #ifndef PROTON_OBJECT_H
2 #define PROTON_OBJECT_H 1
3 
4 /*
5  *
6  * Licensed to the Apache Software Foundation (ASF) under one
7  * or more contributor license agreements. See the NOTICE file
8  * distributed with this work for additional information
9  * regarding copyright ownership. The ASF licenses this file
10  * to you under the Apache License, Version 2.0 (the
11  * "License"); you may not use this file except in compliance
12  * with the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing,
17  * software distributed under the License is distributed on an
18  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19  * KIND, either express or implied. See the License for the
20  * specific language governing permissions and limitations
21  * under the License.
22  *
23  */
24 
25 #include <proton/types.h>
26 #include <stdarg.h>
27 #include <proton/type_compat.h>
28 #include <stddef.h>
29 #include <proton/import_export.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 typedef uintptr_t pn_handle_t;
36 typedef intptr_t pn_shandle_t;
37 
38 typedef struct pn_list_t pn_list_t;
39 typedef struct pn_map_t pn_map_t;
40 typedef struct pn_hash_t pn_hash_t;
41 typedef struct pn_string_t pn_string_t;
42 typedef void *(*pn_iterator_next_t)(void *state);
44 
45 typedef struct {
46  void (*initialize)(void *);
47  void (*finalize)(void *);
48  uintptr_t (*hashcode)(void *);
49  intptr_t (*compare)(void *, void *);
50  int (*inspect)(void *, pn_string_t *);
51 } pn_class_t;
52 
53 #define PN_CLASS(PREFIX) { \
54  PREFIX ## _initialize, \
55  PREFIX ## _finalize, \
56  PREFIX ## _hashcode, \
57  PREFIX ## _compare, \
58  PREFIX ## _inspect \
59 }
60 
61 PN_EXTERN void *pn_new(size_t size, pn_class_t *clazz);
62 PN_EXTERN void pn_initialize(void *object, pn_class_t *clazz);
63 PN_EXTERN void *pn_incref(void *object);
64 PN_EXTERN void pn_decref(void *object);
65 PN_EXTERN int pn_refcount(void *object);
66 PN_EXTERN void pn_finalize(void *object);
67 PN_EXTERN void pn_free(void *object);
68 PN_EXTERN pn_class_t *pn_class(void *object);
69 PN_EXTERN uintptr_t pn_hashcode(void *object);
70 PN_EXTERN intptr_t pn_compare(void *a, void *b);
71 PN_EXTERN bool pn_equals(void *a, void *b);
72 PN_EXTERN int pn_inspect(void *object, pn_string_t *dst);
73 
74 #define PN_REFCOUNT (0x1)
75 
76 PN_EXTERN pn_list_t *pn_list(size_t capacity, int options);
77 PN_EXTERN size_t pn_list_size(pn_list_t *list);
78 PN_EXTERN void *pn_list_get(pn_list_t *list, int index);
79 PN_EXTERN void pn_list_set(pn_list_t *list, int index, void *value);
80 PN_EXTERN int pn_list_add(pn_list_t *list, void *value);
81 PN_EXTERN ssize_t pn_list_index(pn_list_t *list, void *value);
82 PN_EXTERN bool pn_list_remove(pn_list_t *list, void *value);
83 PN_EXTERN void pn_list_del(pn_list_t *list, int index, int n);
86 
87 #define PN_REFCOUNT_KEY (0x2)
88 #define PN_REFCOUNT_VALUE (0x4)
89 
90 PN_EXTERN pn_map_t *pn_map(size_t capacity, float load_factor, int options);
91 PN_EXTERN size_t pn_map_size(pn_map_t *map);
92 PN_EXTERN int pn_map_put(pn_map_t *map, void *key, void *value);
93 PN_EXTERN void *pn_map_get(pn_map_t *map, void *key);
94 PN_EXTERN void pn_map_del(pn_map_t *map, void *key);
95 PN_EXTERN pn_handle_t pn_map_head(pn_map_t *map);
96 PN_EXTERN pn_handle_t pn_map_next(pn_map_t *map, pn_handle_t entry);
97 PN_EXTERN void *pn_map_key(pn_map_t *map, pn_handle_t entry);
98 PN_EXTERN void *pn_map_value(pn_map_t *map, pn_handle_t entry);
99 
100 PN_EXTERN pn_hash_t *pn_hash(size_t capacity, float load_factor, int options);
101 PN_EXTERN size_t pn_hash_size(pn_hash_t *hash);
102 PN_EXTERN int pn_hash_put(pn_hash_t *hash, uintptr_t key, void *value);
103 PN_EXTERN void *pn_hash_get(pn_hash_t *hash, uintptr_t key);
104 PN_EXTERN void pn_hash_del(pn_hash_t *hash, uintptr_t key);
105 PN_EXTERN pn_handle_t pn_hash_head(pn_hash_t *hash);
106 PN_EXTERN pn_handle_t pn_hash_next(pn_hash_t *hash, pn_handle_t entry);
107 PN_EXTERN uintptr_t pn_hash_key(pn_hash_t *hash, pn_handle_t entry);
108 PN_EXTERN void *pn_hash_value(pn_hash_t *hash, pn_handle_t entry);
109 
110 PN_EXTERN pn_string_t *pn_string(const char *bytes);
111 PN_EXTERN pn_string_t *pn_stringn(const char *bytes, size_t n);
112 PN_EXTERN const char *pn_string_get(pn_string_t *string);
113 PN_EXTERN size_t pn_string_size(pn_string_t *string);
114 PN_EXTERN int pn_string_set(pn_string_t *string, const char *bytes);
115 PN_EXTERN int pn_string_setn(pn_string_t *string, const char *bytes, size_t n);
116 PN_EXTERN ssize_t pn_string_put(pn_string_t *string, char *dst);
118 PN_EXTERN int pn_string_format(pn_string_t *string, const char *format, ...)
119 #ifdef __GNUC__
120  __attribute__ ((format (printf, 2, 3)))
121 #endif
122  ;
123 PN_EXTERN int pn_string_vformat(pn_string_t *string, const char *format, va_list ap);
124 PN_EXTERN int pn_string_addf(pn_string_t *string, const char *format, ...)
125 #ifdef __GNUC__
126  __attribute__ ((format (printf, 2, 3)))
127 #endif
128  ;
129 PN_EXTERN int pn_string_vaddf(pn_string_t *string, const char *format, va_list ap);
130 PN_EXTERN int pn_string_grow(pn_string_t *string, size_t capacity);
131 PN_EXTERN char *pn_string_buffer(pn_string_t *string);
133 PN_EXTERN int pn_string_resize(pn_string_t *string, size_t size);
135 
138  pn_iterator_next_t next, size_t size);
139 PN_EXTERN void *pn_iterator_next(pn_iterator_t *iterator);
140 
141 #ifdef __cplusplus
142 }
143 #endif
144 
145 #endif /* object.h */