NamedObject.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2006-2007 by Konstantin V. Arkhipov                     *
00003  *                                                                         *
00004  *   This program is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU Lesser General Public License as        *
00006  *   published by the Free Software Foundation; either version 3 of the    *
00007  *   License, or (at your option) any later version.                       *
00008  *                                                                         *
00009  ***************************************************************************/
00010 /* $Id: NamedObject.c 4687 2007-12-09 18:57:18Z voxus $ */
00011 
00012 #include "onphp.h"
00013 #include "onphp_util.h"
00014 
00015 #include "core/Base/NamedObject.h"
00016 
00017 ONPHP_METHOD(NamedObject, getName)
00018 {
00019     zval *name = ONPHP_READ_PROPERTY(getThis(), "name");
00020 
00021     RETURN_ZVAL(name, 1, 0);
00022 }
00023 
00024 ONPHP_METHOD(NamedObject, setName)
00025 {
00026     zval *name;
00027     
00028     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == SUCCESS) {
00029         ONPHP_UPDATE_PROPERTY(getThis(), "name", name);
00030     }
00031 
00032     RETURN_ZVAL(getThis(), 1, 0);
00033 }
00034 
00035 ONPHP_METHOD(NamedObject, toString)
00036 {
00037     smart_str string = {0};
00038 
00039     smart_str_appends(&string, "[");
00040     onphp_append_zval_to_smart_string(&string, ONPHP_READ_PROPERTY(getThis(), "id"));
00041     smart_str_appends(&string, "] ");
00042     onphp_append_zval_to_smart_string(&string, ONPHP_READ_PROPERTY(getThis(), "name"));
00043     smart_str_0(&string);
00044 
00045     RETURN_STRINGL(string.c, string.len, 0);
00046 }
00047 
00048 ONPHP_METHOD(NamedObject, compareNames)
00049 {
00050     zval *first, *second;
00051     zval *left, *right;
00052     int result;
00053 
00054     if (
00055         (ZEND_NUM_ARGS() != 2)
00056         || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &first, &second) == FAILURE
00057     ) {
00058         WRONG_PARAM_COUNT;
00059     }
00060     
00061     zend_call_method_with_0_params(&first, Z_OBJCE_P(first), NULL, "getname", &left);
00062     
00063     if (EG(exception)) {
00064         return;
00065     }
00066     
00067     zend_call_method_with_0_params(&second, Z_OBJCE_P(second), NULL, "getname", &right);
00068     
00069     if (EG(exception)) {
00070         return;
00071     }
00072     
00073     result = strcasecmp(Z_STRVAL_P(left), Z_STRVAL_P(right));
00074     
00075     ZVAL_FREE(left); ZVAL_FREE(right);
00076     
00077     RETURN_LONG(result);
00078 }
00079 
00080 static ONPHP_ARGINFO_ONE;
00081 
00082 static
00083 ZEND_BEGIN_ARG_INFO(arginfo_two_named_objects, 0)
00084     ZEND_ARG_OBJ_INFO(0, Named, Named, 0)
00085     ZEND_ARG_OBJ_INFO(0, Named, Named, 0)
00086 ZEND_END_ARG_INFO();
00087 
00088 zend_function_entry onphp_funcs_NamedObject[] = {
00089     ONPHP_ME(NamedObject, getName,      NULL, ZEND_ACC_PUBLIC)
00090     ONPHP_ME(NamedObject, setName,      arginfo_one, ZEND_ACC_PUBLIC)
00091     ONPHP_ME(NamedObject, compareNames, arginfo_two_named_objects, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
00092     ONPHP_ME(NamedObject, toString,     NULL, ZEND_ACC_PUBLIC)
00093     {NULL, NULL, NULL}
00094 };

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4