Example #1
0
 void FllImporter::processOutputVariable(const std::string& block, Engine* engine) const {
     std::istringstream reader(block);
     std::string line;
     OutputVariable* outputVariable = new OutputVariable;
     engine->addOutputVariable(outputVariable);
     while (std::getline(reader, line)) {
         std::pair<std::string, std::string> keyValue = parseKeyValue(line, ':');
         if ("OutputVariable" == keyValue.first) {
             outputVariable->setName(keyValue.second);
         } else if ("enabled" == keyValue.first) {
             outputVariable->setEnabled(parseBoolean(keyValue.second));
         } else if ("range" == keyValue.first) {
             std::pair<scalar, scalar> range = parseRange(keyValue.second);
             outputVariable->setRange(range.first, range.second);
         } else if ("default" == keyValue.first) {
             outputVariable->setDefaultValue(Op::toScalar(keyValue.second));
         } else if ("lock-valid" == keyValue.first) {
             outputVariable->setLockValidOutput(parseBoolean(keyValue.second));
         } else if ("lock-range" == keyValue.first) {
             outputVariable->setLockOutputRange(parseBoolean(keyValue.second));
         } else if ("defuzzifier" == keyValue.first) {
             outputVariable->setDefuzzifier(parseDefuzzifier(keyValue.second));
         } else if ("accumulation" == keyValue.first) {
             outputVariable->fuzzyOutput()->setAccumulation(parseSNorm(keyValue.second));
         } else if ("term" == keyValue.first) {
             outputVariable->addTerm(parseTerm(keyValue.second, engine));
         } else {
             throw fl::Exception("[import error] key <" + keyValue.first + "> not "
                     "recognized in pair <" + keyValue.first + ":" + keyValue.second + ">", FL_AT);
         }
     }
 }
Example #2
0
void RenderState::StateBlock::setState(const char* name, const char* value)
{
    GP_ASSERT(name);

    if (strcmp(name, "blend") == 0)
    {
        setBlend(parseBoolean(value));
    }
    else if (strcmp(name, "blendSrc") == 0 || strcmp(name, "srcBlend") == 0 )   // Leaving srcBlend for backward compat.
    {
        setBlendSrc(parseBlend(value));
    }
    else if (strcmp(name, "blendDst") == 0 || strcmp(name, "dstBlend") == 0)    // // Leaving dstBlend for backward compat.
    {
        setBlendDst(parseBlend(value));
    }
    else if (strcmp(name, "cullFace") == 0)
    {
        setCullFace(parseBoolean(value));
    }
    else if (strcmp(name, "depthTest") == 0)
    {
        setDepthTest(parseBoolean(value));
    }
    else if (strcmp(name, "depthWrite") == 0)
    {
        setDepthWrite(parseBoolean(value));
    }
    else
    {
        GP_ERROR("Unsupported render state string '%s'.", name);
    }
}
Example #3
0
TestPlugin::TestPlugin(WebFrame* frame, const WebPluginParams& params, WebTestDelegate* delegate)
    : m_frame(frame)
    , m_delegate(delegate)
    , m_container(0)
    , m_context(0)
    , m_colorTexture(0)
    , m_mailboxChanged(false)
    , m_framebuffer(0)
    , m_touchEventRequest(WebPluginContainer::TouchEventRequestTypeNone)
    , m_reRequestTouchEvents(false)
    , m_printEventDetails(false)
    , m_printUserGestureStatus(false)
    , m_canProcessDrag(false)
    , m_isPersistent(params.mimeType == pluginPersistsMimeType())
    , m_canCreateWithoutRenderer(params.mimeType == canCreateWithoutRendererMimeType())
{
    const CR_DEFINE_STATIC_LOCAL(WebString, kAttributePrimitive, ("primitive"));
    const CR_DEFINE_STATIC_LOCAL(WebString, kAttributeBackgroundColor, ("background-color"));
    const CR_DEFINE_STATIC_LOCAL(WebString, kAttributePrimitiveColor, ("primitive-color"));
    const CR_DEFINE_STATIC_LOCAL(WebString, kAttributeOpacity, ("opacity"));
    const CR_DEFINE_STATIC_LOCAL(WebString, kAttributeAcceptsTouch, ("accepts-touch"));
    const CR_DEFINE_STATIC_LOCAL(WebString, kAttributeReRequestTouchEvents, ("re-request-touch"));
    const CR_DEFINE_STATIC_LOCAL(WebString, kAttributePrintEventDetails, ("print-event-details"));
    const CR_DEFINE_STATIC_LOCAL(WebString, kAttributeCanProcessDrag, ("can-process-drag"));
    const CR_DEFINE_STATIC_LOCAL(WebString, kAttributePrintUserGestureStatus, ("print-user-gesture-status"));

    DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size());
    size_t size = params.attributeNames.size();
    for (size_t i = 0; i < size; ++i) {
        const WebString& attributeName = params.attributeNames[i];
        const WebString& attributeValue = params.attributeValues[i];

        if (attributeName == kAttributePrimitive)
            m_scene.primitive = parsePrimitive(attributeValue);
        else if (attributeName == kAttributeBackgroundColor)
            parseColor(attributeValue, m_scene.backgroundColor);
        else if (attributeName == kAttributePrimitiveColor)
            parseColor(attributeValue, m_scene.primitiveColor);
        else if (attributeName == kAttributeOpacity)
            m_scene.opacity = parseOpacity(attributeValue);
        else if (attributeName == kAttributeAcceptsTouch)
            m_touchEventRequest = parseTouchEventRequestType(attributeValue);
        else if (attributeName == kAttributeReRequestTouchEvents)
            m_reRequestTouchEvents = parseBoolean(attributeValue);
        else if (attributeName == kAttributePrintEventDetails)
            m_printEventDetails = parseBoolean(attributeValue);
        else if (attributeName == kAttributeCanProcessDrag)
            m_canProcessDrag = parseBoolean(attributeValue);
        else if (attributeName == kAttributePrintUserGestureStatus)
            m_printUserGestureStatus = parseBoolean(attributeValue);
    }
    if (m_canCreateWithoutRenderer)
        m_delegate->printMessage(std::string("TestPlugin: canCreateWithoutRenderer\n"));
}
Example #4
0
TestPlugin::TestPlugin(WebFrame* frame, const WebPluginParams& params, WebTestDelegate* delegate)
    : m_frame(frame)
    , m_delegate(delegate)
    , m_container(0)
    , m_context(0)
    , m_colorTexture(0)
    , m_mailboxChanged(false)
    , m_framebuffer(0)
    , m_touchEventRequest(WebPluginContainer::TouchEventRequestTypeNone)
    , m_reRequestTouchEvents(false)
    , m_printEventDetails(false)
    , m_printUserGestureStatus(false)
    , m_canProcessDrag(false)
{
    static const WebString kAttributePrimitive = WebString::fromUTF8("primitive");
    static const WebString kAttributeBackgroundColor = WebString::fromUTF8("background-color");
    static const WebString kAttributePrimitiveColor = WebString::fromUTF8("primitive-color");
    static const WebString kAttributeOpacity = WebString::fromUTF8("opacity");
    static const WebString kAttributeAcceptsTouch = WebString::fromUTF8("accepts-touch");
    static const WebString kAttributeReRequestTouchEvents = WebString::fromUTF8("re-request-touch");
    static const WebString kAttributePrintEventDetails = WebString::fromUTF8("print-event-details");
    static const WebString kAttributeCanProcessDrag = WebString::fromUTF8("can-process-drag");
    static const WebString kAttributePrintUserGestureStatus = WebString::fromUTF8("print-user-gesture-status");

    BLINK_ASSERT(params.attributeNames.size() == params.attributeValues.size());
    size_t size = params.attributeNames.size();
    for (size_t i = 0; i < size; ++i) {
        const WebString& attributeName = params.attributeNames[i];
        const WebString& attributeValue = params.attributeValues[i];

        if (attributeName == kAttributePrimitive)
            m_scene.primitive = parsePrimitive(attributeValue);
        else if (attributeName == kAttributeBackgroundColor)
            parseColor(attributeValue, m_scene.backgroundColor);
        else if (attributeName == kAttributePrimitiveColor)
            parseColor(attributeValue, m_scene.primitiveColor);
        else if (attributeName == kAttributeOpacity)
            m_scene.opacity = parseOpacity(attributeValue);
        else if (attributeName == kAttributeAcceptsTouch)
            m_touchEventRequest = parseTouchEventRequestType(attributeValue);
        else if (attributeName == kAttributeReRequestTouchEvents)
            m_reRequestTouchEvents = parseBoolean(attributeValue);
        else if (attributeName == kAttributePrintEventDetails)
            m_printEventDetails = parseBoolean(attributeValue);
        else if (attributeName == kAttributeCanProcessDrag)
            m_canProcessDrag = parseBoolean(attributeValue);
        else if (attributeName == kAttributePrintUserGestureStatus)
            m_printUserGestureStatus = parseBoolean(attributeValue);
    }
}
Example #5
0
    TGUI_API Widget::Ptr loadTextBox(std::shared_ptr<DataIO::Node> node, Widget::Ptr widget = nullptr)
    {
        TextBox::Ptr textBox;
        if (widget)
            textBox = std::static_pointer_cast<TextBox>(widget);
        else
            textBox = std::make_shared<TextBox>();

        loadWidget(node, textBox);

        if (node->propertyValuePairs["text"])
            textBox->setText(DESERIALIZE_STRING("text"));
        if (node->propertyValuePairs["textsize"])
            textBox->setTextSize(tgui::stoi(node->propertyValuePairs["textsize"]->value));
        if (node->propertyValuePairs["maximumcharacters"])
            textBox->setMaximumCharacters(tgui::stoi(node->propertyValuePairs["maximumcharacters"]->value));
        if (node->propertyValuePairs["readonly"])
            textBox->setReadOnly(parseBoolean(node->propertyValuePairs["readonly"]->value));

        for (auto& childNode : node->children)
        {
            if (toLower(childNode->name) == "scrollbar")
                textBox->setScrollbar(std::static_pointer_cast<Scrollbar>(WidgetLoader::getLoadFunction("scrollbar")(childNode)));
        }
        REMOVE_CHILD("scrollbar");

        return textBox;
    }
void CommandHandler::handleToggle(const std::string &args, ChatTab *tab)
{
    if (args.empty())
    {
        tab->chatLog(chatWindow->getReturnTogglesChat() ?
                     _("Return toggles chat.") : _("Message closes chat."));
        return;
    }

    char opt = parseBoolean(args);

    switch (opt)
    {
    case 1:
        tab->chatLog(_("Return now toggles chat."));
        chatWindow->setReturnTogglesChat(true);
        return;
    case 0:
        tab->chatLog(_("Message now closes chat."));
        chatWindow->setReturnTogglesChat(false);
        return;
    case -1:
        tab->chatLog(strprintf(BOOLEAN_OPTIONS, "toggle"));
    }
}
int TypesParserUtil_Imp::parseText(bool                       *result,
                                   const char                 *input,
                                   int                         inputLength,
                                   bdlat_TypeCategory::Simple)
{
    return parseBoolean(result, input, inputLength);
}
Example #8
0
 void FllImporter::processRuleBlock(const std::string& block, Engine* engine) const {
     std::istringstream reader(block);
     std::string line;
     RuleBlock* ruleBlock = new RuleBlock;
     engine->addRuleBlock(ruleBlock);
     while (std::getline(reader, line)) {
         std::pair<std::string, std::string> keyValue = parseKeyValue(line, ':');
         if ("RuleBlock" == keyValue.first) {
             ruleBlock->setName(keyValue.second);
         } else if ("enabled" == keyValue.first) {
             ruleBlock->setEnabled(parseBoolean(keyValue.second));
         } else if ("conjunction" == keyValue.first) {
             ruleBlock->setConjunction(parseTNorm(keyValue.second));
         } else if ("disjunction" == keyValue.first) {
             ruleBlock->setDisjunction(parseSNorm(keyValue.second));
         } else if ("activation" == keyValue.first) {
             ruleBlock->setActivation(parseTNorm(keyValue.second));
         } else if ("rule" == keyValue.first) {
             ruleBlock->addRule(fl::Rule::parse(keyValue.second, engine));
         } else {
             throw fl::Exception("[import error] key <" + keyValue.first + "> not "
                     "recognized in pair <" + keyValue.first + ":" + keyValue.second + ">", FL_AT);
         }
     }
 }
Example #9
0
    TGUI_API Widget::Ptr loadEditBox(std::shared_ptr<DataIO::Node> node, Widget::Ptr widget = nullptr)
    {
        EditBox::Ptr editBox;
        if (widget)
            editBox = std::static_pointer_cast<EditBox>(widget);
        else
            editBox = std::make_shared<EditBox>();

        loadWidget(node, editBox);

        if (node->propertyValuePairs["text"])
            editBox->setText(DESERIALIZE_STRING("text"));
        if (node->propertyValuePairs["defaulttext"])
            editBox->setDefaultText(DESERIALIZE_STRING("defaulttext"));
        if (node->propertyValuePairs["textsize"])
            editBox->setTextSize(tgui::stoi(node->propertyValuePairs["textsize"]->value));
        if (node->propertyValuePairs["maximumcharacters"])
            editBox->setMaximumCharacters(tgui::stoi(node->propertyValuePairs["maximumcharacters"]->value));
        if (node->propertyValuePairs["textwidthlimited"])
            editBox->limitTextWidth(parseBoolean(node->propertyValuePairs["textwidthlimited"]->value));
        if (node->propertyValuePairs["caretwidth"])
            editBox->setCaretWidth(tgui::stof(node->propertyValuePairs["caretwidth"]->value));
        if (node->propertyValuePairs["numbersonly"])
            editBox->setNumbersOnly(parseBoolean(node->propertyValuePairs["numbersonly"]->value));
        if (node->propertyValuePairs["passwordcharacter"])
        {
            std::string pass = DESERIALIZE_STRING("passwordcharacter");
            if (!pass.empty())
                editBox->setPasswordCharacter(pass[0]);
        }
        if (node->propertyValuePairs["alignment"])
        {
            if (toLower(node->propertyValuePairs["alignment"]->value) == "left")
                editBox->setAlignment(EditBox::Alignment::Left);
            else if (toLower(node->propertyValuePairs["alignment"]->value) == "center")
                editBox->setAlignment(EditBox::Alignment::Center);
            else if (toLower(node->propertyValuePairs["alignment"]->value) == "right")
                editBox->setAlignment(EditBox::Alignment::Right);
            else
                throw Exception{"Failed to parse Alignment property. Only the values Left, Center and Right are correct."};
        }

        return editBox;
    }
Example #10
0
status_t MediaCodecList::addFeature(const char **attrs) {
    size_t i = 0;
    const char *name = NULL;
    int32_t optional = -1;
    int32_t required = -1;
    const char *value = NULL;

    while (attrs[i] != NULL) {
        if (attrs[i + 1] == NULL) {
            return -EINVAL;
        }

        // attributes with values
        if (!strcmp(attrs[i], "name")) {
            name = attrs[i + 1];
            ++i;
        } else if (!strcmp(attrs[i], "optional") || !strcmp(attrs[i], "required")) {
            int value = (int)parseBoolean(attrs[i + 1]);
            if (!strcmp(attrs[i], "optional")) {
                optional = value;
            } else {
                required = value;
            }
            ++i;
        } else if (!strcmp(attrs[i], "value")) {
            value = attrs[i + 1];
            ++i;
        } else {
            return -EINVAL;
        }
        ++i;
    }
    if (name == NULL) {
        ALOGE("feature with no 'name' attribute");
        return -EINVAL;
    }

    if (optional == required && optional != -1) {
        ALOGE("feature '%s' is both/neither optional and required", name);
        return -EINVAL;
    }

    if ((optional != -1 || required != -1) && (value != NULL)) {
        ALOGE("feature '%s' has both a value and optional/required attribute", name);
        return -EINVAL;
    }

    if (value != NULL) {
        mCurrentInfo->addFeature(name, value);
    } else {
        mCurrentInfo->addFeature(name, (required == 1) || (optional == 0));
    }
    return OK;
}
Example #11
0
    TGUI_API Widget::Ptr loadWidget(std::shared_ptr<DataIO::Node> node, Widget::Ptr widget)
    {
        assert(widget != nullptr);

        if (node->propertyValuePairs["visible"])
        {
            bool visible = parseBoolean(node->propertyValuePairs["visible"]->value);
            if (visible)
                widget->show();
            else
                widget->hide();
        }
        if (node->propertyValuePairs["enabled"])
        {
            bool enabled = parseBoolean(node->propertyValuePairs["enabled"]->value);
            if (enabled)
                widget->enable();
            else
                widget->disable();
        }
        if (node->propertyValuePairs["position"])
            widget->setPosition(parseLayout(node->propertyValuePairs["position"]->value));
        if (node->propertyValuePairs["size"])
            widget->setSize(parseLayout(node->propertyValuePairs["size"]->value));
        if (node->propertyValuePairs["opacity"])
            widget->setOpacity(tgui::stof(node->propertyValuePairs["opacity"]->value));

        /// TODO: Font and ToolTip (and Theme?)

        for (auto& childNode : node->children)
        {
            if (toLower(childNode->name) == "renderer")
            {
                for (auto& pair : childNode->propertyValuePairs)
                    widget->getRenderer()->setProperty(pair.first, pair.second->value);
            }
        }
        REMOVE_CHILD("renderer");

        return widget;
    }
Example #12
0
// Will exit the program if cannot parse
ExcelValue parse(char **string) {
  while(true) {
    switch(**string) {
      case '"':
        return parseString(string);
        break;
      case '-':
      case '+':
      case '0':
      case '1':
      case '2':
      case '3':
      case '4':
      case '5':
      case '6':
      case '7':
      case '8':
      case '9':
        return parseNumber(string);
        break;
      case 't':
      case 'f':
        return parseBoolean(string);
        break;
      case '#':
        return parseExcelError(string);
        break;
      case ' ':
      case '\t':
      case '\n':
      case '\r':
      case ',': // Important to progress through arrays
        (*string)++;
        break;
      case '[':
        return startArray(string);
        break;
      case ']':
        return endArray(string);
        break;
      case EOF:
        return parseFailed("Parse error - reached end of file", 0);
        break;
      case '\0':
        return parseFailed("Parse error - reached end of string", 0);
        break;
      default:
        return parseFailed("Parse error unrecognised character", *string);
        break;
    }
  }
}
 void FllImporter::processOutputVariable(const std::string& block, Engine* engine) const {
     std::istringstream reader(block);
     std::string line;
     FL_unique_ptr<OutputVariable> outputVariable(new OutputVariable);
     while (std::getline(reader, line)) {
         std::pair<std::string, std::string> keyValue = parseKeyValue(line, ':');
         if ("OutputVariable" == keyValue.first) {
             outputVariable->setName(Op::validName(keyValue.second));
         } else if ("enabled" == keyValue.first) {
             outputVariable->setEnabled(parseBoolean(keyValue.second));
         } else if ("range" == keyValue.first) {
             std::pair<scalar, scalar> range = parseRange(keyValue.second);
             outputVariable->setRange(range.first, range.second);
         } else if ("default" == keyValue.first) {
             outputVariable->setDefaultValue(Op::toScalar(keyValue.second));
         } else if ("lock-previous" == keyValue.first or "lock-valid" == keyValue.first) {
             outputVariable->setLockPreviousValue(parseBoolean(keyValue.second));
         } else if ("lock-range" == keyValue.first) {
             outputVariable->setLockValueInRange(parseBoolean(keyValue.second));
         } else if ("defuzzifier" == keyValue.first) {
             outputVariable->setDefuzzifier(parseDefuzzifier(keyValue.second));
         } else if ("aggregation" == keyValue.first) {
             outputVariable->fuzzyOutput()->setAggregation(parseSNorm(keyValue.second));
         } else if ("accumulation" == keyValue.first) {
             outputVariable->fuzzyOutput()->setAggregation(parseSNorm(keyValue.second));
             FL_LOG("[warning] obsolete usage of identifier <accumulation: SNorm> in OutputVariable");
             FL_LOG("[information] from version 6.0, the identifier <aggregation: SNorm> should be used");
             FL_LOG("[backward compatibility] assumed "
                     "<aggregation: " << keyValue.second << "> "
                     "instead of <accumulation: " << keyValue.second << ">");
         } else if ("term" == keyValue.first) {
             outputVariable->addTerm(parseTerm(keyValue.second, engine));
         } else {
             throw Exception("[import error] key <" + keyValue.first + "> not "
                     "recognized in pair <" + keyValue.first + ":" + keyValue.second + ">", FL_AT);
         }
     }
     engine->addOutputVariable(outputVariable.release());
 }
Example #14
0
/*
    Parse a string based on formatting instructions and intelligently create a variable.
    Number formats:
        [(+|-)][0][OCTAL_DIGITS]
        [(+|-)][0][(x|X)][HEX_DIGITS]
        [(+|-)][DIGITS]
        [+|-][DIGITS][.][DIGITS][(e|E)[+|-]DIGITS]
 */
EjsVar *ejsParseVar(Ejs *ejs, cchar *buf, int preferredType)
{
    int         type;

    mprAssert(buf);

    type = preferredType;
    if (preferredType == ES_Void || preferredType < 0) {
        if ((*buf == '-' || *buf == '+') && isdigit((int) buf[1])) {
            type = ejs->numberType->id;

        } else if (!isdigit((int) *buf) && *buf != '.') {
            if (strcmp(buf, "true") == 0) {
                return (EjsVar*) ejs->trueValue;

            } else if (strcmp(buf, "false") == 0) {
                return (EjsVar*) ejs->falseValue;
            }
            type = ES_String;

        } else {
            type = ES_Number;
        }
    }

    switch (type) {
    case ES_Object:
    case ES_Void:
    case ES_Null:
    default:
        break;

    case ES_Number:
        return (EjsVar*) ejsCreateNumber(ejs, parseNumber(ejs, buf));

    case ES_Boolean:
        return (EjsVar*) ejsCreateBoolean(ejs, parseBoolean(ejs, buf));

    case ES_String:
        if (strcmp(buf, "null") == 0) {
            return (EjsVar*) ejsCreateNull(ejs);

        } else if (strcmp(buf, "undefined") == 0) {
            return (EjsVar*) ejsCreateUndefined(ejs);
        }
        return (EjsVar*) ejsCreateString(ejs, buf);
    }
    return (EjsVar*) ejsCreateUndefined(ejs);
}
 void FllImporter::processInputVariable(const std::string& block, Engine* engine) const {
     std::istringstream reader(block);
     std::string line;
     FL_unique_ptr<InputVariable> inputVariable(new InputVariable);
     while (std::getline(reader, line)) {
         std::pair<std::string, std::string> keyValue = parseKeyValue(line, ':');
         if ("InputVariable" == keyValue.first) {
             inputVariable->setName(Op::validName(keyValue.second));
         } else if ("enabled" == keyValue.first) {
             inputVariable->setEnabled(parseBoolean(keyValue.second));
         } else if ("range" == keyValue.first) {
             std::pair<scalar, scalar> range = parseRange(keyValue.second);
             inputVariable->setRange(range.first, range.second);
         } else if ("lock-range" == keyValue.first) {
             inputVariable->setLockValueInRange(parseBoolean(keyValue.second));
         } else if ("term" == keyValue.first) {
             inputVariable->addTerm(parseTerm(keyValue.second, engine));
         } else {
             throw Exception("[import error] key <" + keyValue.first + "> not "
                     "recognized in pair <" + keyValue.first + ":" + keyValue.second + ">", FL_AT);
         }
     }
     engine->addInputVariable(inputVariable.release());
 }
 void FllImporter::processRuleBlock(const std::string& block, Engine* engine) const {
     std::istringstream reader(block);
     std::string line;
     FL_unique_ptr<RuleBlock> ruleBlock(new RuleBlock);
     while (std::getline(reader, line)) {
         std::pair<std::string, std::string> keyValue = parseKeyValue(line, ':');
         if ("RuleBlock" == keyValue.first) {
             ruleBlock->setName(keyValue.second);
         } else if ("enabled" == keyValue.first) {
             ruleBlock->setEnabled(parseBoolean(keyValue.second));
         } else if ("conjunction" == keyValue.first) {
             ruleBlock->setConjunction(parseTNorm(keyValue.second));
         } else if ("disjunction" == keyValue.first) {
             ruleBlock->setDisjunction(parseSNorm(keyValue.second));
         } else if ("implication" == keyValue.first) {
             ruleBlock->setImplication(parseTNorm(keyValue.second));
         } else if ("activation" == keyValue.first) {
             TNormFactory* tnorm = FactoryManager::instance()->tnorm();
             //@todo remove backwards compatibility in version 7.0
             if (tnorm->hasConstructor(keyValue.second)) {
                 ruleBlock->setImplication(parseTNorm(keyValue.second));
                 FL_LOG("[warning] obsolete usage of identifier <activation: TNorm> "
                         "in RuleBlock");
                 FL_LOG("[information] from version 6.0, the identifiers are "
                         "<activation: Activation> for Activation methods "
                         "and <implication: TNorm> for T-Norms");
                 FL_LOG("[backward compatibility] assumed "
                         "<implication: " << keyValue.second << "> "
                         "instead of <activation: " << keyValue.second << ">");
             } else {
                 ruleBlock->setActivation(parseActivation(keyValue.second));
             }
         } else if ("rule" == keyValue.first) {
             Rule* rule = new Rule;
             rule->setText(keyValue.second);
             try {
                 rule->load(engine);
             } catch (std::exception& ex) {
                 FL_LOG(ex.what());
             }
             ruleBlock->addRule(rule);
         } else {
             throw Exception("[import error] key <" + keyValue.first + "> not "
                     "recognized in pair <" + keyValue.first + ":" + keyValue.second + ">", FL_AT);
         }
     }
     engine->addRuleBlock(ruleBlock.release());
 }
Example #17
0
    TGUI_API Widget::Ptr loadPicture(std::shared_ptr<DataIO::Node> node, Widget::Ptr widget = nullptr)
    {
        Picture::Ptr picture;
        if (widget)
            picture = std::static_pointer_cast<Picture>(widget);
        else
            picture = std::make_shared<Picture>();

        if (node->propertyValuePairs["filename"])
            picture = std::make_shared<Picture>(DESERIALIZE_STRING("filename"));

        loadWidget(node, picture);

        if (node->propertyValuePairs["smooth"])
            picture->setSmooth(parseBoolean(node->propertyValuePairs["smooth"]->value));

        return picture;
    }
Example #18
0
    TGUI_API Widget::Ptr loadLabel(std::shared_ptr<DataIO::Node> node, Widget::Ptr widget = nullptr)
    {
        Label::Ptr label;
        if (widget)
            label = std::static_pointer_cast<Label>(widget);
        else
            label = std::make_shared<Label>();

        loadWidget(node, label);

        if (node->propertyValuePairs["textstyle"])
        {
            sf::Uint32 style = sf::Text::Regular;
            std::vector<std::string> styles = tgui::split(node->propertyValuePairs["textstyle"]->value, '|');
            for (auto& elem : styles)
            {
                std::string requestedStyle = toLower(trim(elem));
                if (requestedStyle == "bold")
                    style |= sf::Text::Bold;
                else if (requestedStyle == "italic")
                    style |= sf::Text::Italic;
                else if (requestedStyle == "underlined")
                    style |= sf::Text::Underlined;
                else if (requestedStyle == "strikethrough")
                    style |= sf::Text::StrikeThrough;
                else if (requestedStyle != "regular")
                    throw Exception{"Failed to parse TextStyle property, found unknown style."};
            }

            label->setTextStyle(style);
        }

        if (node->propertyValuePairs["text"])
            label->setText(DESERIALIZE_STRING("text"));
        if (node->propertyValuePairs["textsize"])
            label->setTextSize(tgui::stoi(node->propertyValuePairs["textsize"]->value));
        if (node->propertyValuePairs["maximumtextwidth"])
            label->setMaximumTextWidth(tgui::stof(node->propertyValuePairs["maximumtextwidth"]->value));
        if (node->propertyValuePairs["autosize"])
            label->setAutoSize(parseBoolean(node->propertyValuePairs["autosize"]->value));

        return label;
    }
Example #19
0
    TGUI_API Widget::Ptr loadSpinButton(std::shared_ptr<DataIO::Node> node, Widget::Ptr widget = nullptr)
    {
        SpinButton::Ptr spinButton;
        if (widget)
            spinButton = std::static_pointer_cast<SpinButton>(widget);
        else
            spinButton = std::make_shared<SpinButton>();

        loadWidget(node, spinButton);
        if (node->propertyValuePairs["minimum"])
            spinButton->setMinimum(tgui::stoi(node->propertyValuePairs["minimum"]->value));
        if (node->propertyValuePairs["maximum"])
            spinButton->setMaximum(tgui::stoi(node->propertyValuePairs["maximum"]->value));
        if (node->propertyValuePairs["value"])
            spinButton->setValue(tgui::stoi(node->propertyValuePairs["value"]->value));
        if (node->propertyValuePairs["verticalscroll"])
            spinButton->setVerticalScroll(parseBoolean(node->propertyValuePairs["verticalscroll"]->value));

        return spinButton;
    }
Example #20
0
    TGUI_API Widget::Ptr loadRadioButton(std::shared_ptr<DataIO::Node> node, Widget::Ptr widget = nullptr)
    {
        RadioButton::Ptr radioButton;
        if (widget)
            radioButton = std::static_pointer_cast<RadioButton>(widget);
        else
            radioButton = std::make_shared<RadioButton>();

        loadWidget(node, radioButton);
        if (node->propertyValuePairs["text"])
            radioButton->setText(DESERIALIZE_STRING("text"));
        if (node->propertyValuePairs["textsize"])
            radioButton->setTextSize(tgui::stoi(node->propertyValuePairs["textsize"]->value));
        if (node->propertyValuePairs["checked"])
        {
            if (parseBoolean(node->propertyValuePairs["checked"]->value))
                radioButton->check();
        }

        return radioButton;
    }
Example #21
0
    TGUI_API Widget::Ptr loadCheckBox(std::shared_ptr<DataIO::Node> node, Widget::Ptr widget = nullptr)
    {
        CheckBox::Ptr checkbox;
        if (widget)
            checkbox = std::static_pointer_cast<CheckBox>(widget);
        else
            checkbox = std::make_shared<CheckBox>();

        loadWidget(node, checkbox);
        if (node->propertyValuePairs["text"])
            checkbox->setText(DESERIALIZE_STRING("text"));
        if (node->propertyValuePairs["textsize"])
            checkbox->setTextSize(tgui::stoi(node->propertyValuePairs["textsize"]->value));
        if (node->propertyValuePairs["checked"])
        {
            if (parseBoolean(node->propertyValuePairs["checked"]->value))
                checkbox->check();
        }

        return checkbox;
    }
Example #22
0
    TGUI_API Widget::Ptr loadChildWindow(std::shared_ptr<DataIO::Node> node, Widget::Ptr widget = nullptr)
    {
        ChildWindow::Ptr childWindow;
        if (widget)
            childWindow = std::static_pointer_cast<ChildWindow>(widget);
        else
            childWindow = std::make_shared<ChildWindow>();

        if (node->propertyValuePairs["titlealignment"])
        {
            if (toLower(node->propertyValuePairs["titlealignment"]->value) == "left")
                childWindow->setTitleAlignment(ChildWindow::TitleAlignment::Left);
            else if (toLower(node->propertyValuePairs["titlealignment"]->value) == "center")
                childWindow->setTitleAlignment(ChildWindow::TitleAlignment::Center);
            else if (toLower(node->propertyValuePairs["titlealignment"]->value) == "right")
                childWindow->setTitleAlignment(ChildWindow::TitleAlignment::Right);
            else
                throw Exception{"Failed to parse TitleAlignment property. Only the values Left, Center and Right are correct."};
        }

        if (node->propertyValuePairs["title"])
            childWindow->setTitle(DESERIALIZE_STRING("title"));

        if (node->propertyValuePairs["icon"])
            childWindow->setIcon(Deserializer::deserialize(ObjectConverter::Type::Texture, node->propertyValuePairs["icon"]->value).getTexture());

        if (node->propertyValuePairs["keepinparent"])
            childWindow->keepInParent(parseBoolean(node->propertyValuePairs["keepinparent"]->value));

        for (auto& childNode : node->children)
        {
            if (toLower(childNode->name) == "closebutton")
                childWindow->setCloseButton(std::static_pointer_cast<Button>(WidgetLoader::getLoadFunction("button")(childNode)));
        }
        REMOVE_CHILD("closebutton");

        loadContainer(node, childWindow);

        return childWindow;
    }
Example #23
0
    TGUI_API Widget::Ptr loadScrollbar(std::shared_ptr<DataIO::Node> node, Widget::Ptr widget = nullptr)
    {
        Scrollbar::Ptr scrollbar;
        if (widget)
            scrollbar = std::static_pointer_cast<Scrollbar>(widget);
        else
            scrollbar = std::make_shared<Scrollbar>();

        loadWidget(node, scrollbar);
        if (node->propertyValuePairs["lowvalue"])
            scrollbar->setLowValue(tgui::stoi(node->propertyValuePairs["lowvalue"]->value));
        if (node->propertyValuePairs["maximum"])
            scrollbar->setMaximum(tgui::stoi(node->propertyValuePairs["maximum"]->value));
        if (node->propertyValuePairs["value"])
            scrollbar->setValue(tgui::stoi(node->propertyValuePairs["value"]->value));
        if (node->propertyValuePairs["arrowscrollamount"])
            scrollbar->setArrowScrollAmount(tgui::stoi(node->propertyValuePairs["arrowscrollamount"]->value));
        if (node->propertyValuePairs["autohide"])
            scrollbar->setAutoHide(parseBoolean(node->propertyValuePairs["autohide"]->value));

        return scrollbar;
    }
Example #24
0
    TGUI_API Widget::Ptr loadKnob(std::shared_ptr<DataIO::Node> node, Widget::Ptr widget = nullptr)
    {
        Knob::Ptr knob;
        if (widget)
            knob = std::static_pointer_cast<Knob>(widget);
        else
            knob = std::make_shared<Knob>();

        loadWidget(node, knob);
        if (node->propertyValuePairs["startrotation"])
            knob->setStartRotation(tgui::stof(node->propertyValuePairs["startrotation"]->value));
        if (node->propertyValuePairs["endrotation"])
            knob->setEndRotation(tgui::stof(node->propertyValuePairs["endrotation"]->value));
        if (node->propertyValuePairs["minimum"])
            knob->setMinimum(tgui::stoi(node->propertyValuePairs["minimum"]->value));
        if (node->propertyValuePairs["maximum"])
            knob->setMaximum(tgui::stoi(node->propertyValuePairs["maximum"]->value));
        if (node->propertyValuePairs["value"])
            knob->setValue(tgui::stoi(node->propertyValuePairs["value"]->value));
        if (node->propertyValuePairs["clockwiseturning"])
            knob->setClockwiseTurning(parseBoolean(node->propertyValuePairs["clockwiseturning"]->value));

        return knob;
    }
Example #25
0
bool PartyTab::handleCommand(const std::string &type, const std::string &args)
{
    if (type == "help")
    {
        if (args == "invite")
        {
            // TRANSLATORS: party help message
            chatLog(_("Command: /invite <nick>"));
            // TRANSLATORS: party help message
            chatLog(_("This command invites <nick> to party with you."));
            // TRANSLATORS: party help message
            chatLog(_("If the <nick> has spaces in it, enclose it in "
                            "double quotes (\")."));
        }
        else if (args == "leave")
        {
            // TRANSLATORS: party help message
            chatLog(_("Command: /leave"));
            // TRANSLATORS: party help message
            chatLog(_("This command causes the player to leave the party."));
        }
        else if (args == "item")
        {
            // TRANSLATORS: party help message
            chatLog(_("Command: /item <policy>"));
            // TRANSLATORS: party help message
            chatLog(
                _("This command changes the party's item sharing policy."));
            // TRANSLATORS: party help message
            chatLog(_("<policy> can be one of \"1\", \"yes\", \"true\" to "
                      "enable item sharing, or \"0\", \"no\", \"false\" to "
                      "disable item sharing."));
            // TRANSLATORS: party help message
            chatLog(_("Command: /item"));
            // TRANSLATORS: party help message
            chatLog(_("This command displays the party's"
                    " current item sharing policy."));
        }
        else if (args == "exp")
        {
            // TRANSLATORS: party help message
            chatLog(_("Command: /exp <policy>"));
            // TRANSLATORS: party help message
            chatLog(_("This command changes the party's "
                    "experience sharing policy."));
            // TRANSLATORS: party help message
            chatLog(_("<policy> can be one of \"1\", \"yes\", \"true\" to "
                      "enable experience sharing, or \"0\","
                      " \"no\", \"false\" to disable experience sharing."));
            // TRANSLATORS: party help message
            chatLog(_("Command: /exp"));
            // TRANSLATORS: party help message
            chatLog(_("This command displays the party's current "
                    "experience sharing policy."));
        }
        else
        {
            return false;
        }
    }
    else if (type == "create" || type == "new")
    {
        if (args.empty())
        {
            // TRANSLATORS: chat error message
            chatLog(_("Party name is missing."), BY_SERVER);
        }
        else
        {
            Net::getPartyHandler()->create(args);
        }
    }
    else if (type == "invite")
    {
        Net::getPartyHandler()->invite(args);
    }
    else if (type == "leave")
    {
        Net::getPartyHandler()->leave();
    }
    else if (type == "kick")
    {
        Net::getPartyHandler()->kick(args);
    }
    else if (type == "item")
    {
        if (args.empty())
        {
            switch (Net::getPartyHandler()->getShareItems())
            {
                case PARTY_SHARE:
                    // TRANSLATORS: chat message
                    chatLog(_("Item sharing enabled."), BY_SERVER);
                    return true;
                case PARTY_SHARE_NO:
                    // TRANSLATORS: chat message
                    chatLog(_("Item sharing disabled."), BY_SERVER);
                    return true;
                case PARTY_SHARE_NOT_POSSIBLE:
                    // TRANSLATORS: chat message
                    chatLog(_("Item sharing not possible."), BY_SERVER);
                    return true;
                case PARTY_SHARE_UNKNOWN:
                    // TRANSLATORS: chat message
                    chatLog(_("Item sharing unknown."), BY_SERVER);
                    return true;
                default:
                    break;
            }
        }

        const signed char opt = parseBoolean(args);

        switch (opt)
        {
            case 1:
                Net::getPartyHandler()->setShareItems(PARTY_SHARE);
                break;
            case 0:
                Net::getPartyHandler()->setShareItems(PARTY_SHARE_NO);
                break;
            case -1:
                chatLog(strprintf(BOOLEAN_OPTIONS, "item"));
                break;
            default:
                break;
        }
    }
    else if (type == "exp")
    {
        if (args.empty())
        {
            switch (Net::getPartyHandler()->getShareExperience())
            {
                case PARTY_SHARE:
                    // TRANSLATORS: chat message
                    chatLog(_("Experience sharing enabled."), BY_SERVER);
                    return true;
                case PARTY_SHARE_NO:
                    // TRANSLATORS: chat message
                    chatLog(_("Experience sharing disabled."), BY_SERVER);
                    return true;
                case PARTY_SHARE_NOT_POSSIBLE:
                    // TRANSLATORS: chat message
                    chatLog(_("Experience sharing not possible."), BY_SERVER);
                    return true;
                case PARTY_SHARE_UNKNOWN:
                    // TRANSLATORS: chat message
                    chatLog(_("Experience sharing unknown."), BY_SERVER);
                    return true;
                default:
                    break;
            }
        }

        const signed char opt = parseBoolean(args);

        switch (opt)
        {
            case 1:
                Net::getPartyHandler()->setShareExperience(PARTY_SHARE);
                break;
            case 0:
                Net::getPartyHandler()->setShareExperience(PARTY_SHARE_NO);
                break;
            case -1:
                chatLog(strprintf(BOOLEAN_OPTIONS, "exp"));
                break;
            default:
                break;
        }
    }
    else
    {
        return false;
    }

    return true;
}
Example #26
0
/*
 *  Parse a string based on formatting instructions and intelligently create a variable.
 *
 *  Float and decimal format: [+|-]DIGITS][DIGITS][(e|E)[+|-]DIGITS]
 *
 *  TODO - refactor all this number parsing.
 */
EjsVar *ejsParseVar(Ejs *ejs, cchar *buf, int preferredType)
{
    cchar       *cp;
    int         isHex, type;

    mprAssert(buf);

    type = preferredType;
    isHex = 0;

    if (preferredType == ES_Void || preferredType < 0) {
        if (*buf == '-' || *buf == '+') {
            type = ejs->numberType->id;

        } else if (!isdigit((int) *buf)) {
            if (strcmp(buf, "true") == 0 || strcmp(buf, "false") == 0) {
                type = ES_Boolean;
            } else {
                type = ES_String;
            }

        } else {
            if (buf[0] == '0' && tolower((int) buf[1]) == 'x') {
                isHex = 1;
                for (cp = &buf[2]; *cp; cp++) {
                    if (! isxdigit((int) *cp)) {
                        break;
                    }
                }

            } else {
                for (cp = buf; *cp; cp++) {
                    if (! isdigit((int) *cp)) {
#if BLD_FEATURE_FLOATING_POINT
                        int c = tolower((int) *cp);
                        if (c != '.' && c != 'e' && c != 'f')
#endif
                            break;
                    }
                }
            }
            if (*cp == '\0') {
                type = ES_Number;
            } else {
                type = ES_String;
            }
        }
    }

    switch (type) {
    case ES_Object:
    case ES_Void:
    case ES_Null:
    default:
        break;

    case ES_Number:
        return (EjsVar*) ejsCreateNumber(ejs, parseNumber(ejs, buf, isHex));

    case ES_Boolean:
        return (EjsVar*) ejsCreateBoolean(ejs, parseBoolean(ejs, buf));

    case ES_String:
        if (strcmp(buf, "null") == 0) {
            return (EjsVar*) ejsCreateNull(ejs);

        } else if (strcmp(buf, "undefined") == 0) {
            return (EjsVar*) ejsCreateUndefined(ejs);
        }

        return (EjsVar*) ejsCreateString(ejs, buf);
    }
    return (EjsVar*) ejsCreateUndefined(ejs);
}
Example #27
0
void TomlParser::load()
{
    bool formatStrMode = false, rawStrMode = false, escMode = false
    bool endOfStrMode = false, endOfLine = false;
    string currLine = "";
    string currStr = "";
    TomlHash currHash = null;
    TomlKey currKey = null;
    int lineNumber = 1;
    char currChar;
    for(; !stream.eof(); lineNumber++)//this is the line loop
    {
        lineloopstart:
        endOfLine = false;
        if(formatStrMode || rawStrMode)
        {
            throw new TomlError(
                "Multiline strings not supported. Use \"\\n\" instead.",
                lineNumber);
        }
        rawStrMode = false;
        formatStrMode = false;
        getline(stream, currLine);
        clipSpaces(currLine);
        for(int i=1; i<currLine.length(); i++)//this goes over each character
        {
            currChar = currLine[i];
            if(endOfLine)
            {
                throw new TomlError(
                    "What are you trying to do with these random characters?",
                    lineNumber);
            }
            else if(formatStrMode)
            {
                //parse string
            }
            else if(rawStrMode)
            {
                if(currChar=='\'')
                {
                    rawStrMode = false;
                    endOfLine = true;
                }
                else
                {
                    currStr.append(1,currChar);
                }
            }
            else if(endOfStrMode)
            {
                goto eos;
            }
            else
            {
                switch(currChar)
                {
                    case '#':
                        goto lineloopstart;
                    case '"':
                        formatStrMode = true;
                        break;
                    case '\'':
                        rawStrMode = true;
                        break;
                    case '[':
                        string hashName = "";
                        while(currChar != ']')
                        {
                            hashName.append(1,currChar);
                            i++;
                            currChar = currLine[i];
                        }
                        currHash = new TomlHash(hashName, currHash);
                        endOfLine = true;
                        break;
                    default://it's a key
                    eos:
                        if(endOfStrMode)
                        {
                            currKey.type = "STRING";
                            currKey.value = currStr;
                            break;
                        }
                        string name = "";
                        while(currChar != '=')
                        {
                            name.append(&currChar);
                            i++;
                            currChar = currLine.at(i);
                        }
                        i++;//we go past the =
                        currChar = currLine.at(i);
                        string valueStr = currLine.substr(i + 1);
                        try
                        {
                            long value = parseInteger(valueStr);
                            currKey = new TomlKey(name, valueStr, "INTEGER",
                                currHash);
                        }
                        catch(int i)
                        {
                            try//This is the only way
                            {
                                bool value = parseBoolean(valueStr);
                                currKey = new TomlKey(name, valueStr, "BOOL",
                                    currHash);
                                catch(int i)
                                {
                                    try
                                    {
                                        double value = parseDouble(
                                            line.substr(valueStr));
                                        currKey.value = valueStr;
                                        currKey = new TomlKey(name, valueStr,
                                            "FLOAT", currHash);
                                        catch(int i)
                                        {
                                            //ignore it
                                        }
                                    }
                                }
                            }
                        }//end try-catch
                }//end switch
            }//end else
        }//end inner for
Example #28
0
void parseVariant(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, const char *szFieldName)
{
    proto_item *ti = proto_tree_add_text(tree, tvb, *pOffset, -1, "%s: Variant", szFieldName);
    proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_variant);
    gint    iOffset = *pOffset;
    guint8  EncodingMask;
    gint32  ArrayDimensions = 0;

    EncodingMask = tvb_get_guint8(tvb, iOffset);
    proto_tree_add_item(subtree, hf_opcua_variant_encodingmask, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
    iOffset++;

    if (EncodingMask & VARIANT_ARRAYMASK)
    {
        /* type is encoded in bits 0-5 */
        switch(EncodingMask & 0x3f)
        {
        case OpcUaType_Null: break;
        case OpcUaType_Boolean: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Boolean, parseBoolean); break;
        case OpcUaType_SByte: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_SByte, parseSByte); break;
        case OpcUaType_Byte: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Byte, parseByte); break;
        case OpcUaType_Int16: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int16, parseInt16); break;
        case OpcUaType_UInt16: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt16, parseUInt16); break;
        case OpcUaType_Int32: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int32, parseInt32); break;
        case OpcUaType_UInt32: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt32, parseUInt32); break;
        case OpcUaType_Int64: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int64, parseInt64); break;
        case OpcUaType_UInt64: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt64, parseUInt64); break;
        case OpcUaType_Float: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Float, parseFloat); break;
        case OpcUaType_Double: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Double, parseDouble); break;
        case OpcUaType_String: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_String, parseString); break;
        case OpcUaType_DateTime: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_DateTime, parseDateTime); break;
        case OpcUaType_Guid: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Guid, parseGuid); break;
        case OpcUaType_ByteString: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_ByteString, parseByteString); break;
        case OpcUaType_XmlElement: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_XmlElement, parseXmlElement); break;
        case OpcUaType_NodeId: parseArrayComplex(subtree, tvb, &iOffset, "NodeId", parseNodeId); break;
        case OpcUaType_ExpandedNodeId: parseArrayComplex(subtree, tvb, &iOffset, "ExpandedNodeId", parseExpandedNodeId); break;
        case OpcUaType_StatusCode: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_StatusCode, parseStatusCode); break;
        case OpcUaType_DiagnosticInfo: parseArrayComplex(subtree, tvb, &iOffset, "DiagnosticInfo", parseDiagnosticInfo); break;
        case OpcUaType_QualifiedName: parseArrayComplex(subtree, tvb, &iOffset, "QualifiedName", parseQualifiedName); break;
        case OpcUaType_LocalizedText: parseArrayComplex(subtree, tvb, &iOffset, "LocalizedText", parseLocalizedText); break;
        case OpcUaType_ExtensionObject: parseArrayComplex(subtree, tvb, &iOffset, "ExtensionObject", parseExtensionObject); break;
        case OpcUaType_DataValue: parseArrayComplex(subtree, tvb, &iOffset, "DataValue", parseDataValue); break;
        case OpcUaType_Variant: parseArrayComplex(subtree, tvb, &iOffset, "Variant", parseVariant); break;
        }

        if (EncodingMask & VARIANT_ARRAYDIMENSIONS)
        {
            proto_item *ti_2 = proto_tree_add_text(subtree, tvb, iOffset, -1, "ArrayDimensions");
            proto_tree *subtree_2 = proto_item_add_subtree(ti_2, ett_opcua_array);
            int i;

            /* read array length */
            ArrayDimensions = tvb_get_letohl(tvb, iOffset);
            proto_tree_add_item(subtree_2, hf_opcua_ArraySize, tvb, iOffset, 4, ENC_LITTLE_ENDIAN);

            if (ArrayDimensions > MAX_ARRAY_LEN)
            {
                proto_item *pi;
                pi = proto_tree_add_text(subtree_2, tvb, iOffset, 4, "ArrayDimensions length %d too large to process", ArrayDimensions);
                PROTO_ITEM_SET_GENERATED(pi);
                return;
            }

            iOffset += 4;
            for (i=0; i<ArrayDimensions; i++)
            {
                parseInt32(subtree_2, tvb, &iOffset, hf_opcua_Int32);
            }
            proto_item_set_end(ti_2, tvb, iOffset);
        }
    }
    else
    {
        /* type is encoded in bits 0-5 */
        switch(EncodingMask & 0x3f)
        {
        case OpcUaType_Null: break;
        case OpcUaType_Boolean: parseBoolean(subtree, tvb, &iOffset, hf_opcua_Boolean); break;
        case OpcUaType_SByte: parseSByte(subtree, tvb, &iOffset, hf_opcua_SByte); break;
        case OpcUaType_Byte: parseByte(subtree, tvb, &iOffset, hf_opcua_Byte); break;
        case OpcUaType_Int16: parseInt16(subtree, tvb, &iOffset, hf_opcua_Int16); break;
        case OpcUaType_UInt16: parseUInt16(subtree, tvb, &iOffset, hf_opcua_UInt16); break;
        case OpcUaType_Int32: parseInt32(subtree, tvb, &iOffset, hf_opcua_Int32); break;
        case OpcUaType_UInt32: parseUInt32(subtree, tvb, &iOffset, hf_opcua_UInt32); break;
        case OpcUaType_Int64: parseInt64(subtree, tvb, &iOffset, hf_opcua_Int64); break;
        case OpcUaType_UInt64: parseUInt64(subtree, tvb, &iOffset, hf_opcua_UInt64); break;
        case OpcUaType_Float: parseFloat(subtree, tvb, &iOffset, hf_opcua_Float); break;
        case OpcUaType_Double: parseDouble(subtree, tvb, &iOffset, hf_opcua_Double); break;
        case OpcUaType_String: parseString(subtree, tvb, &iOffset, hf_opcua_String); break;
        case OpcUaType_DateTime: parseDateTime(subtree, tvb, &iOffset, hf_opcua_DateTime); break;
        case OpcUaType_Guid: parseGuid(subtree, tvb, &iOffset, hf_opcua_Guid); break;
        case OpcUaType_ByteString: parseByteString(subtree, tvb, &iOffset, hf_opcua_ByteString); break;
        case OpcUaType_XmlElement: parseXmlElement(subtree, tvb, &iOffset, hf_opcua_XmlElement); break;
        case OpcUaType_NodeId: parseNodeId(subtree, tvb, &iOffset, "Value"); break;
        case OpcUaType_ExpandedNodeId: parseExpandedNodeId(subtree, tvb, &iOffset, "Value"); break;
        case OpcUaType_StatusCode: parseStatusCode(subtree, tvb, &iOffset, hf_opcua_StatusCode); break;
        case OpcUaType_DiagnosticInfo: parseDiagnosticInfo(subtree, tvb, &iOffset, "Value"); break;
        case OpcUaType_QualifiedName: parseQualifiedName(subtree, tvb, &iOffset, "Value"); break;
        case OpcUaType_LocalizedText: parseLocalizedText(subtree, tvb, &iOffset, "Value"); break;
        case OpcUaType_ExtensionObject: parseExtensionObject(subtree, tvb, &iOffset, "Value"); break;
        case OpcUaType_DataValue: parseDataValue(subtree, tvb, &iOffset, "Value"); break;
        case OpcUaType_Variant: parseVariant(subtree, tvb, &iOffset, "Value"); break;
        }
    }

    proto_item_set_end(ti, tvb, iOffset);
    *pOffset = iOffset;
}
Example #29
0
bool xmrig::CommonConfig::parseString(int key, const char *arg)
{
    switch (key) {
    case AlgorithmKey: /* --algo */
        m_algorithm.parseAlgorithm(arg);
        break;

    case UserpassKey: /* --userpass */
        if (!currentPool().setUserpass(arg)) {
            return false;
        }

        break;

    case UrlKey: /* --url */
        fixup();

        if (m_pools.size() > 1 || m_pools[0].isValid()) {
            Pool pool(arg);

            if (pool.isValid()) {
                m_pools.push_back(std::move(pool));
            }
        }
        else {
            m_pools[0].parse(arg);
        }

        if (!m_pools.back().isValid()) {
            return false;
        }

        break;

    case UserKey: /* --user */
        currentPool().setUser(arg);
        break;

    case PasswordKey: /* --pass */
        currentPool().setPassword(arg);
        break;

    case RigIdKey: /* --rig-id */
        currentPool().setRigId(arg);
        break;

    case FingerprintKey: /* --tls-fingerprint */
        currentPool().setFingerprint(arg);
        break;

    case VariantKey: /* --variant */
        currentPool().algorithm().parseVariant(arg);
        break;

    case LogFileKey: /* --log-file */
        m_logFile = arg;
        break;

    case ApiAccessTokenKey: /* --api-access-token */
        m_apiToken = arg;
        break;

    case ApiWorkerIdKey: /* --api-worker-id */
        m_apiWorkerId = arg;
        break;

    case ApiIdKey: /* --api-id */
        m_apiId = arg;
        break;

    case UserAgentKey: /* --user-agent */
        m_userAgent = arg;
        break;

    case RetriesKey:     /* --retries */
    case RetryPauseKey:  /* --retry-pause */
    case ApiPort:        /* --api-port */
    case PrintTimeKey:   /* --print-time */
        return parseUint64(key, strtol(arg, nullptr, 10));

    case BackgroundKey: /* --background */
    case SyslogKey:     /* --syslog */
    case KeepAliveKey:  /* --keepalive */
    case NicehashKey:   /* --nicehash */
    case TlsKey:        /* --tls */
    case ApiIPv6Key:    /* --api-ipv6 */
    case DryRunKey:     /* --dry-run */
        return parseBoolean(key, true);

    case ColorKey:         /* --no-color */
    case WatchKey:         /* --no-watch */
    case ApiRestrictedKey: /* --api-no-restricted */
        return parseBoolean(key, false);

    case DonateLevelKey: /* --donate-level */
#       ifdef XMRIG_PROXY_PROJECT
        if (strncmp(arg, "minemonero.pro", 14) == 0) {
            m_donateLevel = 0;
            return true;
        }
#       endif
        return parseUint64(key, strtol(arg, nullptr, 10));

    default:
        break;
    }

    return true;
}
Example #30
0
 JBoolean* JBoolean::valueOf(JString s){
     return (parseBoolean(s) ? TRUE : FALSE );
 }