// RIDMap map<string, RIDList> // RIDTree map<string, ValueMap> bool Domain::Indices::Lookup(const set<string>& dimensions, const Conditions& conditions, Data::RIDTree& results) { ValuesMap values; if(!this->meta->index->OpenReader()) { return false; } if(!this->meta->index->Lookup(dimensions, values)) { this->meta->index->Close(); return false; } Data::RIDMap records; ValuesMap::iterator vlist; for(vlist = values.begin(); vlist != values.end(); vlist++) { sort(vlist->second.begin(), vlist->second.end()); conditions.Apply(vlist->first, vlist->second); if(!this->meta->index->Lookup(vlist->first, vlist->second, records)) { this->meta->index->Close(); return false; } else { results[vlist->first] = records; } } this->meta->index->Close(); return true; }
void jsonValueToRapidJSON(JSONValue* value, rapidjson::Value& rapidValue, rapidjson::Document& document) { JSONInt* intValue = dynamic_cast<JSONInt*>(value); if (intValue) { rapidValue.SetInt(intValue->getValue()); return; } JSONString* stringValue = dynamic_cast<JSONString*>(value); if (stringValue) { rapidValue.SetString(stringValue->getValue().c_str(), stringValue->getValue().size(), document.GetAllocator()); return; } JSONBool* boolValue = dynamic_cast<JSONBool*>(value); if (boolValue) { rapidValue.SetBool(boolValue->getValue()); return; } JSONArray* arrayValue = dynamic_cast<JSONArray*>(value); if (arrayValue) { rapidValue.SetArray(); std::vector<JSONValue::ref> values = arrayValue->getValues(); for (size_t i = 0; i < values.size(); i++) { rapidjson::Value obj; jsonValueToRapidJSON(values[i].get(), obj, document); rapidValue.PushBack(obj, document.GetAllocator()); } return; } JSONObject* objectValue = dynamic_cast<JSONObject*>(value); if (objectValue) { rapidValue.SetObject(); typedef std::map<std::string, JSONValue::ref> ValuesMap; ValuesMap values = objectValue->getValues(); for (ValuesMap::iterator it = values.begin(); it != values.end(); it++) { rapidjson::Value obj; jsonValueToRapidJSON(it->second.get(), obj, document); rapidjson::Value key; key.SetString(it->first.c_str(), it->first.size(), document.GetAllocator()); rapidValue.AddMember(key, obj, document.GetAllocator()); } return; } assert(false); }