void BlockedDOFManagerFactory<LO,GO>::
buildBlocking(const std::string & fieldOrder,std::vector<std::vector<std::string> > & blocks)
{
   // now we don't have to check
   TEUCHOS_ASSERT(requiresBlocking(fieldOrder));

   std::vector<std::string> tokens;

   // break it up on spaces
   StringTokenizer(tokens,fieldOrder," ",true);

   Teuchos::RCP<std::vector<std::string> > current;
   for(std::size_t i=1;i<tokens.size();i++) {
 
      if(tokens[i]!="-" && tokens[i-1]!="-") {
         // if there is something to add, add it to the blocks
         if(current!=Teuchos::null) 
            blocks.push_back(*current);

         current = Teuchos::rcp(new std::vector<std::string>);
      }

      if(tokens[i]!="-")
         current->push_back(tokens[i]);
   }

   if(current!=Teuchos::null) 
      blocks.push_back(*current);
}
bool BlockedDOFManagerFactory<LO,GO>::
requiresBlocking(const std::string & fieldOrder)
{
   std::vector<std::string> tokens;

   // break it up on spaces
   StringTokenizer(tokens,fieldOrder," ",true);
 
   if(tokens.size()<2) // there has to be at least 2 tokens to block
      return false;

   // check the prefix - must signal "blocked"
   if(tokens[0]!="blocked:")
      return false;

   // loop over tokens
   bool acceptsHyphen = false;
   for(std::size_t i=1;i<tokens.size();i++) {

      // acceptsHyphen can't be false, and then a hyphen accepted
      TEUCHOS_TEST_FOR_EXCEPTION(tokens[i]=="-" && !acceptsHyphen,std::logic_error,
                                 "Blocked assembly: Error \"Field Order\" hyphen error at "
                                 "token " << i); 

      if(acceptsHyphen && tokens[i]=="-")
         acceptsHyphen = false; 
      else { // token must be a field
         acceptsHyphen = true; 
      }
   }

   return true;
}
std::shared_ptr<ItemTemplate> ItemTemplateParser::Parse(LPCTSTR pszText)
{
   m_tokenizer = StringTokenizer(pszText);

   // TODO
   return std::shared_ptr<ItemTemplate>();
}
Exemple #4
0
void
KML_Geometry::parseCoords( const Config& conf, KMLContext& cx )
{
    const Config& coords = conf.child("coordinates");
    StringVector tuples;
    StringTokenizer( coords.value(), tuples, " ", "", false, true );
    for( StringVector::const_iterator s=tuples.begin(); s != tuples.end(); ++s )
    {
        StringVector parts;
        StringTokenizer( *s, parts, ",", "", false, true );
        if ( parts.size() >= 2 )
        {
            osg::Vec3d point;
            point.x() = as<double>( parts[0], 0.0 );
            point.y() = as<double>( parts[1], 0.0 );
            if ( parts.size() >= 3 ) {
                point.z() = as<double>( parts[2], 0.0 );
            }
            _geom->push_back(point);
        }
    }
}
Exemple #5
0
Content ONCatEntity::getNestedContent(const Content &content,
                                      const std::string &path) const {
  const auto pathTokens =
      StringTokenizer(path, ".", Mantid::Kernel::StringTokenizer::TOK_TRIM);

  auto currentNode = content;

  // Use the path tokens to drill down through the JSON nodes.
  for (const auto &pathToken : pathTokens) {
    if (!currentNode.isMember(pathToken)) {
      throw ContentError("");
    }
    currentNode = currentNode[pathToken];
  }

  return currentNode;
}
Exemple #6
0
void
Person::appendDrivingStage(const std::string& personID, const std::string& toEdge, const std::string& lines, const std::string& stopID) {
    MSTransportable* p = getPerson(personID);
    const MSEdge* edge = MSEdge::dictionary(toEdge);
    if (!edge) {
        throw TraCIException("Invalid edge '" + toEdge + "' for person: '" + personID + "'");
    }
    if (lines.size() == 0) {
        return throw TraCIException("Empty lines parameter for person: '" + personID + "'");
    }
    MSStoppingPlace* bs = nullptr;
    if (stopID != "") {
        bs = MSNet::getInstance()->getStoppingPlace(stopID, SUMO_TAG_BUS_STOP);
        if (bs == nullptr) {
            throw TraCIException("Invalid stopping place id '" + stopID + "' for person: '" + personID + "'");
        }
    }
    p->appendStage(new MSPerson::MSPersonStage_Driving(edge, bs, -NUMERICAL_EPS, StringTokenizer(lines).getVector()));
}
Exemple #7
0
void
NamedColumnsParser::parseLine(const std::string& line) {
    myLineParser = StringTokenizer(line, myLineDelimiter);
}
std::shared_ptr<Spell> SpellParser::Parse(LPCTSTR pszText)
{
   m_tokenizer = StringTokenizer(pszText);

   unsigned int uiSpellId = ParseUint(m_tokenizer.Next());
   unsigned int uiCooldown = 0;
   unsigned int uiCastTime = 0;
   bool bStackable = false;
   unsigned int uiRange = 0;
   bool bArea = false;
   std::vector<std::shared_ptr<SpellEffect>> vecEffects;

   CString cszToken;
   while (!m_tokenizer.IsEmpty())
   {
      cszToken = m_tokenizer.Next();

      if (cszToken == _T("cooldown"))
      {
         uiCooldown = TimeToSeconds(m_tokenizer.Next());
      }
      else
      if (cszToken == _T("cast-time"))
      {
         uiCastTime = TimeToSeconds(m_tokenizer.Next());
      }
      else
      if (cszToken == _T("stackable"))
      {
         bStackable = true;
      }
      else
      if (cszToken == _T("range"))
      {
         uiRange = ParseUint(m_tokenizer.Next());
      }
      else
      if (cszToken == _T("area"))
      {
         bArea = true;
      }
      else
      if (cszToken == _T("effect"))
      {
         ATLVERIFY(_T("[") == m_tokenizer.Next());
         vecEffects.push_back(ParseEffect());
      }
   }

   if (vecEffects.empty())
      throw Exception(_T("error parsing spell: no effect specified"), __FILE__, __LINE__);

   std::shared_ptr<Spell> spSpell(new Spell(uiSpellId, vecEffects[0]));

   spSpell->Cooldown(uiCooldown);
   spSpell->CastTime(uiCastTime);
   spSpell->Stackable(bStackable);
   spSpell->Range(uiRange);
   spSpell->AreaSpell(bArea);

   if (vecEffects.size() > 2)
      throw Exception(_T("error parsing spell: too many effects specified"), __FILE__, __LINE__);

   if (vecEffects.size() == 2)
      spSpell->Effect2(vecEffects[1]);

   return spSpell;
}
void
NIImporter_OpenStreetMap::insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
                                     const std::vector<int> &passed, NBEdgeCont& ec, NBTypeCont& tc) {
    // patch the id
    std::string id = e->id;
    if (index >= 0) {
        id = id + "#" + toString(index);
    }
    // convert the shape
    PositionVector shape;
    for (std::vector<int>::const_iterator i = passed.begin(); i != passed.end(); ++i) {
        NIOSMNode* n = myOSMNodes.find(*i)->second;
        Position pos(n->lon, n->lat);
        if (!NILoader::transformCoordinates(pos, true)) {
            throw ProcessError("Unable to project coordinates for edge " + id + ".");
        }
        shape.push_back_noDoublePos(pos);
    }

    std::string type = e->myHighWayType;
    if (!tc.knows(type)) {
        if (type.find(compoundTypeSeparator) != std::string::npos) {
            // this edge has a combination type which does not yet exist in the TypeContainer
            StringTokenizer tok = StringTokenizer(type, compoundTypeSeparator);
            std::set<std::string> types;
            while (tok.hasNext()) {
                std::string t = tok.next();
                if (tc.knows(t)) {
                    types.insert(t);
                } else {
                    WRITE_WARNING("Discarding edge " + id + " with type \"" + type + "\" (unknown compound \"" + t + "\").");
                    return;
                }
            }

            if (types.size() == 2 &&
                    types.count("railway.tram") == 1) {
                // compound types concern mostly the special case of tram tracks on a normal road.
                // in this case we simply discard the tram information since the default for road is to allow all vclasses
                types.erase("railway.tram");
                std::string otherCompound = *(types.begin());
                // XXX if otherCompound does not allow all vehicles (e.g. SVC_DELIVERY), tram will still not be allowed
                type = otherCompound;
            } else {
                // other cases not implemented yet
                WRITE_WARNING("Discarding edge " + id + " with unknown type \"" + type + "\".");
                return;
            }
        } else {
            // we do not know the type -> something else, ignore
            //WRITE_WARNING("Discarding edge " + id + " with unknown type \"" + type + "\".");
            return;
        }
    }



    // otherwise it is not an edge and will be ignored
    int noLanes = tc.getNumLanes(type);
    SUMOReal speed = tc.getSpeed(type);
    bool defaultsToOneWay = tc.getIsOneWay(type);
    SUMOVehicleClasses allowedClasses = tc.getAllowedClasses(type);
    SUMOVehicleClasses disallowedClasses = tc.getDisallowedClasses(type);
    // check directions
    bool addSecond = true;
    if (e->myIsOneWay == "true" || e->myIsOneWay == "yes" || e->myIsOneWay == "1" || (defaultsToOneWay && e->myIsOneWay != "no" && e->myIsOneWay != "false" && e->myIsOneWay != "0")) {
        addSecond = false;
    }
    // if we had been able to extract the number of lanes, override the highway type default
    if (e->myNoLanes >= 0) {
        if (!addSecond) {
            noLanes = e->myNoLanes;
        } else {
            noLanes = e->myNoLanes / 2;
        }
    }
    // if we had been able to extract the maximum speed, override the type's default
    if (e->myMaxSpeed != MAXSPEED_UNGIVEN) {
        speed = (SUMOReal)(e->myMaxSpeed / 3.6);
    }

    if (noLanes != 0 && speed != 0) {
        if (e->myIsOneWay != "" && e->myIsOneWay != "false" && e->myIsOneWay != "no" && e->myIsOneWay != "true" && e->myIsOneWay != "yes" && e->myIsOneWay != "-1" && e->myIsOneWay != "1") {
            WRITE_WARNING("New value for oneway found: " + e->myIsOneWay);
        }
        LaneSpreadFunction lsf = addSecond ? LANESPREAD_RIGHT : LANESPREAD_CENTER;
        if (e->myIsOneWay != "-1") {
            NBEdge* nbe = new NBEdge(id, from, to, type, speed, noLanes, tc.getPriority(type),
                                     tc.getWidth(type), NBEdge::UNSPECIFIED_OFFSET, shape, e->streetName, lsf);
            nbe->setVehicleClasses(allowedClasses, disallowedClasses);
            if (!ec.insert(nbe)) {
                delete nbe;
                throw ProcessError("Could not add edge '" + id + "'.");
            }
        }
        if (addSecond) {
            if (e->myIsOneWay != "-1") {
                id = "-" + id;
            }
            NBEdge* nbe = new NBEdge(id, to, from, type, speed, noLanes, tc.getPriority(type),
                                     tc.getWidth(type), NBEdge::UNSPECIFIED_OFFSET, shape.reverse(), e->streetName, lsf);
            nbe->setVehicleClasses(allowedClasses, disallowedClasses);
            if (!ec.insert(nbe)) {
                delete nbe;
                throw ProcessError("Could not add edge '-" + id + "'.");
            }
        }
    }
}