ParameterizedCommand::ParameterizedCommand(const SmartPointer<Command> command, const std::vector<Parameterization>& params) : command(command), hashCode(HASH_CODE_NOT_COMPUTED) { if (!command) { throw Poco::NullPointerException( "A parameterized command cannot have a null command"); } std::vector<IParameter::Pointer> parameters; try { parameters = command->GetParameters(); } catch (const NotDefinedException* /*e*/) { // This should not happen. } if (!params.empty() && !parameters.empty()) { for (unsigned int j = 0; j < parameters.size(); j++) { for (unsigned int i = 0; i < params.size(); i++) { if (parameters[j] == params[i].GetParameter()) { this->parameterizations.push_back(params[i]); } } } } }
void CommandService::RegisterElement(const SmartPointer<IElementReference>& elementReference) { QList<IElementReference::Pointer>& parameterizedCommands = commandCallbacks[elementReference->GetCommandId()]; parameterizedCommands.push_back(elementReference); // If the active handler wants to update the callback, it can do // so now Command::Pointer command = GetCommand(elementReference->GetCommandId()); if (command->IsDefined()) { if (IElementUpdater::Pointer updater = command->GetHandler().Cast<IElementUpdater>()) { updater->UpdateElement(elementReference->GetElement().GetPointer(), elementReference->GetParameters()); } } }
QList<ParameterizedCommand::Pointer> ParameterizedCommand::GenerateCombinations(const SmartPointer<Command> command) { QList<IParameter::Pointer> parameters(command->GetParameters()); typedef QList<QList<Parameterization> > ExpandedParamsType; const ExpandedParamsType expansion(ExpandParameters(0, parameters)); QList<ParameterizedCommand::Pointer> combinations; for (ExpandedParamsType::const_iterator expansionItr = expansion.begin(); expansionItr != expansion.end(); ++expansionItr) { QList<Parameterization> combination(*expansionItr); QList<Parameterization> parameterizations(combination); ParameterizedCommand::Pointer pCmd(new ParameterizedCommand(command, parameterizations)); combinations.push_back(pCmd); } return combinations; }
std::vector<ParameterizedCommand::Pointer> ParameterizedCommand::GenerateCombinations(const SmartPointer<Command> command) throw(NotDefinedException) { std::vector<IParameter::Pointer> parameters(command->GetParameters()); typedef std::vector<std::list<Parameterization> > ExpandedParamsType; const ExpandedParamsType expansion(ExpandParameters(0, parameters)); std::vector<ParameterizedCommand::Pointer> combinations; for (ExpandedParamsType::const_iterator expansionItr = expansion.begin(); expansionItr != expansion.end(); ++expansionItr) { std::list<Parameterization> combination(*expansionItr); std::vector<Parameterization> parameterizations(combination.begin(), combination.end()); ParameterizedCommand::Pointer pCmd(new ParameterizedCommand(command, parameterizations)); combinations.push_back(pCmd); } return combinations; }
SmartPointer<ParameterizedCommand> RegistryPersistence::ReadParameters( const SmartPointer<IConfigurationElement>& configurationElement, QList<SmartPointer<IStatus> >& warningsToLog, const SmartPointer<Command>& command) { const QList<IConfigurationElement::Pointer> parameterElements = configurationElement ->GetChildren(TAG_PARAMETER); if (parameterElements.isEmpty()) { ParameterizedCommand::Pointer result(new ParameterizedCommand(command, QList<Parameterization>())); return result; } QList<Parameterization> parameters; foreach (const IConfigurationElement::Pointer& parameterElement, parameterElements) { // Read out the id. const QString id = parameterElement->GetAttribute(ATT_ID); if (id.isEmpty()) { // The id should never be null. This is invalid. AddWarning(warningsToLog, "Parameters need an id", configurationElement); continue; } // Find the parameter on the command. IParameter::Pointer parameter; try { const QList<IParameter::Pointer> commandParameters = command->GetParameters(); foreach (const IParameter::Pointer& currentParameter, commandParameters) { if (currentParameter->GetId() == id) { parameter = currentParameter; break; } } } catch (const NotDefinedException& /*e*/) { // This should not happen. } if (parameter.IsNull()) { // The name should never be null. This is invalid. AddWarning(warningsToLog, "Could not find a matching parameter", configurationElement, id); continue; } // Read out the value. const QString value = parameterElement->GetAttribute(ATT_VALUE); if (value.isEmpty()) { // The name should never be null. This is invalid. AddWarning(warningsToLog, "Parameters need a value", configurationElement, id); continue; } parameters.push_back(Parameterization(parameter, value)); } if (parameters.isEmpty()) { ParameterizedCommand::Pointer result(new ParameterizedCommand(command, QList<Parameterization>())); return result; } ParameterizedCommand::Pointer result(new ParameterizedCommand(command, parameters)); return result; }