/***************************** {{{ 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 }}} ********************************/ #ifndef DBOBJ_DBDB_dbType_H #define DBOBJ_DBDB_dbType_H #include "php_dbobj.h" #include "objType.h" #include "dbVal.h" //Java-like objects typedef struct _dbType *dbType; //conventional structs typedef struct _dbType_vtable dbType_vtable; /* return the length of the serialized value * * this method should not generate the serialized data, * it should only return it's exact lenght quickly */ typedef uint (*dbVal_serialize_getLen_t)(dbType type, dbVal this); /* write the serialized value to write_ptr * * return the byte after the last written one */ typedef char* (*dbVal_serialize_t)(dbType type, char* write_ptr, dbVal this); /* return the reconstructed dbVal */ typedef dbVal (*dbVal_unserialize_t)(dbType type, STRINGLD(data)); /* destructor (freeer) for a raw data made with dbVal2raw */ typedef void (*raw_dtor_t)(dbType type, void* data); /* convert dbVal to raw data that the DBMS understands * * return the length of the data * allocate memory and return it's address on the second parameter */ typedef uint (*dbVal2raw_t)(dbType type, dbVal this, void** ret); /* convert raw data to dbVal */ typedef dbVal (*raw2dbVal_t)(dbType type, void* data); /* return a new dbVal with default value */ typedef dbVal (*null2dbVal_t)(dbType type); /* convert dbVal to it's basicType * * return a new basicVal for this dbVal */ typedef basicVal (*dbVal2basicVal_t)(dbType type, dbVal this); /* convert a basicVal to dbVal * * return a new dbVal from the basicVal */ typedef dbVal (*basicVal2dbVal_t)(dbType type, basicVal bv); /* compare two dbVals from the same type * * it return an integer less then, equal to, or grater than zero if val1 is less than, matches, or is morte than val2 * so this function can use strcmp or memcmp nicely */ typedef int (*dbVal_compare_t)(dbType type, dbVal val1, dbVal val2); /* destructor for a dbVal */ typedef void (*dbVal_dtor_t)(dbType type, dbVal this); /* destructor for a dbType */ typedef void (*dbType_dtor_t)(dbType type); #define DBTYPE_COMMON \ dbType_vtable *vt; \ basicType basicType struct _dbType_vtable { dbVal_serialize_getLen_t serialize_getLen; dbVal_serialize_t serialize; dbVal_unserialize_t unserialize; raw_dtor_t raw_dtor; dbVal2raw_t dbVal2raw; raw2dbVal_t raw2dbVal; null2dbVal_t null2dbVal; dbVal2basicVal_t dbVal2basicVal; basicVal2dbVal_t basicVal2dbVal; dbVal_compare_t compare; dbVal_dtor_t dbVal_dtor; dbType_dtor_t dbType_dtor; }; struct _dbType { DBTYPE_COMMON; char __[]; /* variable size structure (this is an abstract class) */ }; #endif //DBOBJ_DBDB_dbType_H /* * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */