Back to index

php5  5.3.10
formatter_class.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | This source file is subject to version 3.01 of the PHP license,      |
00006    | that is bundled with this package in the file LICENSE, and is        |
00007    | available through the world-wide-web at the following url:           |
00008    | http://www.php.net/license/3_01.txt                                  |
00009    | If you did not receive a copy of the PHP license and are unable to   |
00010    | obtain it through the world-wide-web, please send a note to          |
00011    | license@php.net so we can mail you a copy immediately.               |
00012    +----------------------------------------------------------------------+
00013    | Authors: Stanislav Malyshev <stas@zend.com>                          |
00014    +----------------------------------------------------------------------+
00015  */
00016 
00017 #include <unicode/unum.h>
00018 
00019 #include "formatter_class.h"
00020 #include "php_intl.h"
00021 #include "formatter_data.h"
00022 #include "formatter_format.h"
00023 #include "formatter_parse.h"
00024 #include "formatter_main.h"
00025 #include "formatter_attr.h"
00026 
00027 zend_class_entry *NumberFormatter_ce_ptr = NULL;
00028 static zend_object_handlers NumberFormatter_handlers;
00029 
00030 /*
00031  * Auxiliary functions needed by objects of 'NumberFormatter' class
00032  */
00033 
00034 /* {{{ NumberFormatter_objects_dtor */
00035 static void NumberFormatter_object_dtor(
00036        void *object,
00037        zend_object_handle handle TSRMLS_DC )
00038 {
00039        zend_objects_destroy_object( object, handle TSRMLS_CC );
00040 }
00041 /* }}} */
00042 
00043 /* {{{ NumberFormatter_objects_free */
00044 void NumberFormatter_object_free( zend_object *object TSRMLS_DC )
00045 {
00046        NumberFormatter_object* nfo = (NumberFormatter_object*)object;
00047 
00048        zend_object_std_dtor( &nfo->zo TSRMLS_CC );
00049 
00050        formatter_data_free( &nfo->nf_data TSRMLS_CC );
00051 
00052        efree( nfo );
00053 }
00054 /* }}} */
00055 
00056 /* {{{ NumberFormatter_object_create */
00057 zend_object_value NumberFormatter_object_create(zend_class_entry *ce TSRMLS_DC)
00058 {
00059        zend_object_value    retval;
00060        NumberFormatter_object*     intern;
00061 
00062        intern = ecalloc( 1, sizeof(NumberFormatter_object) );
00063        formatter_data_init( &intern->nf_data TSRMLS_CC );
00064        zend_object_std_init( &intern->zo, ce TSRMLS_CC );
00065 
00066        retval.handle = zend_objects_store_put(
00067               intern,
00068               NumberFormatter_object_dtor,
00069               (zend_objects_free_object_storage_t)NumberFormatter_object_free,
00070               NULL TSRMLS_CC );
00071 
00072        retval.handlers = &NumberFormatter_handlers;
00073 
00074        return retval;
00075 }
00076 /* }}} */
00077 
00078 /* {{{ NumberFormatter_object_clone */
00079 zend_object_value NumberFormatter_object_clone(zval *object TSRMLS_DC)
00080 {
00081        zend_object_value new_obj_val;
00082        zend_object_handle handle = Z_OBJ_HANDLE_P(object);
00083        NumberFormatter_object *nfo, *new_nfo;
00084 
00085        FORMATTER_METHOD_FETCH_OBJECT;
00086        new_obj_val = NumberFormatter_ce_ptr->create_object(NumberFormatter_ce_ptr TSRMLS_CC);
00087        new_nfo = (NumberFormatter_object *)zend_object_store_get_object_by_handle(new_obj_val.handle TSRMLS_CC);
00088        /* clone standard parts */  
00089        zend_objects_clone_members(&new_nfo->zo, new_obj_val, &nfo->zo, handle TSRMLS_CC);
00090        /* clone formatter object */
00091        FORMATTER_OBJECT(new_nfo) = unum_clone(FORMATTER_OBJECT(nfo),  &INTL_DATA_ERROR_CODE(new_nfo));
00092        if(U_FAILURE(INTL_DATA_ERROR_CODE(new_nfo))) {
00093               /* set up error in case error handler is interested */
00094               intl_error_set( NULL, INTL_DATA_ERROR_CODE(new_nfo), "Failed to clone NumberFormatter object", 0 TSRMLS_CC );
00095               NumberFormatter_object_dtor(new_nfo, new_obj_val.handle TSRMLS_CC); /* free new object */
00096               zend_error(E_ERROR, "Failed to clone NumberFormatter object");
00097        }
00098        return new_obj_val;
00099 }
00100 /* }}} */
00101 
00102 /*
00103  * 'NumberFormatter' class registration structures & functions
00104  */
00105 
00106 /* {{{ arginfo */
00107 ZEND_BEGIN_ARG_INFO_EX(number_parse_arginfo, 0, 0, 1)
00108        ZEND_ARG_INFO(0, string)
00109        ZEND_ARG_INFO(0, type)
00110        ZEND_ARG_INFO(1, position)
00111 ZEND_END_ARG_INFO()
00112 
00113 ZEND_BEGIN_ARG_INFO_EX(number_parse_currency_arginfo, 0, 0, 2)
00114        ZEND_ARG_INFO(0, string)
00115        ZEND_ARG_INFO(1, currency)
00116        ZEND_ARG_INFO(1, position)
00117 ZEND_END_ARG_INFO()
00118 
00119 ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_getattribute, 0, 0, 1)
00120        ZEND_ARG_INFO(0, attr)
00121 ZEND_END_ARG_INFO()
00122 
00123 ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_setattribute, 0, 0, 2)
00124        ZEND_ARG_INFO(0, attr)
00125        ZEND_ARG_INFO(0, value)
00126 ZEND_END_ARG_INFO()
00127 
00128 ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_setsymbol, 0, 0, 2)
00129        ZEND_ARG_INFO(0, attr)
00130        ZEND_ARG_INFO(0, symbol)
00131 ZEND_END_ARG_INFO()
00132 
00133 ZEND_BEGIN_ARG_INFO(arginfo_numberformatter_getpattern, 0)
00134 ZEND_END_ARG_INFO()
00135 
00136 ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_setpattern, 0, 0, 1)
00137        ZEND_ARG_INFO(0, pattern)
00138 ZEND_END_ARG_INFO()
00139 
00140 ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_getlocale, 0, 0, 0)
00141        ZEND_ARG_INFO(0, type)
00142 ZEND_END_ARG_INFO()
00143 
00144 ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter___construct, 0, 0, 2)
00145        ZEND_ARG_INFO(0, locale)
00146        ZEND_ARG_INFO(0, style)
00147        ZEND_ARG_INFO(0, pattern)
00148 ZEND_END_ARG_INFO()
00149 
00150 ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_formatcurrency, 0, 0, 2)
00151        ZEND_ARG_INFO(0, num)
00152        ZEND_ARG_INFO(0, currency)
00153 ZEND_END_ARG_INFO()
00154 
00155 ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_format, 0, 0, 1)
00156        ZEND_ARG_INFO(0, num)
00157        ZEND_ARG_INFO(0, type)
00158 ZEND_END_ARG_INFO()
00159 /* }}} */
00160 
00161 /* {{{ NumberFormatter_class_functions
00162  * Every 'NumberFormatter' class method has an entry in this table
00163  */
00164 static function_entry NumberFormatter_class_functions[] = {
00165        PHP_ME( NumberFormatter, __construct, arginfo_numberformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
00166        ZEND_FENTRY( create, ZEND_FN( numfmt_create ), arginfo_numberformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
00167        PHP_NAMED_FE( format, ZEND_FN( numfmt_format ), arginfo_numberformatter_format )
00168        PHP_NAMED_FE( parse, ZEND_FN( numfmt_parse ), number_parse_arginfo )
00169        PHP_NAMED_FE( formatCurrency, ZEND_FN( numfmt_format_currency ), arginfo_numberformatter_formatcurrency )
00170        PHP_NAMED_FE( parseCurrency, ZEND_FN( numfmt_parse_currency ), number_parse_currency_arginfo )
00171        PHP_NAMED_FE( setAttribute, ZEND_FN( numfmt_set_attribute ), arginfo_numberformatter_setattribute )
00172        PHP_NAMED_FE( getAttribute, ZEND_FN( numfmt_get_attribute ), arginfo_numberformatter_getattribute )
00173        PHP_NAMED_FE( setTextAttribute, ZEND_FN( numfmt_set_text_attribute ), arginfo_numberformatter_setattribute )
00174        PHP_NAMED_FE( getTextAttribute, ZEND_FN( numfmt_get_text_attribute ), arginfo_numberformatter_getattribute )
00175        PHP_NAMED_FE( setSymbol, ZEND_FN( numfmt_set_symbol ), arginfo_numberformatter_setsymbol )
00176        PHP_NAMED_FE( getSymbol, ZEND_FN( numfmt_get_symbol ), arginfo_numberformatter_getattribute )
00177        PHP_NAMED_FE( setPattern, ZEND_FN( numfmt_set_pattern ), arginfo_numberformatter_setpattern )
00178        PHP_NAMED_FE( getPattern, ZEND_FN( numfmt_get_pattern ), arginfo_numberformatter_getpattern )
00179        PHP_NAMED_FE( getLocale, ZEND_FN( numfmt_get_locale ), arginfo_numberformatter_getlocale )
00180        PHP_NAMED_FE( getErrorCode, ZEND_FN( numfmt_get_error_code ), arginfo_numberformatter_getpattern )
00181        PHP_NAMED_FE( getErrorMessage, ZEND_FN( numfmt_get_error_message ), arginfo_numberformatter_getpattern )
00182        PHP_FE_END
00183 };
00184 /* }}} */
00185 
00186 /* {{{ formatter_register_class
00187  * Initialize 'NumberFormatter' class
00188  */
00189 void formatter_register_class( TSRMLS_D )
00190 {
00191        zend_class_entry ce;
00192 
00193        /* Create and register 'NumberFormatter' class. */
00194        INIT_CLASS_ENTRY( ce, "NumberFormatter", NumberFormatter_class_functions );
00195        ce.create_object = NumberFormatter_object_create;
00196        NumberFormatter_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );
00197 
00198        memcpy(&NumberFormatter_handlers, zend_get_std_object_handlers(),
00199               sizeof(NumberFormatter_handlers));
00200        NumberFormatter_handlers.clone_obj = NumberFormatter_object_clone;
00201 
00202        /* Declare 'NumberFormatter' class properties. */
00203        if( !NumberFormatter_ce_ptr )
00204        {
00205               zend_error(E_ERROR, "Failed to register NumberFormatter class");
00206               return;
00207        }
00208 }
00209 /* }}} */
00210 
00211 /*
00212  * Local variables:
00213  * tab-width: 4
00214  * c-basic-offset: 4
00215  * End:
00216  * vim600: noet sw=4 ts=4 fdm=marker
00217  * vim<600: noet sw=4 ts=4
00218  */