-
Notifications
You must be signed in to change notification settings - Fork 0
/
DKNumber.h
151 lines (110 loc) · 8.35 KB
/
DKNumber.h
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*****************************************************************************************
DKNumber.h
Copyright (c) 2014 Derek W. Nylen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*****************************************************************************************/
#ifndef _DK_NUMBER_H_
#define _DK_NUMBER_H_
#ifdef __cplusplus
extern "C"
{
#endif
#define DKNumberInt8 DKEncode( DKEncodingTypeInt8, 1 )
#define DKNumberInt16 DKEncode( DKEncodingTypeInt16, 1 )
#define DKNumberInt32 DKEncode( DKEncodingTypeInt32, 1 )
#define DKNumberInt64 DKEncode( DKEncodingTypeInt64, 1 )
#define DKNumberUInt8 DKEncode( DKEncodingTypeUInt8, 1 )
#define DKNumberUInt16 DKEncode( DKEncodingTypeUInt16, 1 )
#define DKNumberUInt32 DKEncode( DKEncodingTypeUInt32, 1 )
#define DKNumberUInt64 DKEncode( DKEncodingTypeUInt64, 1 )
#define DKNumberFloat DKEncode( DKEncodingTypeFloat, 1 )
#define DKNumberDouble DKEncode( DKEncodingTypeDouble, 1 )
#define DKNumberUUID DKEncode( DKEncodingTypeUInt8, 16 )
#define DKNumberDate DKEncode( DKEncodingTypeDouble, 1 )
// typedef struct DKNumber * DKNumberRef; -- Declared in DKPlatform.h
DK_API DKClassRef DKNumberClass( void );
DK_API DKClassRef DKVariableNumberClass( void );
#define DKNumber( value, encoding ) DKAutorelease( DKNumberInit( DKAlloc( DKNumberClass() ), value, encoding ) )
#define DKNewNumber( value, encoding ) DKNumberInit( DKAlloc( DKNumberClass() ), value, encoding )
#define DKNumberWithNumber( number, encodingType ) DKAutorelease( DKNumberInitWithNumber( DKAlloc( DKNumberClass() ), number, encodingType ) )
#define DKNewNumberWithNumber( number, encodingType ) DKNumberInitWithNumber( DKAlloc( DKNumberClass() ), number, encodingType )
#define DKVariableNumber( value, encoding ) DKAutorelease( DKNumberInit( DKAlloc( DKVariableNumberClass() ), value, encoding ) )
#define DKNewVariableNumber( value, encoding ) DKNumberInit( DKAlloc( DKVariableNumberClass() ), value, encoding )
DK_API DKNumberRef DKNewNumberWithInt32( int32_t x );
DK_API DKNumberRef DKNewNumberWithInt64( int64_t x );
DK_API DKNumberRef DKNewNumberWithUInt32( uint32_t x );
DK_API DKNumberRef DKNewNumberWithUInt64( uint64_t x );
DK_API DKNumberRef DKNewNumberWithFloat( float x );
DK_API DKNumberRef DKNewNumberWithDouble( double x );
DK_API DKNumberRef DKNewNumberWithUUID( const DKUUID * uuid ); // Passing NULL will generate a new UUID
DK_API DKNumberRef DKNewNumberWithDate( const DKDateTime * date ); // Passing NULL will retrieve the current date+time
#define DKNumberWithInt32( x ) DKAutorelease( DKNewNumberWithInt32( x ) )
#define DKNumberWithInt64( x ) DKAutorelease( DKNewNumberWithInt64( x ) )
#define DKNumberWithUInt32( x ) DKAutorelease( DKNewNumberWithUInt32( x ) )
#define DKNumberWithUInt64( x ) DKAutorelease( DKNewNumberWithUInt64( x ) )
#define DKNumberWithFloat( x ) DKAutorelease( DKNewNumberWithFloat( x ) )
#define DKNumberWithDouble( x ) DKAutorelease( DKNewNumberWithDouble( x ) )
#define DKNumberWithUUID( x ) DKAutorelease( DKNewNumberWithUUID( x ) )
#define DKNumberWithDate( x ) DKAutorelease( DKNewNumberWithDate( x ) )
DK_API DKObjectRef DKNumberInit( DKObjectRef _self, const void * value, DKEncoding encoding );
DK_API DKObjectRef DKNumberInitWithNumber( DKObjectRef _self, DKNumberRef number, DKEncodingType encodingType );
DK_API DKEncoding DKNumberGetEncoding( DKNumberRef _self );
DK_API size_t DKNumberGetValue( DKNumberRef _self, void * value );
DK_API size_t DKNumberSetValue( DKNumberRef _self, const void * value, DKEncoding encoding ); // Variable numbers only
DK_API const void* DKNumberGetValuePtr( DKNumberRef _self );
DK_API void * DKNumberGetVariableValuePtr( DKNumberRef _self ); // Variable numbers only
DK_API size_t DKNumberCastValue( DKNumberRef _self, void * value, DKEncoding encoding );
DK_API const void* DKNumberQueryValuePtr( DKNumberRef _self, DKEncoding * encoding );
DK_API void * DKNumberQueryVariableValuePtr( DKNumberRef _self, DKEncoding * encoding );
#define DKNumberGetValueAs( _self, type ) (*((type *)DKNumberGetValuePtr( _self )))
DK_API void DKNumberEnumerateValue( DKNumberRef _self, DKEncodingType encodingType,
void (*callback)( const void * value, size_t valueIndex, void * context ), void * context );
DK_API void DKNumberSetEnumeratedValue( DKNumberRef _self, DKEncodingType encodingType,
void (*callback)( void * value, size_t valueIndex, void * context ), void * context ); // Variable numbers only
DK_API void DKNumberEnumerateMatrixValue( DKNumberRef _self, DKEncodingType encodingType,
void (*callback)( const void * value, unsigned int row, unsigned int col, void * context ), void * context );
DK_API void DKNumberSetEnumeratedMatrixValue( DKNumberRef _self, DKEncodingType encodingType,
void (*callback)( void * value, unsigned int row, unsigned int col, void * context ), void * context ); // Variable numbers only
DK_API bool DKNumberGetBool( DKNumberRef _self );
DK_API int32_t DKNumberGetInt32( DKNumberRef _self );
DK_API int64_t DKNumberGetInt64( DKNumberRef _self );
DK_API float DKNumberGetFloat( DKNumberRef _self );
DK_API double DKNumberGetDouble( DKNumberRef _self );
#define DKNumberGetString( _self ) DKNumberFormatString( _self, " " )
#define DKNumberGetInt8( _self ) ((_self) ? *((int8_t *)DKNumberGetValuePtr( _self )) : 0)
#define DKNumberGetInt16( _self ) ((_self) ? *((int16_t *)DKNumberGetValuePtr( _self )) : 0)
//#define DKNumberGetInt32( _self ) ((_self) ? *((int32_t *)DKNumberGetValuePtr( _self )) : 0)
//#define DKNumberGetInt64( _self ) ((_self) ? *((int64_t *)DKNumberGetValuePtr( _self )) : 0)
#define DKNumberGetUInt8( _self ) ((_self) ? *((uint8_t *)DKNumberGetValuePtr( _self )) : 0)
#define DKNumberGetUInt16( _self ) ((_self) ? *((uint16_t *)DKNumberGetValuePtr( _self )) : 0)
#define DKNumberGetUInt32( _self ) ((_self) ? *((uint32_t *)DKNumberGetValuePtr( _self )) : 0)
#define DKNumberGetUInt64( _self ) ((_self) ? *((uint64_t *)DKNumberGetValuePtr( _self )) : 0)
//#define DKNumberGetFloat( _self ) ((_self) ? *((float *)DKNumberGetValuePtr( _self )) : 0)
//#define DKNumberGetDouble( _self ) ((_self) ? *((double *)DKNumberGetValuePtr( _self )) : 0)
#define DKNumberGetUUID( _self ) ((_self) ? *((DKUUID *)DKNumberGetValuePtr( _self )) : DKUUIDZero)
#define DKNumberGetDate( _self ) ((_self) ? *((DKDateTime *)DKNumberGetValuePtr( _self )) : 0)
DK_API bool DKNumberEqual( DKNumberRef a, DKNumberRef b );
DK_API int DKNumberCompare( DKNumberRef a, DKNumberRef b );
DK_API DKHashCode DKNumberHash( DKNumberRef _self );
DK_API DKStringRef DKNumberFormatString( DKNumberRef _self, const char * seperator );
DK_API DKStringRef DKNumberGetDescription( DKNumberRef _self );
// Utility function for converting number types
DK_API size_t DKNumberConvert( const void * src, DKEncoding srcType, void * dst, DKEncoding dstType );
#ifdef __cplusplus
}
#endif
#endif // _DK_NUMBER_H_