ObjFW
src/OFBlock.h
00001 /*
00002  * Copyright (c) 2008, 2009, 2010, 2011
00003  *   Jonathan Schleifer <js@webkeks.org>
00004  *
00005  * All rights reserved.
00006  *
00007  * This file is part of ObjFW. It may be distributed under the terms of the
00008  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
00009  * the packaging of this file.
00010  *
00011  * Alternatively, it may be distributed under the terms of the GNU General
00012  * Public License, either version 2 or 3, which can be found in the file
00013  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
00014  * file.
00015  */
00016 
00017 #import "OFObject.h"
00018 
00019 typedef struct of_block_literal_t {
00020         Class isa;
00021         int flags;
00022         int reserved;
00023         void (*invoke)(void *, ...);
00024         struct of_block_descriptor_t {
00025                 unsigned long reserved;
00026                 unsigned long size;
00027                 void (*copy_helper)(void *dest, void *src);
00028                 void (*dispose_helper)(void *src);
00029                 const char *signature;
00030         } *descriptor;
00031 } of_block_literal_t;
00032 
00033 typedef struct of_block_byref_t of_block_byref_t;
00034 struct of_block_byref_t {
00035         Class isa;
00036         of_block_byref_t *forwarding;
00037         int flags;
00038         int size;
00039         void (*byref_keep)(void *dest, void *src);
00040         void (*byref_dispose)(void*);
00041 };
00042 
00043 enum {
00044         OF_BLOCK_HAS_COPY_DISPOSE = (1 << 25),
00045         OF_BLOCK_HAS_CTOR         = (1 << 26),
00046         OF_BLOCK_IS_GLOBAL        = (1 << 28),
00047         OF_BLOCK_HAS_STRET        = (1 << 29),
00048         OF_BLOCK_HAS_SIGNATURE    = (1 << 30),
00049 };
00050 #define OF_BLOCK_REFCOUNT_MASK \
00051         ~(OF_BLOCK_HAS_COPY_DISPOSE | OF_BLOCK_HAS_CTOR | OF_BLOCK_IS_GLOBAL | \
00052         OF_BLOCK_HAS_STRET | OF_BLOCK_HAS_SIGNATURE)
00053 
00054 enum {
00055         OF_BLOCK_FIELD_IS_OBJECT =   3,
00056         OF_BLOCK_FIELD_IS_BLOCK  =   7,
00057         OF_BLOCK_FIELD_IS_BYREF  =   8,
00058         OF_BLOCK_FIELD_IS_WEAK   =  16,
00059         OF_BLOCK_BYREF_CALLER    = 128,
00060 };
00061 
00062 #ifdef __cplusplus
00063 extern "C" {
00064 #endif
00065 extern void* _Block_copy(const void*);
00066 extern void _Block_release(const void*);
00067 #ifdef __cplusplus
00068 }
00069 #endif
00070 
00071 #ifndef Block_copy
00072 # define Block_copy(x) ((__typeof__(x))_Block_copy((const void*)(x)))
00073 #endif
00074 #ifndef Block_release
00075 # define Block_release(x) _Block_release((const void*)(x))
00076 #endif
00077 
00078 @interface OFBlock: OFObject
00079 @end
00080 
00081 @interface OFStackBlock: OFBlock
00082 @end
00083 
00084 @interface OFGlobalBlock: OFBlock
00085 @end
00086 
00087 @interface OFMallocBlock: OFBlock
00088 @end
 All Classes Functions Variables