C AMQP Protocol Engine API  0.6
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros 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 #ifndef __cplusplus
28 #include <stdbool.h>
29 #include <stdint.h>
30 #else
31 #include <proton/type_compat.h>
32 #endif
33 #include <stddef.h>
34 #include <proton/import_export.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 typedef uintptr_t pn_handle_t;
41 typedef intptr_t pn_shandle_t;
42 
43 typedef struct pn_list_t pn_list_t;
44 typedef struct pn_map_t pn_map_t;
45 typedef struct pn_hash_t pn_hash_t;
46 typedef struct pn_string_t pn_string_t;
47 
48 typedef struct {
49  void (*initialize)(void *);
50  void (*finalize)(void *);
51  uintptr_t (*hashcode)(void *);
52  intptr_t (*compare)(void *, void *);
53  int (*inspect)(void *, pn_string_t *);
54 } pn_class_t;
55 
56 #define PN_CLASS(PREFIX) { \
57  PREFIX ## _initialize, \
58  PREFIX ## _finalize, \
59  PREFIX ## _hashcode, \
60  PREFIX ## _compare, \
61  PREFIX ## _inspect \
62 }
63 
64 PN_EXTERN void *pn_new(size_t size, pn_class_t *clazz);
65 PN_EXTERN void pn_initialize(void *object, pn_class_t *clazz);
66 PN_EXTERN void *pn_incref(void *object);
67 PN_EXTERN void pn_decref(void *object);
68 PN_EXTERN int pn_refcount(void *object);
69 PN_EXTERN void pn_finalize(void *object);
70 PN_EXTERN void pn_free(void *object);
71 PN_EXTERN pn_class_t *pn_class(void *object);
72 PN_EXTERN uintptr_t pn_hashcode(void *object);
73 PN_EXTERN intptr_t pn_compare(void *a, void *b);
74 PN_EXTERN bool pn_equals(void *a, void *b);
75 PN_EXTERN int pn_inspect(void *object, pn_string_t *dst);
76 
77 #define PN_REFCOUNT (0x1)
78 
79 PN_EXTERN pn_list_t *pn_list(size_t capacity, int options);
80 PN_EXTERN size_t pn_list_size(pn_list_t *list);
81 PN_EXTERN void *pn_list_get(pn_list_t *list, int index);
82 PN_EXTERN void pn_list_set(pn_list_t *list, int index, void *value);
83 PN_EXTERN int pn_list_add(pn_list_t *list, void *value);
84 PN_EXTERN ssize_t pn_list_index(pn_list_t *list, void *value);
85 PN_EXTERN bool pn_list_remove(pn_list_t *list, void *value);
86 PN_EXTERN void pn_list_del(pn_list_t *list, int index, int n);
87 
88 #define PN_REFCOUNT_KEY (0x2)
89 #define PN_REFCOUNT_VALUE (0x4)
90 
91 PN_EXTERN pn_map_t *pn_map(size_t capacity, float load_factor, int options);
92 PN_EXTERN size_t pn_map_size(pn_map_t *map);
93 PN_EXTERN int pn_map_put(pn_map_t *map, void *key, void *value);
94 PN_EXTERN void *pn_map_get(pn_map_t *map, void *key);
95 PN_EXTERN void pn_map_del(pn_map_t *map, void *key);
96 PN_EXTERN pn_handle_t pn_map_head(pn_map_t *map);
97 PN_EXTERN pn_handle_t pn_map_next(pn_map_t *map, pn_handle_t entry);
98 PN_EXTERN void *pn_map_key(pn_map_t *map, pn_handle_t entry);
99 PN_EXTERN void *pn_map_value(pn_map_t *map, pn_handle_t entry);
100 
101 PN_EXTERN pn_hash_t *pn_hash(size_t capacity, float load_factor, int options);
102 PN_EXTERN size_t pn_hash_size(pn_hash_t *hash);
103 PN_EXTERN int pn_hash_put(pn_hash_t *hash, uintptr_t key, void *value);
104 PN_EXTERN void *pn_hash_get(pn_hash_t *hash, uintptr_t key);
105 PN_EXTERN void pn_hash_del(pn_hash_t *hash, uintptr_t key);
106 PN_EXTERN pn_handle_t pn_hash_head(pn_hash_t *hash);
107 PN_EXTERN pn_handle_t pn_hash_next(pn_hash_t *hash, pn_handle_t entry);
108 PN_EXTERN uintptr_t pn_hash_key(pn_hash_t *hash, pn_handle_t entry);
109 PN_EXTERN void *pn_hash_value(pn_hash_t *hash, pn_handle_t entry);
110 
111 PN_EXTERN pn_string_t *pn_string(const char *bytes);
112 PN_EXTERN pn_string_t *pn_stringn(const char *bytes, size_t n);
113 PN_EXTERN const char *pn_string_get(pn_string_t *string);
114 PN_EXTERN size_t pn_string_size(pn_string_t *string);
115 PN_EXTERN int pn_string_set(pn_string_t *string, const char *bytes);
116 PN_EXTERN int pn_string_setn(pn_string_t *string, const char *bytes, size_t n);
117 PN_EXTERN ssize_t pn_string_put(pn_string_t *string, char *dst);
119 PN_EXTERN int pn_string_format(pn_string_t *string, const char *format, ...)
120 #ifdef __GNUC__
121  __attribute__ ((format (printf, 2, 3)))
122 #endif
123  ;
124 PN_EXTERN int pn_string_vformat(pn_string_t *string, const char *format, va_list ap);
125 PN_EXTERN int pn_string_addf(pn_string_t *string, const char *format, ...)
126 #ifdef __GNUC__
127  __attribute__ ((format (printf, 2, 3)))
128 #endif
129  ;
130 PN_EXTERN int pn_string_vaddf(pn_string_t *string, const char *format, va_list ap);
131 PN_EXTERN int pn_string_grow(pn_string_t *string, size_t capacity);
132 PN_EXTERN char *pn_string_buffer(pn_string_t *string);
134 PN_EXTERN int pn_string_resize(pn_string_t *string, size_t size);
136 
137 
138 #ifdef __cplusplus
139 }
140 #endif
141 
142 #endif /* object.h */