File: typeEncodingHelper.h

package info (click to toggle)
gnustep-base 1.31.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,580 kB
  • sloc: objc: 239,446; ansic: 36,519; cpp: 122; sh: 112; makefile: 100; xml: 32
file content (62 lines) | stat: -rw-r--r-- 2,728 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/** Type-Encoding Helper
   Copyright (C) 2024 Free Software Foundation, Inc.

   Written by:  Hugo Melder <hugo@algoriddim.com>
   Created: August 2024

   This file is part of the GNUstep Base Library.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the Free
   Software Foundation, Inc., 31 Milk Street #960789 Boston, MA 02196 USA.
*/

#ifndef __TYPE_ENCODING_HELPER_H
#define __TYPE_ENCODING_HELPER_H

/*
* Type-encoding for known structs in Foundation and CoreGraphics.
* From macOS 14.4.1 23E224 arm64:

* @encoding(NSRect) -> {CGRect={CGPoint=dd}{CGSize=dd}}
* @encoding(CGRect) -> {CGRect={CGPoint=dd}{CGSize=dd}}
* @encoding(NSPoint) -> {CGPoint=dd}
* @encoding(CGPoint) -> {CGPoint=dd}
* @encoding(NSSize) -> {CGSize=dd}
* @encoding(CGSize) -> {CGSize=dd}
* @encoding(NSRange) -> {_NSRange=QQ}
* @encoding(CFRange) -> {?=qq}
* @encoding(NSEdgeInsets) -> {NSEdgeInsets=dddd}
*
* Note that NSRange and CFRange are not toll-free bridged.
* You cannot pass a CFRange to +[NSValue valueWithRange:]
* as type encoding is different.
*
* We cannot enforce this using static asserts, as @encode
* is not a constexpr. It is therefore checked in
* Tests/base/KVC/type_encoding.m
*/

static const char *CGPOINT_ENCODING_PREFIX = "{CGPoint=";
static const char *CGSIZE_ENCODING_PREFIX = "{CGSize=";
static const char *CGRECT_ENCODING_PREFIX = "{CGRect=";
static const char *NSINSETS_ENCODING_PREFIX __attribute__((used)) = "{NSEdgeInsets=";
static const char *NSRANGE_ENCODING_PREFIX = "{_NSRange=";

#define IS_CGPOINT_ENCODING(encoding) (strncmp(encoding, CGPOINT_ENCODING_PREFIX, strlen(CGPOINT_ENCODING_PREFIX)) == 0)
#define IS_CGSIZE_ENCODING(encoding) (strncmp(encoding, CGSIZE_ENCODING_PREFIX, strlen(CGSIZE_ENCODING_PREFIX)) == 0)
#define IS_CGRECT_ENCODING(encoding) (strncmp(encoding, CGRECT_ENCODING_PREFIX, strlen(CGRECT_ENCODING_PREFIX)) == 0)
#define IS_NSINSETS_ENCODING(encoding) (strncmp(encoding, NSINSETS_ENCODING_PREFIX, strlen(NSINSETS_ENCODING_PREFIX)) == 0)
#define IS_NSRANGE_ENCODING(encoding) (strncmp(encoding, NSRANGE_ENCODING_PREFIX, strlen(NSRANGE_ENCODING_PREFIX)) == 0)

#endif /* __TYPE_ENCODING_HELPER_H */