std::set<Name> Strategy::listRegistered() { std::set<Name> strategyNames; boost::copy(getRegistry() | boost::adaptors::map_keys, std::inserter(strategyNames, strategyNames.end())); return strategyNames; }
RegTextureMapped::RegTextureMapped(std::string gName, std::string gFull, float *gx, float *gy){ tex = getRegistry()->getTexture(gFull); name = gName.c_str(); source = gFull.c_str(); for(int z = 0; z<4; z++){ x[z] = gx[z]; y[z] = gy[z]; } }
RegTextureMapped::RegTextureMapped(std::string gName, std::string gFull){ tex = getRegistry()->getTexture(gFull); name = gName; source = gFull; float tmpx[4] = {0.0, 1.0, 1.0, 0.0}; float tmpy[4] = {0.0, 0.0, 1.0, 1.0}; for(int z = 0; z < 4; z++){ x[z] = tmpx[z]; y[z] = tmpy[z]; } }
unique_ptr<ProtocolFactory> ProtocolFactory::create(const std::string& id, const CtorParams& params) { Registry& registry = getRegistry(); auto found = registry.find(id); if (found == registry.end()) { return nullptr; } return found->second(params); }
void Settings::load() { auto regPtr = getRegistry(); auto ® = *regPtr; reg.beginGroup("settings"); m_priority = static_cast<ProcessPriority>(reg.value("priority", static_cast<int>(NormalPriority)).toInt()); m_lastOpenDir = QDir{reg.value("lastOpenDir").toString()}; m_lastOutputDir = QDir{reg.value("lastOutputDir").toString()}; m_lastConfigDir = QDir{reg.value("lastConfigDir").toString()}; m_lastMatroskaFileDir = QDir{reg.value("lastMatroskaFileDir").toString()}; m_oftenUsedLanguages = reg.value("oftenUsedLanguages").toStringList(); m_oftenUsedCountries = reg.value("oftenUsedCountries").toStringList(); m_oftenUsedCharacterSets = reg.value("oftenUsedCharacterSets").toStringList(); m_scanForPlaylistsPolicy = static_cast<ScanForPlaylistsPolicy>(reg.value("scanForPlaylistsPolicy", static_cast<int>(AskBeforeScanning)).toInt()); m_minimumPlaylistDuration = reg.value("minimumPlaylistDuration", 120).toUInt(); m_setAudioDelayFromFileName = reg.value("setAudioDelayFromFileName", true).toBool(); m_autoSetFileTitle = reg.value("autoSetFileTitle", true).toBool(); m_uniqueOutputFileNames = reg.value("uniqueOutputFileNames", true).toBool(); m_outputFileNamePolicy = static_cast<OutputFileNamePolicy>(reg.value("outputFileNamePolicy", static_cast<int>(ToPreviousDirectory)).toInt()); m_fixedOutputDir = QDir{reg.value("fixedOutputDir").toString()}; m_jobRemovalPolicy = static_cast<JobRemovalPolicy>(reg.value("jobRemovalPolicy", static_cast<int>(JobRemovalPolicy::Never)).toInt()); reg.beginGroup("updates"); m_checkForUpdates = reg.value("checkForUpdates", true).toBool(); m_lastUpdateCheck = reg.value("lastUpdateCheck", QDateTime{}).toDateTime(); reg.endGroup(); // settings.updates reg.endGroup(); // settings reg.beginGroup("defaults"); m_defaultTrackLanguage = reg.value("defaultTrackLanguage", Q("und")).toString(); m_defaultChapterLanguage = reg.value("defaultChapterLanguage", Q("und")).toString(); m_defaultChapterCountry = reg.value("defaultChapterCountry").toString(); m_defaultSubtitleCharset = reg.value("defaultSubtitleCharset").toString(); reg.endGroup(); // defaults if (m_oftenUsedLanguages.isEmpty()) for (auto const &languageCode : g_popular_language_codes) m_oftenUsedLanguages << Q(languageCode); if (m_oftenUsedCountries.isEmpty()) for (auto const &countryCode : g_popular_country_codes) m_oftenUsedCountries << Q(countryCode); if (m_oftenUsedCharacterSets.isEmpty()) for (auto const &characterSet : g_popular_character_sets) m_oftenUsedCharacterSets << Q(characterSet); }
static char * getCygwinBin(int use64) { char *dir; DWORD size = MAX_PATH; dir = smalloc(size); dir[0] = '\0'; if (ERROR_SUCCESS == getRegistry(dir, &size, CYGWIN_U_SETUP_ROOTDIR, use64) || ERROR_SUCCESS == getRegistry(dir, &size, CYGWIN_S_SETUP_ROOTDIR, use64)) { strcat(dir, "\\bin"); } else { sfree(dir); dir = 0; } return dir; }
const OptionsFactorySharedPtr OptionsRegistry::getFactory(const String& factoryName, const String& factoryVersion) { ObjectRegistry& registry = getRegistry(); const ManagedObjectSharedPtr& baseFactoryPtr = registry.findByNameAndVersion(factoryName, factoryVersion); OptionsFactorySharedPtr factoryPtr = CHECKED_SHARED_POINTER_CAST(OptionsFactory,ManagedObject,baseFactoryPtr); return factoryPtr; }
void Settings::withGroup(QString const &group, std::function<void(QSettings &)> worker) { auto reg = getRegistry(); auto groups = group.split(Q("/")); for (auto const &subGroup : groups) reg->beginGroup(subGroup); worker(*reg); for (auto idx = groups.size(); idx > 0; --idx) reg->endGroup(); }
void Registry::registerActionsTo(ActionFactory & f, const std::set<std::string> & labels) { auto & r = getRegistry(); for (const auto & label : labels) { r._known_labels.insert(label); if (r._per_label_actions.count(label) == 0) continue; for (const auto & obj : r._per_label_actions[label]) f.reg( obj._classname, obj._name, obj._build_action_ptr, obj._params_ptr, obj._file, obj._line); } }
unique_ptr<Strategy> Strategy::create(const Name& instanceName, Forwarder& forwarder) { auto found = Strategy::find(instanceName); if (found == getRegistry().end()) { NFD_LOG_DEBUG("create " << instanceName << " not-found"); return nullptr; } unique_ptr<Strategy> instance = found->second(forwarder, instanceName); NFD_LOG_DEBUG("create " << instanceName << " found=" << found->first << " created=" << instance->getInstanceName()); BOOST_ASSERT(!instance->getInstanceName().empty()); return instance; }
void Settings::save() const { auto regPtr = getRegistry(); auto ® = *regPtr; reg.beginGroup("settings"); reg.setValue("priority", static_cast<int>(m_priority)); reg.setValue("lastOpenDir", m_lastOpenDir.path()); reg.setValue("lastOutputDir", m_lastOutputDir.path()); reg.setValue("lastConfigDir", m_lastConfigDir.path()); reg.setValue("lastMatroskaFileDir", m_lastMatroskaFileDir.path()); reg.setValue("oftenUsedLanguages", m_oftenUsedLanguages); reg.setValue("oftenUsedCountries", m_oftenUsedCountries); reg.setValue("oftenUsedCharacterSets", m_oftenUsedCharacterSets); reg.setValue("scanForPlaylistsPolicy", static_cast<int>(m_scanForPlaylistsPolicy)); reg.setValue("minimumPlaylistDuration", m_minimumPlaylistDuration); reg.setValue("setAudioDelayFromFileName", m_setAudioDelayFromFileName); reg.setValue("autoSetFileTitle", m_autoSetFileTitle); reg.setValue("outputFileNamePolicy", static_cast<int>(m_outputFileNamePolicy)); reg.setValue("fixedOutputDir", m_fixedOutputDir.path()); reg.setValue("uniqueOutputFileNames", m_uniqueOutputFileNames); reg.setValue("jobRemovalPolicy", static_cast<int>(m_jobRemovalPolicy)); reg.beginGroup("updates"); reg.setValue("checkForUpdates", m_checkForUpdates); reg.setValue("lastUpdateCheck", m_lastUpdateCheck); reg.endGroup(); // settings.updates reg.endGroup(); // settings reg.beginGroup("defaults"); reg.setValue("defaultTrackLanguage", m_defaultTrackLanguage); reg.setValue("defaultChapterLanguage", m_defaultChapterLanguage); reg.setValue("defaultChapterCountry", m_defaultChapterCountry); reg.setValue("defaultSubtitleCharset", m_defaultSubtitleCharset); reg.endGroup(); // defaults }
void Registry::checkLabels(const std::set<std::string> & known_labels) { auto & r = getRegistry(); std::vector<RegistryEntry> orphs; for (auto & entry : r._per_label_objects) if (known_labels.count(entry.first) == 0 && r._known_labels.count(entry.first) == 0) orphs.insert(orphs.end(), entry.second.begin(), entry.second.end()); for (auto & entry : r._per_label_actions) if (known_labels.count(entry.first) == 0 && r._known_labels.count(entry.first) == 0) orphs.insert(orphs.end(), entry.second.begin(), entry.second.end()); if (orphs.size() > 0) { std::stringstream lst; for (auto & orph : orphs) lst << "\n\t" << orph._classname << " (app='" << orph._label << "')"; mooseError("The following objects/actions have been registered to unknown applications/labels:", lst.str()); } }
Strategy::Registry::const_iterator Strategy::find(const Name& instanceName) { const Registry& registry = getRegistry(); ParsedInstanceName parsed = parseInstanceName(instanceName); if (parsed.version) { // specified version: find exact or next higher version auto found = registry.lower_bound(parsed.strategyName); if (found != registry.end()) { if (parsed.strategyName.getPrefix(-1).isPrefixOf(found->first)) { NFD_LOG_TRACE("find " << instanceName << " versioned found=" << found->first); return found; } } NFD_LOG_TRACE("find " << instanceName << " versioned not-found"); return registry.end(); } // no version specified: find highest version if (!parsed.strategyName.empty()) { // Name().getSuccessor() would be invalid auto found = registry.lower_bound(parsed.strategyName.getSuccessor()); if (found != registry.begin()) { --found; if (parsed.strategyName.isPrefixOf(found->first)) { NFD_LOG_TRACE("find " << instanceName << " unversioned found=" << found->first); return found; } } } NFD_LOG_TRACE("find " << instanceName << " unversioned not-found"); return registry.end(); }
const std::map<std::string, std::vector<RegistryEntry>> & Registry::allObjects() { return getRegistry()._per_label_objects; }
void RegTextureMapped::rePoint(){ tex = getRegistry()->getTexture(source); }
Type() { getRegistry().push_back(this); }
static Warrior* createWarrior( Warrior_ID id ) { Registry& r = getRegistry(); if( r.find(id) != r.end() ) return r[id]->clone(); return 0; }
vector<string> OptimizerMode::listNames() { vector<string> names; copy(getRegistry() | map_keys,back_inserter(names)); return boost::move(names); }
OptimizerMode const& OptimizerMode::lookupName(string const& name) { OptimizerModeRegistry const& registry = getRegistry(); OptimizerModeRegistry::const_iterator iter = registry.find(name); if(iter == registry.end()) throw NoSuchOptimizerModeError(name); else return iter->second; }
static void removePrototype( Warrior_ID id ) { Registry& r = getRegistry(); r.erase( r.find( id ) ); }
ActiveMigrationsRegistry& ActiveMigrationsRegistry::get(ServiceContext* service) { return getRegistry(service); }
void ArgSemExtAtom::retrieve(const Query& query, Answer& answer) throw (PluginError) { assert(query.input.size() == 6); RegistryPtr reg = getRegistry(); // check if pspoil is true { // id of constant of saturate/spoil predicate ID saturate_pred = query.input[4]; // get id of 0-ary atom OrdinaryAtom saturate_oatom(ID::MAINKIND_ATOM | ID::SUBKIND_ATOM_ORDINARYG); saturate_oatom.tuple.push_back(saturate_pred); ID saturate_atom = reg->storeOrdinaryGAtom(saturate_oatom); DBGLOG(DBG,"got saturate_pred=" << saturate_pred << " and saturate_atom=" << saturate_atom); // check if atom <saturate_pred> is true in interpretation bool saturate = query.interpretation->getFact(saturate_atom.address); LOG(DBG,"ArgSemExtAtom called with pos saturate=" << saturate); if( saturate ) { // always return true answer.get().push_back(Tuple()); return; } } // check if nspoil is true { // id of constant of saturate/spoil predicate ID saturate_pred = query.input[5]; // get id of 0-ary atom OrdinaryAtom saturate_oatom(ID::MAINKIND_ATOM | ID::SUBKIND_ATOM_ORDINARYG); saturate_oatom.tuple.push_back(saturate_pred); ID saturate_atom = reg->storeOrdinaryGAtom(saturate_oatom); DBGLOG(DBG,"got saturate_pred=" << saturate_pred << " and saturate_atom=" << saturate_atom); // check if atom <saturate_pred> is true in interpretation bool saturate = query.interpretation->getFact(saturate_atom.address); LOG(DBG,"ArgSemExtAtom called with neg saturate=" << saturate); if( saturate ) { // always return false answer.use(); return; } } // get arguments const std::string& semantics = reg->getTermStringByID(query.input[0]); ID argRelId = query.input[1]; ID attRelId = query.input[2]; ID extRelId = query.input[3]; // assemble facts from input std::stringstream s; { // add argumentation framework (att, arg) as predicates att/2 and arg/1 // (ignore predicate name of given atoms) // TODO: we could do this more efficiently using extctx.edb->setFact(...); and not by parsing // arguments { PredicateMask& argMask = getPredicateMask(argRelId, reg); argMask.updateMask(); InterpretationPtr argInt(new Interpretation(*query.interpretation)); argInt->bit_and(*argMask.mask()); for(auto begend = argInt->trueBits(); begend.first != begend.second; ++begend.first++) { auto bit_it = begend.first; const OrdinaryAtom& atom = argInt->getAtomToBit(bit_it); assert(atom.tuple.size() == 2); s << "arg(" << printToString<RawPrinter>(atom.tuple[1], reg) << ").\n"; } } // attacks { PredicateMask& attMask = getPredicateMask(attRelId, reg); attMask.updateMask(); InterpretationPtr attInt(new Interpretation(*query.interpretation)); attInt->bit_and(*attMask.mask()); for(auto begend = attInt->trueBits(); begend.first != begend.second; ++begend.first++) { auto bit_it = begend.first; const OrdinaryAtom& atom = attInt->getAtomToBit(bit_it); assert(atom.tuple.size() == 3); s << "att(" << printToString<RawPrinter>(atom.tuple[1], reg) << "," << printToString<RawPrinter>(atom.tuple[2], reg) << ").\n"; } } // extension to check { PredicateMask& extMask = getPredicateMask(extRelId, reg); extMask.updateMask(); InterpretationPtr extInt(new Interpretation(*query.interpretation)); extInt->bit_and(*extMask.mask()); for(auto begend = extInt->trueBits(); begend.first != begend.second; ++begend.first++) { auto bit_it = begend.first; const OrdinaryAtom& atom = extInt->getAtomToBit(bit_it); assert(atom.tuple.size() == 2); s << "ext(" << printToString<RawPrinter>(atom.tuple[1], reg) << ").\n"; } } // add check s << "%% check if ext/1 is an extension\n" ":- arg(X), ext(X), out(X).\n" ":- arg(X), not ext(X), in(X).\n"; } // build program InputProviderPtr input(new InputProvider); input->addStringInput(s.str(),"facts_from_predicate_input"); input->addFileInput(semantics + ".encoding"); #if 0 // we use an extra registry for an external program ProgramCtx extctx; extctx.setupRegistry(RegistryPtr(new Registry)); // parse ModuleHexParser parser; parser.parse(input, extctx); DBGLOG(DBG,"after parsing input: idb and edb are" << std::endl << std::endl << printManyToString<RawPrinter>(extctx.idb,"\n",extctx.registry()) << std::endl << *extctx.edb << std::endl); // check if there is one answer set, if yes return true, false otherwise { typedef ASPSolverManager::SoftwareConfiguration<ASPSolver::DLVSoftware> DLVConfiguration; DLVConfiguration dlv; OrdinaryASPProgram program(extctx.registry(), extctx.idb, extctx.edb, extctx.maxint); ASPSolverManager mgr; ASPSolverManager::ResultsPtr res = mgr.solve(dlv, program); AnswerSet::Ptr firstAnswerSet = res->getNextAnswerSet(); if( firstAnswerSet != 0 ) { LOG(DBG,"got answer set " << *firstAnswerSet->interpretation); // true answer.get().push_back(Tuple()); } else { LOG(DBG,"got no answer set!"); // false (-> mark as used) answer.use(); } } #else ProgramCtx subctx = ctx; subctx.changeRegistry(RegistryPtr(new Registry)); subctx.edb.reset(new Interpretation(subctx.registry())); subctx.inputProvider = input; input.reset(); // parse into subctx, but do not call converters if( !subctx.parser ) { subctx.parser.reset(new ModuleHexParser); } subctx.parser->parse(subctx.inputProvider, subctx); std::vector<InterpretationPtr> subas = ctx.evaluateSubprogram(subctx, false); if( !subas.empty() ) { LOG(DBG,"got answer set " << *subas.front()); // true answer.get().push_back(Tuple()); } else { LOG(DBG,"got no answer set!"); // false (-> mark as used) answer.use(); } #endif }
const std::map<std::string, std::vector<RegistryEntry>> & Registry::allActions() { return getRegistry()._per_label_actions; }
void registerConversionImplementation(ConversionImpl *module, int priority) { assert(module); getRegistry().insert(pair<int,ConversionImpl*>(priority,module)); }
void Registry::addInner(const RegistryEntry & info) { auto & r = getRegistry(); r._per_label_objects[info._label].push_back(info); }
void Registry::addActionInner(const RegistryEntry & info) { auto & r = getRegistry(); r._per_label_actions[info._label].push_back(info); }
void TestFactoryRegistry::addRegistry( const std::string &name ) { registerFactory( &getRegistry( name ) ); }
bool Strategy::canCreate(const Name& instanceName) { return Strategy::find(instanceName) != getRegistry().end(); }
Module Module::import(std::string const & name) const { Module module(name); getRegistry().import(module.getRegistry()); return module; }
static void addProtopype( Warrior_ID id, Warrior* prototype) { Registry& r = getRegistry(); r[id] = prototype; }