~ubuntu-branches/ubuntu/lucid/postgresql-8.4/lucid-security

« back to all changes in this revision

Viewing changes to src/include/utils/varbit.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * varbit.h
 
4
 *        Functions for the SQL datatypes BIT() and BIT VARYING().
 
5
 *
 
6
 * Code originally contributed by Adriaan Joubert.
 
7
 *
 
8
 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
 
9
 * Portions Copyright (c) 1994, Regents of the University of California
 
10
 *
 
11
 * $PostgreSQL$
 
12
 *
 
13
 *-------------------------------------------------------------------------
 
14
 */
 
15
#ifndef VARBIT_H
 
16
#define VARBIT_H
 
17
 
 
18
#include "fmgr.h"
 
19
 
 
20
/*
 
21
 * Modeled on struct varlena from postgres.h, but data type is bits8.
 
22
 */
 
23
typedef struct
 
24
{
 
25
        int32           vl_len_;                /* varlena header (do not touch directly!) */
 
26
        int32           bit_len;                /* number of valid bits */
 
27
        bits8           bit_dat[1];             /* bit string, most sig. byte first */
 
28
} VarBit;
 
29
 
 
30
/*
 
31
 * fmgr interface macros
 
32
 *
 
33
 * BIT and BIT VARYING are toastable varlena types.  They are the same
 
34
 * as far as representation goes, so we just have one set of macros.
 
35
 */
 
36
#define DatumGetVarBitP(X)                 ((VarBit *) PG_DETOAST_DATUM(X))
 
37
#define DatumGetVarBitPCopy(X)     ((VarBit *) PG_DETOAST_DATUM_COPY(X))
 
38
#define VarBitPGetDatum(X)                 PointerGetDatum(X)
 
39
#define PG_GETARG_VARBIT_P(n)      DatumGetVarBitP(PG_GETARG_DATUM(n))
 
40
#define PG_GETARG_VARBIT_P_COPY(n) DatumGetVarBitPCopy(PG_GETARG_DATUM(n))
 
41
#define PG_RETURN_VARBIT_P(x)      return VarBitPGetDatum(x)
 
42
 
 
43
/* Header overhead *in addition to* VARHDRSZ */
 
44
#define VARBITHDRSZ                     sizeof(int32)
 
45
/* Number of bits in this bit string */
 
46
#define VARBITLEN(PTR)          (((VarBit *) (PTR))->bit_len)
 
47
/* Pointer to the first byte containing bit string data */
 
48
#define VARBITS(PTR)            (((VarBit *) (PTR))->bit_dat)
 
49
/* Number of bytes in the data section of a bit string */
 
50
#define VARBITBYTES(PTR)        (VARSIZE(PTR) - VARHDRSZ - VARBITHDRSZ)
 
51
/* Padding of the bit string at the end (in bits) */
 
52
#define VARBITPAD(PTR)          (VARBITBYTES(PTR)*BITS_PER_BYTE - VARBITLEN(PTR))
 
53
/* Number of bytes needed to store a bit string of a given length */
 
54
#define VARBITTOTALLEN(BITLEN)  (((BITLEN) + BITS_PER_BYTE-1)/BITS_PER_BYTE + \
 
55
                                                                 VARHDRSZ + VARBITHDRSZ)
 
56
/* pointer beyond the end of the bit string (like end() in STL containers) */
 
57
#define VARBITEND(PTR)          (((bits8 *) (PTR)) + VARSIZE(PTR))
 
58
/* Mask that will cover exactly one byte, i.e. BITS_PER_BYTE bits */
 
59
#define BITMASK 0xFF
 
60
 
 
61
 
 
62
extern Datum bit_in(PG_FUNCTION_ARGS);
 
63
extern Datum bit_out(PG_FUNCTION_ARGS);
 
64
extern Datum bit_recv(PG_FUNCTION_ARGS);
 
65
extern Datum bit_send(PG_FUNCTION_ARGS);
 
66
extern Datum bittypmodin(PG_FUNCTION_ARGS);
 
67
extern Datum bittypmodout(PG_FUNCTION_ARGS);
 
68
extern Datum varbit_in(PG_FUNCTION_ARGS);
 
69
extern Datum varbit_out(PG_FUNCTION_ARGS);
 
70
extern Datum varbit_recv(PG_FUNCTION_ARGS);
 
71
extern Datum varbit_send(PG_FUNCTION_ARGS);
 
72
extern Datum varbittypmodin(PG_FUNCTION_ARGS);
 
73
extern Datum varbittypmodout(PG_FUNCTION_ARGS);
 
74
extern Datum bit(PG_FUNCTION_ARGS);
 
75
extern Datum varbit(PG_FUNCTION_ARGS);
 
76
extern Datum biteq(PG_FUNCTION_ARGS);
 
77
extern Datum bitne(PG_FUNCTION_ARGS);
 
78
extern Datum bitlt(PG_FUNCTION_ARGS);
 
79
extern Datum bitle(PG_FUNCTION_ARGS);
 
80
extern Datum bitgt(PG_FUNCTION_ARGS);
 
81
extern Datum bitge(PG_FUNCTION_ARGS);
 
82
extern Datum bitcmp(PG_FUNCTION_ARGS);
 
83
extern Datum bitand(PG_FUNCTION_ARGS);
 
84
extern Datum bitor(PG_FUNCTION_ARGS);
 
85
extern Datum bitxor(PG_FUNCTION_ARGS);
 
86
extern Datum bitnot(PG_FUNCTION_ARGS);
 
87
extern Datum bitshiftleft(PG_FUNCTION_ARGS);
 
88
extern Datum bitshiftright(PG_FUNCTION_ARGS);
 
89
extern Datum bitcat(PG_FUNCTION_ARGS);
 
90
extern Datum bitsubstr(PG_FUNCTION_ARGS);
 
91
extern Datum bitlength(PG_FUNCTION_ARGS);
 
92
extern Datum bitoctetlength(PG_FUNCTION_ARGS);
 
93
extern Datum bitfromint4(PG_FUNCTION_ARGS);
 
94
extern Datum bittoint4(PG_FUNCTION_ARGS);
 
95
extern Datum bitfromint8(PG_FUNCTION_ARGS);
 
96
extern Datum bittoint8(PG_FUNCTION_ARGS);
 
97
extern Datum bitposition(PG_FUNCTION_ARGS);
 
98
 
 
99
#endif