Context* GetContext(lua_State* L) { HashMap<void*, Context*>::ConstIterator i = contextMapping.Find(L); if (i == contextMapping.End()) { lua_State* L1 = lua_getmainthread(L); return (L == L1) ? 0 : GetContext(L1); } return i->second_; }
ECode CWifiP2pDnsSdServiceResponse::ReadDnsName( /* [in] */ IDataInput* idi, /* [out] */ String* dnsName) { VALIDATE_NOT_NULL(dnsName); *dnsName = String(NULL); StringBuilder sb; // copy virtual memory packet. HashMap<Int32, String> vmpack; HashMap<Int32, String>::Iterator it; if (!mDnsQueryName.IsNull()) { vmpack[0x27] = mDnsQueryName; } // try { Int32 i, temp; while (TRUE) { FAIL_RETURN(idi->ReadUnsignedByte(&i)); if (i == 0x00) { *dnsName = sb.ToString(); return NOERROR; } else if (i == 0xc0) { // refer to pointer. FAIL_RETURN(idi->ReadUnsignedByte(&temp)); it = vmpack.Find(temp); if (it == vmpack.End()) { //invalid. return NOERROR; } sb += it->mSecond; *dnsName = sb.ToString(); return NOERROR; } else { AutoPtr<ArrayOf<Byte> > data = ArrayOf<Byte>::Alloc(i); if (data == NULL) return E_OUT_OF_MEMORY; FAIL_RETURN(idi->ReadFully((ArrayOf<Byte>*)data)); sb += String((const char *)data->GetPayload()); sb += "."; } } // catch (IOException e) { // e.printStackTrace(); // } return NOERROR; }
void RemoveNamedAttribute(HashMap<StringHash, Vector<AttributeInfo> >& attributes, StringHash objectType, const char* name) { HashMap<StringHash, Vector<AttributeInfo> >::Iterator i = attributes.Find(objectType); if (i == attributes.End()) return; Vector<AttributeInfo>& infos = i->second_; for (Vector<AttributeInfo>::Iterator j = infos.Begin(); j != infos.End(); ++j) { if (!j->name_.Compare(name, true)) { infos.Erase(j); break; } } // If the vector became empty, erase the object type from the map if (infos.Empty()) attributes.Erase(i); }