Annotation of embedaddon/mpd/src/contrib/libpdel/structs/type/union.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_UNION_H_
! 42: #define _PDEL_STRUCTS_TYPE_UNION_H_
! 43:
! 44: /*********************************************************************
! 45: UNION TYPES
! 46: *********************************************************************/
! 47:
! 48: /*
! 49: * Union type.
! 50: *
! 51: * The data must be a 'struct structs_union', or a structure
! 52: * defined using the DEFINE_STRUCTS_UNION() macro.
! 53: */
! 54: struct structs_union {
! 55: #ifdef __cplusplus
! 56: const char *field_name; /* name of field in use */
! 57: #else
! 58: const char *const field_name; /* name of field in use */
! 59: #endif
! 60: void *un; /* pointer to field contents */
! 61: };
! 62:
! 63: /*
! 64: * Use this to get the 'un' field declared having the correct type.
! 65: */
! 66: #ifdef __cplusplus
! 67: #define DEFINE_STRUCTS_UNION(sname, uname) \
! 68: struct sname { \
! 69: const char *field_name; /* name of field in use */ \
! 70: union uname *un; /* pointer to the field */ \
! 71: }
! 72: #else
! 73: #define DEFINE_STRUCTS_UNION(sname, uname) \
! 74: struct sname { \
! 75: const char *const field_name; /* name of field in use */ \
! 76: union uname *un; /* pointer to the field */ \
! 77: }
! 78: #endif
! 79:
! 80: /* This structure describes one field in a union */
! 81: struct structs_ufield {
! 82: const char *name; /* name of field */
! 83: const struct structs_type *type; /* type of field */
! 84: char *dummy; /* for type checking */
! 85: };
! 86:
! 87: /* Use this macro to initialize a 'struct structs_ufield' */
! 88: #define STRUCTS_UNION_FIELD(fname, ftype) \
! 89: { #fname, ftype, NULL }
! 90:
! 91: /* This macro terminates a list of 'struct structs_ufield' structures */
! 92: #define STRUCTS_UNION_FIELD_END { NULL, NULL, NULL }
! 93:
! 94: __BEGIN_DECLS
! 95:
! 96: /*
! 97: * Union type
! 98: *
! 99: * Type-specific arguments:
! 100: * [const struct structs_ufield *] List of union fields, terminated
! 101: * by entry with name == NULL.
! 102: * [const char *] Memory allocation type for "un"
! 103: */
! 104: extern structs_init_t structs_union_init;
! 105: extern structs_copy_t structs_union_copy;
! 106: extern structs_equal_t structs_union_equal;
! 107: extern structs_encode_t structs_union_encode;
! 108: extern structs_decode_t structs_union_decode;
! 109: extern structs_uninit_t structs_union_free;
! 110:
! 111: #define STRUCTS_UNION_TYPE(uname, flist) { \
! 112: sizeof(struct structs_union), \
! 113: "union", \
! 114: STRUCTS_TYPE_UNION, \
! 115: structs_union_init, \
! 116: structs_union_copy, \
! 117: structs_union_equal, \
! 118: structs_notsupp_ascify, \
! 119: structs_notsupp_binify, \
! 120: structs_union_encode, \
! 121: structs_union_decode, \
! 122: structs_union_free, \
! 123: { { (void *)(flist) }, { (void *)("union " #uname) }, { NULL } }\
! 124: }
! 125:
! 126: /* Functions */
! 127: extern int structs_union_set(const struct structs_type *type,
! 128: const char *name, void *data, const char *field_name);
! 129:
! 130: __END_DECLS
! 131:
! 132: #endif /* _PDEL_STRUCTS_TYPE_UNION_H_ */
! 133:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>