Annotation of embedaddon/mpd/src/contrib/libpdel/structs/type/array.h, revision 1.1
1.1 ! misho 1:
! 2: /*
! 3: * Copyright (c) 2001-2002 Packet Design, LLC.
! 4: * All rights reserved.
! 5: *
! 6: * Subject to the following obligations and disclaimer of warranty,
! 7: * use and redistribution of this software, in source or object code
! 8: * forms, with or without modifications are expressly permitted by
! 9: * Packet Design; provided, however, that:
! 10: *
! 11: * (i) Any and all reproductions of the source or object code
! 12: * must include the copyright notice above and the following
! 13: * disclaimer of warranties; and
! 14: * (ii) No rights are granted, in any manner or form, to use
! 15: * Packet Design trademarks, including the mark "PACKET DESIGN"
! 16: * on advertising, endorsements, or otherwise except as such
! 17: * appears in the above copyright notice or in the software.
! 18: *
! 19: * THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
! 20: * TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
! 21: * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
! 22: * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
! 23: * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
! 24: * OR NON-INFRINGEMENT. PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
! 25: * OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
! 26: * OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
! 27: * RELIABILITY OR OTHERWISE. IN NO EVENT SHALL PACKET DESIGN BE
! 28: * LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
! 29: * OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
! 30: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
! 31: * DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
! 32: * USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
! 33: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
! 34: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
! 35: * THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
! 36: * THE POSSIBILITY OF SUCH DAMAGE.
! 37: *
! 38: * Author: Archie Cobbs <archie@freebsd.org>
! 39: */
! 40:
! 41: #ifndef _PDEL_STRUCTS_TYPE_ARRAY_H_
! 42: #define _PDEL_STRUCTS_TYPE_ARRAY_H_
! 43:
! 44: /*********************************************************************
! 45: VARIABLE LENGTH ARRAYS
! 46: *********************************************************************/
! 47:
! 48: /*
! 49: * The data must be a 'struct structs_array', or a structure
! 50: * defined using the DEFINE_STRUCTS_ARRAY() macro.
! 51: */
! 52: struct structs_array {
! 53: u_int length; /* number of elements in array */
! 54: void *elems; /* array elements */
! 55: };
! 56:
! 57: /*
! 58: * Use this to get 'elems' declared as the right type
! 59: */
! 60: #define DEFINE_STRUCTS_ARRAY(name, etype) \
! 61: struct name { \
! 62: u_int length; /* number of elements in array */ \
! 63: etype *elems; /* array elements */ \
! 64: }
! 65:
! 66: /*
! 67: * Macro arguments:
! 68: * [const struct structs_type *] Element type
! 69: * [const char *] Memory allocation type for "elems"
! 70: * [const char *] XML tag for individual elements
! 71: */
! 72: #define STRUCTS_ARRAY_TYPE(etype, mtype, etag) { \
! 73: sizeof(struct structs_array), \
! 74: "array", \
! 75: STRUCTS_TYPE_ARRAY, \
! 76: structs_region_init, \
! 77: structs_array_copy, \
! 78: structs_array_equal, \
! 79: structs_notsupp_ascify, \
! 80: structs_notsupp_binify, \
! 81: structs_array_encode, \
! 82: structs_array_decode, \
! 83: structs_array_free, \
! 84: { { (void *)(etype) }, { (void *)(mtype) }, { (void *)(etag) } }\
! 85: }
! 86:
! 87: __BEGIN_DECLS
! 88:
! 89: extern structs_copy_t structs_array_copy;
! 90: extern structs_equal_t structs_array_equal;
! 91: extern structs_encode_t structs_array_encode;
! 92: extern structs_decode_t structs_array_decode;
! 93: extern structs_uninit_t structs_array_free;
! 94:
! 95: /*
! 96: * Additional functions for handling arrays
! 97: */
! 98: extern int structs_array_length(const struct structs_type *type,
! 99: const char *name, const void *data);
! 100: extern int structs_array_reset(const struct structs_type *type,
! 101: const char *name, void *data);
! 102: extern int structs_array_insert(const struct structs_type *type,
! 103: const char *name, u_int indx, void *data);
! 104: extern int structs_array_delete(const struct structs_type *type,
! 105: const char *name, u_int indx, void *data);
! 106: extern int structs_array_prep(const struct structs_type *type,
! 107: const char *name, void *data);
! 108:
! 109: __END_DECLS
! 110:
! 111: /*********************************************************************
! 112: FIXED LENGTH ARRAYS
! 113: *********************************************************************/
! 114:
! 115: /*
! 116: * Fixed length array type.
! 117: */
! 118:
! 119: /*
! 120: * Macro arguments:
! 121: * [const struct structs_type *] Element type
! 122: * [u_int] Size of each element
! 123: * [u_int] Length of array
! 124: * [const char *] XML tag for individual elements
! 125: */
! 126: #define STRUCTS_FIXEDARRAY_TYPE(etype, esize, alen, etag) { \
! 127: (esize) * (alen), \
! 128: "fixedarray", \
! 129: STRUCTS_TYPE_FIXEDARRAY, \
! 130: structs_fixedarray_init, \
! 131: structs_fixedarray_copy, \
! 132: structs_fixedarray_equal, \
! 133: structs_notsupp_ascify, \
! 134: structs_notsupp_binify, \
! 135: structs_fixedarray_encode, \
! 136: structs_fixedarray_decode, \
! 137: structs_fixedarray_free, \
! 138: { { (void *)(etype) }, { (void *)(etag) }, { (void *)(alen) } } \
! 139: }
! 140:
! 141: __BEGIN_DECLS
! 142:
! 143: extern structs_init_t structs_fixedarray_init;
! 144: extern structs_copy_t structs_fixedarray_copy;
! 145: extern structs_equal_t structs_fixedarray_equal;
! 146: extern structs_encode_t structs_fixedarray_encode;
! 147: extern structs_decode_t structs_fixedarray_decode;
! 148: extern structs_uninit_t structs_fixedarray_free;
! 149:
! 150: __END_DECLS
! 151:
! 152: #endif /* _PDEL_STRUCTS_TYPE_ARRAY_H_ */
! 153:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>