Avis Client Library: avis/attributes.h Source File

- Main Page
- Data Structures
- Files

# avis/attributes.h

Go to the documentation of this file.

    00001 /*
    00002  *  Avis Elvin client library for C.
    00003  *
    00004  *  Copyright (C) 2008 Matthew Phillips <avis@mattp.name>
    00005  *
    00006  *  This program is free software; you can redistribute it and/or
    00007  *  modify it under the terms of version 3 of the GNU Lesser General
    00008  *  Public License as published by the Free Software Foundation.
    00009  *
    00010  *  This program is distributed in the hope that it will be useful,
    00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    00013  *  General Public License for more details.
    00014  *
    00015  *  You should have received a copy of the GNU General Public License
    00016  *  along with this program. If not, see <http://www.gnu.org/licenses/>.
    00017  */
    00021 #ifndef AVIS_ATTRIBUTES_H
    00022 #define AVIS_ATTRIBUTES_H
    00023
    00024 #include <avis/stdtypes.h>
    00025 #include <avis/errors.h>
    00026 #include <avis/values.h>
    00027
    00028 struct hashtable;
    00029
    00046 typedef struct
    00047 {
    00048   struct hashtable *table;
    00049 } Attributes;
    00050
    00056 typedef struct
    00057 {
    00058   /* below is a copy of hashtable_iter from hashtable_iter.h */
    00059   struct
    00060   {
    00061     void *h;
    00062     void *e;
    00063     void *parent;
    00064     unsigned int index;
    00065   } hash_iter;
    00066
    00067   bool has_next;
    00068 } AttributesIter;
    00069
    00070 AVIS_PUBLIC_DATA
    00071 Attributes _empty_attributes;
    00072
    00073 #define EMPTY_ATTRIBUTES (&_empty_attributes)
    00074
    00082 #define attributes_create() \
    00083   (attributes_init ((Attributes *)avis_emalloc (sizeof (Attributes))))
    00084
    00091 AVIS_PUBLIC
    00092 Attributes *attributes_init (Attributes *);
    00093
    00099 #define attributes_destroy(attributes) \
    00100   if ((attributes) && (attributes) != EMPTY_ATTRIBUTES) \
    00101   { \
    00102     attributes_free (attributes), free (attributes), attributes = NULL; \
    00103   }
    00104
    00111 AVIS_PUBLIC
    00112 void attributes_free (Attributes *attributes);
    00113
    00117 AVIS_PUBLIC
    00118 void attributes_clear (Attributes *attributes);
    00119
    00129 AVIS_PUBLIC
    00130 Attributes *attributes_copy (Attributes *target, const Attributes *source);
    00131
    00140 #define attributes_clone(source) attributes_copy (attributes_create (), source)
    00141
    00145 AVIS_PUBLIC
    00146 unsigned int attributes_size (Attributes *attributes);
    00147
    00151 #define attributes_iter_create(attributes) \
    00152   attributes_iter_init \
    00153     ((AttributesIter *)avis_emalloc (sizeof (AttributesIter)), (attributes))
    00154
    00158 #define attributes_iter_destroy(iter) (free (iter), (iter) = NULL)
    00159
    00187 AVIS_PUBLIC
    00188 AttributesIter *attributes_iter_init (AttributesIter *iter,
    00189                                       const Attributes *attributes);
    00190
    00195 AVIS_PUBLIC
    00196 const char *attributes_iter_name (const AttributesIter *iter);
    00197
    00202 AVIS_PUBLIC
    00203 const Value *attributes_iter_value (const AttributesIter *iter);
    00204
    00205 #define attributes_iter_has_next(iter) ((iter)->has_next)
    00206
    00213 AVIS_PUBLIC
    00214 bool attributes_iter_next (AttributesIter *iter);
    00215
    00229 AVIS_PUBLIC
    00230 void attributes_set (Attributes *attributes, const char *name, Value *value);
    00231
    00245 AVIS_PUBLIC
    00246 void attributes_set_nocopy (Attributes *attributes, char *name, Value *value);
    00247
    00257 AVIS_PUBLIC
    00258 Value *attributes_get (Attributes *attributes, const char *name);
    00259
    00263 AVIS_PUBLIC
    00264 bool attributes_contains (Attributes *attributes, const char *name);
    00265
    00278 AVIS_PUBLIC
    00279 Value *attributes_remove (Attributes *attributes, const char *name);
    00280
    00291 #define attributes_set_int32(attributes, name, value) \
    00292   (attributes_set (attributes, name, value_create_int32 (value)))
    00293
    00305 AVIS_PUBLIC
    00306 int32_t attributes_get_int32 (Attributes *attributes, const char *name);
    00307
    00318 #define attributes_set_int64(attributes, name, value) \
    00319   (attributes_set (attributes, name, value_create_int64 (value)))
    00320
    00332 AVIS_PUBLIC
    00333 int64_t attributes_get_int64 (Attributes *attributes, const char *name);
    00334
    00345 #define attributes_set_real64(attributes, name, value) \
    00346   (attributes_set (attributes, name, value_create_real64 (value)))
    00347
    00359 AVIS_PUBLIC
    00360 real64_t attributes_get_real64 (Attributes *attributes, const char *name);
    00361
    00375 #define attributes_set_string(attributes, name, value) \
    00376   (attributes_set (attributes, name, value_create_string (value)))
    00377
    00389 AVIS_PUBLIC
    00390 const char *attributes_get_string (Attributes *attributes, const char *name);
    00391
    00405 #define attributes_set_opaque(attributes, name, value) \
    00406   (attributes_set (attributes, name, value_create_opaque (value)))
    00407
    00419 AVIS_PUBLIC
    00420 Array *attributes_get_opaque (Attributes *attributes, const char *name);
    00421
    00422 #endif /* AVIS_ATTRIBUTES_H */