os/textandloc/fontservices/textshaperplugin/IcuSource/common/ucmp8.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/fontservices/textshaperplugin/IcuSource/common/ucmp8.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,244 @@
     1.4 +/*
     1.5 + ********************************************************************
     1.6 + * COPYRIGHT: 
     1.7 + * Copyright (c) 1996-2004, International Business Machines Corporation and
     1.8 + * others. All Rights Reserved.
     1.9 + ********************************************************************
    1.10 + */
    1.11 +
    1.12 +
    1.13 +
    1.14 +#ifndef UCMP8_H
    1.15 +#define UCMP8_H
    1.16 +
    1.17 +/* 32-bits.
    1.18 +  Bump this whenever the internal structure changes.
    1.19 +*/
    1.20 +#define ICU_UCMP8_VERSION 0x01260000
    1.21 +
    1.22 +#include "unicode/utypes.h"
    1.23 +
    1.24 +/*====================================
    1.25 + * class CompactByteArray
    1.26 + * Provides a compact way to store information that is indexed by Unicode values,
    1.27 + * such as character properties, types, keyboard values, etc.
    1.28 + * The ATypes are used by value, so should be small, integers or pointers.
    1.29 + *====================================
    1.30 + */
    1.31 +
    1.32 +U_CAPI int32_t U_EXPORT2 ucmp8_getkUnicodeCount(void);
    1.33 +U_CAPI int32_t U_EXPORT2 ucmp8_getkBlockCount(void);
    1.34 +
    1.35 +typedef struct CompactByteArray {
    1.36 +  uint32_t fStructSize;
    1.37 +  int8_t* fArray;
    1.38 +  uint16_t* fIndex;
    1.39 +  int32_t fCount;
    1.40 +  UBool fCompact;
    1.41 +  UBool fBogus;
    1.42 +  UBool fAlias;
    1.43 +  UBool fIAmOwned; /* don't free CBA on close */
    1.44 +} CompactByteArray;
    1.45 +
    1.46 +#define UCMP8_kUnicodeCount 65536
    1.47 +#define UCMP8_kBlockShift 7
    1.48 +#define UCMP8_kBlockCount (1<<UCMP8_kBlockShift)
    1.49 +#define UCMP8_kIndexShift (16-UCMP8_kBlockShift)
    1.50 +#define UCMP8_kIndexCount (1<<UCMP8_kIndexShift)
    1.51 +#define UCMP8_kBlockMask (UCMP8_kBlockCount-1)
    1.52 +
    1.53 +
    1.54 +/**
    1.55 + * Construct an empty CompactByteArray with uprv_malloc(). Do not call any of the
    1.56 + * ucmp8_init*() functions after using this function. They will cause a memory
    1.57 + * leak.
    1.58 + *
    1.59 + * @param defaultValue the default value for all characters not explicitly in the array
    1.60 + * @see ucmp8_init
    1.61 + * @see ucmp8_initBogus
    1.62 + * @return The initialized array.
    1.63 + */
    1.64 +U_CAPI  CompactByteArray* U_EXPORT2 ucmp8_open(int8_t defaultValue);
    1.65 +
    1.66 +/**
    1.67 + * Construct a CompactByteArray from a pre-computed index and values array. The values
    1.68 + * will be adopted by the CompactByteArray. Memory is allocated with uprv_malloc.
    1.69 + * Note: for speed, the compact method will only re-use blocks in the values array
    1.70 + * that are on a block boundary. The pre-computed arrays passed in to this constructor
    1.71 + * may re-use blocks at any position in the values array. The indexArray and newValues
    1.72 + * will be uprv_free'd when ucmp16_close() is called.
    1.73 + *
    1.74 + * @param indexArray the index array to be adopted
    1.75 + * @param newValues the value array to be adopted
    1.76 + * @param count the number of entries in the value array
    1.77 + * @return the newly constructed ComapctByteArray
    1.78 + * @see compact
    1.79 + */
    1.80 +U_CAPI  CompactByteArray* U_EXPORT2 ucmp8_openAdopt(uint16_t* indexArray, 
    1.81 +                               int8_t* newValues,
    1.82 +                               int32_t count);
    1.83 +
    1.84 +/**
    1.85 + * Construct a CompactByteArray from a pre-computed index and values array. The values
    1.86 + * will be aliased by the CompactByteArray. Memory is allocated with uprv_malloc.
    1.87 + * Note: for speed, the compact method will only re-use blocks in the values array
    1.88 + * that are on a block boundary. The pre-computed arrays passed in to this constructor
    1.89 + * may re-use blocks at any position in the values array.
    1.90 + *
    1.91 + * @param indexArray the index array to be adopted
    1.92 + * @param newValues the value array to be adopted
    1.93 + * @param count the number of entries in the value array
    1.94 + * @return the newly constructed CompactByteArray
    1.95 + * @see compact
    1.96 + */
    1.97 +U_CAPI  CompactByteArray* U_EXPORT2 ucmp8_openAlias(uint16_t* indexArray, 
    1.98 +                               int8_t* newValues,
    1.99 +                               int32_t count);
   1.100 +
   1.101 +
   1.102 +/**
   1.103 + * Initialize an empty CompactByteArray. Do not call this function
   1.104 + * if you created the array with ucmp8_open() because it will cause a memory
   1.105 + * leak.
   1.106 + *
   1.107 + * @param defaultValue the default value for all characters not explicitly in the array
   1.108 + * @param array An uninitialized CompactByteArray
   1.109 + * @see ucmp8_open
   1.110 + */
   1.111 +U_CAPI  void U_EXPORT2 ucmp8_init(CompactByteArray* array, int8_t defaultValue);
   1.112 +
   1.113 +/**
   1.114 + * Initialize an empty CompactByteArray to the bogus value. Do not call this
   1.115 + * function if you created the array with ucmp8_open() because it will cause
   1.116 + * a memory leak.
   1.117 + *
   1.118 + * @param array An uninitialized CompactByteArray
   1.119 + * @see ucmp8_open
   1.120 + * @see ucmp8_isBogus
   1.121 + */
   1.122 +U_CAPI  void U_EXPORT2 ucmp8_initBogus(CompactByteArray* array);
   1.123 +
   1.124 +/**
   1.125 + * Initialize a CompactByteArray from a pre-computed index and values array. The values
   1.126 + * will be adopted by the CompactByteArray. Memory is allocated with uprv_malloc.
   1.127 + * Note: for speed, the compact method will only re-use blocks in the values array
   1.128 + * that are on a block boundary. The pre-computed arrays passed in to this constructor
   1.129 + * may re-use blocks at any position in the values array. The indexArray and newValues
   1.130 + * will be uprv_free'd when ucmp16_close() is called.
   1.131 + *
   1.132 + * @param this_obj An uninitialized CompactByteArray
   1.133 + * @param indexArray the index array to be adopted
   1.134 + * @param newValues the value array to be adopted
   1.135 + * @param count the number of entries in the value array
   1.136 + * @return the pointer refers to the CompactByteArray
   1.137 + * @see compact
   1.138 + */
   1.139 +U_CAPI  CompactByteArray* U_EXPORT2 ucmp8_initAdopt(CompactByteArray *this_obj,
   1.140 +                               uint16_t* indexArray, 
   1.141 +                               int8_t* newValues,
   1.142 +                               int32_t count);
   1.143 +
   1.144 +/**
   1.145 + * Initialize a CompactByteArray from a pre-computed index and values array. The values
   1.146 + * will be aliased by the CompactByteArray. Memory is allocated with uprv_malloc.
   1.147 + * Note: for speed, the compact method will only re-use blocks in the values array
   1.148 + * that are on a block boundary. The pre-computed arrays passed in to this constructor
   1.149 + * may re-use blocks at any position in the values array.
   1.150 + *
   1.151 + * @param this_obj An uninitialized CompactByteArray
   1.152 + * @param indexArray the index array to be adopted
   1.153 + * @param newValues the value array to be adopted
   1.154 + * @param count the number of entries in the value array
   1.155 + * @return the pointer refers to the CompactByteArray
   1.156 + * @see compact
   1.157 + */
   1.158 +U_CAPI  CompactByteArray* U_EXPORT2 ucmp8_initAlias(CompactByteArray *this_obj,
   1.159 +                               uint16_t* indexArray, 
   1.160 +                               int8_t* newValues,
   1.161 +                               int32_t count);
   1.162 +
   1.163 +/**
   1.164 + * Free up any allocated memory associated with this compact array.
   1.165 + * The memory that is uprv_free'd depends on how the array was initialized
   1.166 + * or opened.
   1.167 + * 
   1.168 + * @param array The compact array to close
   1.169 + */
   1.170 +U_CAPI  void U_EXPORT2 ucmp8_close(CompactByteArray* array);
   1.171 +
   1.172 +/**
   1.173 + * Returns TRUE if the creation of the compact array fails.
   1.174 + * @param array The CompactByteArray to be created.
   1.175 + * @return TRUE if the creation of the compact array fails.
   1.176 + */
   1.177 +U_CAPI  UBool U_EXPORT2 ucmp8_isBogus(const CompactByteArray* array);
   1.178 +
   1.179 +/**
   1.180 + * Get the mapped value of a Unicode character.
   1.181 + *
   1.182 + * @param index the character to get the mapped value with
   1.183 + * @return the mapped value of the given character
   1.184 + */
   1.185 +#define ucmp8_get(array, index)  (array->fArray[(array->fIndex[index >> UCMP8_kBlockShift] & 0xFFFF) + (index & UCMP8_kBlockMask)])
   1.186 +
   1.187 +#define ucmp8_getu(array,index) (uint8_t)ucmp8_get(array,index)
   1.188 +
   1.189 +
   1.190 +/**
   1.191 + * Set a new value for a Unicode character.
   1.192 + * Set automatically expands the array if it is compacted.
   1.193 + *
   1.194 + * @param array the CompactByteArray to be set
   1.195 + * @param character the character to set the mapped value with
   1.196 + * @param value the new mapped value
   1.197 + */
   1.198 +U_CAPI  void U_EXPORT2 ucmp8_set(CompactByteArray* array,
   1.199 +                 UChar character,
   1.200 +                 int8_t value);
   1.201 +
   1.202 +/**
   1.203 + * Set new values for a range of Unicode character.
   1.204 + *
   1.205 + * @param array the CompactByteArray to be set
   1.206 + * @param start the starting offset of the range
   1.207 + * @param end the ending offset of the range
   1.208 + * @param value the new mapped value
   1.209 + */
   1.210 +U_CAPI  void U_EXPORT2 ucmp8_setRange(CompactByteArray* array, 
   1.211 +                  UChar start,
   1.212 +                  UChar end, 
   1.213 +                  int8_t value);
   1.214 +
   1.215 +U_CAPI  int32_t U_EXPORT2 ucmp8_getCount(const CompactByteArray* array);
   1.216 +U_CAPI  const int8_t* U_EXPORT2 ucmp8_getArray(const CompactByteArray* array);
   1.217 +U_CAPI  const uint16_t* U_EXPORT2 ucmp8_getIndex(const CompactByteArray* array);
   1.218 +
   1.219 +/**
   1.220 + * Compact the array.
   1.221 + * The value of cycle determines how large the overlap can be.
   1.222 + * A cycle of 1 is the most compacted, but takes the most time to do.
   1.223 + * If values stored in the array tend to repeat in cycles of, say, 16,
   1.224 + * then using that will be faster than cycle = 1, and get almost the
   1.225 + * same compression.
   1.226 + * @param array The CompactByteArray to be compacted
   1.227 + * @param cycle The value determines how large the overlap can be.
   1.228 + */
   1.229 +U_CAPI  void U_EXPORT2 ucmp8_compact(CompactByteArray* array, 
   1.230 +                 uint32_t cycle);
   1.231 +
   1.232 +/** Expanded takes the array back to a 65536 element array
   1.233 + *  @param array The CompactByteArray to be expanded
   1.234 + */
   1.235 +U_CAPI  void U_EXPORT2 ucmp8_expand(CompactByteArray* array);
   1.236 +
   1.237 +/** 
   1.238 + * Flatten into a memory structure. Pass in NULL to pre-flight to get the required size.
   1.239 + * @internal
   1.240 + */
   1.241 +U_CAPI  uint32_t U_EXPORT2 ucmp8_flattenMem(const CompactByteArray* array, uint8_t *MS);
   1.242 +
   1.243 +/* initializes an existing CBA from memory.  Will cause ucmp8_close() to not deallocate anything. */
   1.244 +U_CAPI  void U_EXPORT2 ucmp8_initFromData(CompactByteArray* array, const uint8_t **source, UErrorCode *status);
   1.245 +
   1.246 +#endif
   1.247 +