Back to index

php5  5.3.10
collator_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: Vadim Savchuk <vsavchuk@productengine.com>                  |
00014    |          Dmitry Lakhtyuk <dlakhtyuk@productengine.com>               |
00015    +----------------------------------------------------------------------+
00016  */
00017 
00018 #include "collator_class.h"
00019 #include "php_intl.h"
00020 #include "collator_attr.h"
00021 #include "collator_compare.h"
00022 #include "collator_sort.h"
00023 #include "collator_convert.h"
00024 #include "collator_locale.h"
00025 #include "collator_create.h"
00026 #include "collator_error.h"
00027 #include "intl_error.h"
00028 
00029 #include <unicode/ucol.h>
00030 
00031 zend_class_entry *Collator_ce_ptr = NULL;
00032 static zend_object_handlers Collator_handlers;
00033 
00034 /*
00035  * Auxiliary functions needed by objects of 'Collator' class
00036  */
00037 
00038 /* {{{ Collator_objects_dtor */
00039 static void Collator_objects_dtor(
00040        void *object,
00041        zend_object_handle handle TSRMLS_DC )
00042 {
00043        zend_objects_destroy_object( object, handle TSRMLS_CC );
00044 }
00045 /* }}} */
00046 
00047 /* {{{ Collator_objects_free */
00048 void Collator_objects_free( zend_object *object TSRMLS_DC )
00049 {
00050        Collator_object* co = (Collator_object*)object;
00051 
00052        zend_object_std_dtor( &co->zo TSRMLS_CC );
00053 
00054        collator_object_destroy( co TSRMLS_CC );
00055 
00056        efree( co );
00057 }
00058 /* }}} */
00059 
00060 /* {{{ Collator_object_create */
00061 zend_object_value Collator_object_create(
00062        zend_class_entry *ce TSRMLS_DC )
00063 {
00064        zend_object_value    retval;
00065        Collator_object*     intern;
00066 
00067        intern = ecalloc( 1, sizeof(Collator_object) );
00068        intl_error_init( COLLATOR_ERROR_P( intern ) TSRMLS_CC );
00069        zend_object_std_init( &intern->zo, ce TSRMLS_CC );
00070 
00071        retval.handle = zend_objects_store_put(
00072               intern,
00073               Collator_objects_dtor,
00074               (zend_objects_free_object_storage_t)Collator_objects_free,
00075               NULL TSRMLS_CC );
00076 
00077        retval.handlers = &Collator_handlers;
00078 
00079        return retval;
00080 }
00081 /* }}} */
00082 
00083 /*
00084  * 'Collator' class registration structures & functions
00085  */
00086 
00087 /* {{{ Collator methods arguments info */
00088 /* NOTE: modifying 'collator_XX_args' do not forget to
00089        modify approptiate 'collator_XX_args' for
00090        the procedural API.
00091 */
00092 ZEND_BEGIN_ARG_INFO_EX( collator_0_args, 0, 0, 0 )
00093 ZEND_END_ARG_INFO()
00094 
00095 ZEND_BEGIN_ARG_INFO_EX( collator_1_arg, 0, 0, 1 )
00096        ZEND_ARG_INFO( 0, arg1 )
00097 ZEND_END_ARG_INFO()
00098 
00099 ZEND_BEGIN_ARG_INFO_EX( collator_2_args, 0, 0, 2 )
00100        ZEND_ARG_INFO( 0, arg1 )
00101        ZEND_ARG_INFO( 0, arg2 )
00102 ZEND_END_ARG_INFO()
00103 
00104 ZEND_BEGIN_ARG_INFO_EX( collator_sort_args, 0, 0, 1 )
00105        ZEND_ARG_ARRAY_INFO( 1, arr, 0 )
00106        ZEND_ARG_INFO( 0, flags )
00107 ZEND_END_ARG_INFO()
00108 
00109 /* }}} */
00110 
00111 /* {{{ Collator_class_functions
00112  * Every 'Collator' class method has an entry in this table
00113  */
00114 
00115 function_entry Collator_class_functions[] = {
00116        PHP_ME( Collator, __construct, collator_1_arg, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
00117        ZEND_FENTRY( create, ZEND_FN( collator_create ), collator_1_arg, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
00118        PHP_NAMED_FE( compare, ZEND_FN( collator_compare ), collator_2_args )
00119        PHP_NAMED_FE( sort, ZEND_FN( collator_sort ), collator_sort_args )
00120        PHP_NAMED_FE( sortWithSortKeys, ZEND_FN( collator_sort_with_sort_keys ), collator_sort_args )
00121        PHP_NAMED_FE( asort, ZEND_FN( collator_asort ), collator_sort_args )
00122        PHP_NAMED_FE( getAttribute, ZEND_FN( collator_get_attribute ), collator_1_arg )
00123        PHP_NAMED_FE( setAttribute, ZEND_FN( collator_set_attribute ), collator_2_args )
00124        PHP_NAMED_FE( getStrength, ZEND_FN( collator_get_strength ), collator_0_args )
00125        PHP_NAMED_FE( setStrength, ZEND_FN( collator_set_strength ), collator_1_arg )
00126        PHP_NAMED_FE( getLocale, ZEND_FN( collator_get_locale ), collator_1_arg )
00127        PHP_NAMED_FE( getErrorCode, ZEND_FN( collator_get_error_code ), collator_0_args )
00128        PHP_NAMED_FE( getErrorMessage, ZEND_FN( collator_get_error_message ), collator_0_args )
00129        PHP_NAMED_FE( getSortKey, ZEND_FN( collator_get_sort_key ), collator_2_args )
00130        PHP_FE_END
00131 };
00132 /* }}} */
00133 
00134 /* {{{ collator_register_Collator_class
00135  * Initialize 'Collator' class
00136  */
00137 void collator_register_Collator_class( TSRMLS_D )
00138 {
00139        zend_class_entry ce;
00140 
00141        /* Create and register 'Collator' class. */
00142        INIT_CLASS_ENTRY( ce, "Collator", Collator_class_functions );
00143        ce.create_object = Collator_object_create;
00144        Collator_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );
00145 
00146        memcpy(&Collator_handlers, zend_get_std_object_handlers(),
00147               sizeof Collator_handlers);
00148        /* Collator has no usable clone semantics - ucol_cloneBinary/ucol_openBinary require binary buffer 
00149           for which we don't have the place to keep */  
00150        Collator_handlers.clone_obj = NULL; 
00151 
00152        /* Declare 'Collator' class properties. */
00153        if( !Collator_ce_ptr )
00154        {
00155               zend_error( E_ERROR,
00156                      "Collator: attempt to create properties "
00157                      "on a non-registered class." );
00158               return;
00159        }
00160 }
00161 /* }}} */
00162 
00163 /* {{{ void collator_object_init( Collator_object* co )
00164  * Initialize internals of Collator_object.
00165  * Must be called before any other call to 'collator_object_...' functions.
00166  */
00167 void collator_object_init( Collator_object* co TSRMLS_DC )
00168 {
00169        if( !co )
00170               return;
00171 
00172        intl_error_init( COLLATOR_ERROR_P( co ) TSRMLS_CC );
00173 }
00174 /* }}} */
00175 
00176 /* {{{ void collator_object_destroy( Collator_object* co )
00177  * Clean up mem allocted by internals of Collator_object
00178  */
00179 void collator_object_destroy( Collator_object* co TSRMLS_DC )
00180 {
00181        if( !co )
00182               return;
00183 
00184        if( co->ucoll )
00185        {
00186               ucol_close( co->ucoll );
00187               co->ucoll = NULL;
00188        }
00189 
00190        intl_error_reset( COLLATOR_ERROR_P( co ) TSRMLS_CC );
00191 }
00192 /* }}} */
00193 
00194 /*
00195  * Local variables:
00196  * tab-width: 4
00197  * c-basic-offset: 4
00198  * End:
00199  * vim600: noet sw=4 ts=4 fdm=marker
00200  * vim<600: noet sw=4 ts=4
00201  */