static string typeTag( Type *t ){ if( t->intType() ) return ""; if( t->floatType() ) return "#"; if( t->stringType() ) return "$"; if( StructType *s=t->structType() ) return "."+s->ident; if( VectorType *v=t->vectorType() ){ string s=typeTag( v->elementType )+"["; for( int k=0;k<v->sizes.size();++k ){ if( k ) s+=","; s+=itoa( v->sizes[k]-1 ); } return s+"]"; } return ""; }
GadgetTreeReader::GadgetTreeReader(libember::util::OctetStream& input) { m_root = nullptr; auto& factory = GlowNodeFactory::getFactory(); auto reader = dom::DomReader(); auto node = reader.decodeTree(input, factory); if (node != nullptr) { auto const type = ber::Type::fromTag(node->typeTag()); if(type.isApplicationDefined()) { if (type.value() == GlowType::RootElementCollection) { auto collection = dynamic_cast<GlowRootElementCollection*>(node); if (collection != nullptr) { iterate(collection); } } } } }
HTREEITEM DebugTree::insertVar( void *var,Decl *d,const string &name,HTREEITEM it,HTREEITEM parent ){ string s=name; ConstType *ct=d->type->constType(); StructType *st=d->type->structType(); VectorType *vt=d->type->vectorType(); if( ct ){ Type *t=ct->valueType; s+=typeTag(t); if( t->intType() ){ s+="="+itoa( ct->intValue ); }else if( t->floatType() ){ s+="="+ftoa( ct->floatValue ); }else if( t->stringType() ){ s+="=\""+ct->stringValue+'\"'; } }else if( var ){ Type *t=d->type; s+=typeTag( t ); if( t->intType() ){ s+="="+itoa( *(int*)var ); }else if( t->floatType() ){ s+="="+ftoa( *(float*)var ); }else if( t->stringType() ){ BBStr *str=*(BBStr**)var; if( str ) s+="=\""+*str+'\"'; else s+="=\"\""; }else if( st ){ var=*(void**)var; if( var ) var=*(void**)var; if( !var ) s+=" (Null)"; } } if( it ){ if( GetItemText( it )!=s.c_str() ){ SetItemText( it,s.c_str() ); } }else{ it=InsertItem( s.c_str(),parent ); } ++st_nest; if( st ){ if( var ){ if( st_nest<4 ){ HTREEITEM st_it=GetChildItem( it ); for( int k=0;k<st->fields->size();++k ){ Decl *st_d=st->fields->decls[k]; void *st_var=(char*)var+st_d->offset; char name[256]; st_d->getName( name ); st_it=insertVar( st_var,st_d,name,st_it,it ); } } }else{ while( HTREEITEM t=GetChildItem( it ) ){ DeleteItem( t ); } } } --st_nest; return it ? GetNextSiblingItem( it ) : 0; }
// ============================================================================ // CWidgetEntry::InternalizeXmlL() // read from persistent storage(file) // // @since 5.0 // ============================================================================ // void CWidgetEntry::InternalizeXmlL( RFs& aFileSession, xmlDocPtr aDoc, xmlNode* n, CWidgetRegistryXml* aXmlProcessor ) { // <prop>name<val>value<type>typename</type></val></prop> // // prop subtree traversal assumes strict adherence to the // prototype structure, otherwise code leaves with corrupt code for ( ; n; ) { // permit some non element stuff (comment, whitespace...) before <prop> while ( n && ( n->type != XML_ELEMENT_NODE ) ) { n = n->next; } if ( NULL == n ) { for (TInt i = iPropertyValues.Count(); i < EWidgetPropertyIdCount; i++) { CWidgetPropertyValue* val = CWidgetPropertyValue::NewL(); CleanupStack::PushL(val); iPropertyValues.AppendL( val ); CleanupStack::Pop(); // val } return; } TPtrC8 propTag( n->name ); if ( 0 != propTag.Compare( KXmlPropTag() ) ) { // TODO unrecognized subtree? return; } // TODO validate n->children != NULL and type XML_TEXT_NODE HBufC* name; aXmlProcessor->GetContentL( aFileSession, aDoc, n->children, &name ); // get value array index (TWidgetPropertyId) for name TPtr namePtr( name->Des() ); TInt propId = aXmlProcessor->GetPropertyId( namePtr ); delete name; name = NULL; if ( EWidgetPropertyIdInvalid == propId ) { User::Leave( KErrNoMemory ); } for (TInt i = iPropertyValues.Count(); i <= propId; i++) { CWidgetPropertyValue* val = CWidgetPropertyValue::NewL(); CleanupStack::PushL(val); iPropertyValues.AppendL( val ); CleanupStack::Pop(); // val } n = n->children->next; // down to val if ( NULL == n ) { User::Leave( KErrCorrupt ); } TPtrC8 valTag( n->name ); if ( 0 != valTag.Compare( KXmlValTag() ) ) { User::Leave( KErrCorrupt ); } if (propId >= EWidgetPropertyIdCount) // unsupported property { HBufC* value = NULL; if (n->children) { aXmlProcessor->GetTextContentAsStringL( aFileSession, aDoc, n->children, &value ); } else { value = KNullDesC().AllocL(); } (*this)[propId].iValue.s = value; (*this)[propId].iType = EWidgetPropTypeBlob; n = (n->parent)->next; // up two and next sibling continue; } // TODO validate n->children != NULL and type XML_TEXT_NODE HBufC* value; aXmlProcessor->GetContentL( aFileSession, aDoc, n->children, &value ); CleanupStack::PushL( value ); n = n->children->next; // down to type if ( NULL == n ) { User::Leave( KErrCorrupt ); } TPtrC8 typeTag( n->name ); if ( 0 != typeTag.Compare( KXmlTypeTag() ) ) { User::Leave( KErrCorrupt ); } // TODO validate n->children != NULL and type XML_TEXT_NODE HBufC* type; aXmlProcessor->GetContentL( aFileSession, aDoc, n->children, &type ); CleanupStack::PushL( type ); // now have: name, value, type // convert type string to TWidgetPropertyType // // assume void/unknown is not put in XML format so anything // not recognized should be handled like other unrecognized // subtree TWidgetPropertyType typeEnum = EWidgetPropTypeUnknown; if ( 0 == type->Des().Compare( KXmlDataTypeBool() ) ) { typeEnum = EWidgetPropTypeBool; } else if ( 0 == type->Des().Compare( KXmlDataTypeInt() ) ) { typeEnum = EWidgetPropTypeInt; } else if ( 0 == type->Des().Compare( KXmlDataTypeString() ) ) { typeEnum = EWidgetPropTypeString; } else if ( 0 == type->Des().Compare( KXmlDataTypeUid() ) ) { typeEnum = EWidgetPropTypeUid; } CleanupStack::PopAndDestroy( type ); // TODO handle unknown type due to future extensions: add prop // subtree to list of unrecognized subtrees // set prop according to type switch ( typeEnum ) { case EWidgetPropTypeBool: if ( 0 == value->Des().Compare( _L("0") ) ) { (*this)[propId].iValue.i = 0; } else { (*this)[propId].iValue.i = 1; } break; case EWidgetPropTypeInt: { TLex toInt( value->Des() ); TInt k; if ( KErrNone != toInt.Val( k ) ) { User::Leave( KErrCorrupt ); } (*this)[propId].iValue.i = k; } break; case EWidgetPropTypeString: (*this)[propId].iValue.s = value; break; case EWidgetPropTypeUid: { TLex toUid( value->Des() ); TInt u; if ( KErrNone != toUid.Val( u ) ) { User::Leave( KErrCorrupt ); } (*this)[propId].iValue.uid = TUid::Uid( u ); } break; }; (*this)[propId].iType = typeEnum; CleanupStack::Pop( value ); if ( EWidgetPropTypeString != typeEnum ) { delete value; } n = ((n->parent)->parent)->next; // up two and next sibling } }