root/ext/intl/collator/collator_class.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. Collator_objects_dtor
  2. Collator_objects_free
  3. Collator_object_create
  4. collator_register_Collator_class
  5. collator_object_init
  6. collator_object_destroy

   1 /*
   2    +----------------------------------------------------------------------+
   3    | PHP Version 5                                                        |
   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: Vadim Savchuk <vsavchuk@productengine.com>                  |
  14    |          Dmitry Lakhtyuk <dlakhtyuk@productengine.com>               |
  15    +----------------------------------------------------------------------+
  16  */
  17 
  18 #include "collator_class.h"
  19 #include "php_intl.h"
  20 #include "collator_attr.h"
  21 #include "collator_compare.h"
  22 #include "collator_sort.h"
  23 #include "collator_convert.h"
  24 #include "collator_locale.h"
  25 #include "collator_create.h"
  26 #include "collator_error.h"
  27 #include "intl_error.h"
  28 
  29 #include <unicode/ucol.h>
  30 
  31 zend_class_entry *Collator_ce_ptr = NULL;
  32 static zend_object_handlers Collator_handlers;
  33 
  34 /*
  35  * Auxiliary functions needed by objects of 'Collator' class
  36  */
  37 
  38 /* {{{ Collator_objects_dtor */
  39 static void Collator_objects_dtor(
  40         void *object,
  41         zend_object_handle handle TSRMLS_DC )
  42 {
  43         zend_objects_destroy_object( object, handle TSRMLS_CC );
  44 }
  45 /* }}} */
  46 
  47 /* {{{ Collator_objects_free */
  48 void Collator_objects_free( zend_object *object TSRMLS_DC )
  49 {
  50         Collator_object* co = (Collator_object*)object;
  51 
  52         zend_object_std_dtor( &co->zo TSRMLS_CC );
  53 
  54         collator_object_destroy( co TSRMLS_CC );
  55 
  56         efree( co );
  57 }
  58 /* }}} */
  59 
  60 /* {{{ Collator_object_create */
  61 zend_object_value Collator_object_create(
  62         zend_class_entry *ce TSRMLS_DC )
  63 {
  64         zend_object_value    retval;
  65         Collator_object*     intern;
  66 
  67         intern = ecalloc( 1, sizeof(Collator_object) );
  68         intl_error_init( COLLATOR_ERROR_P( intern ) TSRMLS_CC );
  69         zend_object_std_init( &intern->zo, ce TSRMLS_CC );
  70         object_properties_init(&intern->zo, ce);
  71 
  72         retval.handle = zend_objects_store_put(
  73                 intern,
  74                 Collator_objects_dtor,
  75                 (zend_objects_free_object_storage_t)Collator_objects_free,
  76                 NULL TSRMLS_CC );
  77 
  78         retval.handlers = &Collator_handlers;
  79 
  80         return retval;
  81 }
  82 /* }}} */
  83 
  84 /*
  85  * 'Collator' class registration structures & functions
  86  */
  87 
  88 /* {{{ Collator methods arguments info */
  89 /* NOTE: modifying 'collator_XX_args' do not forget to
  90        modify approptiate 'collator_XX_args' for
  91        the procedural API.
  92 */
  93 ZEND_BEGIN_ARG_INFO_EX( collator_0_args, 0, 0, 0 )
  94 ZEND_END_ARG_INFO()
  95 
  96 ZEND_BEGIN_ARG_INFO_EX( collator_1_arg, 0, 0, 1 )
  97         ZEND_ARG_INFO( 0, arg1 )
  98 ZEND_END_ARG_INFO()
  99 
 100 ZEND_BEGIN_ARG_INFO_EX( collator_2_args, 0, 0, 2 )
 101         ZEND_ARG_INFO( 0, arg1 )
 102         ZEND_ARG_INFO( 0, arg2 )
 103 ZEND_END_ARG_INFO()
 104 
 105 ZEND_BEGIN_ARG_INFO_EX( collator_sort_args, 0, 0, 1 )
 106         ZEND_ARG_ARRAY_INFO( 1, arr, 0 )
 107         ZEND_ARG_INFO( 0, flags )
 108 ZEND_END_ARG_INFO()
 109 
 110 /* }}} */
 111 
 112 /* {{{ Collator_class_functions
 113  * Every 'Collator' class method has an entry in this table
 114  */
 115 
 116 zend_function_entry Collator_class_functions[] = {
 117         PHP_ME( Collator, __construct, collator_1_arg, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
 118         ZEND_FENTRY( create, ZEND_FN( collator_create ), collator_1_arg, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
 119         PHP_NAMED_FE( compare, ZEND_FN( collator_compare ), collator_2_args )
 120         PHP_NAMED_FE( sort, ZEND_FN( collator_sort ), collator_sort_args )
 121         PHP_NAMED_FE( sortWithSortKeys, ZEND_FN( collator_sort_with_sort_keys ), collator_sort_args )
 122         PHP_NAMED_FE( asort, ZEND_FN( collator_asort ), collator_sort_args )
 123         PHP_NAMED_FE( getAttribute, ZEND_FN( collator_get_attribute ), collator_1_arg )
 124         PHP_NAMED_FE( setAttribute, ZEND_FN( collator_set_attribute ), collator_2_args )
 125         PHP_NAMED_FE( getStrength, ZEND_FN( collator_get_strength ), collator_0_args )
 126         PHP_NAMED_FE( setStrength, ZEND_FN( collator_set_strength ), collator_1_arg )
 127         PHP_NAMED_FE( getLocale, ZEND_FN( collator_get_locale ), collator_1_arg )
 128         PHP_NAMED_FE( getErrorCode, ZEND_FN( collator_get_error_code ), collator_0_args )
 129         PHP_NAMED_FE( getErrorMessage, ZEND_FN( collator_get_error_message ), collator_0_args )
 130         PHP_NAMED_FE( getSortKey, ZEND_FN( collator_get_sort_key ), collator_2_args )
 131         PHP_FE_END
 132 };
 133 /* }}} */
 134 
 135 /* {{{ collator_register_Collator_class
 136  * Initialize 'Collator' class
 137  */
 138 void collator_register_Collator_class( TSRMLS_D )
 139 {
 140         zend_class_entry ce;
 141 
 142         /* Create and register 'Collator' class. */
 143         INIT_CLASS_ENTRY( ce, "Collator", Collator_class_functions );
 144         ce.create_object = Collator_object_create;
 145         Collator_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );
 146 
 147         memcpy(&Collator_handlers, zend_get_std_object_handlers(),
 148                 sizeof Collator_handlers);
 149         /* Collator has no usable clone semantics - ucol_cloneBinary/ucol_openBinary require binary buffer 
 150            for which we don't have the place to keep */ 
 151         Collator_handlers.clone_obj = NULL; 
 152 
 153         /* Declare 'Collator' class properties. */
 154         if( !Collator_ce_ptr )
 155         {
 156                 zend_error( E_ERROR,
 157                         "Collator: attempt to create properties "
 158                         "on a non-registered class." );
 159                 return;
 160         }
 161 }
 162 /* }}} */
 163 
 164 /* {{{ void collator_object_init( Collator_object* co )
 165  * Initialize internals of Collator_object.
 166  * Must be called before any other call to 'collator_object_...' functions.
 167  */
 168 void collator_object_init( Collator_object* co TSRMLS_DC )
 169 {
 170         if( !co )
 171                 return;
 172 
 173         intl_error_init( COLLATOR_ERROR_P( co ) TSRMLS_CC );
 174 }
 175 /* }}} */
 176 
 177 /* {{{ void collator_object_destroy( Collator_object* co )
 178  * Clean up mem allocted by internals of Collator_object
 179  */
 180 void collator_object_destroy( Collator_object* co TSRMLS_DC )
 181 {
 182         if( !co )
 183                 return;
 184 
 185         if( co->ucoll )
 186         {
 187                 ucol_close( co->ucoll );
 188                 co->ucoll = NULL;
 189         }
 190 
 191         intl_error_reset( COLLATOR_ERROR_P( co ) TSRMLS_CC );
 192 }
 193 /* }}} */
 194 
 195 /*
 196  * Local variables:
 197  * tab-width: 4
 198  * c-basic-offset: 4
 199  * End:
 200  * vim600: noet sw=4 ts=4 fdm=marker
 201  * vim<600: noet sw=4 ts=4
 202  */

/* [<][>][^][v][top][bottom][index][help] */