xref: /PHP-7.4/ext/intl/calendar/calendar_class.h (revision d8200e48)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | This source file is subject to version 3.01 of the PHP license,      |
6    | that is bundled with this package in the file LICENSE, and is        |
7    | available through the world-wide-web at the following url:           |
8    | http://www.php.net/license/3_01.txt                                  |
9    | If you did not receive a copy of the PHP license and are unable to   |
10    | obtain it through the world-wide-web, please send a note to          |
11    | license@php.net so we can mail you a copy immediately.               |
12    +----------------------------------------------------------------------+
13    | Authors: Gustavo Lopes <cataphract@php.net>                          |
14    +----------------------------------------------------------------------+
15  */
16 
17 #ifndef CALENDAR_CLASS_H
18 #define CALENDAR_CLASS_H
19 
20 //redefinition of inline in PHP headers causes problems, so include this before
21 #include <math.h>
22 
23 #include <php.h>
24 #include "intl_error.h"
25 #include "intl_data.h"
26 
27 #ifndef USE_CALENDAR_POINTER
28 typedef void Calendar;
29 #else
30 using icu::Calendar;
31 #endif
32 
33 typedef struct {
34 	// 	error handling
35 	intl_error  err;
36 
37 	// ICU calendar
38 	Calendar*	ucal;
39 
40 	zend_object	zo;
41 } Calendar_object;
42 
php_intl_calendar_fetch_object(zend_object * obj)43 static inline Calendar_object *php_intl_calendar_fetch_object(zend_object *obj) {
44 	return (Calendar_object *)((char*)(obj) - XtOffsetOf(Calendar_object, zo));
45 }
46 #define Z_INTL_CALENDAR_P(zv) php_intl_calendar_fetch_object(Z_OBJ_P(zv))
47 
48 #define CALENDAR_ERROR(co)		(co)->err
49 #define CALENDAR_ERROR_P(co)	&(CALENDAR_ERROR(co))
50 
51 #define CALENDAR_ERROR_CODE(co)		INTL_ERROR_CODE(CALENDAR_ERROR(co))
52 #define CALENDAR_ERROR_CODE_P(co)	&(INTL_ERROR_CODE(CALENDAR_ERROR(co)))
53 
54 #define CALENDAR_METHOD_INIT_VARS		        INTL_METHOD_INIT_VARS(Calendar, co)
55 #define CALENDAR_METHOD_FETCH_OBJECT_NO_CHECK	INTL_METHOD_FETCH_OBJECT(INTL_CALENDAR, co)
56 #define CALENDAR_METHOD_FETCH_OBJECT \
57 	CALENDAR_METHOD_FETCH_OBJECT_NO_CHECK; \
58 	if (co->ucal == NULL) \
59 	{ \
60 		intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlCalendar", 0); \
61 		RETURN_FALSE; \
62 	}
63 
64 void calendar_object_create(zval *object, Calendar *calendar);
65 
66 Calendar *calendar_fetch_native_calendar(zval *object);
67 
68 void calendar_object_construct(zval *object, Calendar *calendar);
69 
70 void calendar_register_IntlCalendar_class(void);
71 
72 extern zend_class_entry *Calendar_ce_ptr,
73 						*GregorianCalendar_ce_ptr;
74 
75 extern zend_object_handlers Calendar_handlers;
76 
77 #endif /* #ifndef CALENDAR_CLASS_H */
78