1 /*
2 +----------------------------------------------------------------------+
3 | PHP Version 5 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1997-2007 The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Author: Alexandre Kalendarev akalend@mail.ru Copyright (c) 2009-2010 |
16 | Lead: |
17 | - Pieter de Zwart |
18 | Maintainers: |
19 | - Brad Rodriguez |
20 | - Jonathan Tansavatdi |
21 +----------------------------------------------------------------------+
22 */
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "php.h"
28 #include "zend_exceptions.h"
29 #include "php_amqp.h"
30
31 zend_class_entry *amqp_decimal_class_entry;
32 #define this_ce amqp_decimal_class_entry
33
34 static const PHP5to7_param_long_type_t AMQP_DECIMAL_EXPONENT_MIN = 0;
35 static const PHP5to7_param_long_type_t AMQP_DECIMAL_EXPONENT_MAX = UINT8_MAX;
36 static const PHP5to7_param_long_type_t AMQP_DECIMAL_SIGNIFICAND_MIN = 0;
37 static const PHP5to7_param_long_type_t AMQP_DECIMAL_SIGNIFICAND_MAX = UINT32_MAX;
38
39
40 /* {{{ proto AMQPDecimal::__construct(int $e, int $n)
41 */
PHP_METHOD(amqp_decimal_class,__construct)42 static PHP_METHOD(amqp_decimal_class, __construct)
43 {
44 PHP5to7_param_long_type_t exponent, significand;
45
46 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &exponent, &significand) == FAILURE) {
47 return;
48 }
49
50 if (exponent < AMQP_DECIMAL_EXPONENT_MIN) {
51 zend_throw_exception_ex(amqp_value_exception_class_entry, 0 TSRMLS_CC, "Decimal exponent value must be unsigned.");
52 return;
53 }
54
55 if (exponent > AMQP_DECIMAL_EXPONENT_MAX) {
56 zend_throw_exception_ex(amqp_value_exception_class_entry, 0 TSRMLS_CC, "Decimal exponent value must be less than %u.", AMQP_DECIMAL_EXPONENT_MAX);
57 return;
58 }
59 if (significand < AMQP_DECIMAL_SIGNIFICAND_MIN) {
60 zend_throw_exception_ex(amqp_value_exception_class_entry, 0 TSRMLS_CC, "Decimal significand value must be unsigned.");
61 return;
62 }
63
64 if (significand > AMQP_DECIMAL_SIGNIFICAND_MAX) {
65 zend_throw_exception_ex(amqp_value_exception_class_entry, 0 TSRMLS_CC, "Decimal significand value must be less than %u.", AMQP_DECIMAL_SIGNIFICAND_MAX);
66 return;
67 }
68
69 zend_update_property_long(this_ce, getThis(), ZEND_STRL("exponent"), exponent TSRMLS_CC);
70 zend_update_property_long(this_ce, getThis(), ZEND_STRL("significand"), significand TSRMLS_CC);
71 }
72 /* }}} */
73
74 /* {{{ proto int AMQPDecimal::getExponent()
75 Get exponent */
PHP_METHOD(amqp_decimal_class,getExponent)76 static PHP_METHOD(amqp_decimal_class, getExponent)
77 {
78 PHP5to7_READ_PROP_RV_PARAM_DECL;
79 PHP_AMQP_NOPARAMS();
80
81 PHP_AMQP_RETURN_THIS_PROP("exponent");
82 }
83 /* }}} */
84
85 /* {{{ proto int AMQPDecimal::getSignificand()
86 Get E */
PHP_METHOD(amqp_decimal_class,getSignificand)87 static PHP_METHOD(amqp_decimal_class, getSignificand)
88 {
89 PHP5to7_READ_PROP_RV_PARAM_DECL;
90 PHP_AMQP_NOPARAMS();
91
92 PHP_AMQP_RETURN_THIS_PROP("significand");
93 }
94 /* }}} */
95
96
97 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_decimal_class_construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 2)
98 ZEND_ARG_INFO(0, exponent)
99 ZEND_ARG_INFO(0, significand)
100 ZEND_END_ARG_INFO()
101
102 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_decimal_class_getExponent, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
103 ZEND_END_ARG_INFO()
104
105 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_decimal_class_getSignificand, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
106 ZEND_END_ARG_INFO()
107
108
109 zend_function_entry amqp_decimal_class_functions[] = {
110 PHP_ME(amqp_decimal_class, __construct, arginfo_amqp_decimal_class_construct, ZEND_ACC_PUBLIC)
111 PHP_ME(amqp_decimal_class, getExponent, arginfo_amqp_decimal_class_getExponent, ZEND_ACC_PUBLIC)
112 PHP_ME(amqp_decimal_class, getSignificand, arginfo_amqp_decimal_class_getSignificand, ZEND_ACC_PUBLIC)
113
114 {NULL, NULL, NULL}
115 };
116
117
PHP_MINIT_FUNCTION(amqp_decimal)118 PHP_MINIT_FUNCTION(amqp_decimal)
119 {
120 zend_class_entry ce;
121
122 INIT_CLASS_ENTRY(ce, "AMQPDecimal", amqp_decimal_class_functions);
123 this_ce = zend_register_internal_class(&ce TSRMLS_CC);
124 this_ce->ce_flags = this_ce->ce_flags | PHP5to7_ZEND_ACC_FINAL_CLASS;
125
126 zend_declare_class_constant_long(this_ce, ZEND_STRL("EXPONENT_MIN"), AMQP_DECIMAL_EXPONENT_MIN TSRMLS_CC);
127 zend_declare_class_constant_long(this_ce, ZEND_STRL("EXPONENT_MAX"), AMQP_DECIMAL_EXPONENT_MAX TSRMLS_CC);
128 zend_declare_class_constant_long(this_ce, ZEND_STRL("SIGNIFICAND_MIN"), AMQP_DECIMAL_SIGNIFICAND_MIN TSRMLS_CC);
129 zend_declare_class_constant_long(this_ce, ZEND_STRL("SIGNIFICAND_MAX"), AMQP_DECIMAL_SIGNIFICAND_MAX TSRMLS_CC);
130
131 zend_declare_property_long(this_ce, ZEND_STRL("exponent"), 0, ZEND_ACC_PRIVATE TSRMLS_CC);
132 zend_declare_property_long(this_ce, ZEND_STRL("significand"), 0, ZEND_ACC_PRIVATE TSRMLS_CC);
133
134 return SUCCESS;
135 }
136
137 /*
138 *Local variables:
139 *tab-width: 4
140 *c-basic-offset: 4
141 *End:
142 *vim600: noet sw=4 ts=4 fdm=marker
143 *vim<6
144 */
145