Annotation of embedaddon/mpd/src/contrib/libpdel/structs/type/array.h, revision 1.1.1.2

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,                                             \
1.1.1.2 ! misho      84:        { { (const void *)(etype) }, { (const void *)(mtype) },         \
        !            85:          { (const void *)(etag) } }                                    \
1.1       misho      86: }
                     87: 
                     88: __BEGIN_DECLS
                     89: 
                     90: extern structs_copy_t          structs_array_copy;
                     91: extern structs_equal_t         structs_array_equal;
                     92: extern structs_encode_t                structs_array_encode;
                     93: extern structs_decode_t                structs_array_decode;
                     94: extern structs_uninit_t                structs_array_free;
                     95: 
                     96: /*
                     97:  * Additional functions for handling arrays
                     98:  */
                     99: extern int     structs_array_length(const struct structs_type *type,
                    100:                        const char *name, const void *data);
                    101: extern int     structs_array_reset(const struct structs_type *type,
                    102:                        const char *name, void *data);
                    103: extern int     structs_array_insert(const struct structs_type *type,
                    104:                        const char *name, u_int indx, void *data);
                    105: extern int     structs_array_delete(const struct structs_type *type,
                    106:                        const char *name, u_int indx, void *data);
                    107: extern int     structs_array_prep(const struct structs_type *type,
                    108:                        const char *name, void *data);
                    109: 
                    110: __END_DECLS
                    111: 
                    112: /*********************************************************************
                    113:                        FIXED LENGTH ARRAYS
                    114: *********************************************************************/
                    115: 
                    116: /*
                    117:  * Fixed length array type.
                    118:  */
                    119: 
                    120: /*
                    121:  * Macro arguments:
                    122:  *     [const struct structs_type *]   Element type
                    123:  *     [u_int]                         Size of each element
                    124:  *     [u_int]                         Length of array
                    125:  *     [const char *]                  XML tag for individual elements
                    126:  */
                    127: #define STRUCTS_FIXEDARRAY_TYPE(etype, esize, alen, etag) {            \
                    128:        (esize) * (alen),                                               \
                    129:        "fixedarray",                                                   \
                    130:        STRUCTS_TYPE_FIXEDARRAY,                                        \
                    131:        structs_fixedarray_init,                                        \
                    132:        structs_fixedarray_copy,                                        \
                    133:        structs_fixedarray_equal,                                       \
                    134:        structs_notsupp_ascify,                                         \
                    135:        structs_notsupp_binify,                                         \
                    136:        structs_fixedarray_encode,                                      \
                    137:        structs_fixedarray_decode,                                      \
                    138:        structs_fixedarray_free,                                        \
                    139:        { { (void *)(etype) }, { (void *)(etag) }, { (void *)(alen) } } \
                    140: }
                    141: 
                    142: __BEGIN_DECLS
                    143: 
                    144: extern structs_init_t          structs_fixedarray_init;
                    145: extern structs_copy_t          structs_fixedarray_copy;
                    146: extern structs_equal_t         structs_fixedarray_equal;
                    147: extern structs_encode_t                structs_fixedarray_encode;
                    148: extern structs_decode_t                structs_fixedarray_decode;
                    149: extern structs_uninit_t                structs_fixedarray_free;
                    150: 
                    151: __END_DECLS
                    152: 
                    153: #endif /* _PDEL_STRUCTS_TYPE_ARRAY_H_ */
                    154: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>