static void getDictString(iTJSDispatch2 *dict, IWriter *writer) { writer->write(L"%["); //writer->addIndent(); DictMemberDispCaller *caller = new DictMemberDispCaller(writer); tTJSVariantClosure closure(caller); dict->EnumMembers(TJS_IGNOREPROP, &closure, dict); caller->Release(); //writer->delIndent(); writer->write((tjs_char)']'); }
/** * tTJSVariant を XMLノードに変換 * @param var 変換元の値 * @param doc XMLドキュメント * @return 作成したノード */ static xml_node * createNodeFromVariant(tTJSVariant &var, xml_document &doc) { switch(var.Type()) { case tvtObject: { iTJSDispatch2 *obj = var.AsObjectNoAddRef(); if (obj == NULL) { // NULL return doc.allocate_node(rapidxml::node_element, L"null"); } else if (obj->IsInstanceOf(TJS_IGNOREPROP,NULL,NULL,L"Array",obj) == TJS_S_TRUE) { // 配列 xml_node *node = doc.allocate_node(rapidxml::node_element, L"array"); tjs_int count = 0; { tTJSVariant result; if (TJS_SUCCEEDED(obj->PropGet(0, L"count", NULL, &result, obj))) { count = result; } } for (tjs_int i=0; i<count; i++) { tTJSVariant result; if (obj->PropGetByNum(TJS_IGNOREPROP, i, &result, obj) == TJS_S_OK) { xml_node *prop = doc.allocate_node(rapidxml::node_element, L"property"); prop->append_attribute(doc.allocate_attribute(L"id", ttstr(i).c_str())); prop->append_node(createNodeFromVariant(result, doc)); node->append_node(prop); } } return node; } else { // 辞書 xml_node *node = doc.allocate_node(rapidxml::node_element, L"object"); DictMemberDispCaller *caller = new DictMemberDispCaller(doc, node); tTJSVariantClosure closure(caller); obj->EnumMembers(TJS_IGNOREPROP, &closure, obj); caller->Release(); return node; } } break; case tvtString: return doc.allocate_node(rapidxml::node_element, L"string", var.GetString()); case tvtInteger: case tvtReal: return doc.allocate_node(rapidxml::node_element, L"number", ttstr(var).c_str()); case tvtVoid: return doc.allocate_node(rapidxml::node_element, L"undefined"); default: return doc.allocate_node(rapidxml::node_element, L"null"); } }