/* ** OSSP act - Abstract Container Types ** Copyright (c) 1999-2003 Ralf S. Engelschall ** Copyright (c) 1999-2003 The OSSP Project ** ** This file is part of OSSP act, an abstract container type library ** which can be found at http://www.ossp.org/pkg/lib/act/. ** ** Permission to use, copy, modify, and distribute this software for ** any purpose with or without fee is hereby granted, provided that ** the above copyright notice and this permission notice appear in all ** copies. ** ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. ** ** act.h: public Application Programming Interface (API) */ #ifndef _ACT_H_ #define _ACT_H_ /* the library version */ #ifndef ACT_VERSION #define ACT_VERSION @ACT_VERSION_HEX@ #endif /* essential headers */ #include /* for ssize_t, off_t */ /* essential typedefs */ @HAVE_ACT_UINT8_T@ @HAVE_ACT_UINT16_T@ @HAVE_ACT_UINT32_T@ @HAVE_ACT_UINT64_T@ @HAVE_ACT_SIZE_T@ typedef @ACT_UINT8_T@ act_uint8_t; typedef @ACT_UINT16_T@ act_uint16_t; typedef @ACT_UINT32_T@ act_uint32_t; typedef @ACT_UINT64_T@ act_uint64_t; typedef @ACT_SIZE_T@ act_size_t; /* C++ support */ #ifdef __cplusplus #define BEGIN_DECLARATION extern "C" { #define END_DECLARATION } #else #define BEGIN_DECLARATION /*nop*/ #define END_DECLARATION /*nop*/ #endif /* true and false boolean values */ #ifndef FALSE #define FALSE 0 #endif #ifndef TRUE /* Do not depend on the exact TRUE value, i.e. never do: x == TRUE. Use TRUE only for return or assignment. */ #define TRUE !FALSE #endif /* null values for pointers and characters */ #ifndef NULL #define NULL ((void *)0) #endif #ifndef NUL #define NUL '\0' #endif /* * Internal Bitmask Calculation Macros * (Notice: bit positions are counted n...0, i.e. lowest bit is position 0) */ /* generate a bitmask consisting of 1 bits from (and including) bit position `l' (left) to (and including) bit position `r' */ #define _BM_MASK(l,r) (((1<<((l)-(r)+1))-1)<<(r)) /* extract a value v from a word w at position `l' to `r' and return value */ #define _BM_GET(w,l,r) (((w)>>(r))&_BM_MASK((l)-(r),0)) /* insert a value v into a word w at position `l' to `r' and return word */ #define _BM_SET(w,l,r,v) ((w)|(((v)&_BM_MASK((l)-(r),0))<<(r))) /* generate a single bit `b' (0 or 1) at bit position `n' */ #define _BM_BIT(n,b) ((b)<<(n)) /* generate a quad word octet of bits (a half byte, i.e. bit positions 3 to 0) */ #define _BM_QUAD(b3,b2,b1,b0) (_BM_BIT(3,(b3))|_BM_BIT(2,(b2))|_BM_BIT(1,(b1))|_BM_BIT(0,(b0))) /* generate an octet word of bits (a byte, i.e. bit positions 7 to 0) */ #define _BM_OCTET(b7,b6,b5,b4,b3,b2,b1,b0) ((_BM_QUAD(b7,b6,b5,b4)<<4)|_BM_QUAD(b3,b2,b1,b0)) /* generate the value 2^n */ #define _BM_POW2(n) _BM_BIT(1,n) /* shift word w k bits to the left or to the right */ #define _BM_SHL(w,k) ((w)<<(k)) #define _BM_SHR(w,k) ((w)>>(k)) /* rotate word w (of bits n..0) k bits to the left or to the right */ #define _BM_ROL(w,n,k) (_BM_SHL((w),(k))&_BM_MASK(n,0))|_BM_SHR(((w)&_BM_MASK(n,0)),(n)-(k)) #define _BM_ROR(w,n,k) (_BM_SHR(((w)&_BM_MASK(n,0)),(k)))|_BM_SHL(((w),(n)-(k))&_BM_MASK(n,0)) /* * Some math functions */ #ifndef _M_MIN #define _M_MIN(a,b) (((a)<(b)) ? (a) : (b)) #endif #ifndef _M_MAX #define _M_MAX(a,b) (((a)>(b)) ? (a) : (b)) #endif #ifndef _M_ABS #define _M_ABS(a) (((a)>0) ? (a) : -(a)) #endif #ifndef _M_ALIGN #define _M_ALIGN(a) (((unsigned long int)(a)+(sizeof((void *)-1)))&(~(sizeof((void *)-1)))) #endif /* * A hacker macro for finding the offset of a `field' * in a structure of type `type'. */ #define _OffsetOf(type,s_field) \ ((unsigned int)(((char *)(&(((type *)0)->field)))-((char *)0))) /* * ACT data types */ enum act_type_en { act_type_ptr, act_type_int, act_type_long, act_type_double }; typedef enum act_type_en act_type_t; /* * Act return types */ typedef enum { ACT_OK = 0, ACT_ERR_ARG, ACT_ERR_USE, ACT_ERR_INT, ACT_ERR_IMP, ACT_ERR_SYS } act_rc_t; /* * ??? */ /* additional errno values */ #define ACT_E_NOMEM 0 #define ACT_E_INVAL 0 #define ACT_E_INTERN 0 /* positions */ #define ACT_POS_ABOVE 0 #define ACT_POS_BELOW 0 #define ACT_POS_BEFORE 0 #define ACT_POS_AFTER 0 /* walking */ #define ACT_MOV_PARENT 0 #define ACT_MOV_CHILD(n) 0 #define ACT_MOV_PREV 0 #define ACT_MOV_NEXT 0 /* boolean type */ typedef unsigned short int act_bool_t; #define ACT_CTX_KEY_SIZE ACT_CTX_ID(int,COMMON,0) #define ACT_CTX_KEY_LOAN ACT_CTX_ID(int,COMMON,1) #define ACT_CTX_KEY_ISPTR ACT_CTX_ID(int,COMMON,2) #define ACT_CTX_VAL_SIZE ACT_CTX_ID(int,COMMON,3) #define ACT_CTX_VAL_LOAN ACT_CTX_ID(int,COMMON,4) #define ACT_CTX_VAL_ISPTR ACT_CTX_ID(int,COMMON,5) #define ACT_CTX_VAL_EXPECT ACT_CTX_ID(int,COMMON,6) #include "act_lib.h" #include "act_ctx.h" #endif /* _ACT_H_ */