[Kde-bindings] playground/bindings/phpqt/src
Thomas Moenicke
tm at php-qt.org
Sun Apr 6 10:33:51 UTC 2008
SVN commit 794043 by moenicke:
* added Marshaler for QStringList
* added Marshaler for int64
* fixed wrong hash table handler
CCMAIL: kde-bindings at kde.org
M +84 -0 handlers.cpp
M +19 -0 marshall_basetypes.h
M +1 -0 php_qt.cpp
M +1 -1 phpqt_internals.cpp
--- trunk/playground/bindings/phpqt/src/handlers.cpp #794042:794043
@@ -325,6 +325,85 @@
// delete n;
}
+static void marshall_QStringList(Marshall* m) {
+
+ switch( m->action() ) {
+ case Marshall::FromZVAL:
+ {
+ QStringList* stringList = new QStringList;
+ zval* list = m->var();
+ char* assocKey;
+ ulong numKey;
+ if ( list->type != IS_ARRAY ) {
+ m->item().s_voidp = 0;
+ break;
+ }
+ HashTable* list_hash = HASH_OF( list );
+ zval **list_iterator;
+ zend_hash_internal_pointer_reset( list_hash );
+ while( zend_hash_has_more_elements( list_hash ) == SUCCESS )
+ {
+ zend_hash_get_current_key( list_hash, &assocKey, &numKey, 0 );
+ zend_hash_get_current_data( list_hash, (void**) &list_iterator );
+ if( (*list_iterator)->type == IS_STRING )
+ stringList->append( Z_STRVAL_PP( list_iterator ) );
+ else if ( (*list_iterator)->type == IS_OBJECT ) {
+ smokephp_object* o = PHPQt::getSmokePHPObjectFromZval( (*list_iterator) );
+ if( o->classId() == QSTRING_CLASSID )
+ {
+ QString* s = reinterpret_cast< QString*> ( o->mPtr() );
+ stringList->append( *s );
+ }
+ }
+ zend_hash_move_forward( list_hash );
+ }
+
+ m->item().s_voidp = stringList;
+ m->next();
+
+ // it might be changed if not const
+ if ( stringList != 0 && !m->type().isConst() ) {
+ array_init( list );
+ for(QStringList::Iterator it = stringList->begin(); it != stringList->end(); ++it)
+ add_next_index_string( list , const_cast<char*>( (*it).toLatin1().constData() ), 0 );
+ }
+
+ if (m->cleanup()) {
+ delete stringList;
+ }
+ break;
+ }
+ case Marshall::ToZVAL:
+ {
+ QStringList *stringlist = static_cast<QStringList *>( m->item().s_voidp );
+ if ( !stringlist ) {
+ *(m->var()) = *Qnil;
+ break;
+ }
+
+ // TODO linking QStringList
+ zval* av;
+ ALLOC_HASHTABLE( av->value.ht );
+ zend_hash_init( av->value.ht, 0, NULL, ZVAL_PTR_DTOR, 0 );
+ for (QStringList::Iterator it = stringlist->begin(); it != stringlist->end(); ++it) {
+ add_next_index_string( av, const_cast<char*> ( (*it).toAscii().constData() ) , 1 );
+ }
+
+ *(m->var()) = *av;
+
+ if (m->cleanup()) {
+ delete stringlist;
+ }
+
+
+ }
+ break;
+ default:
+ m->unsupported();
+ break;
+ }
+}
+
TypeHandler Qt_handlers[] = {
{ "WId", marshall_it<WId> },
{ "Q_PID", marshall_it<Q_PID> },
@@ -334,6 +413,11 @@
{ "int&", marshall_IntR },
{ "char**", marshall_charPP },
{ "char*", marshall_charP },
+ { "qint64", marshall_it<long long> },
+ { "qint64&", marshall_it<long long> },
+ { "QStringList", marshall_QStringList },
+ { "QStringList*", marshall_QStringList },
+ { "QStringList&", marshall_QStringList },
{ 0, 0 }
};
--- trunk/playground/bindings/phpqt/src/marshall_basetypes.h #794042:794043
@@ -274,3 +274,22 @@
{
m->unsupported();
}
+
+template <>
+static void marshall_from_php<long long>(Marshall *m)
+{
+ zval* zobj = m->var();
+ m->item().s_voidp = reinterpret_cast< void* >( php_to_primitive< long >( zobj ) );
+}
+
+template <>
+static void marshall_to_php<long long>(Marshall *m)
+{
+ const long long i = reinterpret_cast< long long > ( m->item().s_voidp );
+ zval* zobj = m->var();
+ if( i < LONG_MAX ) {
+ ZVAL_LONG( zobj, (long) i );
+ } else {
+ ZVAL_LONG( zobj, LONG_MAX );
+ }
+}
--- trunk/playground/bindings/phpqt/src/php_qt.cpp #794042:794043
@@ -213,6 +213,7 @@
o->setAllocated( true );
// Metaobject
+ // TODO only if derived
if(smokephp_isQObject(PQ::smoke()->idClass(ce->name)))
PHPQt::createMetaObject(o, getThis());
--- trunk/playground/bindings/phpqt/src/phpqt_internals.cpp #794042:794043
@@ -236,7 +236,7 @@
/// write class signature
signature[0] = 1;
- signature[4] = zend_hash_num_elements(function_table)+zend_hash_num_elements(signals_hash);
+ signature[4] = zend_hash_num_elements(slots_hash)+zend_hash_num_elements(signals_hash);
signature[5] = 10;
/// write classname
More information about the Kde-bindings
mailing list