C AMQP Protocol Engine API  0.5
proton/object.h
Go to the documentation of this file.
00001 #ifndef PROTON_OBJECT_H
00002 #define PROTON_OBJECT_H 1
00003 
00004 /*
00005  *
00006  * Licensed to the Apache Software Foundation (ASF) under one
00007  * or more contributor license agreements.  See the NOTICE file
00008  * distributed with this work for additional information
00009  * regarding copyright ownership.  The ASF licenses this file
00010  * to you under the Apache License, Version 2.0 (the
00011  * "License"); you may not use this file except in compliance
00012  * with the License.  You may obtain a copy of the License at
00013  *
00014  *   http://www.apache.org/licenses/LICENSE-2.0
00015  *
00016  * Unless required by applicable law or agreed to in writing,
00017  * software distributed under the License is distributed on an
00018  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00019  * KIND, either express or implied.  See the License for the
00020  * specific language governing permissions and limitations
00021  * under the License.
00022  *
00023  */
00024 
00025 #include <proton/types.h>
00026 #include <stdarg.h>
00027 #ifndef __cplusplus
00028 #include <stdbool.h>
00029 #include <stdint.h>
00030 #else
00031 #include <proton/type_compat.h>
00032 #endif
00033 #include <stddef.h>
00034 #include <proton/import_export.h>
00035 
00036 #ifdef __cplusplus
00037 extern "C" {
00038 #endif
00039 
00040 typedef uintptr_t pn_handle_t;
00041 typedef intptr_t pn_shandle_t;
00042 
00043 typedef struct pn_list_t pn_list_t;
00044 typedef struct pn_map_t pn_map_t;
00045 typedef struct pn_hash_t pn_hash_t;
00046 typedef struct pn_string_t pn_string_t;
00047 
00048 typedef struct {
00049   void (*finalize)(void *);
00050   uintptr_t (*hashcode)(void *);
00051   intptr_t (*compare)(void *, void *);
00052   int (*inspect)(void *, pn_string_t *);
00053 } pn_class_t;
00054 
00055 PN_EXTERN void *pn_new(size_t size, pn_class_t *clazz);
00056 PN_EXTERN void *pn_incref(void *object);
00057 PN_EXTERN void pn_decref(void *object);
00058 PN_EXTERN int pn_refcount(void *object);
00059 PN_EXTERN void pn_free(void *object);
00060 PN_EXTERN pn_class_t *pn_class(void *object);
00061 PN_EXTERN uintptr_t pn_hashcode(void *object);
00062 PN_EXTERN intptr_t pn_compare(void *a, void *b);
00063 PN_EXTERN bool pn_equals(void *a, void *b);
00064 PN_EXTERN int pn_inspect(void *object, pn_string_t *dst);
00065 
00066 #define PN_REFCOUNT (0x1)
00067 
00068 PN_EXTERN pn_list_t *pn_list(size_t capacity, int options);
00069 PN_EXTERN size_t pn_list_size(pn_list_t *list);
00070 PN_EXTERN void *pn_list_get(pn_list_t *list, int index);
00071 PN_EXTERN void pn_list_set(pn_list_t *list, int index, void *value);
00072 PN_EXTERN int pn_list_add(pn_list_t *list, void *value);
00073 PN_EXTERN ssize_t pn_list_index(pn_list_t *list, void *value);
00074 PN_EXTERN bool pn_list_remove(pn_list_t *list, void *value);
00075 PN_EXTERN void pn_list_del(pn_list_t *list, int index, int n);
00076 
00077 #define PN_REFCOUNT_KEY (0x2)
00078 #define PN_REFCOUNT_VALUE (0x4)
00079 
00080 PN_EXTERN pn_map_t *pn_map(size_t capacity, float load_factor, int options);
00081 PN_EXTERN size_t pn_map_size(pn_map_t *map);
00082 PN_EXTERN int pn_map_put(pn_map_t *map, void *key, void *value);
00083 PN_EXTERN void *pn_map_get(pn_map_t *map, void *key);
00084 PN_EXTERN void pn_map_del(pn_map_t *map, void *key);
00085 PN_EXTERN pn_handle_t pn_map_head(pn_map_t *map);
00086 PN_EXTERN pn_handle_t pn_map_next(pn_map_t *map, pn_handle_t entry);
00087 PN_EXTERN void *pn_map_key(pn_map_t *map, pn_handle_t entry);
00088 PN_EXTERN void *pn_map_value(pn_map_t *map, pn_handle_t entry);
00089 
00090 PN_EXTERN pn_hash_t *pn_hash(size_t capacity, float load_factor, int options);
00091 PN_EXTERN size_t pn_hash_size(pn_hash_t *hash);
00092 PN_EXTERN int pn_hash_put(pn_hash_t *hash, uintptr_t key, void *value);
00093 PN_EXTERN void *pn_hash_get(pn_hash_t *hash, uintptr_t key);
00094 PN_EXTERN void pn_hash_del(pn_hash_t *hash, uintptr_t key);
00095 PN_EXTERN pn_handle_t pn_hash_head(pn_hash_t *hash);
00096 PN_EXTERN pn_handle_t pn_hash_next(pn_hash_t *hash, pn_handle_t entry);
00097 PN_EXTERN uintptr_t pn_hash_key(pn_hash_t *hash, pn_handle_t entry);
00098 PN_EXTERN void *pn_hash_value(pn_hash_t *hash, pn_handle_t entry);
00099 
00100 PN_EXTERN pn_string_t *pn_string(const char *bytes);
00101 PN_EXTERN pn_string_t *pn_stringn(const char *bytes, size_t n);
00102 PN_EXTERN const char *pn_string_get(pn_string_t *string);
00103 PN_EXTERN size_t pn_string_size(pn_string_t *string);
00104 PN_EXTERN int pn_string_set(pn_string_t *string, const char *bytes);
00105 PN_EXTERN int pn_string_setn(pn_string_t *string, const char *bytes, size_t n);
00106 PN_EXTERN ssize_t pn_string_put(pn_string_t *string, char *dst);
00107 PN_EXTERN void pn_string_clear(pn_string_t *string);
00108 PN_EXTERN int pn_string_format(pn_string_t *string, const char *format, ...)
00109 #ifdef __GNUC__
00110   __attribute__ ((format (printf, 2, 3)))
00111 #endif
00112     ;
00113 PN_EXTERN int pn_string_vformat(pn_string_t *string, const char *format, va_list ap);
00114 PN_EXTERN int pn_string_addf(pn_string_t *string, const char *format, ...)
00115 #ifdef __GNUC__
00116   __attribute__ ((format (printf, 2, 3)))
00117 #endif
00118     ;
00119 PN_EXTERN int pn_string_vaddf(pn_string_t *string, const char *format, va_list ap);
00120 PN_EXTERN int pn_string_grow(pn_string_t *string, size_t capacity);
00121 PN_EXTERN char *pn_string_buffer(pn_string_t *string);
00122 PN_EXTERN size_t pn_string_capacity(pn_string_t *string);
00123 PN_EXTERN int pn_string_resize(pn_string_t *string, size_t size);
00124 PN_EXTERN int pn_string_copy(pn_string_t *string, pn_string_t *src);
00125 
00126 
00127 #ifdef __cplusplus
00128 }
00129 #endif
00130 
00131 #endif /* object.h */