Documentation | SupportKit | TypeConstants
SYNOPSIS
Perl
use HaikuR1::TypeConstants qw(B_STRING_TYPE B_MESSAGE_TYPE)
Python
from HaikuR1.SupportKit import B_STRING_TYPE, B_MESSAGE_TYPE
Python
Note that TypeConstants
does not actually exist as a submodule; instead,
the constants are imported from SupportKit
.
DESCRIPTION
Contains the type constants and some utility functions
For more information on type constants, see the Be Book descriptions.
FUNCTIONS
These utility functions are not part of the Haiku R1 API; they are for convenience.
guess_type
Given a native value, tries to guess the type.
It uses a relatively simple guessing algorithm:
For integers, it returns the highest range it fits into, in the order B_INT32_TYPE B_UINT32_TYPE B_INT64_TYPE B_UINT64_TYPE.
For floating point numbers, it returns B_DOUBLE_TYPE.
For booleans, it returns B_BOOL_TYPE.
Perl
Since Perl does not have a distinct boolean type, the Perl version will never return B_BOOL_TYPE.
For a string that does not contain embedded bytes, it returns B_STRING_TYPE.
For a 1-dimensional native list, it returns B_STRING_LIST_TYPE; for any other native list, it returns B_PATTERN_TYPE.
For a B_CMAP8 Bitmap object that is
32x32
or 16x16
, it returns B_LARGE_ICON_TYPE or B_MINI_ICON_TYPE,
respectively.
For several object classes, it returns the appropriate type:
- AffineTransform: B_AFFINE_TRANSFORM_TYPE
- Alignment: B_ALIGNMENT_TYPE
- Message: B_MESSAGE_TYPE
- Messenger: B_MESSENGER_TYPE
- Point: B_POINT_TYPE
- PropertyInfo: B_PROPERTY_INFO_TYPE
- Rect: B_RECT_TYPE
- rgb_color: B_RGB_32_BIT_TYPE
- Size: B_SIZE_TYPE
For anything else, it returns B_RAW_TYPE.
Perl
my $type = guess_type($value);
Python
type = guess_type(value)
value
A native value.
For anything else, it returns B_RAW_TYPE.
value_to_typed_data
For supported types, it converts the native value into a string of bytes.
Returns two values: the byte string and the type that was used to convert the value.
Perl
my ($data, $type) = value_to_typed_data($value, $type);
Python
retval = value_to_typed_data(value, type);
value
A native value.
type
The type to use for conversion. If not provided, the guess_type algorithm will be used.
typed_data_to_value
For supported types, it converts a string of bytes into a native value.
Perl
my $value = value_to_typed_data($data, $type);
Python
value = value_to_typed_data(data, type);
data
A byte string.
type
The type to use for conversion.
CONSTANTS
Basic types
Perl
use HaikuR1::TypeConstants qw(:types)
Python
Python does not support export tags.
- B_AFFINE_TRANSFORM_TYPE
- B_ALIGNMENT_TYPE
- B_ANY_TYPE (automatic conversion not supported)
- B_ATOM_TYPE (automatic conversion not supported)
- B_ATOMREF_TYPE (automatic conversion not supported)
- B_BOOL_TYPE
- B_CHAR_TYPE
- B_COLOR_8_BIT_TYPE (automatic conversion not supported)
- B_DOUBLE_TYPE
- B_FLOAT_TYPE
- B_GRAYSCALE_8_BIT_TYPE (automatic conversion not supported)
- B_INT16_TYPE
- B_INT32_TYPE
- B_INT64_TYPE
- B_INT8_TYPE
- B_LARGE_ICON_TYPE
- B_MEDIA_PARAMETER_GROUP_TYPE (automatic conversion not supported)
- B_MEDIA_PARAMETER_TYPE (automatic conversion not supported)
- B_MEDIA_PARAMETER_WEB_TYPE (automatic conversion not supported)
- B_MESSAGE_TYPE
- B_MESSENGER_TYPE
- B_MIME_TYPE
- B_MIME_STRING_TYPE
- B_MINI_ICON_TYPE
- B_MONOCHROME_1_BIT_TYPE (automatic conversion not supported)
- B_OBJECT_TYPE (automatic conversion not supported)
- B_OFF_T_TYPE
- B_PATTERN_TYPE
- B_POINTER_TYPE
- B_POINT_TYPE
- B_PROPERTY_INFO_TYPE
- B_RAW_TYPE
- B_RECT_TYPE
- B_REF_TYPE
- B_RGB_32_BIT_TYPE
- B_RGB_COLOR_TYPE
- B_SIZE_TYPE
- B_SIZE_T_TYPE
- B_SSIZE_T_TYPE
- B_STRING_TYPE
- B_STRING_LIST_TYPE
- B_TIME_TYPE
- B_UINT16_TYPE
- B_UINT32_TYPE
- B_UINT64_TYPE
- B_UINT8_TYPE
- B_VECTOR_ICON_TYPE (automatic conversion not supported)
- B_XATTR_TYPE (automatic conversion not supported)
- B_NETWORK_ADDRESS_TYPE (automatic conversion not supported)
- B_ASCII_TYPE (automatic conversion not supported)
URL types
Automatic conversion is not supported for these types.
Perl
use HaikuR1::TypeConstants qw(:url_types)
Python
Python does not support export tags.
- B_URL_HTTP
- B_URL_HTTPS
- B_URL_FTP
- B_URL_GOPHER
- B_URL_MAILTO
- B_URL_NEWS
- B_URL_NNTP
- B_URL_TELNET
- B_URL_RLOGIN
- B_URL_TN3270
- B_URL_WAIS
- B_URL_FILE