int main() { // Get syms from an input message std::vector<Symbol> symbols = toSymbols(toBits(promptMessage())); // Print out for (int i = 0; i < symbols.size(); i++) { std::cout << symbols[i].expo << std::endl; } return 0; }
/*! * \internal */ bool DataValidation::saveToXml(QXmlStreamWriter &writer) const { static QMap<DataValidation::ValidationType, QString> typeMap; static QMap<DataValidation::ValidationOperator, QString> opMap; static QMap<DataValidation::ErrorStyle, QString> esMap; if (typeMap.isEmpty()) { typeMap.insert(DataValidation::None, QStringLiteral("none")); typeMap.insert(DataValidation::Whole, QStringLiteral("whole")); typeMap.insert(DataValidation::Decimal, QStringLiteral("decimal")); typeMap.insert(DataValidation::List, QStringLiteral("list")); typeMap.insert(DataValidation::Date, QStringLiteral("date")); typeMap.insert(DataValidation::Time, QStringLiteral("time")); typeMap.insert(DataValidation::TextLength, QStringLiteral("textLength")); typeMap.insert(DataValidation::Custom, QStringLiteral("custom")); opMap.insert(DataValidation::Between, QStringLiteral("between")); opMap.insert(DataValidation::NotBetween, QStringLiteral("notBetween")); opMap.insert(DataValidation::Equal, QStringLiteral("equal")); opMap.insert(DataValidation::NotEqual, QStringLiteral("notEqual")); opMap.insert(DataValidation::LessThan, QStringLiteral("lessThan")); opMap.insert(DataValidation::LessThanOrEqual, QStringLiteral("lessThanOrEqual")); opMap.insert(DataValidation::GreaterThan, QStringLiteral("greaterThan")); opMap.insert(DataValidation::GreaterThanOrEqual, QStringLiteral("greaterThanOrEqual")); esMap.insert(DataValidation::Stop, QStringLiteral("stop")); esMap.insert(DataValidation::Warning, QStringLiteral("warning")); esMap.insert(DataValidation::Information, QStringLiteral("information")); } writer.writeStartElement(QStringLiteral("dataValidation")); if (validationType() != DataValidation::None) writer.writeAttribute(QStringLiteral("type"), typeMap[validationType()]); if (errorStyle() != DataValidation::Stop) writer.writeAttribute(QStringLiteral("errorStyle"), esMap[errorStyle()]); if (validationOperator() != DataValidation::Between) writer.writeAttribute(QStringLiteral("operator"), opMap[validationOperator()]); if (allowBlank()) writer.writeAttribute(QStringLiteral("allowBlank"), QStringLiteral("1")); // if (dropDownVisible()) // writer.writeAttribute(QStringLiteral("showDropDown"), QStringLiteral("1")); if (isPromptMessageVisible()) writer.writeAttribute(QStringLiteral("showInputMessage"), QStringLiteral("1")); if (isErrorMessageVisible()) writer.writeAttribute(QStringLiteral("showErrorMessage"), QStringLiteral("1")); if (!errorMessageTitle().isEmpty()) writer.writeAttribute(QStringLiteral("errorTitle"), errorMessageTitle()); if (!errorMessage().isEmpty()) writer.writeAttribute(QStringLiteral("error"), errorMessage()); if (!promptMessageTitle().isEmpty()) writer.writeAttribute(QStringLiteral("promptTitle"), promptMessageTitle()); if (!promptMessage().isEmpty()) writer.writeAttribute(QStringLiteral("prompt"), promptMessage()); QStringList sqref; foreach (CellRange range, ranges()) sqref.append(range.toString()); writer.writeAttribute(QStringLiteral("sqref"), sqref.join(QLatin1Char(' '))); if (!formula1().isEmpty()) writer.writeTextElement(QStringLiteral("formula1"), formula1()); if (!formula2().isEmpty()) writer.writeTextElement(QStringLiteral("formula2"), formula2()); writer.writeEndElement(); //dataValidation return true; }
//============================================================================= // METHOD: SPELLserverCif::prompt //============================================================================= std::string SPELLserverCif::prompt( const std::string& message, PromptOptions options, unsigned int ptype, unsigned int scope ) { DEBUG("[CIF] Prompt message"); std::string timeStr = getTimestampUsec(); SPELLipcMessage promptMessage(MessageId::MSG_ID_PROMPT); completeMessage( &promptMessage ); promptMessage.setType(MSG_TYPE_PROMPT); promptMessage.set(MessageField::FIELD_PROC_ID, getProcId() ); promptMessage.set(MessageField::FIELD_TEXT, message); promptMessage.set(MessageField::FIELD_DATA_TYPE, ISTR(ptype)); promptMessage.set(MessageField::FIELD_TIME, timeStr); promptMessage.set(MessageField::FIELD_SCOPE, ISTR(scope)); // Used for the prompt display message PromptOptions optionsToShow; DEBUG("[CIF] Prompt typecode " + ISTR(ptype)); if (ptype == LanguageConstants::PROMPT_NUM || ptype == LanguageConstants::PROMPT_ALPHA || ptype == LanguageConstants::PROMPT_DATE ) { DEBUG("[CIF] Prompt is simple"); promptMessage.set(MessageField::FIELD_EXPECTED, ""); } else if ( ptype & LanguageConstants::PROMPT_LIST ) { DEBUG("[CIF] Prompt is list"); PromptOptions::iterator it; int keyCount = 1; std::string optionStr = ""; std::string expectedStr = ""; // Iterate over the option list and build the option and expected values strings for( it = options.begin(); it != options.end(); it++) { std::string key; std::string value; std::string opt = (*it); DEBUG("[CIF] Option: " + opt); if (optionStr.size()>0) optionStr += IPCinternals::OPT_SEPARATOR; if (expectedStr.size()>0) expectedStr += IPCinternals::OPT_SEPARATOR; if ( opt.find(IPCinternals::KEY_SEPARATOR) == std::string::npos ) { // Put an internal key in this case key = ISTR(keyCount); value = opt; // Trim the value trim(value); } else { int idx = opt.find(IPCinternals::KEY_SEPARATOR); key = opt.substr(0, idx); // Trim the key trim(key); value = opt.substr(idx+1, opt.size()-idx); // Trim the value trim(value); } DEBUG("[CIF] Option key: '" + key + "'"); DEBUG("[CIF] Option value: '" + value + "'"); optionStr += key + IPCinternals::KEY_SEPARATOR + value; optionsToShow.push_back(key + ": " + value); if (ptype & LanguageConstants::PROMPT_ALPHA) { expectedStr += value; DEBUG("[CIF] Expected: " + value); } else { expectedStr += key; DEBUG("[CIF] Expected: " + key); } keyCount++; } promptMessage.set(MessageField::FIELD_EXPECTED, expectedStr); promptMessage.set(MessageField::FIELD_OPTIONS, optionStr); } else if (ptype == LanguageConstants::PROMPT_OK) { promptMessage.set(MessageField::FIELD_EXPECTED, "O"); promptMessage.set(MessageField::FIELD_OPTIONS, "O" + IPCinternals::KEY_SEPARATOR + " Ok"); optionsToShow.push_back("O: Ok"); } else if (ptype == LanguageConstants::PROMPT_CANCEL) { promptMessage.set(MessageField::FIELD_EXPECTED, "C"); promptMessage.set(MessageField::FIELD_OPTIONS, "C" + IPCinternals::KEY_SEPARATOR + " Cancel"); optionsToShow.push_back("C: Cancel"); } else if (ptype == LanguageConstants::PROMPT_YES) { promptMessage.set(MessageField::FIELD_EXPECTED, "Y"); promptMessage.set(MessageField::FIELD_OPTIONS, "Y" + IPCinternals::KEY_SEPARATOR + " Yes"); optionsToShow.push_back("Y: Yes"); } else if (ptype == LanguageConstants::PROMPT_NO) { promptMessage.set(MessageField::FIELD_EXPECTED, "N"); promptMessage.set(MessageField::FIELD_OPTIONS, "N" + IPCinternals::KEY_SEPARATOR + " No"); optionsToShow.push_back("N: No"); } else if (ptype == LanguageConstants::PROMPT_YES_NO) { promptMessage.set(MessageField::FIELD_EXPECTED, "Y|N"); promptMessage.set(MessageField::FIELD_OPTIONS, "Y" + IPCinternals::KEY_SEPARATOR + " Yes|N" + IPCinternals::KEY_SEPARATOR + " No"); optionsToShow.push_back("Y: Yes"); optionsToShow.push_back("N: No"); } else if (ptype == LanguageConstants::PROMPT_OK_CANCEL) { promptMessage.set(MessageField::FIELD_EXPECTED, "O|C"); promptMessage.set(MessageField::FIELD_OPTIONS, "O" + IPCinternals::KEY_SEPARATOR + " Ok|C" + IPCinternals::KEY_SEPARATOR + " Cancel"); optionsToShow.push_back("O: Ok"); optionsToShow.push_back("C: Cancel"); } DEBUG("[CIF] Option string: " + promptMessage.get(MessageField::FIELD_OPTIONS)); DEBUG("[CIF] Expected string: " + promptMessage.get(MessageField::FIELD_EXPECTED)); // Write the prompt display std::string msgToShow = message; if (optionsToShow.size()>0) { msgToShow += "\nAvailable options:\n"; for(PromptOptions::iterator pit = optionsToShow.begin(); pit != optionsToShow.end(); pit++) { msgToShow += " - " + (*pit) + "\n"; } } // Send the display message via the buffer to ensure synchronization m_buffer->prompt(msgToShow, LanguageConstants::SCOPE_PROMPT); // Ensure buffer is flushed m_buffer->flush(); // Write the prompt in the asrun m_asRun->writePrompt( getStack(), message, scope ); DEBUG("[CIF] Messsage prepared"); // Send request to client SPELLipcMessage* response = sendGUIRequest(&promptMessage, SPELL_CIF_PROMPT_TIMEOUT_SEC); DEBUG("[CIF] Prompt response received"); std::string toProcess = ""; if (response->getId() == MessageId::MSG_ID_CANCEL) { LOG_WARN("Prompt cancelled"); DEBUG("[CIF] Prompt cancelled"); toProcess = PROMPT_CANCELLED; // Abort execution in this case SPELLexecutor::instance().abort("Prompt cancelled",true); } else if (response->getId() == MessageId::MSG_ID_TIMEOUT) { LOG_ERROR("Prompt timed out"); DEBUG("[CIF] Prompt timed out"); toProcess = PROMPT_TIMEOUT; // Abort execution in this case SPELLexecutor::instance().abort("Prompt timed out", true); } else if (response->getType() == MSG_TYPE_ERROR) { std::string errorMsg = response->get( MessageField::FIELD_ERROR ); DEBUG("[CIF] Prompt error: " + errorMsg ); LOG_ERROR("Prompt error: " + errorMsg); toProcess = PROMPT_ERROR; // \todo Should fix this and use an error code if (errorMsg == "No controlling client") { warning("No controlling client to issue prompt!", LanguageConstants::SCOPE_SYS ); SPELLexecutor::instance().pause(); } else { error( "Prompt error: " + errorMsg, LanguageConstants::SCOPE_SYS ); // Abort execution in this case SPELLexecutor::instance().abort("Prompt error",true); } } else { toProcess = response->get(MessageField::FIELD_RVALUE); DEBUG("[CIF] Prompt response: " + toProcess); } // \todo When there is no controlling client we should keep the child procedure in prompt waiting state // Send the display message via the buffer to ensure synchronization m_buffer->write("Answer: '" + toProcess + "'", LanguageConstants::SCOPE_PROMPT); m_buffer->flush(); m_asRun->writeAnswer( getStack(), toProcess, scope ); return toProcess; }