void CNcdPreminetProtocolDataBlocksParser::OnStartElementL( const Xml::RTagInfo& aElement, 
                                                             const Xml::RAttributeArray& aAttributes, 
                                                             TInt aErrorCode ) 
    {
    CNcdSubParser::OnStartElementL( aElement, aAttributes, aErrorCode );
    
    TPtrC8 tag( aElement.LocalName().DesC() );
    DLTRACE(("dataBlocks tag=%S error=%d depth=%d",&aElement.LocalName().DesC(),aErrorCode,iDepth));

    if( iSubParser )
        {
        // Use existing subparser.
        iSubParser->OnStartElementL( aElement, aAttributes, aErrorCode );
        }
    else if( tag == KTagDataBlock )
        {
        iCurrentDataBlock = CNcdPreminetProtocolDataBlockImpl::NewL();

        // data block attributes
        // id
        NcdProtocolUtils::AssignDesL( iCurrentDataBlock->iId, AttributeValue( KAttrId, aAttributes ) );
        // name space
        NcdProtocolUtils::AssignDesL( iCurrentDataBlock->iNameSpace, AttributeValue( KAttrNamespace, aAttributes ) );

        }
    else
        {
        iSubParser = CNcdUnknownParser::NewL( *iObservers, *this, iDepth+1, aElement, aAttributes );
        }
    }
void CNcdPreminetProtocolPurchaseInformationParser::ConstructL( 
    const Xml::RTagInfo& aElement,
    const Xml::RAttributeArray& aAttributes,
    const TDesC& /*aParentId*/ )
    {
    CNcdSubParser::ConstructL( aElement );

    DLTRACEIN(("depth=%d tag=%S",iDepth,iTag));
    //DLINFO((_L("parent=%S"),&aParentId));

    if (!iInformation)
        {
        iInformation = CNcdPreminetProtocolPurchaseInformationImpl::NewL();
        }
    
    // read attributes here    
    TPtrC8 uri = AttributeValue( KAttrUri, aAttributes );
    NcdProtocolUtils::AssignDesL(iInformation->iUri, uri);
    
    TPtrC8 ns = AttributeValue( KAttrNamespace, aAttributes );
    NcdProtocolUtils::AssignDesL(iInformation->iNamespace, ns);
    TPtrC8 initiateSession = 
        AttributeValue( KAttrInitiateSession, aAttributes );
    NcdProtocolUtils::DesToBool(iInformation->iInitiateSession, initiateSession);
    }
Пример #3
0
static inline AttributeValue binop(AttributeValue const& lhs, AttributeValue const& rhs, char op) {
  if (!lhs.text.empty()) return lhs;
  if (!rhs.text.empty()) return rhs;
  switch (op) {
  case '+': return lhs + rhs;
  case '-': return lhs - rhs;
  case '*': return lhs * rhs;
  case '/': return lhs / rhs;
  case '>': return (lhs.max > rhs.max ? 1.0 : 0.0);
  case '<': return (lhs.max < rhs.max ? 1.0 : 0.0);
  case funcMin: return AttributeValue(std::min(lhs.min, rhs.min), std::min(lhs.max, rhs.max));
  case funcMax: return AttributeValue(std::max(lhs.min, rhs.min), std::max(lhs.max, rhs.max));
  case funcTable:
    if (lhs.table == nullptr) {
      return 0;
    } else {
      int imin = static_cast<int>(rhs.min);
      int imax = static_cast<int>(rhs.max);
      if (imin < 0 || imax > 75) return 0;
      return AttributeValue(std::min(lhs.table[imin], lhs.table[imax]),
        std::max(lhs.table[imin], lhs.table[imax]));
    }
    break;
  default: return AttributeValue();
  }
}
void CNcdPreminetProtocolRightsParser::ConstructL( 
    const Xml::RTagInfo& aElement,
    const Xml::RAttributeArray& aAttributes,
    const TDesC& /*aParentId*/ )
    {
    CNcdSubParser::ConstructL( aElement );

    DLTRACEIN(("depth=%d tag=%S",iDepth,iTag));
    //DLINFO((_L("parent=%S"),&aParentId));

    if (!iRights)
        {
        iRights = CNcdPreminetProtocolRightsImpl::NewL();
        }

    // read attributes here
    TPtrC8 activationKey = AttributeValue( KAttrActivationKey, aAttributes );
    NcdProtocolUtils::AssignDesL(iRights->iActivationKey, activationKey);

    TPtrC8 issuerUri = AttributeValue( KAttrIssuerUri, aAttributes );
    NcdProtocolUtils::AssignDesL(iRights->iIssuerUri, issuerUri);

    TPtrC8 uri = AttributeValue( KAttrUri, aAttributes );
    NcdProtocolUtils::AssignDesL(iRights->iUri, uri);

    TPtrC8 type = AttributeValue( KAttrType, aAttributes );
    NcdProtocolUtils::AssignDesL(iRights->iType, type);

    TPtrC8 name = AttributeValue( KAttrName, aAttributes );
    NcdProtocolUtils::AssignDesL(iRights->iName, name);

    }
void CNcdPreminetProtocolRightsParser::OnStartElementL( 
    const Xml::RTagInfo& aElement, 
    const Xml::RAttributeArray& aAttributes, 
    TInt aErrorCode) 
    {
    CNcdSubParser::OnStartElementL( aElement, aAttributes, aErrorCode );

    DLTRACEIN(("rights start tag=%S error=%d depth=%d",
        &aElement.LocalName().DesC(),aErrorCode,iDepth));
    
    TPtrC8 tag( aElement.LocalName().DesC() );
    
    if ( iSubParser )
        {
        iSubParser->OnStartElementL( aElement, aAttributes, aErrorCode );
        }
    else if ( tag == KTagRightsObject && iRights )
        {
        TPtrC8 dataBlock = AttributeValue( KAttrDataBlock, aAttributes );
        NcdProtocolUtils::AssignDesL(iRights->iRightsObjectDataBlock, dataBlock);

        TPtrC8 mime = AttributeValue( KAttrMime, aAttributes );
        NcdProtocolUtils::AssignDesL(iRights->iRightsObjectMime, mime);
        
        // data saved in OnEndElementL
        }
    else
        {
        iSubParser = CNcdUnknownParser::NewL( 
            *iObservers, *this, iDepth+1, aElement, aAttributes );
        }
    }
Пример #6
0
void VariableExpression::evaluateTo( const text::Transition * currentAnnotation, const matchers::Variable currentVar, const Context & ctx, ValueList & results ) const {
	Context::ConstRange range = ctx.getValues( variable );

	for ( Context::ConstIterator it = range.first; it != range.second; ++ it )
		results.push_back( AttributeValue( *it->second ) );

	if ( currentVar == variable )
		results.push_back( AttributeValue( *currentAnnotation ) );
}
Пример #7
0
QScriptValue ScriptedMetavoxelGuide::visit(QScriptContext* context, QScriptEngine* engine) {
    ScriptedMetavoxelGuide* guide = static_cast<ScriptedMetavoxelGuide*>(context->callee().data().toVariant().value<void*>());

    // start with the basics, including inherited attribute values
    QScriptValue infoValue = context->argument(0);
    QScriptValue minimum = infoValue.property(guide->_minimumHandle);
    MetavoxelInfo info = {
        glm::vec3(minimum.property(0).toNumber(), minimum.property(1).toNumber(), minimum.property(2).toNumber()),
        infoValue.property(guide->_sizeHandle).toNumber(), guide->_visitation->info.inputValues,
        guide->_visitation->info.outputValues, infoValue.property(guide->_isLeafHandle).toBool() };
    
    // extract and convert the values provided by the script
    QScriptValue inputValues = infoValue.property(guide->_inputValuesHandle);
    const QVector<AttributePointer>& inputs = guide->_visitation->visitor.getInputs();
    for (int i = 0; i < inputs.size(); i++) {
        QScriptValue attributeValue = inputValues.property(i);
        if (attributeValue.isValid()) {
            info.inputValues[i] = AttributeValue(inputs.at(i),
                inputs.at(i)->createFromScript(attributeValue, engine));
        }
    }
    
    QScriptValue result = guide->_visitation->visitor.visit(info);
    
    // destroy any created values
    for (int i = 0; i < inputs.size(); i++) {
        if (inputValues.property(i).isValid()) {
            info.inputValues[i].getAttribute()->destroy(info.inputValues[i].getValue());
        }
    }
    
    return result;
}
void CNcdConfigurationProtocolErrorParser::ConstructL( const Xml::RTagInfo& aElement,
                                                       const Xml::RAttributeArray& aAttributes )
    {
    CNcdSubParser::ConstructL( aElement );
    iError = new(ELeave) CNcdPreminetProtocolErrorImpl();

    // attributes
    // code
    TPtrC8 code = AttributeValue( KAttrCode, aAttributes );
    if( code != KNullDesC8 )
        {
        iError->iCode = NcdProtocolUtils::DesDecToIntL( code );
        }
    // id
    NcdProtocolUtils::AssignDesL( iError->iId, AttributeValue( KAttrId, aAttributes ) );

    }
void CNcdPreminetProtocolPurchaseInformationParser::OnStartElementL( 
    const Xml::RTagInfo& aElement, 
    const Xml::RAttributeArray& aAttributes, 
    TInt aErrorCode) 
    {
    CNcdSubParser::OnStartElementL( aElement, aAttributes, aErrorCode );
    
    TPtrC8 tag( aElement.LocalName().DesC() );
    
    if( iSubParser == 0 )
        {
        DLTRACEIN(("purchaseInformation start tag=%S error=%d depth=%d",
            &aElement.LocalName().DesC(),aErrorCode,iDepth));
        if( tag == KTagPayments )
            {
            // skip this tag
            }
        else if( tag == KTagPayment )
            {
            iSubParser = CNcdPreminetProtocolPaymentParser::NewL(
                *iObservers, *this, iDepth+1, aElement, aAttributes,
                KNullDesC /*no parent id*/ );
            }
        else if( tag == KTagDisclaimer )
            {
            iSubParser = CNcdConfigurationProtocolQueryParser::NewL( 
                *iObservers, *this, iDepth+1, aElement, aAttributes );
            }
        else if( tag == KTagTotalPrice )
            {
            TPtrC8 currency = AttributeValue( KAttrCurrency, aAttributes );
            NcdProtocolUtils::AssignDesL(
                iInformation->iTotalPriceCurrency, currency);
            // parsing myself
            }
        else if( tag == KTagEntities )
            {
            // skip this tag
            }
        else if( tag == KTagEntity )
            {
            iSubParser = CNcdPreminetProtocolPurchaseEntityParser::NewL( 
                *iObservers, *this, iDepth+1, aElement, aAttributes,
                KNullDesC /*no parent id*/ );
            }
        else
            {
            iSubParser = CNcdUnknownParser::NewL( 
                *iObservers, *this, iDepth+1, aElement, aAttributes );
            }
        }
    else
        {
        iSubParser->OnStartElementL( aElement, aAttributes, aErrorCode );
        }
    }
Пример #10
0
//---------------------------------------------------------------------------
const std::vector<double> ChessGame::AttributeValues(
  const std::vector<ChessMove>& moves) const
{
  const int nMoves = moves.size();
  std::vector<double> v(nMoves,0.0);
  for (int i=0; i!=nMoves; ++i)
  {
    v[i] = AttributeValue(moves[i]);
  }
  return v;
}
Пример #11
0
char*
XMLEntity::ToString(bool encoded, int level)
{
	string text = "";
	string indent = "";
	string character_data = EscapeText(CharacterData());

	for(int i=0; i<level; ++i) indent += "\t";
	
	text  = indent;
	text += "<";
	text += Name();

	for(int i=0; i < CountAttributes(); ++i) {
		text += " ";
		text += AttributeKey(i);
		text += "=";
		text += "\"";
		text += EscapeText(AttributeValue(i));
		text += "\"";
	}

	if (character_data.size() == 0 && CountChildren() == 0)	text += "/";
	text += ">";
	text += character_data;

	if (CountChildren() > 0)
	{
		text += "\n";

		for (int i=0; i < CountChildren(); ++i)
		{
			char *str = Child(i)->ToString(encoded, level + 1);
			if (str)
			{
				text += str;
				free(str);
			}
		}
		
		text += indent;
	}

	if (CountChildren() > 0 || character_data.size() > 0)
	{
		text += "</";
		text += Name();
		text += ">";
	}

	text += "\n";

	return strdup(text.c_str());	
}
Пример #12
0
void GenerateGems(json::Value& value, json::Value& data) {
  TranslateJson(value, data);
  auto names = Strings::list("Items");
  auto powers = Strings::list("ItemPassivePowerDescriptions");
  for (auto& kv : value["gemColors"].getMap()) {
    std::string id = kv.first;
    id[0] = toupper(id[0]);
    size_t levels = value["gemQualities"].length();
    auto& dst = value["gemColors"][kv.first]["names"];
    for (size_t level = 1; level <= levels; ++level) {
      dst.append(names.getfmt("x1_%s_%02d", id.c_str(), level));
    }
  }
  for (auto& gem : data["legendaryGems"].getMap()) {
    std::string id = gem.second["id"].getString();
    auto* item = ItemLibrary::get(id);
    if (!names.has(id) || !item) {
      Logger::log("Item not found: %s", id.c_str());
      continue;
    }
    auto& dst = value["legendaryGems"][gem.first];
    dst["name"] = names[id];
    if (gem.second.has("effects")) {
      if (gem.second["effects"].has("0") && gem.second["effects"]["0"].has("format")) {
        char const* name = Power::name(item->x4B8_AttributeSpecifier.x04_Param);
        auto* tag = PowerTags::getraw(item->x4B8_AttributeSpecifier.x04_Param);
        if (!name || !tag || !powers.has(name)) {
          Logger::log("Power(0) not found for %s", id.c_str());
        } else {
          std::string fmt = powers[name];
          auto values = GameAffixes::defaultMap();
          values["value1"] = AttributeValue("%");
          dst["effects"]["0"]["format"] = FormatDescription(powers[name], FormatTags, values, tag);
        }
      }
      if (gem.second["effects"].has("1") && gem.second["effects"]["1"].has("format")) {
        std::vector<AttributeSpecifier> specs;
        specs.emplace_back(item->x4D0_AttributeSpecifier);
        auto format = GameAffixes::format(specs, FormatTags);
        if (format.empty()) {
          Logger::log("Unknown power(1) for %s", id.c_str());
        } else {
          dst["effects"]["1"]["format"] = format[0];
        }
      }
    }
  }
}
Пример #13
0
void MetavoxelSystem::init() {
    if (!_program.isLinked()) {
        switchToResourcesParentIfRequired();
        _program.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/metavoxel_point.vert");
        _program.link();
       
        _pointScaleLocation = _program.uniformLocation("pointScale");
    }
    
    AttributeRegistry::getInstance()->configureScriptEngine(&_scriptEngine);
    
    QFile scriptFile("resources/scripts/sphere.js");
    scriptFile.open(QIODevice::ReadOnly);
    QScriptValue guideFunction = _scriptEngine.evaluate(QTextStream(&scriptFile).readAll());
    _data.setAttributeValue(MetavoxelPath(), AttributeValue(AttributeRegistry::getInstance()->getGuideAttribute(),
        encodeInline(PolymorphicDataPointer(new ScriptedMetavoxelGuide(guideFunction)))));
    
    _buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw);
    _buffer.create();
}
Пример #14
0
FormulaParser::Value FormulaParser::eval() {
  int digits = 0;
  bool plus = false;

  EvalStack stack;
  stack.ops.push('{');
  while (int type = fnext()) {
    if (type == tChar && chr == ']') break;
    if (type == tChar && chr == '|') {
      type = fnext();
      if (type == tNum) {
        digits = static_cast<int>(val);
      } else if (type == tChar && chr == '+') {
        plus = true;
      }
      fnext();
    } else if (type == tName) {
      std::vector<std::string> parts;
      bool isfunc = false;
      while (type == tName) {
        parts.push_back(tag);
        size_t prev = pos;
        if ((type = fnext()) != tChar || chr != '.') {
          if (type == tChar && chr == '(') {
            isfunc = true;
          } else {
            pos = prev;
          }
          break;
        }
        type = fnext();
      }
      std::string result = "";
      for (auto& part : parts) {
        if (!result.empty()) result.push_back('.');
        result.append(part);
      }
      if (isfunc) {
        char funcId = getFunction(result);
        OpInfo const& op = opInfo(funcId);
        while (stack.ops.size() && opInfo(stack.ops.top()).rprio >= op.lprio) {
          stack.exec(stack.ops.top());
          stack.ops.pop();
        }
        stack.ops.push(funcId);
        stack.needval = op.rval;
      } else if (!stack.ops.empty() && stack.ops.top() == funcTable) {
        stack.vals.push(AttributeValue(PowerTags::table(result)));
      } else {
        static re::Prog sfid("sf_(\\d+)", -1, re::Prog::CaseInsensitive);
        static re::Prog sftag(R"/(powertag.(\w+)."(.*)")/", -1, re::Prog::CaseInsensitive);
        //static re::Prog lookup(R"(table.(\w+).(\w+))", -1, re::Prog::CaseInsensitive);
        std::vector<std::string> match;
        if (context && sfid.match(result, &match)) {
          stack.vals.emplace(context->get(atoi(match[1].c_str()), values));
        } else if (sftag.match(result, &match)) {
          stack.vals.emplace(PowerTags::get(match[1], match[2], values));
        } else {
          auto it = values.find(result);
          stack.vals.push(it == values.end() ? 0.0 : it->second);
        }
      }
      stack.needval = 0;
    } else if (type == tTag) {
      auto it = values.find(tag);
      if (it != values.end()) {
        prevtag = it->second;
      } else if (context) {
        prevtag = context->get(tag, values);
      } else {
        prevtag = 0.0;
      }
      stack.vals.push(prevtag);
      stack.needval = 0;
    } else if (type == tNum) {
      stack.vals.push(val);
      stack.needval = 0;
    } else if (type == tChar) {
      if (chr == '-' && stack.needval) chr = '~';
      OpInfo const& op = opInfo(chr);
      while (stack.ops.size() && opInfo(stack.ops.top()).rprio >= op.lprio) {
        char top = stack.ops.top();
        stack.exec(top);
        stack.ops.pop();
        if (opInfo(top).rprio == 0) break;
      }
      if (chr != ')') stack.ops.push(chr);
      stack.needval = op.rval;
    }
  }
  OpInfo const& op = opInfo('}');
  while (stack.ops.size() && opInfo(stack.ops.top()).rprio >= op.lprio) {
    stack.exec(stack.ops.top());
    stack.ops.pop();
  }
  AttributeValue res;
  if (stack.vals.size()) res = stack.vals.top();
  return Value(res, digits, plus);
}

std::string FormulaParser::parse() {
  std::string result;
  int newlines = 0;
  while (int type = next()) {
    if ((flags & FormatHTML) && newlines && (type != tChar || chr != '\n')) {
      if (newlines == 1) {
        result.append("<br/>");
      } else {
        result.append("</p><p>");
      }
      newlines = 0;
    }
    switch (type) {
    case tChar:
      if (chr == '[') {
        result.append(eval().format());
      } else if (chr == '|') {
        next(); // 4
        std::string lhs, rhs;
        while (next() == tChar && chr != ':') {
          lhs.push_back(chr);
        }
        while (next() == tChar && chr != ';') {
          rhs.push_back(chr);
        }
        if (prevtag.min != 1 || prevtag.max != 1) {
          result.append(rhs);
        } else {
          result.append(lhs);
        }
      } else if (chr == '\n' && (flags & FormatHTML)) {
        ++newlines;
      } else {
        if (flags & FormatTags) {
          if (chr == ' ' && (result.empty() || result.back() == '\n')) {
            break;
          }
          if (chr == '%') {
            result.push_back('%');
          }
        }
        result.push_back(chr);
      }
      break;
    case tTag:
      if (tag.substr(0, 2) == "/c" || tag.substr(0, 2) == "c:" || pretags.find(tag) != pretags.end()) {
        if (flags & FormatHTML) {
          if (tag.substr(0, 2) == "/c") {
            result.append("</span>");
          } else if (tag.substr(0, 2) == "c:") {
            result.append(fmtstring("<span style=\"color: #%s\">", tag.substr(4).c_str()));
          } else {
            result.append(pretags[tag]);
          }
        } else if ((flags & FormatTags) && tag == "icon:bullet") {
          result.push_back('*');
        }
      } else {
        auto it = values.find(tag);
        if (it != values.end()) {
          prevtag = it->second;
        } else if (context) {
          prevtag = context->get(tag, values);
        } else {
          prevtag = 0.0;
        }
        result.append(Value(prevtag).format());
      }
      break;
    }
Пример #15
0
AttributeValue SpannerQRgbAttribute::inherit(const AttributeValue& parentValue) const {
    return AttributeValue(parentValue.getAttribute());
}
Пример #16
0
AttributeValue MetavoxelNode::getAttributeValue(const AttributePointer& attribute) const {
    return AttributeValue(attribute, _attributeValue);
}
Пример #17
0
void DefaultMetavoxelGuide::guide(MetavoxelVisitation& visitation) {
    visitation.info.isLeaf = visitation.allInputNodesLeaves();
    bool keepGoing = visitation.visitor.visit(visitation.info);
    for (int i = 0; i < visitation.outputNodes.size(); i++) {
        AttributeValue& value = visitation.info.outputValues[i];
        if (!value.getAttribute()) {
            continue;
        }
        MetavoxelNode*& node = visitation.outputNodes[i];
        if (node && node->isLeaf() && value.getAttribute()->equal(value.getValue(), node->getAttributeValue())) {
            // "set" to same value; disregard
            value = AttributeValue();
        } else {
            node = new MetavoxelNode(value);
        }
    }
    if (!keepGoing) {
        return;
    }
    MetavoxelVisitation nextVisitation = { &visitation, visitation.visitor,
        QVector<MetavoxelNode*>(visitation.inputNodes.size()), QVector<MetavoxelNode*>(visitation.outputNodes.size()),
        { glm::vec3(), visitation.info.size * 0.5f, QVector<AttributeValue>(visitation.inputNodes.size()),
            QVector<AttributeValue>(visitation.outputNodes.size()) } };
    for (int i = 0; i < MetavoxelNode::CHILD_COUNT; i++) {
        for (int j = 0; j < visitation.inputNodes.size(); j++) {
            MetavoxelNode* node = visitation.inputNodes.at(j);
            MetavoxelNode* child = node ? node->getChild(i) : NULL;
            nextVisitation.info.inputValues[j] = ((nextVisitation.inputNodes[j] = child)) ?
                child->getAttributeValue(visitation.info.inputValues[j].getAttribute()) :
                    visitation.info.inputValues[j];
        }
        for (int j = 0; j < visitation.outputNodes.size(); j++) {
            MetavoxelNode* node = visitation.outputNodes.at(j);
            MetavoxelNode* child = node ? node->getChild(i) : NULL;
            nextVisitation.outputNodes[j] = child;
        }
        nextVisitation.info.minimum = visitation.info.minimum + glm::vec3(
            (i & X_MAXIMUM_FLAG) ? nextVisitation.info.size : 0.0f,
            (i & Y_MAXIMUM_FLAG) ? nextVisitation.info.size : 0.0f,
            (i & Z_MAXIMUM_FLAG) ? nextVisitation.info.size : 0.0f);
        static_cast<MetavoxelGuide*>(nextVisitation.info.inputValues.last().getInlineValue<
            PolymorphicDataPointer>().data())->guide(nextVisitation);
        for (int j = 0; j < nextVisitation.outputNodes.size(); j++) {
            AttributeValue& value = nextVisitation.info.outputValues[j];
            if (!value.getAttribute()) {
                continue;
            }
            // replace the child
            AttributeValue& parentValue = visitation.info.outputValues[j];
            if (!parentValue.getAttribute()) {
                // shallow-copy the parent node on first change
                parentValue = value;
                MetavoxelNode*& node = visitation.outputNodes[j];
                if (node) {
                    node = new MetavoxelNode(value.getAttribute(), node);
                } else {
                    // create leaf with inherited value
                    node = new MetavoxelNode(visitation.getInheritedOutputValue(j));
                }
            }
            MetavoxelNode* node = visitation.outputNodes.at(j);
            MetavoxelNode* child = node->getChild(i);
            if (child) {
                child->decrementReferenceCount(value.getAttribute());
            } else {
                // it's a leaf; we need to split it up
                AttributeValue nodeValue = node->getAttributeValue(value.getAttribute());
                for (int k = 1; k < MetavoxelNode::CHILD_COUNT; k++) {
                    node->setChild((i + k) % MetavoxelNode::CHILD_COUNT, new MetavoxelNode(nodeValue));
                }
            }
            node->setChild(i, nextVisitation.outputNodes.at(j));
            value = AttributeValue();
        }
    }
    for (int i = 0; i < visitation.outputNodes.size(); i++) {
        AttributeValue& value = visitation.info.outputValues[i];
        if (value.getAttribute()) {
            MetavoxelNode* node = visitation.outputNodes.at(i);
            node->mergeChildren(value.getAttribute());
            value = node->getAttributeValue(value.getAttribute()); 
        }
    }
}
Пример #18
0
void CurrentAnnotationExpression::evaluateTo( const text::Transition * currentAnnotation, const matchers::Variable currentVar, const Context & ctx, ValueList & results ) const {
	results.push_back( AttributeValue( *currentAnnotation ) );
}
Пример #19
0
AttributeValue Transition::getAttribute( AttributeKey key ) const {
	if ( key == AttributeKey::TEXT ) // Если запрашиваемый аттрибут - текст
		return AttributeValue( getRangeString() ); // Возвращаем текст, как строковый аттрибут

	return AttributeValue::UNDEFINED;
}
Пример #20
0
std::string FormatTag(std::string const& src, json::Value& data) {
  if (src.empty()) return src;
  if (src[0] == '$' && src.back() == '$') return src;
  size_t slash = src.find('/');
  if (slash == std::string::npos) return src;
  auto list = Strings::list(src.substr(0, slash));
  if (!list) {
    Logger::log("StringList not found: %s", src.substr(0, slash).c_str());
    return src;
  }
  size_t at = src.find('@', slash);
  std::string text = src.substr(slash + 1, at == std::string::npos ? at : at - slash - 1);
  if (!list.has(text)) {
    Logger::log("String not found: %s", src.substr(0, at).c_str());
    return src;
  }
  text = list[text];
  if (at != std::string::npos) {
    size_t quest = src.find('?', at);
    if (quest == std::string::npos) quest = src.length();
    FormatFlags flags = FormatTags;
    PowerTag* context = nullptr;
    AttributeMap values = GameAffixes::defaultMap();
    if (quest > at + 1) {
      flags = FormatHTML;
      context = PowerTags::get(src.substr(at + 1, quest - at - 1));
      if (!context) {
        Logger::log("PowerTag not found: %s", src.substr(at + 1, quest - at - 1).c_str());
      }
    } else {
      values["value"] = AttributeValue("%");
      values["value1"] = AttributeValue("%");
      values["value2"] = AttributeValue("%");
      values["value3"] = AttributeValue("%");
    }
    std::map<std::string, std::string> replace;
    if (quest < src.length()) {
      std::vector<std::string> parts = split(src.substr(quest + 1), '&');
      for (auto& p : parts) {
        size_t eq = p.find('=');
        if (eq == std::string::npos) continue;
        std::string key = p.substr(0, eq);
        std::string value = p.substr(eq + 1);
        if (!testString(key, isalnum)) {
          size_t pos = text.find(key);
          if (pos == std::string::npos) continue;
          std::string rval = fmtstring("@%d", replace.size() + 1);
          replace.emplace(rval, value);
          text.replace(pos, key.length(), rval);
          continue;
        }
        if (testString(value, isdigit)) {
          values.emplace(key, atof(value.c_str()));
          continue;
        }
        size_t ss = value.find('/');
        if (ss == std::string::npos) {
          values[key] = AttributeValue(value);
        } else {
          std::string listname = value.substr(0, ss);
          if (!testString(listname, isalpha)) {
            values[key] = AttributeValue(value); continue;
          }
          auto sublist = Strings::list(listname);
          if (!sublist) {
            Logger::log("StringList not found: %s", listname.c_str());
            continue;
          }
          std::string subtext = value.substr(ss + 1);
          if (!sublist.has(subtext)) {
            Logger::log("String not found: %s", value.c_str());
            continue;
          }
          values[key] = AttributeValue(sublist[subtext]);
        }
      }
    }
    text = FormatDescription(text, flags, values, context);
    for (auto& kv : replace) {
      size_t pos = text.find(kv.first);
      if (pos == std::string::npos) continue;
      text.replace(pos, kv.first.length(), kv.second);
    }
  }
  return text;
}
Пример #21
0
void GenerateItems(json::Value& value, json::Value& data) {
  auto names = Strings::list("Items");
  auto powers = Strings::list("ItemPassivePowerDescriptions");
  uint32 powId = fixAttrId(1270, true);
  std::map<std::string, std::string> powerFix;
  powerFix.emplace("Unique_Amulet_109_x1_210", "ItemPassive_x1_Amulet_norm_unique_25_DemonHunter");

  std::map<uint32, GameBalance::Type::AffixTableEntry*> affixes;
  SnoFile<GameBalance> affixFile("1xx_AffixList");
  for (auto& afx : affixFile->x078_AffixTable) {
    affixes.emplace(HashNameLower(afx.x000_Text), &afx);
  }
  for (auto& rcp : SnoLoader::All<Recipe>()) {
    std::string item = rcp->x0C_ItemSpecifierData.x00_ItemsGameBalanceId.name();
    if (item.empty()) continue;
    uint32 power = 0;
    for (auto& id : rcp->x0C_ItemSpecifierData.x08_GameBalanceIds) {
      if (affixes.count(id)) {
        for (auto& attr : affixes[id]->x260_AttributeSpecifiers) {
          if (attr.x00_Type == powId) {
            power = attr.x04_Param;
            break;
          }
        }
      }
      if (power) break;
    }
    char const* pname = (power ? Power::name(power) : nullptr);
    if (pname) powerFix.emplace(item, pname);
  }

  for (auto& kv : data["itemById"].getMap()) {
    if (kv.second.has("required")) {
      std::string key = kv.second["required"]["custom"]["id"].getString();
      data["legendaryMap"][key] = kv.first;
    }
    auto* item = ItemLibrary::get(kv.first);
    if (!names.has(kv.first) || !item) {
      if (kv.first != "Unique_Ring_017_p4") {
        Logger::log("Item not found: %s", kv.first.c_str());
        continue;
      }
    }
    auto& dst = value["itemById"][kv.first];
    dst["name"] = names[kv.first == "Unique_Ring_017_p4" ? "Unique_Ring_017_p2" : kv.first];
    if (kv.second.has("required")) {
      std::string key = kv.second["required"]["custom"]["id"].getString();
      data["stringlist"]["Items"][key]["text"] = kv.second["required"]["custom"]["name"];
      data["stringlist"]["Items"][key]["tip"] = names[kv.first] + " (short effect name)";
      dst["required"]["custom"]["name"] = fmtstring("$Items/%s$", key.c_str());
      bool found = false;
      for (auto& attr : item->x1F8_AttributeSpecifiers) {
        if (attr.x00_Type != powId) continue;
        char const* name = Power::name(attr.x04_Param);
        auto* tag = PowerTags::getraw(attr.x04_Param);
        if (!name || !tag || !powers.has(name)) {
          Logger::log("Power not found for %s", kv.first.c_str());
          continue;
        }
        auto values = GameAffixes::defaultMap();
        AttributeValue value = ExecFormula(
          reinterpret_cast<uint32 const*>(attr.x08_Data.begin()),
          reinterpret_cast<uint32 const*>(attr.x08_Data.end()),
          values);
        if (value.min != value.max) {
          values["value1"] = AttributeValue("%");
        } else {
          values["value1"] = value;
        }
        dst["required"]["custom"]["format"] = FormatDescription(powers[name], FormatTags, values, tag);
        found = true;
        break;
      }
      if (!found) {
        if (powerFix.count(kv.first)) {
          auto* tag = PowerTags::get(powerFix[kv.first]);
          auto values = GameAffixes::defaultMap();
          values["value1"] = AttributeValue("%");
          dst["required"]["custom"]["format"] = FormatDescription(powers[powerFix[kv.first]], FormatTags, values, tag);
        } else if (kv.first == "x1_Amulet_norm_unique_25") {
          // hellfire
          std::string x = powers["ItemPassive_Unique_Ring_770_x1"];
          std::string y = Strings::get("Powers", "Trait_PoundOfFlesh");
          size_t pos = x.find(y);
          if (pos != std::string::npos) {
            x.replace(pos, y.length(), "%p");
            dst["required"]["custom"]["format"] = x;
          }
        } else {
          Logger::log("Power not found for %s", kv.first.c_str());
        }
      }
      if (dst["required"]["custom"].has("format")) {
        data["locale_tips"]["Items"][key] = dst["required"]["custom"]["format"];
      }
    }
  }
}
Пример #22
0
/* ----------------------------------------------------------------------
   TtaAttachAttribute

   Attaches an attribute to an element.
   Parameters:
   element: the element to which the attribute has to be attached.
   attribute: the attribute to be attached.
   document: the document to which the element belongs.
   ---------------------------------------------------------------------- */
void TtaAttachAttribute (Element element, Attribute attribute, Document document)
{
  PtrAttribute        pAttr;
  PtrDocument         pDoc;
  ThotBool            obligatory;

  UserErrorCode = 0;
  if (element == NULL || attribute == NULL ||
      ((PtrElement) element)->ElStructSchema == NULL)
    TtaError (ERR_invalid_parameter);
  else if (document < 1 || document > MAX_DOCUMENTS)
    TtaError (ERR_invalid_document_parameter);
  else
    {
      pDoc = LoadedDocument[document - 1];
      if (pDoc == NULL)
        TtaError (ERR_invalid_document_parameter);
      else if (AttributeValue ((PtrElement) element,
                               (PtrAttribute) attribute) != NULL)
        /* parameter document is correct */
        /* has the element an attribute of the same type ? */
        /* yes, error */ 
        TtaError (ERR_duplicate_attribute);
      else if ((pDoc)->DocCheckingMode & STR_CHECK_MASK &&
               !CanAssociateAttr ((PtrElement) element, NULL, 
                                  (PtrAttribute) attribute, &obligatory))
        /* can wa apply the attribute to the element ? */
        /* no, error */
        TtaError (ERR_attribute_element_mismatch);
      else
        {
#ifndef NODISPLAY
          UndisplayInheritedAttributes ((PtrElement) element,
                                        (PtrAttribute) attribute, document, FALSE);
#endif
          if (((PtrElement) element)->ElFirstAttr == NULL)
            ((PtrElement) element)->ElFirstAttr = (PtrAttribute) attribute;
          else
            {
              pAttr = ((PtrElement) element)->ElFirstAttr;
              while (pAttr->AeNext != NULL)
                pAttr = pAttr->AeNext;
              pAttr->AeNext = (PtrAttribute) attribute;
            }
          /* update the menu attributes */
          if (pDoc == SelectedDocument &&
              (PtrElement) element == FirstSelectedElement)
            if (ThotLocalActions[T_chattr] != NULL)
              (*(Proc1)ThotLocalActions[T_chattr]) ((void *)pDoc);
	   
          pAttr = (PtrAttribute) attribute;
          pAttr->AeNext = NULL;
          pAttr->AeDefAttr = FALSE;
          if (pAttr->AeAttrType == AtReferenceAttr)
            if (pAttr->AeAttrReference != NULL)
              pAttr->AeAttrReference->RdElement = (PtrElement) element;
#ifndef NODISPLAY
          DisplayAttribute ((PtrElement) element, pAttr, document);
#endif
        }
    }
}
Пример #23
0
Expression * CreateStringLiteralExpressionImpl::operator()( const char * start, const char * end ) const {
	return new ConstantExpression( AttributeValue( Morphology::instance().upcase( start, end ) ) );
}
Пример #24
0
int DPM_session::Initialize( xmlNode *SessionNode ) {

    double tstart    = 0.0;
    double tstop     = DBL_MAX;
    double frequency = DBL_MAX;

    int n_product_files, n_runs;

    if (SessionNode == NULL) {
         std::cerr << "ERROR: DPM_session::Initialize: Bad parameters." << std::endl;
         return -1;
    }

    if (strcmp((char*) SessionNode->name, "session") != 0) {
        std::cerr << "ERROR: Expected <session> specification but alas didnt find it." << std::endl;
        return -1;
    }

    if ( !strcasecmp(AttributeValue("presentation") , "stream" ) ) {
        if ( AttributeValue("machine") == NULL ) {
            std::cerr << "ERROR: Expected attribute \"machine\" when using stream presentation" << std::endl;
            return -1;
        }
        if ( AttributeValue("port") == NULL ) {
            std::cerr << "ERROR: Expected attribute \"port\" when using stream presentation" << std::endl;
            return -1;
        }
    }

    if (AttributeValue("device") != NULL) {
        if (setDevice((char*)AttributeValue("device")) < 0) {
            return -1;
        }
    } else {
        sessionDevice = DPM_session::TERMINAL;
    }



    /* Process children */
    xmlNode *current_node = SessionNode->children;

    while (current_node != NULL) {
        if (current_node->type == XML_ELEMENT_NODE) {
            if ( strcmp( (char *)current_node->name, "run") == 0) {
                DPM_run *run;
                try {
                    run = new DPM_run( this, current_node);
                } catch (std::invalid_argument) {
                    run = NULL;
                    std::cerr << "ERROR: one of this <session>s <run>s is invalid." << std::endl;
                }
                if (run != NULL) {
                    run_list.push_back( run);
                }
            } else if ( strcmp( (char*)current_node->name, "product_files") == 0) {
                xmlNode *current_child_node;
                current_child_node = current_node->children;
                while (current_child_node != NULL) {
                    if (current_child_node->type == XML_ELEMENT_NODE) {
                        if ( strcmp( (const char *)current_child_node->name, "file") == 0) {
                            char *product_file;
                            xmlNode *text_node = current_child_node->children;
                            product_file = strdup( (const char *)text_node->content);
                            if (product_file != NULL) {
                                product_file_list.push_back( product_file);
                            }
                        } else {
                            std::cerr << "WARNING: <product_files> specification contains an unknown element \"<" <<
                                    current_child_node->name << ">\". Skipping." << std::endl;
                        }
                    }
                    current_child_node = current_child_node->next;
                }
            } else if ( strcmp( (const char *)current_node->name, "tstart") == 0) {
                xmlNode *text_node = current_node->children;
                tstart = strtod((const char *)text_node->content,(char **)NULL);

            } else if ( strcmp( (const char *)current_node->name, "tstop") == 0) {
                xmlNode *text_node = current_node->children;
                tstop = strtod((const char *)text_node->content,(char **)NULL);

            } else if ( strcmp( (const char *)current_node->name, "frequency") == 0) {
                xmlNode *text_node = current_node->children;
                frequency = strtod((const char *)text_node->content,(char**)NULL);

            } else {
                std::cerr << "WARNING: <session> specification contains an unknown element \"<" <<
                        current_node->name << ">\". Skipping." << std::endl;
            }
        }
        current_node = current_node->next;
    }
    time_constraints = new DPM_time_constraints(tstart, tstop, frequency);

    // Validation criteria:
    // 1. Session requires at least one RUN directory.
    // 2. Session requires at least one Product file.

    n_product_files = (int)product_file_list.size();
    if (n_product_files < 1) {
        std::cerr << "ERROR: <session> requires at least one product file." << std::endl;
        return -1;
    }

    n_runs = (int)run_list.size();
    if (n_runs < 1) {
        std::cerr << "ERROR: <session> requires at least one RUN." << std::endl;
        return -1;
    }

    return 0;
}
void CNcdPreminetProtocolEntityRefParser::ConstructL( const Xml::RTagInfo& aElement,
                                                      const Xml::RAttributeArray& aAttributes,
                                                      const TDesC& aParentId,
                                                      const TDesC& aParentNamespace )
    {
    CNcdSubParser::ConstructL( aElement );
    
    DLTRACEIN(("depth=%d tag=%S",iDepth,iTag));
    DLINFO((_L("parent=%S namespace=%S"),&aParentId,&aParentNamespace));
    
    NcdProtocolUtils::AssignDesL( iParentNamespace, aParentNamespace );


    TPtrC8 type = AttributeValue( KAttrType, aAttributes );
    if( type == KNullDesC8 )
        {
        type.Set( AttributePrefix( KAttrXsiType, aAttributes ) );
        }

    if( type == KValueFolderRef )
        {
        CNcdPreminetProtocolFolderRefImpl* folderRef = CNcdPreminetProtocolFolderRefImpl::NewL();
        iFolderRef = folderRef;
        DLINFO(("New Folder ref!"));
        TPtrC8 count = AttributeValue( KAttrCount, aAttributes );
        if( count != KNullDesC8 )
            {
            folderRef->iCount = NcdProtocolUtils::DesDecToIntL( count );
            }
        TPtrC8 authorizedCount = AttributeValue( KAttrAuthorizedCount, aAttributes );
        if( count != KNullDesC8 )
            {
            folderRef->iAuthorizedCount = NcdProtocolUtils::DesDecToIntL( count );
            }

        // @ Description
        NcdProtocolUtils::AssignDesL( iFolderRef->iParentId, aParentId );
        NcdProtocolUtils::AssignDesL( iFolderRef->iId, AttributeValue( KAttrId, aAttributes ) );
        NcdProtocolUtils::AssignDesL( iFolderRef->iNamespace, AttributeValue( KAttrNamespace, aAttributes ) );
        NcdProtocolUtils::AssignDesL( iFolderRef->iTimestamp, AttributeValue( KAttrTimestamp, aAttributes ) );
        NcdProtocolUtils::AssignDesL( iFolderRef->iServerUri, iObservers->SessionOrigin() );
        NcdProtocolUtils::AssignDesL( iFolderRef->iParentNamespace, *iParentNamespace );
        NcdProtocolUtils::AssignDesL( iFolderRef->iRemoteUri, AttributeValue( KAttrUri, aAttributes ) );

        if( *iFolderRef->iNamespace == KNullDesC )
            {
            // Namespace was not set, use parent.
            NcdProtocolUtils::AssignDesL( iFolderRef->iNamespace, *iParentNamespace );
            }

        }
    else if( type == KValueItemRef || type == KValueActionRef )
        {
        DLINFO(("New Item ref!"));
        iItemRef = CNcdPreminetProtocolItemRefImpl::NewL();
        
        // @ Description
        NcdProtocolUtils::AssignDesL( iItemRef->iParentId, aParentId );
        NcdProtocolUtils::AssignDesL( iItemRef->iId, AttributeValue( KAttrId, aAttributes ) );
        NcdProtocolUtils::AssignDesL( iItemRef->iNamespace, AttributeValue( KAttrNamespace, aAttributes ) );
        NcdProtocolUtils::AssignDesL( iItemRef->iTimestamp, AttributeValue( KAttrTimestamp, aAttributes ) );
        NcdProtocolUtils::AssignDesL( iItemRef->iServerUri, iObservers->SessionOrigin() );
        NcdProtocolUtils::AssignDesL( iItemRef->iParentNamespace, *iParentNamespace );
        NcdProtocolUtils::AssignDesL( iItemRef->iRemoteUri, AttributeValue( KAttrUri, aAttributes ) );

        if( *iItemRef->iNamespace == KNullDesC )
            {
            // Namespace was not set, use parent.
            NcdProtocolUtils::AssignDesL( iItemRef->iNamespace, *iParentNamespace );
            }
 
       }
    else
        {
        // unknown type!
        DLERROR(("Unknown item type=%S",&type));
        // Should there be more some informatic error?
        }

    DLTRACEOUT((""));
    }
Пример #26
0
AttributeValue SpannerPackedNormalAttribute::inherit(const AttributeValue& parentValue) const {
    return AttributeValue(parentValue.getAttribute());
}
Пример #27
0
TEST_F(ConfigNodeTest, AttributeValue)
{
	const auto node = config.LoadFromStringAndGetFirstChild(ConfigNodeData_1);
	EXPECT_EQ("hello", node.AttributeValue("id"));
}
void CNcdPreminetProtocolEntityRefParser::OnStartElementL( const Xml::RTagInfo& aElement, 
                                                           const Xml::RAttributeArray& aAttributes, 
                                                           TInt aErrorCode) 
    {

    DLTRACE((""));

    if( iSubParser )
        {
        // Use existing subparser.
        iSubParser->OnStartElementL( aElement, aAttributes, aErrorCode );
        }
    else if( iFolderRef == 0 && iItemRef == 0 )
        {
        // Skip everything if there was no supported type found earlier.
        DLERROR(("Skipping unknown entityref"));
        iSubParser = CNcdUnknownParser::NewL( *iObservers, *this, iDepth+1, aElement, aAttributes );
        }
    else
        {
        // If there is no subparser, we should handle all tags ourselves.
        TPtrC8 tag( aElement.LocalName().DesC() );
        DLTRACE(("entity start tag=%S error=%d depth=%d",&aElement.LocalName().DesC(),aErrorCode,iDepth));

        // First handle simple tags if we can.
        if( tag == KTagValidUntil )
            {
            DLTRACE(("validuntil delta=%S",&AttributeValue(KAttrDelta,aAttributes)));
            if( iItemRef )
                {
                iItemRef->iValidUntilDelta = 
                    NcdProtocolUtils::DesDecToIntL( AttributeValue( KAttrDelta, aAttributes ) );
                iItemRef->iValidUntilAutoUpdate = EFalse;
                NcdProtocolUtils::DesToBool( iItemRef->iValidUntilAutoUpdate,
                                              AttributeValue( KAttrAutoUpdate, aAttributes ) );
                }
            else
                {
                DASSERT( iFolderRef );
                iFolderRef->iValidUntilDelta = 
                    NcdProtocolUtils::DesDecToIntL( AttributeValue( KAttrDelta, aAttributes ) );
                iFolderRef->iValidUntilAutoUpdate = EFalse;
                NcdProtocolUtils::DesToBool( iFolderRef->iValidUntilAutoUpdate,
                                              AttributeValue( KAttrAutoUpdate, aAttributes ) );
                }
            }
        else if( tag == KTagQueries )
            {
            DLTRACE(("queries"));
            // We don't really need to handle this tag at all, it suffices to react to
            // individual <query> tags. This assumes that <query> tags don't come anywhere else
            // in this entity.
            }
        else if( tag == KTagQuery )
            {
            TInt queryId = NcdProtocolUtils::DesDecToIntL( AttributeValue( KAttrId, aAttributes ) );
            DLTRACE(("query id=%d",queryId));
            if( iItemRef )
                {
                User::LeaveIfError( iItemRef->iQueries.Append( queryId ) );
                }
            else
                {
                User::LeaveIfError( iFolderRef->iQueries.Append( queryId ) );
                }
            }
        else if( tag == KTagEntity && iFolderRef )
            {
            DLTRACE(("subentity for folder"));
            // Subentities, this is allowed for folderrefs.
            // : Observer callback here, the parent entity is finished?
            // This might result in child entities finishing before the parent?
            iSubParser = CNcdPreminetProtocolEntityRefParser::NewL( *iObservers, *this, iDepth+1, aElement, aAttributes,
                                                                    iFolderRef->Id() /*parent entity id*/, *iParentNamespace );
            }
        else
            {
            iSubParser = CNcdUnknownParser::NewL( *iObservers, *this, iDepth+1, aElement, aAttributes );
            }

        }
    }