Eneboo - Documentación para desarrolladores
src/libpq/include/utils/array.h
Ir a la documentación de este archivo.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * array.h
00004  *        Utilities for the new array code. Contains prototypes from the
00005  *        following files:
00006  *                              utils/adt/arrayfuncs.c
00007  *                              utils/adt/arrayutils.c
00008  *
00009  *
00010  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
00011  * Portions Copyright (c) 1994, Regents of the University of California
00012  *
00013  * $PostgreSQL: pgsql/src/include/utils/array.h,v 1.55 2005/10/15 02:49:46 momjian Exp $
00014  *
00015  *-------------------------------------------------------------------------
00016  */
00017 #ifndef ARRAY_H
00018 #define ARRAY_H
00019 
00020 #include "fmgr.h"
00021 
00022 /*
00023  * Arrays are varlena objects, so must meet the varlena convention that
00024  * the first int32 of the object contains the total object size in bytes.
00025  *
00026  * CAUTION: if you change the header for ordinary arrays you will also
00027  * need to change the headers for oidvector and int2vector!
00028  */
00029 typedef struct
00030 {
00031         int32           size;                   /* total array size (varlena requirement) */
00032         int                     ndim;                   /* # of dimensions */
00033         int                     flags;                  /* implementation flags */
00034         /* flags field is currently unused, always zero. */
00035         Oid                     elemtype;               /* element type OID */
00036 } ArrayType;
00037 
00038 typedef struct ArrayBuildState
00039 {
00040         MemoryContext mcontext;         /* where all the temp stuff is kept */
00041         Datum      *dvalues;            /* array of accumulated Datums */
00042 
00043         /*
00044          * The allocated size of dvalues[] is always a multiple of
00045          * ARRAY_ELEMS_CHUNKSIZE
00046          */
00047 #define ARRAY_ELEMS_CHUNKSIZE   64
00048         int                     nelems;                 /* number of valid Datums in dvalues[] */
00049         Oid                     element_type;   /* data type of the Datums */
00050         int16           typlen;                 /* needed info about datatype */
00051         bool            typbyval;
00052         char            typalign;
00053 } ArrayBuildState;
00054 
00055 /*
00056  * structure to cache type metadata needed for array manipulation
00057  */
00058 typedef struct ArrayMetaState
00059 {
00060         Oid                     element_type;
00061         int16           typlen;
00062         bool            typbyval;
00063         char            typalign;
00064         char            typdelim;
00065         Oid                     typioparam;
00066         Oid                     typiofunc;
00067         FmgrInfo        proc;
00068 } ArrayMetaState;
00069 
00070 /*
00071  * private state needed by array_map (here because caller must provide it)
00072  */
00073 typedef struct ArrayMapState
00074 {
00075         ArrayMetaState inp_extra;
00076         ArrayMetaState ret_extra;
00077 } ArrayMapState;
00078 
00079 /*
00080  * fmgr macros for array objects
00081  */
00082 #define DatumGetArrayTypeP(X)             ((ArrayType *) PG_DETOAST_DATUM(X))
00083 #define DatumGetArrayTypePCopy(X)         ((ArrayType *) PG_DETOAST_DATUM_COPY(X))
00084 #define PG_GETARG_ARRAYTYPE_P(n)          DatumGetArrayTypeP(PG_GETARG_DATUM(n))
00085 #define PG_GETARG_ARRAYTYPE_P_COPY(n) DatumGetArrayTypePCopy(PG_GETARG_DATUM(n))
00086 #define PG_RETURN_ARRAYTYPE_P(x)          PG_RETURN_POINTER(x)
00087 
00088 /*
00089  * Access macros for array header fields.
00090  *
00091  * ARR_DIMS returns a pointer to an array of array dimensions (number of
00092  * elements along the various array axes).
00093  *
00094  * ARR_LBOUND returns a pointer to an array of array lower bounds.
00095  *
00096  * That is: if the third axis of an array has elements 5 through 8, then
00097  * ARR_DIMS(a)[2] == 4 and ARR_LBOUND(a)[2] == 5.
00098  *
00099  * Unlike C, the default lower bound is 1.
00100  */
00101 #define ARR_SIZE(a)                             (((ArrayType *) (a))->size)
00102 #define ARR_NDIM(a)                             (((ArrayType *) (a))->ndim)
00103 #define ARR_ELEMTYPE(a)                 (((ArrayType *) (a))->elemtype)
00104 
00105 #define ARR_DIMS(a) \
00106                 ((int *) (((char *) (a)) + sizeof(ArrayType)))
00107 #define ARR_LBOUND(a) \
00108                 ((int *) (((char *) (a)) + sizeof(ArrayType) + \
00109                                   (sizeof(int) * ARR_NDIM(a))))
00110 
00111 /*
00112  * The total array header size for an array of dimension n (in bytes).
00113  */
00114 #define ARR_OVERHEAD(n) \
00115                 (MAXALIGN(sizeof(ArrayType) + 2 * sizeof(int) * (n)))
00116 
00117 /*
00118  * Returns a pointer to the actual array data.
00119  */
00120 #define ARR_DATA_PTR(a) \
00121                 (((char *) (a)) + ARR_OVERHEAD(ARR_NDIM(a)))
00122 
00123 
00124 /*
00125  * prototypes for functions defined in arrayfuncs.c
00126  */
00127 extern Datum array_in(PG_FUNCTION_ARGS);
00128 extern Datum array_out(PG_FUNCTION_ARGS);
00129 extern Datum array_recv(PG_FUNCTION_ARGS);
00130 extern Datum array_send(PG_FUNCTION_ARGS);
00131 extern Datum array_eq(PG_FUNCTION_ARGS);
00132 extern Datum array_ne(PG_FUNCTION_ARGS);
00133 extern Datum array_lt(PG_FUNCTION_ARGS);
00134 extern Datum array_gt(PG_FUNCTION_ARGS);
00135 extern Datum array_le(PG_FUNCTION_ARGS);
00136 extern Datum array_ge(PG_FUNCTION_ARGS);
00137 extern Datum btarraycmp(PG_FUNCTION_ARGS);
00138 extern Datum array_dims(PG_FUNCTION_ARGS);
00139 extern Datum array_lower(PG_FUNCTION_ARGS);
00140 extern Datum array_upper(PG_FUNCTION_ARGS);
00141 extern Datum array_type_coerce(PG_FUNCTION_ARGS);
00142 extern Datum array_type_length_coerce(PG_FUNCTION_ARGS);
00143 extern Datum array_length_coerce(PG_FUNCTION_ARGS);
00144 extern Datum array_larger(PG_FUNCTION_ARGS);
00145 extern Datum array_smaller(PG_FUNCTION_ARGS);
00146 
00147 extern Datum array_ref(ArrayType *array, int nSubscripts, int *indx,
00148                   int arraylen, int elmlen, bool elmbyval, char elmalign,
00149                   bool *isNull);
00150 extern ArrayType *array_set(ArrayType *array, int nSubscripts, int *indx,
00151                   Datum dataValue,
00152                   int arraylen, int elmlen, bool elmbyval, char elmalign,
00153                   bool *isNull);
00154 extern ArrayType *array_get_slice(ArrayType *array, int nSubscripts,
00155                                 int *upperIndx, int *lowerIndx,
00156                                 int arraylen, int elmlen, bool elmbyval, char elmalign,
00157                                 bool *isNull);
00158 extern ArrayType *array_set_slice(ArrayType *array, int nSubscripts,
00159                                 int *upperIndx, int *lowerIndx,
00160                                 ArrayType *srcArray,
00161                                 int arraylen, int elmlen, bool elmbyval, char elmalign,
00162                                 bool *isNull);
00163 
00164 extern Datum array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType,
00165                   ArrayMapState *amstate);
00166 
00167 extern ArrayType *construct_array(Datum *elems, int nelems,
00168                                 Oid elmtype,
00169                                 int elmlen, bool elmbyval, char elmalign);
00170 extern ArrayType *construct_md_array(Datum *elems,
00171                                    int ndims,
00172                                    int *dims,
00173                                    int *lbs,
00174                                    Oid elmtype, int elmlen, bool elmbyval, char elmalign);
00175 extern void deconstruct_array(ArrayType *array,
00176                                   Oid elmtype,
00177                                   int elmlen, bool elmbyval, char elmalign,
00178                                   Datum **elemsp, int *nelemsp);
00179 extern ArrayBuildState *accumArrayResult(ArrayBuildState *astate,
00180                                  Datum dvalue, bool disnull,
00181                                  Oid element_type,
00182                                  MemoryContext rcontext);
00183 extern Datum makeArrayResult(ArrayBuildState *astate,
00184                                 MemoryContext rcontext);
00185 extern Datum makeMdArrayResult(ArrayBuildState *astate, int ndims,
00186                                   int *dims, int *lbs, MemoryContext rcontext);
00187 
00188 /*
00189  * prototypes for functions defined in arrayutils.c
00190  */
00191 
00192 extern int      ArrayGetOffset(int n, int *dim, int *lb, int *indx);
00193 extern int      ArrayGetOffset0(int n, int *tup, int *scale);
00194 extern int      ArrayGetNItems(int ndims, int *dims);
00195 extern void mda_get_range(int n, int *span, int *st, int *endp);
00196 extern void mda_get_prod(int n, int *range, int *prod);
00197 extern void mda_get_offset_values(int n, int *dist, int *prod, int *span);
00198 extern int      mda_next_tuple(int n, int *curr, int *span);
00199 
00200 /*
00201  * prototypes for functions defined in array_userfuncs.c
00202  */
00203 extern Datum array_push(PG_FUNCTION_ARGS);
00204 extern Datum array_cat(PG_FUNCTION_ARGS);
00205 
00206 extern ArrayType *create_singleton_array(FunctionCallInfo fcinfo,
00207                                            Oid element_type,
00208                                            Datum element,
00209                                            int ndims);
00210 
00211 #endif   /* ARRAY_H */
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'