void CastingPlatform<TSubClass, issueError>::issueCastError(const Item &validationError, const Item &sourceValue, const ReportContext::Ptr &context) const { Q_ASSERT(validationError); Q_ASSERT(context); Q_ASSERT(validationError.isAtomicValue()); Q_ASSERT(validationError.template as<AtomicValue>()->hasError()); const ValidationError::Ptr err(validationError.template as<ValidationError>()); QString msg(err->message()); if(msg.isNull()) { msg = QtXmlPatterns::tr("It's not possible to cast the value %1 of type %2 to %3") .arg(formatData(sourceValue.stringValue())) .arg(formatType(context->namePool(), sourceValue.type())) .arg(formatType(context->namePool(), targetType())); } else { Q_ASSERT(!msg.isEmpty()); msg = QtXmlPatterns::tr("Failure when casting from %1 to %2: %3") .arg(formatType(context->namePool(), sourceValue.type())) .arg(formatType(context->namePool(), targetType())) .arg(msg); } /* If m_errorCode is FORG0001, we assume our sub-classer doesn't have a * special wish about error code, so then we use the error object's code. */ context->error(msg, m_errorCode == ReportContext::FORG0001 ? err->errorCode() : m_errorCode, static_cast<const TSubClass*>(this)); }
/************************************************************************* returns a pointer to the requested WindowFactory object *************************************************************************/ WindowFactory* WindowFactoryManager::getFactory(const String& type) const { // first, dereference aliased types, as needed. String targetType(getDereferencedAliasType(type)); // try for a 'real' type WindowFactoryRegistry::const_iterator pos = d_factoryRegistry.find(targetType); // found an actual factory for this type if (pos != d_factoryRegistry.end()) { return pos->second; } // no concrete type, try for a falagard mapped type else { FalagardMapRegistry::const_iterator falagard = d_falagardRegistry.find(targetType); // found falagard mapping for this type if (falagard != d_falagardRegistry.end()) { // recursively call getFactory on the target base type return getFactory(falagard->second.d_baseType); } // type not found anywhere, give up with an exception. else { throw UnknownObjectException("WindowFactoryManager::getFactory - A WindowFactory object, an alias, or mapping for '" + type + "' Window objects is not registered with the system."); } } }
Item CastingPlatform<TSubClass, issueError>::cast(const Item &sourceValue, const ReportContext::Ptr &context) const { Q_ASSERT(sourceValue); Q_ASSERT(context); Q_ASSERT(targetType()); if(m_caster) return castWithCaster(sourceValue, m_caster, context); else { bool castImpossible = false; const AtomicCaster::Ptr caster(locateCaster(sourceValue.type(), context, castImpossible, static_cast<const TSubClass *>(this), targetType())); if(!issueError && castImpossible) { /* If we're supposed to issue an error(issueError) then this * line will never be reached, because locateCaster() will in * that case throw. */ return ValidationError::createError(); } else return castWithCaster(sourceValue, caster, context); } }
bool World::sendMessage(SmartMessage & message, Component * sender) { bool anyReceiver = false; if(message->getEntityTargetType()) { // Intentamos conseguir una lista con todas las entidades que comparten un tipo determinado. std::string targetType(message->getEntityTargetType()); EntityStringTableIterator victim = _entitiesByType.find(targetType); if(victim != _entitiesByType.end()) { EntityListIterator i = victim->second.begin(); EntityListIterator end = victim->second.end(); if(message->getEntityTargetName()) { // Mandamos el mensaje a todas las entidades con un tipo y nombre determinado. std::string targetName(message->getEntityTargetName()); for(; i != end; ++i) { if((*i)->getName() == targetName) { anyReceiver = (*i)->sendMessage(message, sender) || anyReceiver; } } } else { // Mandamos el mensaje a todas las entidades con un tipo determinado. for(; i != end; ++i) { anyReceiver = (*i)->sendMessage(message, sender) || anyReceiver; } } } } else if(message->getEntityTargetName()) { // Intentamos conseguir una lista con todas las entidades que comparten un nombre determinado. std::string targetName(message->getEntityTargetName()); EntityStringTableIterator victim = _entitiesByName.find(targetName); if(victim != _entitiesByName.end()) { // Mandamos el mensaje a todas las entidades con un nombre determinado. EntityListIterator i = victim->second.begin(); EntityListIterator end = victim->second.end(); for(; i != end; ++i) { anyReceiver = (*i)->sendMessage(message, sender) || anyReceiver; } } } else { // Mandamos el mensaje a todas las entidades que han sido registradas. EntityIdTableIterator i = _entitiesById.begin(); EntityIdTableIterator end = _entitiesById.end(); for(; i != end; ++i) { anyReceiver = i->second->sendMessage(message, sender) || anyReceiver; } } return anyReceiver; }
/************************************************************************* Returns true if a WindowFactory, an alias, or a falagard mapping for a specified window type is present *************************************************************************/ bool WindowFactoryManager::isFactoryPresent(const String& name) const { // first, dereference aliased types, as needed. String targetType(getDereferencedAliasType(name)); // now try for a 'real' type if (d_factoryRegistry.find(targetType) != d_factoryRegistry.end()) { return true; } // not a concrete type, so return whether it's a Falagard mapped type. else { return (d_falagardRegistry.find(targetType) != d_falagardRegistry.end()); } }
bool SpellScript::TargetHook::CheckEffect(SpellInfo const* spellEntry, uint8 effIndex) { if (!targetType) return false; if (spellEntry->Effects[effIndex].TargetA.GetTarget() != targetType && spellEntry->Effects[effIndex].TargetB.GetTarget() != targetType) return false; SpellImplicitTargetInfo targetType(this->targetType); switch (targetType.GetSelectionCategory()) { case TARGET_SELECT_CATEGORY_CHANNEL: // SINGLE return !area; case TARGET_SELECT_CATEGORY_NEARBY: // BOTH return true; case TARGET_SELECT_CATEGORY_CONE: // AREA case TARGET_SELECT_CATEGORY_AREA: // AREA return area; case TARGET_SELECT_CATEGORY_DEFAULT: switch (targetType.GetObjectType()) { case TARGET_OBJECT_TYPE_SRC: // EMPTY case TARGET_OBJECT_TYPE_DEST: // EMPTY return false; default: switch(targetType.GetReferenceType()) { case TARGET_REFERENCE_TYPE_CASTER: // SINGLE return !area; case TARGET_REFERENCE_TYPE_TARGET: // BOTH return true; } break; } break; } return false; }
bool CastingPlatform<TSubClass, issueError>::prepareCasting(const ReportContext::Ptr &context, const ItemType::Ptr &sourceType) { Q_ASSERT(sourceType); Q_ASSERT(context); if(*sourceType == *BuiltinTypes::xsAnyAtomicType || *sourceType == *BuiltinTypes::item || *sourceType == *CommonSequenceTypes::Empty || *sourceType == *BuiltinTypes::numeric) return true; /* The type could not be narrowed better than xs:anyAtomicType or numeric at compile time. We'll do lookup at runtime instead. */ bool castImpossible = false; m_caster = locateCaster(sourceType, context, castImpossible, static_cast<const TSubClass *>(this), targetType()); return !castImpossible; }
Lexicon<ComplexType> LexiconLearner::run(vector<list<string> > &sentences, int nbIterations, float dirichletPrior, bool verbose) { SimpleType targetType("s", 0); for(int i = 0; i < nbIterations; i++) { // /* if(i > 0) verbose = false; // */ Lexicon<ComplexType> counts; cout << "ITERATION "<<i+1<<endl; float logLikelihood = 0; // Parsing and counting for(unsigned int s = 0; s < sentences.size(); s++) { FrameString fs(mLex, sentences[s], targetType); if(verbose) cout << fs.toString() << endl; SPGParser ps(fs); float totalProba = ps.run(); if(verbose) cout << "Probability : "<<totalProba<<endl; set<Assignment> as = ps.getAssignments(); for(set<Assignment>::iterator it = as.begin(); it != as.end(); it++) { Assignment a = *it; float proba = ps.proba(a); list<string>::iterator word = sentences[s].begin(); if(verbose) cout << "Assignment (proba "<<proba<<"): "<<endl; for(Assignment::iterator typ = a.begin(); typ != a.end(); typ++) { if(word != sentences[s].end()) { if(verbose) cout << *word << " -> "<< fs.getType(*typ).toString() << " (type id "<<*typ<<")"<<endl; counts[*word].addCount(fs.getType(*typ), proba); word++; } } } if(verbose) cout << endl; else cout << "." << flush; logLikelihood += log(totalProba); } if(!verbose) cout << endl; // Normalizing counts.normalize(dirichletPrior); // Pruning counts.pruneZeros(); cout << counts.toString(); mLex = counts; cout << "Perplexity (before last step): "<<-logLikelihood<<endl; } return mLex; }
/***preinitBlock_hasInitialValue($channel)***/ static $targetType(output) $actorSymbol(storedValue_$channel) = ($targetType(output)) $val(initialValue); static unsigned int $actorSymbol(storedValue_$channel_hasValue) = 1; /**/ /***preinitBlock_noInitialValue($channel)***/ static $targetType(output) $actorSymbol(storedValue_$channel); static unsigned int $actorSymbol(storedValue_$channel_hasValue) = 0; /**/ /***triggerBlock($channel)***/ if ($hasToken(trigger) && $actorSymbol(storedValue_$channel_hasValue)) { $put(output#$channel, $actorSymbol(storedValue_$channel)) } /**/ /***updateValueBlock($channel)***/ if ($hasToken(input#$channel)) { $actorSymbol(storedValue_$channel) = ($targetType(output)) $get(input#$channel); $actorSymbol(storedValue_$channel_hasValue) = 1; } /**/