Tesseract  3.02
tesseract-ocr/cutil/tessarray.h
Go to the documentation of this file.
00001 /* -*-C-*-
00002  ********************************************************************************
00003  *
00004  * File:        array.h  (Formerly array.h)
00005  * Description:  Dynamic Array of String
00006  * Author:       Mark Seaman, SW Productivity
00007  * Created:      Fri Oct 16 14:37:00 1987
00008  * Modified:     Mon Sep 24 14:15:59 1990 (Mark Seaman) marks@hpgrlt
00009  * Language:     C
00010  * Package:      N/A
00011  * Status:       Reusable Software Component
00012  *
00013  * (c) Copyright 1987, Hewlett-Packard Company.
00014  ** Licensed under the Apache License, Version 2.0 (the "License");
00015  ** you may not use this file except in compliance with the License.
00016  ** You may obtain a copy of the License at
00017  ** http://www.apache.org/licenses/LICENSE-2.0
00018  ** Unless required by applicable law or agreed to in writing, software
00019  ** distributed under the License is distributed on an "AS IS" BASIS,
00020  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00021  ** See the License for the specific language governing permissions and
00022  ** limitations under the License.
00023  *
00024  *****************************************************************************
00025 
00026 This file contains a set of general purpose dynamic array of string routines.
00027 These routines can be used in a wide variety of ways to provide several
00028 different popular data structures. A new "das" can be created by declaring
00029 a variable of type 'DAS'
00030 ******************************************************************************/
00031 
00032 #ifndef TESSARRAY_H
00033 #define TESSARRAY_H
00034 
00035 /*
00036 ----------------------------------------------------------------------
00037               I n c l u d e s
00038 ----------------------------------------------------------------------
00039 */
00040 
00041 #include <stdio.h>
00042 
00043 /*
00044 ----------------------------------------------------------------------
00045               T y p e s
00046 ----------------------------------------------------------------------
00047 */
00048 
00049 typedef struct array_record
00050 {
00051   size_t limit;
00052   size_t top;
00053   void *base[2];
00054 } *ARRAY;
00055 
00056 typedef void (*voidProc) ();
00057 
00058 typedef int (*intProc) ();
00059 
00060 /*
00061 ----------------------------------------------------------------------
00062               M a c r o s
00063 ----------------------------------------------------------------------
00064 */
00065 
00066 #define DEFAULT_SIZE 2
00067 
00068 /**********************************************************************
00069  * array_count
00070  *
00071  * Return the value of the number of elements currently in the array.
00072  **********************************************************************/
00073 
00074 #define array_count(a)  \
00075 ((a)->top)
00076 
00077 /**********************************************************************
00078  * array_free
00079  *
00080  * Free the memory allocated to this array.
00081  **********************************************************************/
00082 
00083 #define array_free  \
00084 memfree
00085 
00086 /**********************************************************************
00087  * array_index
00088  *
00089  * Check to make sure that the index value is valid. Return the
00090  * value of the nth element currently in the array.
00091  **********************************************************************/
00092 
00093 #define array_index(a,i)   \
00094 ((i<array_count(a)) ? (a)->base[i] : 0)
00095 
00096 /**********************************************************************
00097  * array_limit
00098  *
00099  * Return the maximum number of elements that could be currently held
00100  * in this array without further expansion.
00101  **********************************************************************/
00102 
00103 #define array_limit(a)     \
00104 ((a)->limit)
00105 
00106 /**********************************************************************
00107  * array_loop
00108  *
00109  * Iterate through each of the array elements.  Each value can then be
00110  * accessed by:
00111  *    array_index (a, x)
00112  **********************************************************************/
00113 
00114 #define array_loop(a,x)    \
00115 for (x=0; x < array_count (a); x++)
00116 
00117 /**********************************************************************
00118  * array_top
00119  *
00120  * Return the last element that was pushed on this array.
00121  **********************************************************************/
00122 
00123 #define array_top(a)       \
00124 ((a)->base[array_count (a) - 1])
00125 
00126 /**********************************************************************
00127  * array_value
00128  *
00129  * Return the nth element of the array.  Don't do range checking.
00130  **********************************************************************/
00131 
00132 #define array_value(a,i)   \
00133 ((a)->base[i])
00134 
00135 /*----------------------------------------------------------------------
00136               F u n c t i o n s
00137 ----------------------------------------------------------------------*/
00138 ARRAY array_insert(ARRAY array, int index, void *value);
00139 
00140 ARRAY array_new(int num);
00141 
00142 ARRAY array_push(ARRAY array, void *value);
00143 
00144 /*
00145 #if defined(__STDC__) || defined(__cplusplus)
00146 # define        _ARGS(s) s
00147 #else
00148 # define        _ARGS(s) ()
00149 #endif*/
00150 
00151 /* array.c
00152 ARRAY array_insert
00153   _ARGS((ARRAY array,
00154   int index,
00155   char *value));
00156 
00157 ARRAY array_new
00158   _ARGS((int num));
00159 
00160 ARRAY array_push
00161   _ARGS((ARRAY array,
00162   char *value));
00163 
00164 #undef _ARGS
00165 */
00166 #endif