/***************************** {{{ LICENSE ********************************\ * dbobj, the relational object persistence module for PHP * * Copyright (C) 2006 Adam Banko * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * \***************************** LICENSE }}} ********************************/ #include "objType.h" #include "objTypes.h" #include "objType/char.h" #include "objType/integer.h" #include "objType/relation.h" #include "objType/text.h" typedef struct _objType_modules_listItem { char* key; uint keyL; objType_module* value; struct _objType_modules_listItem* next; } *objType_modules_listItem; /* names will be searhed in order, so order is important * inverse abc order ensures longer names are matched first */ objType_modules_listItem objType_modules = NULL; DBOBJ_API void objType_register_module(objType_module *module) { objType_modules_listItem prev, curr, newitem; uint i; for(i = 0; i < module->namesL; i++ ) { newitem = pemalloc(sizeof(*newitem),1); newitem->key = module->names[i]; newitem->keyL = strlen(module->names[i]); newitem->value = module; for(prev=NULL, curr = objType_modules; curr; curr = curr->next) { if(curr->keyL == newitem->keyL && strncmp(curr->key, newitem->key, newitem->keyL) < 0) break; prev = curr; } if(!prev) { newitem->next = objType_modules; objType_modules = newitem; } else { prev->next = newitem; newitem->next = curr; } } } DBOBJ_API basicType basicType_from_string(STRINGLD(s) TSRMLS_DC) { objType_modules_listItem p; p = objType_modules; for(p = objType_modules; p; p = p->next) { if(strncmp(p->key, s, p->keyL) == 0) { return p->value->basicType_from_string(s+p->keyL, sL - p->keyL TSRMLS_CC); } } DBOBJ_ERROR("can't find handler for objType '%s'",s); return NULL; } DBOBJ_API complexType complexType_from_string(STRINGLD(s), basicType sourceTypes[] TSRMLS_DC) { objType_modules_listItem p; for(p = objType_modules; p; p = p->next) { if(strncmp(p->key, s, p->keyL) == 0) { return p->value->complexType_from_string(s, sL, sourceTypes TSRMLS_CC); } } DBOBJ_ERROR("can't find handler for objType '%s'",s); return NULL; } DBOBJ_API void php_dbobj_MINIT_objTypes(TSRMLS_D) { objType_register_module(&objType_char_module); objType_register_module(&objType_integer_module); objType_register_module(&objType_text_module); objType_register_module(&objType_relation_module); } /* * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */