Avis Client Library: avis/values.h Source File

- Main Page
- Data Structures
- Files

# avis/values.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_VALUES_H_
    00022 #define AVIS_VALUES_H_
    00023
    00024 #include <string.h>
    00025
    00026 #include <avis/stdtypes.h>
    00027 #include <avis/arrays.h>
    00028 #include <avis/defs.h>
    00029
    00034 typedef enum
    00035 {
    00036   TYPE_INT32 = 1, TYPE_INT64 = 2, TYPE_REAL64 = 3,
    00037   TYPE_STRING = 4, TYPE_OPAQUE = 5
    00038 } ValueType;
    00039
    00044 typedef struct
    00045 {
    00047   ValueType type;
    00048
    00050   union
    00051   {
    00052     int32_t   int32;
    00053     int64_t   int64;
    00054     real64_t  real64;
    00055     char *    str;
    00056     Array     bytes;
    00057   } value;
    00058 } Value;
    00059
    00072 AVIS_PUBLIC
    00073 Value *value_init (Value *value, ValueType type, ...);
    00074
    00078 AVIS_PUBLIC
    00079 void value_free (Value *value);
    00080
    00090 AVIS_PUBLIC
    00091 Value *value_copy (Value *target, const Value *source);
    00092
    00101 #define value_clone(source) value_copy (value_create (), source)
    00102
    00106 #define value_create() ((Value *)avis_emalloc (sizeof (Value)))
    00107
    00111 #define value_destroy(value) \
    00112   (value_free (value), free (value), value = NULL)
    00113
    00117 #define value_create_int32(value) \
    00118   (value_init (value_create (), TYPE_INT32, (int32_t)(value)))
    00119
    00123 #define value_create_int64(value) \
    00124   (value_init (value_create (), TYPE_INT64, (int64_t)(value)))
    00125
    00129 #define value_create_real64(value) \
    00130   (value_init (value_create (), TYPE_REAL64, (real64_t)(value)))
    00131
    00139 #define value_create_string(value) \
    00140   (value_init (value_create (), TYPE_STRING, avis_estrdup (value)))
    00141
    00149 #define value_create_string_nocopy(value) \
    00150   (value_init (value_create (), TYPE_STRING, value))
    00151
    00161 #define value_create_opaque(value) \
    00162   (value_init (value_create (), TYPE_OPAQUE, value))
    00163
    00173 AVIS_PUBLIC
    00174 Array *array_init (Array *array, size_t item_count, size_t item_length);
    00175
    00179 AVIS_PUBLIC
    00180 void array_free (Array *array);
    00181
    00188 #define array_create(item_type, item_count) \
    00189   (array_init ((Array *)avis_emalloc (sizeof (Array)), \
    00190                item_count, sizeof (item_type)))
    00191
    00195 #define array_destroy(value) \
    00196   (array_free (value), free (value), value = NULL)
    00197
    00205 #define array_get(array, index, item_type) \
    00206   (((item_type *)array->items) [index])
    00207
    00211 AVIS_PUBLIC
    00212 bool array_equals (Array *array1, Array *array2);
    00213
    00214 #endif /*AVIS_VALUES_H_*/