/* * Function handle the insertion of an object within the prototype framework. Note that this does not adjust internal values * of other objects, use add_object() for that. */ int insert_object(struct obj_data *obj, obj_vnum ovnum) { int i; top_of_objt++; RECREATE(obj_index, struct index_data, top_of_objt + 1); RECREATE(obj_proto, struct obj_data, top_of_objt + 1); /* * Start counting through both tables. */ for (i = top_of_objt; i > 0; i--) { /* * Check if current virtual is bigger than our virtual number. */ if (ovnum > obj_index[i - 1].vnum) return index_object(obj, ovnum, i); /* Copy over the object that should be here. */ obj_index[i] = obj_index[i - 1]; obj_proto[i] = obj_proto[i - 1]; obj_proto[i].item_number = i; } /* Not found, place at 0. */ return index_object(obj, ovnum, 0); }
void property_indexer::index_objects(model& m) { BOOST_LOG_SEV(lg, debug) << "Indexing objects: " << m.objects().size(); std::unordered_set<sml::qname> processed_qnames; for (auto& pair : m.objects()) { auto& o(pair.second); if (o.generation_type() == generation_types::no_generation) continue; index_object(o, m, processed_qnames); } }
MRUManager::MRUManager(const std::string &config, const std::string &default_config): config_name(config) { LOG_D("agi/mru") << "Loading MRU List"; json::UnknownElement root = json_util::file(config, default_config); const json::Object& root_new = (json::Object)root; json::Object::const_iterator index_object(root_new.Begin()), index_objectEnd(root_new.End()); for (; index_object != index_objectEnd; ++index_object) { const json::Object::Member& member = *index_object; const std::string &member_name = member.name; const json::UnknownElement& element = member.element; Load(member_name, (json::Array)element); } }
void property_indexer::index_object(object& o, model& m, std::unordered_set<sml::qname>& processed_qnames) { BOOST_LOG_SEV(lg, debug) << "Indexing object: " << sml::string_converter::convert(o.name()); if (processed_qnames.find(o.name()) != processed_qnames.end()) { BOOST_LOG_SEV(lg, debug) << "Object already processed: " << sml::string_converter::convert(o.name()); return; } std::list<property> concept_properties; auto i(o.relationships().find(relationship_types::modeled_concepts)); if (i != o.relationships().end()) { for (const auto& qn : i->second) { auto& c(find_concept(qn, m)); concept_properties.insert(concept_properties.end(), c.local_properties().begin(), c.local_properties().end()); } } o.local_properties().insert(o.local_properties().begin(), concept_properties.begin(), concept_properties.end()); i = o.relationships().find(relationship_types::parents); if (i != o.relationships().end()) { for (const auto& qn : i->second) { auto& parent(find_object(qn, m)); index_object(parent, m, processed_qnames); if (!parent.all_properties().empty()) o.inherited_properties().insert( std::make_pair(parent.name(), parent.all_properties())); o.all_properties().insert(o.all_properties().end(), parent.all_properties().begin(), parent.all_properties().end()); } } o.all_properties().insert(o.all_properties().end(), o.local_properties().begin(), o.local_properties().end()); processed_qnames.insert(o.name()); }
void concept_indexer::index_object(object& o, model& m, std::unordered_set<qname>& processed_qnames) { BOOST_LOG_SEV(lg, debug) << "Indexing object: " << string_converter::convert(o.name()); if (processed_qnames.find(o.name()) != processed_qnames.end()) { BOOST_LOG_SEV(lg, debug) << "Object already processed."; return; } const auto i(o.relationships().find(relationship_types::modeled_concepts)); if (i == o.relationships().end() || i->second.empty()) { processed_qnames.insert(o.name()); BOOST_LOG_SEV(lg, debug) << "Object models no concepts."; return; } std::list<qname> expanded_refines; for (auto& qn : i->second) { auto& c(find_concept(qn, m)); expanded_refines.push_back(qn); expanded_refines.insert(expanded_refines.end(), c.refines().begin(), c.refines().end()); } remove_duplicates(expanded_refines); if (!o.is_child()) { i->second = expanded_refines; BOOST_LOG_SEV(lg, debug) << "Object has no parents, using reduced set."; return; } std::set<qname> our_concepts; our_concepts.insert(expanded_refines.begin(), expanded_refines.end()); std::set<qname> their_concepts; for (const auto& qn : find_relationships(relationship_types::parents, o)) { auto& parent(find_object(qn, m)); index_object(parent, m, processed_qnames); auto& pr(parent.relationships()); const auto j(pr.find(relationship_types::modeled_concepts)); if (j == pr.end() || j->second.empty()) continue; their_concepts.insert(j->second.begin(), j->second.end()); } /* we want to only model concepts which have not yet been modeled * by any of our parents. */ std::set<qname> result; std::set_difference(our_concepts.begin(), our_concepts.end(), their_concepts.begin(), their_concepts.end(), std::inserter(result, result.end())); /* reinsert all of the modeled concepts which are part of the set * difference. we do this instead of just using the set difference * directly to preserve order. */ BOOST_LOG_SEV(lg, debug) << "Object has parents, computing set difference."; i->second.clear(); for (const auto& qn : expanded_refines) { if (result.find(qn) != result.end()) i->second.push_back(qn); } BOOST_LOG_SEV(lg, debug) << "Finished indexing object."; }