(root)/
gcc-13.2.0/
gcc/
testsuite/
objc-obj-c++-shared/
GNUStep/
CoreFoundation/
CFBase.h
       1  /* CFBase.h
       2     
       3     Copyright (C) 2010 Free Software Foundation, Inc.
       4     
       5     Written by: Stefan Bidigaray
       6     Date: January, 2010
       7     
       8     This file is part of the GNUstep CoreBase Library.
       9     
      10     This library is free software; you can redistribute it and/or
      11     modify it under the terms of the GNU Lesser General Public
      12     License as published by the Free Software Foundation; either
      13     version 2.1 of the License, or (at your option) any later version.
      14  
      15     This library is distributed in the hope that it will be useful,
      16     but WITHOUT ANY WARRANTY; without even the implied warranty of
      17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
      18     Lesser General Public License for more details.
      19  
      20     You should have received a copy of the GNU Lesser General Public
      21     License along with this library; see the file COPYING.LIB.
      22     If not, see <http://www.gnu.org/licenses/> or write to the 
      23     Free Software Foundation, 51 Franklin Street, Fifth Floor, 
      24     Boston, MA 02110-1301, USA.
      25  */
      26  
      27  
      28  #ifndef __COREFOUNDATION_CFBASE_H__
      29  #define __COREFOUNDATION_CFBASE_H__
      30  
      31  /* CoreFoundation defines __LITTLE_ENDIAN__ or __BIG_ENDIAN__ so we'll
      32   * do the same here for compatibility.
      33   */
      34  #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
      35  #define __LITTLE_ENDIAN__ 1
      36  #endif
      37  
      38  #include "CFAvailability.h"
      39  #include "../GNUstepBase/GSVersionMacros.h"
      40  
      41  /*
      42   * CoreFoundation types
      43   */
      44  typedef unsigned char Boolean;
      45  typedef unsigned char UInt8;
      46  typedef signed char SInt8;
      47  typedef unsigned short UInt16;
      48  typedef signed short SInt16;
      49  typedef unsigned int UInt32;
      50  typedef signed int SInt32;
      51  typedef unsigned long long UInt64;
      52  typedef signed long long SInt64;
      53  typedef SInt32 OSStatus;
      54  
      55  typedef float Float32;
      56  typedef double Float64;
      57  typedef UInt16 UniChar;
      58  typedef UInt8 *StringPtr;
      59  typedef const StringPtr *ConstStringPtr;
      60  typedef UInt8 Str255[256];
      61  typedef const Str255 *ConstStr255Param;
      62  typedef SInt16 OSErr;
      63  typedef SInt16 RegionCode;
      64  typedef SInt16 LangCode;
      65  typedef SInt16 ScriptCode;
      66  typedef UInt32 FourCharCode;
      67  #ifndef OSTYPE_DECLARED
      68  typedef FourCharCode OSType;
      69  #define OSTYPE_DECLARED
      70  #endif
      71  typedef UInt8 Byte;
      72  typedef SInt8 SignedByte;
      73  
      74  #ifndef UTF32Char               /* UTF32Char is also defined in GSConfig.h */
      75  typedef UInt32 UTF32Char;
      76  #endif
      77  typedef UInt16 UTF16Char;
      78  typedef UInt8 UTF8Char;
      79  
      80  #if !defined(CF_EXTERN_C_BEGIN)
      81  #if defined(__cplusplus)
      82  #define CF_EXTERN_C_BEGIN extern "C" {
      83  #define CF_EXTERN_C_END }
      84  #else
      85  #define CF_EXTERN_C_BEGIN
      86  #define CF_EXTERN_C_END
      87  #endif
      88  #endif
      89  
      90  #if defined(_WIN32)
      91  #if defined(BUILDING_SELF)
      92  #if defined(__cplusplus)
      93  #define CF_EXPORT extern "C" __declspec(dllexport)
      94  #else
      95  #define CF_EXPORT extern __declspec(dllexport)
      96  #endif
      97  #else
      98  #if defined(__cplusplus)
      99  #define CF_EXPORT extern "C" __declspec(dllimport)
     100  #else
     101  #define CF_EXPORT extern __declspec(dllimport)
     102  #endif
     103  #endif
     104  #else
     105  #if defined(__cplusplus)
     106  #define CF_EXPORT extern "C"
     107  #else
     108  #define CF_EXPORT extern
     109  #endif
     110  #endif
     111  
     112  #if !defined(__bool_true_false_are_defined)
     113  #define true 1
     114  #define false 0
     115  #endif
     116  
     117  #ifndef TRUE
     118  #define TRUE  1
     119  #endif
     120  #ifndef FALSE
     121  #define FALSE 0
     122  #endif
     123  
     124  #if !defined(CF_INLINE)
     125  #if defined(__GNUC__) && (__GNUC__ >= 4)
     126  #define CF_INLINE static __inline__ __attribute__((always_inline))
     127  #elif defined(__GNUC__)
     128  #define CF_INLINE static __inline__
     129  #elif defined(__MWERKS__) || defined(__cplusplus)
     130  #define CF_INLINE static inline
     131  #elif defined(_MSC_VER)
     132  #define CF_INLINE static __inline
     133  #elif _WIN32
     134  #define CF_INLINE static __inline__
     135  #else
     136  #define CF_INLINE static inline
     137  #endif
     138  #endif
     139  
     140  #if defined(__GNUC__) || defined(__llvm__)
     141  #define GS_PURE_FUNCTION __attribute__((pure))
     142  #else
     143  #define GS_PURE_FUNCTION
     144  #endif
     145  
     146  CF_EXTERN_C_BEGIN
     147  /** \defgroup CFTypeRef CFType Reference
     148      \{
     149   */
     150  typedef unsigned long CFTypeID;
     151  typedef const void *CFTypeRef;
     152  /** @}
     153   */
     154  
     155  /** \defgroup BaseUtils Base Utilities
     156      \{
     157   */
     158  /** An integer value to store a hash code. */
     159  typedef unsigned long CFHashCode;
     160  /** A bitfield for passing information to functions.  Can hold as many bits
     161      as a word.
     162   */
     163  typedef unsigned long CFOptionFlags;
     164  /** A signed integer representing an index, size, length or count. */
     165  typedef signed long CFIndex;
     166  
     167  /** A structure that represents a range of items in a container, such as
     168      an array.
     169   */
     170  typedef struct CFRange CFRange;
     171  struct CFRange
     172  {
     173    CFIndex location;
     174      /**< An integer representing the start location of the range, inclusive. */
     175    CFIndex length;
     176      /**< An integer representing the total number of items in the range */
     177  };
     178  
     179  /** Creates a CFRange structure.
     180      \param location The starting location.
     181      \param length The length.
     182      \return An initialized CFRange structure.
     183   */
     184  CF_INLINE CFRange
     185  CFRangeMake (CFIndex location, CFIndex length)
     186  {
     187    CFRange range;
     188  
     189    range.location = location;
     190    range.length = length;
     191    return range;
     192  }
     193  
     194  /* Returned by comparison functions */
     195  typedef enum
     196  {
     197    kCFCompareLessThan = -1,
     198    kCFCompareEqualTo = 0,
     199    kCFCompareGreaterThan = 1
     200  } CFComparisonResult;
     201  
     202  /* Return when a value is not found */
     203  enum
     204  {
     205    kCFNotFound = -1
     206  };
     207  
     208  /* Definition for standard comparison function callback. */
     209  typedef CFComparisonResult (*CFComparatorFunction) (const void *val1,
     210                                                      const void *val2,
     211                                                      void *context);
     212  
     213  /* CoreFoundation version numbers */
     214  /** \name Library Version Numbers
     215      \{
     216   */
     217  CF_EXPORT const double kCFCoreFoundationVersionNumber;
     218  #define kCFCoreFoundationVersionNumber10_0    196.40
     219  #define kCFCoreFoundationVersionNumber10_0_3  196.50
     220  #define kCFCoreFoundationVersionNumber10_1    226.00
     221  #define kCFCoreFoundationVersionNumber10_1_1  226.00
     222  #define kCFCoreFoundationVersionNumber10_1_2  227.20
     223  #define kCFCoreFoundationVersionNumber10_1_3  227.20
     224  #define kCFCoreFoundationVersionNumber10_1_4  227.30
     225  #define kCFCoreFoundationVersionNumber10_2    263.00
     226  #define kCFCoreFoundationVersionNumber10_2_1  263.10
     227  #define kCFCoreFoundationVersionNumber10_2_2  263.10
     228  #define kCFCoreFoundationVersionNumber10_2_3  263.30
     229  #define kCFCoreFoundationVersionNumber10_2_4  263.30
     230  #define kCFCoreFoundationVersionNumber10_2_5  263.50
     231  #define kCFCoreFoundationVersionNumber10_2_6  263.50
     232  #define kCFCoreFoundationVersionNumber10_2_7  263.50
     233  #define kCFCoreFoundationVersionNumber10_2_8  263.50
     234  #define kCFCoreFoundationVersionNumber10_3    299.00
     235  #define kCFCoreFoundationVersionNumber10_3_1  299.00
     236  #define kCFCoreFoundationVersionNumber10_3_2  299.00
     237  #define kCFCoreFoundationVersionNumber10_3_3  299.30
     238  #define kCFCoreFoundationVersionNumber10_3_4  299.31
     239  #define kCFCoreFoundationVersionNumber10_3_5  299.31
     240  #define kCFCoreFoundationVersionNumber10_3_6  299.32
     241  #define kCFCoreFoundationVersionNumber10_3_7  299.33
     242  #define kCFCoreFoundationVersionNumber10_3_8  299.33
     243  #define kCFCoreFoundationVersionNumber10_3_9  299.35
     244  #define kCFCoreFoundationVersionNumber10_4    368.00
     245  #define kCFCoreFoundationVersionNumber10_4_1  368.10
     246  #define kCFCoreFoundationVersionNumber10_4_2  368.11
     247  #define kCFCoreFoundationVersionNumber10_4_3  368.18
     248  #define kCFCoreFoundationVersionNumber10_4_4_Intel   368.26
     249  #define kCFCoreFoundationVersionNumber10_4_4_PowerPC 368.25
     250  #define kCFCoreFoundationVersionNumber10_4_5_Intel   368.26
     251  #define kCFCoreFoundationVersionNumber10_4_5_PowerPC 368.25
     252  #define kCFCoreFoundationVersionNumber10_4_6_Intel   368.26
     253  #define kCFCoreFoundationVersionNumber10_4_6_PowerPC 368.25
     254  #define kCFCoreFoundationVersionNumber10_4_7  368.27
     255  #define kCFCoreFoundationVersionNumber10_4_8  368.27
     256  #define kCFCoreFoundationVersionNumber10_4_9  368.28
     257  #define kCFCoreFoundationVersionNumber10_4_10 368.28
     258  #define kCFCoreFoundationVersionNumber10_4_11 368.31
     259  #define kCFCoreFoundationVersionNumber10_5    476.00
     260  #define kCFCoreFoundationVersionNumber10_5_1  476.00
     261  #define kCFCoreFoundationVersionNumber10_5_2  476.10
     262  #define kCFCoreFoundationVersionNumber10_5_3  476.13
     263  #define kCFCoreFoundationVersionNumber10_5_4  476.14
     264  #define kCFCoreFoundationVersionNumber10_5_5  476.15
     265  #define kCFCoreFoundationVersionNumber10_5_6  476.17
     266  /** \} */
     267  /** \} */
     268  
     269  #if __has_feature(attribute_cf_returns_retained)
     270  #define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
     271  #else
     272  #define CF_RETURNS_RETAINED
     273  #endif
     274  
     275  #if __has_feature(attribute_cf_returns_not_retained)
     276  #define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained))
     277  #else
     278  #define CF_RETURNS_NOT_RETAINED
     279  #endif
     280  
     281  /** \ingroup CFPropertyListRef
     282   */
     283  typedef CFTypeRef CFPropertyListRef;
     284  
     285  /** \ingroup CFStringRef
     286   */
     287  typedef const struct __CFString *CFStringRef;
     288  /** \ingroup CFMutableStringRef
     289   */
     290  typedef struct __CFString *CFMutableStringRef;
     291  
     292  
     293  
     294  /** \defgroup CFAllocatorRef CFAllocator Reference
     295      \brief CFAllocator is an opaque type used to allocate and deallocate
     296      memory.
     297      \{
     298   */
     299  /** \brief A reference to a CFAllocator object.
     300   */
     301  typedef const struct __CFAllocator *CFAllocatorRef;
     302  
     303  typedef void *(*CFAllocatorAllocateCallBack) (CFIndex allocSize,
     304                                                CFOptionFlags hint, void *info);
     305  typedef void (*CFAllocatorDeallocateCallBack) (void *ptr, void *info);
     306  typedef void *(*CFAllocatorReallocateCallBack) (void *ptr,
     307                                                  CFIndex newsize,
     308                                                  CFOptionFlags hint, void *info);
     309  typedef CFIndex (*CFAllocatorPreferredSizeCallBack) (CFIndex size,
     310                                                       CFOptionFlags hint,
     311                                                       void *info);
     312  typedef const void *(*CFAllocatorRetainCallBack) (const void *info);
     313  typedef void (*CFAllocatorReleaseCallBack) (const void *info);
     314  typedef CFStringRef (*CFAllocatorCopyDescriptionCallBack) (const void *info);
     315  
     316  struct _CFAllocatorContext
     317  {
     318    CFIndex version;
     319    void *info;
     320    CFAllocatorRetainCallBack retain;
     321    CFAllocatorReleaseCallBack release;
     322    CFAllocatorCopyDescriptionCallBack copyDescription;
     323    CFAllocatorAllocateCallBack allocate;
     324    CFAllocatorReallocateCallBack reallocate;
     325    CFAllocatorDeallocateCallBack deallocate;
     326    CFAllocatorPreferredSizeCallBack preferredSize;
     327  };
     328  typedef struct _CFAllocatorContext CFAllocatorContext;
     329  
     330  /** The default allocator and is equivalent to NULL.
     331      \see CFAllocatorGetDefault()
     332      \see CFAllocatorSetDefault()
     333   */
     334  CF_EXPORT CFAllocatorRef kCFAllocatorDefault;
     335  /** The default system allocator is used internally by GNUstep and is the
     336      default allocator if none is been defined.
     337      \see CFAllocatorSetDefault()
     338   */
     339  CF_EXPORT CFAllocatorRef kCFAllocatorSystemDefault;
     340  /** An allocator that uses the system's malloc, realloc and free functions.
     341   */
     342  CF_EXPORT CFAllocatorRef kCFAllocatorMalloc;
     343  #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
     344  /** Equivalent to kCFAllocatorSystemDefault
     345   */
     346  CF_EXPORT CFAllocatorRef kCFAllocatorMallocZone;
     347  #endif
     348  /** The NULL allocator does perform any operations.  Can be passed as
     349      a deallocator if you do not want GNUstep to deallocate the data.
     350   */
     351  CF_EXPORT CFAllocatorRef kCFAllocatorNull;
     352  /** This is a special case allocator directing CFAllocatorCreate() to use
     353      the given CFAllocatorContext structure to allocate the new allocator.
     354   */
     355  CF_EXPORT CFAllocatorRef kCFAllocatorUseContext;
     356  
     357  /** Create a new CFAllocator.
     358      \param allocator The allocator used to create this allocator or
     359        kCFAllocatorUseContext to use the functions in \b context.
     360      \param context The new allocator's context functions.
     361      \return A new CFAllocator or NULL in case of failure.
     362      \see CFAllocatorContext
     363   */
     364  CF_EXPORT CFAllocatorRef
     365  CFAllocatorCreate (CFAllocatorRef allocator, CFAllocatorContext * context);
     366  
     367  /** Allocate new memory.
     368      \param allocator The CFAllocator to use.
     369      \param size The number of bytes to allocate.
     370      \param hint Option flags.  Currently unused and should be 0.
     371      \return Newly allocated memory of NULL in case of failure.
     372      \see CFAllocatorDeallocate()
     373   */
     374  CF_EXPORT void *CFAllocatorAllocate (CFAllocatorRef allocator, CFIndex size,
     375                                       CFOptionFlags hint);
     376  
     377  /** Deallocate the memory pointed to by \b ptr.
     378      \param allocator The CFAllocator to use.
     379      \param ptr A pointer previously allocated by CFAllocatorAllocate().
     380      \see CFAllocatorAllocate()
     381   */
     382  CF_EXPORT void CFAllocatorDeallocate (CFAllocatorRef allocator, void *ptr);
     383  
     384  CF_EXPORT CFIndex
     385  CFAllocatorGetPreferredSizeForSize (CFAllocatorRef allocator, CFIndex size,
     386                                      CFOptionFlags hint);
     387  
     388  CF_EXPORT void *CFAllocatorReallocate (CFAllocatorRef allocator, void *ptr,
     389                                         CFIndex newsize, CFOptionFlags hint);
     390  
     391  CF_EXPORT CFAllocatorRef CFAllocatorGetDefault (void);
     392  
     393  CF_EXPORT void CFAllocatorSetDefault (CFAllocatorRef allocator);
     394  
     395  CF_EXPORT void
     396  CFAllocatorGetContext (CFAllocatorRef allocator, CFAllocatorContext * context);
     397  
     398  CF_EXPORT CFTypeID CFAllocatorGetTypeID (void);
     399  /** \} */
     400  
     401  
     402  
     403  /** \ingroup CFTypeRef
     404      \{
     405   */
     406  /* These function will be implemented in CFRuntime.c since they 
     407     require runtime support. */
     408  CF_EXPORT CFStringRef CFCopyDescription (CFTypeRef cf);
     409  
     410  CF_EXPORT CFStringRef CFCopyTypeIDDescription (CFTypeID typeID);
     411  
     412  CF_EXPORT Boolean CFEqual (CFTypeRef cf1, CFTypeRef cf2);
     413  
     414  CF_EXPORT CFAllocatorRef CFGetAllocator (CFTypeRef cf);
     415  
     416  CF_EXPORT CFIndex CFGetRetainCount (CFTypeRef cf);
     417  
     418  CF_EXPORT CFTypeID CFGetTypeID (CFTypeRef cf);
     419  
     420  CF_EXPORT CFHashCode CFHash (CFTypeRef cf);
     421  
     422  #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
     423  CF_EXPORT CFTypeRef CFMakeCollectable (CFTypeRef cf);
     424  #endif
     425  
     426  CF_EXPORT void CFRelease (CFTypeRef cf);
     427  
     428  CF_EXPORT CFTypeRef CFRetain (CFTypeRef cf);
     429  
     430  CF_EXPORT CFTypeRef CFAutorelease(CFTypeRef arg);
     431  
     432  #if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)
     433  CF_EXPORT void *_CFBridgingRelease (CFTypeRef cf);
     434  CF_EXPORT CFTypeRef _CFBridgingRetain (void *obj);
     435  
     436  #if __has_feature(objc_arc)
     437  #define CFBridgingRetain(x) (__bridge_retained CFTypeRef)(x)
     438  #define CFBridgingRelease(x) (__bridge_transfer id)(x)
     439  #elif __OBJC__
     440  #define CFBridgingRetain(x) _CFBridgingRetain((void *)(x))
     441  #define CFBridgingRelease(x) (id)_CFBridgingRelease((x))
     442  #else
     443  #define CFBridgingRetain(x) _CFBridgingRetain((void *)(x))
     444  #define CFBridgingRelease(x) _CFBridgingRelease((x))
     445  #endif
     446  #endif
     447  /** \} */
     448  
     449  
     450  
     451  /** \defgroup CFNullRef CFNull Reference
     452      \{
     453   */
     454  #if OS_API_VERSION(MAC_OS_X_VERSION_10_2, GS_API_LATEST)
     455  typedef struct __CFNull *CFNullRef;
     456  
     457  CF_EXPORT CFNullRef kCFNull;
     458  
     459  CFTypeID CFNullGetTypeID (void);
     460  #endif
     461  /** \} */
     462  
     463  CF_EXTERN_C_END
     464  #endif /* __COREFOUNDATION_CFBASE_H__ */