Example #1
0
inline nanos_event_value_t InstrumentationKeyDescriptor::registerValue ( const std::string &value, const std::string &description,
                                                                      bool abort_when_registered )
{
   return registerValue( value.c_str(), description.c_str(), abort_when_registered );
}
Example #2
0
bool OsmAnd::MapStyle_P::parse( QXmlStreamReader& xmlReader )
{
    auto rulesetType = MapStyleRulesetType::Invalid;

    struct Lexeme
    {
        enum Type
        {
            Rule,
            Group,
        };

        Lexeme(Type type_, MapStyle_P* style_)
            : type(type_)
            , style(style_)
        {}

        const Type type;
        MapStyle_P* const style;
    };

    struct Rule : public Lexeme
    {
        Rule(std::shared_ptr<MapStyleRule> rule_, MapStyle_P* style_)
            : Lexeme(Lexeme::Rule, style_)
            , rule(rule_)
        {}

        const std::shared_ptr<MapStyleRule> rule;
    };

    struct Group : public Lexeme
    {
        Group(MapStyle_P* const style_)
            : Lexeme(Lexeme::Group, style_)
        {}

        QHash< QString, QString > attributes;
        QList< std::shared_ptr<MapStyleRule> > children;
        QList< std::shared_ptr<Lexeme> > subgroups;

        void addGroupFilter(const std::shared_ptr<MapStyleRule>& rule)
        {
            for(auto itChild = children.cbegin(); itChild != children.cend(); ++itChild)
            {
                auto child = *itChild;

                child->_d->_ifChildren.push_back(rule);
            }

            for(auto itSubgroup = subgroups.cbegin(); itSubgroup != subgroups.cend(); ++itSubgroup)
            {
                auto subgroup = *itSubgroup;

                assert(subgroup->type == Lexeme::Group);
                std::static_pointer_cast<Group>(subgroup)->addGroupFilter(rule);
            }
        }

        bool registerGlobalRules(const MapStyleRulesetType type)
        {
            for(auto itChild = children.cbegin(); itChild != children.cend(); ++itChild)
            {
                auto child = *itChild;

                if(!style->registerRule(type, child))
                    return false;
            }

            for(auto itSubgroup = subgroups.cbegin(); itSubgroup != subgroups.cend(); ++itSubgroup)
            {
                auto subgroup = *itSubgroup;

                assert(subgroup->type == Lexeme::Group);
                if(!std::static_pointer_cast<Group>(subgroup)->registerGlobalRules(type))
                    return false;
            }

            return true;
        }
    };

    QStack< std::shared_ptr<Lexeme> > stack;

    while (!xmlReader.atEnd() && !xmlReader.hasError())
    {
        xmlReader.readNext();
        const auto tagName = xmlReader.name();
        if (xmlReader.isStartElement())
        {
            if(tagName == QLatin1String("renderingStyle"))
            {
                // We have already parsed metadata and resolved dependencies, so here we don't need to do anything
            }
            else if(tagName == QLatin1String("renderingConstant"))
            {
                const auto& attribs = xmlReader.attributes();

                auto name = attribs.value(QLatin1String("name")).toString();
                auto value = attribs.value(QLatin1String("value")).toString();
                _parsetimeConstants.insert(name, value);
            }
            else if(tagName == QLatin1String("renderingProperty"))
            {
                MapStyleConfigurableInputValue* inputValue = nullptr;

                const auto& attribs = xmlReader.attributes();
                auto name = obtainValue(attribs.value(QLatin1String("attr")).toString());
                auto type = obtainValue(attribs.value(QLatin1String("type")).toString());
                auto title = obtainValue(attribs.value(QLatin1String("name")).toString());
                auto description = attribs.value(QLatin1String("description")).toString();
                auto encodedPossibleValues = attribs.value(QLatin1String("possibleValues"));
                QStringList possibleValues;
                if(!encodedPossibleValues.isEmpty())
                    possibleValues = encodedPossibleValues.toString().split(',', QString::SkipEmptyParts);
                for(auto itPossibleValue = possibleValues.begin(); itPossibleValue != possibleValues.end(); ++itPossibleValue)
                {
                    auto& possibleValue = *itPossibleValue;
                    possibleValue = obtainValue(possibleValue);
                }
                if(type == QLatin1String("string"))
                {
                    inputValue = new MapStyleConfigurableInputValue(
                        MapStyleValueDataType::String,
                        name,
                        title,
                        description,
                        possibleValues);
                }
                else if(type == QLatin1String("boolean"))
                {
                    inputValue = new MapStyleConfigurableInputValue(
                        MapStyleValueDataType::Boolean,
                        name,
                        title,
                        description,
                        possibleValues);
                }
                else // treat as integer
                {
                    inputValue = new MapStyleConfigurableInputValue(
                        MapStyleValueDataType::Integer,
                        name,
                        title,
                        description,
                        possibleValues);
                }

                registerValue(inputValue);
            }
            else if(tagName == QLatin1String("renderingAttribute"))
            {
                const auto& attribs = xmlReader.attributes();

                auto name = obtainValue(attribs.value(QLatin1String("name")).toString());

                std::shared_ptr<MapStyleRule> attribute(new MapStyleRule(owner, QHash< QString, QString >()));
                _attributes.insert(name, attribute);

                std::shared_ptr<Lexeme> selector(new Rule(attribute, this));
                stack.push(qMove(selector));
            }
            else if(tagName == QLatin1String("filter"))
            {
                QHash< QString, QString > ruleAttributes;

                if(!stack.isEmpty())
                {
                    auto lexeme = stack.top();

                    if(lexeme->type == Lexeme::Group)
                        ruleAttributes.unite(std::static_pointer_cast<Group>(lexeme)->attributes);
                }

                const auto& attribs = xmlReader.attributes();
                for(auto itXmlAttrib = attribs.cbegin(); itXmlAttrib != attribs.cend(); ++itXmlAttrib)
                {
                    const auto& xmlAttrib = *itXmlAttrib;

                    const auto tag = xmlAttrib.name().toString();
                    const auto value = obtainValue(xmlAttrib.value().toString());
                    ruleAttributes.insert(qMove(tag), qMove(value));
                }

                const std::shared_ptr<MapStyleRule> rule(new MapStyleRule(owner, ruleAttributes));

                if(!stack.isEmpty())
                {
                    auto lexeme = stack.top();

                    if(lexeme->type == Lexeme::Group)
                    {
                        std::static_pointer_cast<Group>(lexeme)->children.push_back(rule);
                    }
                    else if(lexeme->type == Lexeme::Rule)
                    {
                        std::static_pointer_cast<Rule>(lexeme)->rule->_d->_ifElseChildren.push_back(rule);
                    }
                }
                else
                {
                    if(!registerRule(rulesetType, rule))
                        return false;
                }

                stack.push(qMove(std::shared_ptr<Lexeme>(new Rule(rule, this))));
            }
            else if(tagName == QLatin1String("groupFilter"))
            {
                QHash< QString, QString > attributes;

                const auto& attribs = xmlReader.attributes();
                for(auto itXmlAttrib = attribs.cbegin(); itXmlAttrib != attribs.cend(); ++itXmlAttrib)
                {
                    const auto& xmlAttrib = *itXmlAttrib;

                    const auto tag = xmlAttrib.name().toString();
                    const auto value = obtainValue(xmlAttrib.value().toString());
                    attributes.insert(qMove(tag), qMove(value));
                }

                std::shared_ptr<MapStyleRule> rule(new MapStyleRule(owner, attributes));

                if(stack.isEmpty())
                {
                    OsmAnd::LogPrintf(OsmAnd::LogSeverityLevel::Error, "Group filter without parent");
                    return false;
                }

                auto lexeme = stack.top();
                if(lexeme->type == Lexeme::Group)
                {
                    std::static_pointer_cast<Group>(lexeme)->addGroupFilter(rule);
                }
                else if(lexeme->type == Lexeme::Rule)
                {
                    std::static_pointer_cast<Rule>(lexeme)->rule->_d->_ifChildren.push_back(rule);
                }

                stack.push(qMove(std::shared_ptr<Lexeme>(new Rule(rule, this))));
            }
            else if(tagName == QLatin1String("group"))
            {
                const auto group = new Group(this);
                if(!stack.isEmpty())
                {
                    auto lexeme = stack.top();
                    if(lexeme->type == Lexeme::Group)
                        group->attributes.unite(std::static_pointer_cast<Group>(lexeme)->attributes);
                }

                const auto& attribs = xmlReader.attributes();
                for(auto itXmlAttrib = attribs.cbegin(); itXmlAttrib != attribs.cend(); ++itXmlAttrib)
                {
                    const auto& xmlAttrib = *itXmlAttrib;

                    const auto tag = xmlAttrib.name().toString();
                    const auto value = obtainValue(xmlAttrib.value().toString());
                    group->attributes.insert(qMove(tag), qMove(value));
                }

                stack.push(qMove(std::shared_ptr<Lexeme>(group)));
            }
            else if(tagName == QLatin1String("order"))
            {
                rulesetType = MapStyleRulesetType::Order;
            }
            else if(tagName == QLatin1String("text"))
            {
                rulesetType = MapStyleRulesetType::Text;
            }
            else if(tagName == QLatin1String("point"))
            {
                rulesetType = MapStyleRulesetType::Point;
            }
            else if(tagName == QLatin1String("line"))
            {
                rulesetType = MapStyleRulesetType::Polyline;
            }
            else if(tagName == QLatin1String("polygon"))
            {
                rulesetType = MapStyleRulesetType::Polygon;
            } 
        }
        else if(xmlReader.isEndElement())
        {
            if(tagName == QLatin1String("filter"))
            {
                stack.pop();
            }
            else if(tagName == QLatin1String("group"))
            {
                const auto lexeme = stack.pop();

                if (stack.isEmpty())
                {
                    assert(lexeme->type == Lexeme::Group);
                    if(!std::static_pointer_cast<Group>(lexeme)->registerGlobalRules(rulesetType))
                        return false;
                }
                else
                {
                    const auto group = stack.top();
                    if(group->type == Lexeme::Group)
                        std::static_pointer_cast<Group>(group)->subgroups.push_back(qMove(lexeme));
                }
            }
            else if(tagName == QLatin1String("groupFilter"))
            {
                stack.pop();
            }
            else if(tagName == QLatin1String("renderingAttribute"))
            {
                stack.pop();
            }
        }
    }
    if(xmlReader.hasError())
    {
        std::cerr << qPrintable(xmlReader.errorString()) << "(" << xmlReader.lineNumber() << ", " << xmlReader.columnNumber() << ")" << std::endl;
        return false;
    }

    return true;
}
Example #3
0
int main(int argc, char *argv[])
{
  struct Arguments	args = {
    .tags        = { [0] = {false,0} },
    .do_set      = false,
    .dir         = 0,
    .is_missingok= false,
    .xid         = VC_NOCTX,
  };
  size_t		i;

  assert(DIM_OF(UTS_MAPPING) == DIM_OF(args.tags));
  
  while (1) {
    int		c = getopt_long(argc, argv, "+gst:", CMDLINE_OPTIONS, 0);
    if (c==-1) break;

    switch (c) {
      case CMD_HELP	:  showHelp(1, argv[0], 0);
      case CMD_VERSION	:  showVersion();
      case CMD_DIR	:  args.dir          = optarg; break;
      case CMD_MISSINGOK:  args.is_missingok = true;   break;
      case 'g'		:  args.do_set       = false;  break;
      case 's'		:  args.do_set       = true;   break;
      case 'x'		:  args.xid = Evc_xidopt2xid(optarg,true); break;
      case 't'		:  registerValue(optarg, args.tags);       break;
      default		:
	WRITE_MSG(2, "Try '");
	WRITE_STR(2, argv[0]);
	WRITE_MSG(2, " --help' for more information.\n");
	return EXIT_FAILURE;
	break;
    }
  }

  if (args.xid==VC_NOCTX) {
    WRITE_MSG(2, "No context specified; try '--help' for more information\n");
    exit(wrapper_exit_code);
  }

  if (args.dir)
    setFromDir(args.dir, args.is_missingok, args.xid);
  else if (args.do_set) {
    for (i=0; i<DIM_OF(args.tags); ++i) {
      if (!args.tags[i].is_set) continue;
      Evc_set_vhi_name(args.xid, i, args.tags[i].value, strlen(args.tags[i].value));
    }
  }
  else if (optind==argc) {
    char const *	delim = "";
    for (i=0; i<DIM_OF(UTS_MAPPING); ++i) {
      WRITE_STR(1, delim);
      printUtsValue(args.xid, i);
      delim = " ";
    }
    WRITE_MSG(1, "\n");

    return EXIT_SUCCESS;
  }
  else {
    char const *	delim = "";
    while (optind <argc) {
      int		idx = findUtsIdx(argv[optind], strlen(argv[optind]));
      WRITE_STR(1, delim);
      printUtsValue(args.xid, idx);
      delim = " ";

      ++optind;
    }
    WRITE_MSG(1, "\n");
    
    return EXIT_SUCCESS;
  }

  if (optind<argc)
    EexecvpD(argv[optind], argv+optind);

  return EXIT_SUCCESS;
}
Example #4
0
BlackBoard::IdType BlackBoard::registerValue(const char* buffer, int len) {
    return registerValue(reinterpret_cast<const int8_t*>(buffer),len);
}