citrus_mapper.h revision 219019
1219019Sgabor/* $FreeBSD: head/lib/libc/iconv/citrus_mapper.h 219019 2011-02-25 00:04:39Z gabor $ */ 2219019Sgabor/* $NetBSD: citrus_mapper.h,v 1.3 2003/07/12 15:39:19 tshiozak Exp $ */ 3219019Sgabor 4219019Sgabor/*- 5219019Sgabor * Copyright (c)2003 Citrus Project, 6219019Sgabor * All rights reserved. 7219019Sgabor * 8219019Sgabor * Redistribution and use in source and binary forms, with or without 9219019Sgabor * modification, are permitted provided that the following conditions 10219019Sgabor * are met: 11219019Sgabor * 1. Redistributions of source code must retain the above copyright 12219019Sgabor * notice, this list of conditions and the following disclaimer. 13219019Sgabor * 2. Redistributions in binary form must reproduce the above copyright 14219019Sgabor * notice, this list of conditions and the following disclaimer in the 15219019Sgabor * documentation and/or other materials provided with the distribution. 16219019Sgabor * 17219019Sgabor * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18219019Sgabor * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19219019Sgabor * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20219019Sgabor * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21219019Sgabor * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22219019Sgabor * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23219019Sgabor * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24219019Sgabor * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25219019Sgabor * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26219019Sgabor * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27219019Sgabor * SUCH DAMAGE. 28219019Sgabor */ 29219019Sgabor 30219019Sgabor#ifndef _CITRUS_MAPPER_H_ 31219019Sgabor#define _CITRUS_MAPPER_H_ 32219019Sgabor 33219019Sgaborstruct _citrus_mapper_area; 34219019Sgaborstruct _citrus_mapper; 35219019Sgaborstruct _citrus_mapper_ops; 36219019Sgaborstruct _citrus_mapper_traits; 37219019Sgabor 38219019Sgabor__BEGIN_DECLS 39219019Sgaborint _citrus_mapper_create_area( 40219019Sgabor struct _citrus_mapper_area *__restrict *__restrict, 41219019Sgabor const char *__restrict); 42219019Sgaborint _citrus_mapper_open(struct _citrus_mapper_area *__restrict, 43219019Sgabor struct _citrus_mapper *__restrict *__restrict, 44219019Sgabor const char *__restrict); 45219019Sgaborint _citrus_mapper_open_direct( 46219019Sgabor struct _citrus_mapper_area *__restrict, 47219019Sgabor struct _citrus_mapper *__restrict *__restrict, 48219019Sgabor const char *__restrict, const char *__restrict); 49219019Sgaborvoid _citrus_mapper_close(struct _citrus_mapper *); 50219019Sgaborvoid _citrus_mapper_set_persistent(struct _citrus_mapper * __restrict); 51219019Sgabor__END_DECLS 52219019Sgabor 53219019Sgabor#include "citrus_mapper_local.h" 54219019Sgabor 55219019Sgabor/* return values of _citrus_mapper_convert */ 56219019Sgabor#define _CITRUS_MAPPER_CONVERT_SUCCESS (0) 57219019Sgabor#define _CITRUS_MAPPER_CONVERT_NONIDENTICAL (1) 58219019Sgabor#define _CITRUS_MAPPER_CONVERT_SRC_MORE (2) 59219019Sgabor#define _CITRUS_MAPPER_CONVERT_DST_MORE (3) 60219019Sgabor#define _CITRUS_MAPPER_CONVERT_ILSEQ (4) 61219019Sgabor#define _CITRUS_MAPPER_CONVERT_FATAL (5) 62219019Sgabor 63219019Sgabor/* 64219019Sgabor * _citrus_mapper_convert: 65219019Sgabor * convert an index. 66219019Sgabor * - if the converter supports M:1 converter, the function may return 67219019Sgabor * _CITRUS_MAPPER_CONVERT_SRC_MORE and the storage pointed by dst 68219019Sgabor * may be unchanged in this case, although the internal status of 69219019Sgabor * the mapper is affected. 70219019Sgabor * - if the converter supports 1:N converter, the function may return 71219019Sgabor * _CITRUS_MAPPER_CONVERT_DST_MORE. In this case, the contiguous 72219019Sgabor * call of this function ignores src and changes the storage pointed 73219019Sgabor * by dst. 74219019Sgabor * - if the converter supports M:N converter, the function may behave 75219019Sgabor * the combination of the above. 76219019Sgabor * 77219019Sgabor */ 78219019Sgaborstatic __inline int 79219019Sgabor_citrus_mapper_convert(struct _citrus_mapper * __restrict cm, 80219019Sgabor _citrus_index_t * __restrict dst, _citrus_index_t src, 81219019Sgabor void * __restrict ps) 82219019Sgabor{ 83219019Sgabor 84219019Sgabor return ((*cm->cm_ops->mo_convert)(cm, dst, src, ps)); 85219019Sgabor} 86219019Sgabor 87219019Sgabor/* 88219019Sgabor * _citrus_mapper_init_state: 89219019Sgabor * initialize the state. 90219019Sgabor */ 91219019Sgaborstatic __inline void 92219019Sgabor_citrus_mapper_init_state(struct _citrus_mapper * __restrict cm) 93219019Sgabor{ 94219019Sgabor 95219019Sgabor (*cm->cm_ops->mo_init_state)(); 96219019Sgabor} 97219019Sgabor 98219019Sgabor/* 99219019Sgabor * _citrus_mapper_get_state_size: 100219019Sgabor * get the size of state storage. 101219019Sgabor */ 102219019Sgaborstatic __inline size_t 103219019Sgabor_citrus_mapper_get_state_size(struct _citrus_mapper * __restrict cm) 104219019Sgabor{ 105219019Sgabor 106219019Sgabor return (cm->cm_traits->mt_state_size); 107219019Sgabor} 108219019Sgabor 109219019Sgabor/* 110219019Sgabor * _citrus_mapper_get_src_max: 111219019Sgabor * get the maximum number of suspended sources. 112219019Sgabor */ 113219019Sgaborstatic __inline size_t 114219019Sgabor_citrus_mapper_get_src_max(struct _citrus_mapper * __restrict cm) 115219019Sgabor{ 116219019Sgabor 117219019Sgabor return (cm->cm_traits->mt_src_max); 118219019Sgabor} 119219019Sgabor 120219019Sgabor/* 121219019Sgabor * _citrus_mapper_get_dst_max: 122219019Sgabor * get the maximum number of suspended destinations. 123219019Sgabor */ 124219019Sgaborstatic __inline size_t 125219019Sgabor_citrus_mapper_get_dst_max(struct _citrus_mapper * __restrict cm) 126219019Sgabor{ 127219019Sgabor 128219019Sgabor return (cm->cm_traits->mt_dst_max); 129219019Sgabor} 130219019Sgabor 131219019Sgabor#endif 132