示例#1
0
文件: exec.cpp 项目: ardiny/aseba
int main(int argc, char *argv[])
{
	std::vector<std::string> targets;
	
	if (argc < 3)
	{
		DumpHelp(std::cerr, argv[0]);
		return 1;
	}
	
	const unsigned msgId(atoi(argv[1]));
	const char *programName(argv[2]);
	int argCounter = 3;
	while (argCounter < argc)
	{
		const char *arg = argv[argCounter];
		
		if ((strcmp(arg, "-h") == 0) || (strcmp(arg, "--help") == 0))
		{
			DumpHelp(std::cout, argv[0]);
			return 0;
		}
		else if ((strcmp(arg, "-V") == 0) || (strcmp(arg, "--version") == 0))
		{
			DumpVersion(std::cout);
			return 0;
		}
		else
		{
			targets.push_back(argv[argCounter]);
		}
		argCounter++;
	}
	
	if (targets.empty())
		targets.push_back(ASEBA_DEFAULT_TARGET);
	
	try
	{
		Aseba::Exec Exec(msgId, programName);
		for (size_t i = 0; i < targets.size(); i++)
			Exec.connect(targets[i]);
		Exec.run();
	}
	catch(Dashel::DashelException e)
	{
		std::cerr << e.what() << std::endl;
	}
	
	return 0;
}
示例#2
0
int main(int argc, char* argv[])
{
  osmscout::ImportParameter parameter;
  osmscout::ConsoleProgress progress;
  bool                      parameterError=false;
  bool                      firstRouterOption=true;

  std::list<std::string>    mapfiles;

  osmscout::VehicleMask     defaultVehicleMask=osmscout::vehicleBicycle|osmscout::vehicleFoot|osmscout::vehicleCar;

  parameter.AddRouter(osmscout::ImportParameter::Router(defaultVehicleMask,
                                                        "router"));

  // Simple way to analyze command line parameters, but enough for now...
  int i=1;
  while (i<argc) {
    if (strcmp(argv[i],"-h")==0 ||
        strcmp(argv[i],"-?")==0 ||
        strcmp(argv[i],"--help")==0) {
      DumpHelp(parameter);

      return 0;
    }
    else if (strcmp(argv[i],"-s")==0) {
      size_t startStep;

      if (ParseSizeTArgument(argc,
                             argv,
                             i,
                             startStep)) {
        parameter.SetSteps(startStep,
                           parameter.GetEndStep());
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"-e")==0) {
      size_t endStep;

      if (ParseSizeTArgument(argc,
                             argv,
                             i,
                             endStep)) {
        parameter.SetSteps(parameter.GetStartStep(),
                           endStep);

      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"-d")==0) {
      progress.SetOutputDebug(true);

      i++;
    }
    else if (strcmp(argv[i],"--typefile")==0) {
      std::string typefile;

      if (ParseStringArgument(argc,
                              argv,
                              i,
                              typefile)) {
        parameter.SetTypefile(typefile);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--destinationDirectory")==0) {
      std::string destinationDirectory;

      if (ParseStringArgument(argc,
                              argv,
                              i,
                              destinationDirectory)) {
        parameter.SetDestinationDirectory(destinationDirectory);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--router")==0) {
      if (firstRouterOption) {
        parameter.ClearRouter();
        firstRouterOption=false;
      }

      osmscout::ImportParameter::RouterRef router=ParseRouterArgument(argc,
                                                                      argv,
                                                                      i);
      if (router) {
        parameter.AddRouter(*router);
      }
      else {
        parameterError=true;
      }

    }
    else if (strcmp(argv[i],"--strictAreas")==0) {
      bool strictAreas;

      if (ParseBoolArgument(argc,
                            argv,
                            i,
                            strictAreas)) {
        parameter.SetStrictAreas(strictAreas);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--numericIndexPageSize")==0) {
      size_t numericIndexPageSize;

      if (ParseSizeTArgument(argc,
                             argv,
                             i,
                             numericIndexPageSize)) {
        parameter.SetNumericIndexPageSize(numericIndexPageSize);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--coordDataMemoryMaped")==0) {
      bool coordDataMemoryMaped;

      if (ParseBoolArgument(argc,
                            argv,
                            i,
                            coordDataMemoryMaped)) {
        parameter.SetCoordDataMemoryMaped(coordDataMemoryMaped);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--rawNodeDataMemoryMaped")==0) {
      bool rawNodeDataMemoryMaped;

      if (ParseBoolArgument(argc,
                            argv,
                            i,
                            rawNodeDataMemoryMaped)) {
        parameter.SetRawNodeDataMemoryMaped(rawNodeDataMemoryMaped);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--rawWayIndexMemoryMaped")==0) {
      bool rawWayIndexMemoryMaped;

      if (ParseBoolArgument(argc,
                            argv,
                            i,
                            rawWayIndexMemoryMaped)) {
        parameter.SetRawWayIndexMemoryMaped(rawWayIndexMemoryMaped);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--rawWayDataMemoryMaped")==0) {
      bool rawWayDataMemoryMaped;

      if (ParseBoolArgument(argc,
                            argv,
                            i,
                            rawWayDataMemoryMaped)) {
        parameter.SetRawWayDataMemoryMaped(rawWayDataMemoryMaped);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--rawWayIndexCacheSize")==0) {
      size_t rawWayIndexCacheSize;

      if (ParseSizeTArgument(argc,
                             argv,
                             i,
                             rawWayIndexCacheSize)) {
        parameter.SetRawWayIndexCacheSize(rawWayIndexCacheSize);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--rawWayBlockSize")==0) {
      size_t rawWayBlockSize;

      if (ParseSizeTArgument(argc,
                             argv,
                             i,
                             rawWayBlockSize)) {
        parameter.SetRawWayBlockSize(rawWayBlockSize);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"-noSort")==0) {
      parameter.SetSortObjects(false);

      i++;
    }
    else if (strcmp(argv[i],"--sortBlockSize")==0) {
      size_t sortBlockSize;

      if (ParseSizeTArgument(argc,
                             argv,
                             i,
                             sortBlockSize)) {
        parameter.SetSortBlockSize(sortBlockSize);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--areaDataMemoryMaped")==0) {
      bool areaDataMemoryMaped;

      if (ParseBoolArgument(argc,
                            argv,
                            i,
                            areaDataMemoryMaped)) {
        parameter.SetAreaDataMemoryMaped(areaDataMemoryMaped);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--areaDataCacheSize")==0) {
      size_t areaDataCacheSize;

      if (ParseSizeTArgument(argc,
                             argv,
                             i,
                             areaDataCacheSize)) {
        parameter.SetAreaDataCacheSize(areaDataCacheSize);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--wayDataMemoryMaped")==0) {
      bool wayDataMemoryMaped;

      if (ParseBoolArgument(argc,
                            argv,
                            i,
                            wayDataMemoryMaped)) {
        parameter.SetWayDataMemoryMaped(wayDataMemoryMaped);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--wayDataCacheSize")==0) {
      size_t wayDataCacheSize;

      if (ParseSizeTArgument(argc,
                             argv,
                             i,
                             wayDataCacheSize)) {
        parameter.SetWayDataCacheSize(wayDataCacheSize);
      }
      else {
        parameterError=true;
      }
    }
    else if (strcmp(argv[i],"--routeNodeBlockSize")==0) {
      size_t routeNodeBlockSize;

      if (ParseSizeTArgument(argc,
                             argv,
                             i,
                             routeNodeBlockSize)) {
        parameter.SetRouteNodeBlockSize(routeNodeBlockSize);
      }
      else {
        parameterError=true;
      }
    }
    else if (strncmp(argv[i],"--",2)==0) {
      std::cerr << "Unknown option: " << argv[i] << std::endl;

      parameterError=true;
      i++;
    }
    else {
      mapfiles.push_back(argv[i]);

      i++;
    }
  }

  if (parameter.GetStartStep()==1 &&
      mapfiles.empty()) {
    parameterError=true;
  }

  if (parameterError) {
    DumpHelp(parameter);
    return 1;
  }

  parameter.SetMapfiles(mapfiles);

  parameter.SetOptimizationWayMethod(osmscout::TransPolygon::quality);

  progress.SetStep("Dump parameter");
  for (const auto& filename : parameter.GetMapfiles()) {
    progress.Info(std::string("Mapfile: ")+filename);
  }

  progress.Info(std::string("typefile: ")+parameter.GetTypefile());
  progress.Info(std::string("Destination directory: ")+parameter.GetDestinationDirectory());
  progress.Info(std::string("Steps: ")+
                osmscout::NumberToString(parameter.GetStartStep())+
                " - "+
                osmscout::NumberToString(parameter.GetEndStep()));

  for (const auto& router : parameter.GetRouter()) {
    progress.Info(std::string("Router: ")+VehcileMaskToString(router.GetVehicleMask())+ " - '"+router.GetFilenamebase()+"'");
  }

  progress.Info(std::string("StrictAreas: ")+
                (parameter.GetStrictAreas() ? "true" : "false"));

  progress.Info(std::string("NumericIndexPageSize: ")+
                osmscout::NumberToString(parameter.GetNumericIndexPageSize()));

  progress.Info(std::string("CoordDataMemoryMaped: ")+
                (parameter.GetCoordDataMemoryMaped() ? "true" : "false"));

  progress.Info(std::string("RawNodeDataMemoryMaped: ")+
                (parameter.GetRawNodeDataMemoryMaped() ? "true" : "false"));

  progress.Info(std::string("RawWayIndexMemoryMaped: ")+
                (parameter.GetRawWayIndexMemoryMaped() ? "true" : "false"));
  progress.Info(std::string("RawWayDataMemoryMaped: ")+
                (parameter.GetRawWayDataMemoryMaped() ? "true" : "false"));
  progress.Info(std::string("RawWayIndexCacheSize: ")+
                osmscout::NumberToString(parameter.GetRawWayIndexCacheSize()));
  progress.Info(std::string("RawWayBlockSize: ")+
                osmscout::NumberToString(parameter.GetRawWayBlockSize()));


  progress.Info(std::string("SortObjects: ")+
                (parameter.GetSortObjects() ? "true" : "false"));
  progress.Info(std::string("SortBlockSize: ")+
                osmscout::NumberToString(parameter.GetSortBlockSize()));

  progress.Info(std::string("AreaDataMemoryMaped: ")+
                (parameter.GetAreaDataMemoryMaped() ? "true" : "false"));
  progress.Info(std::string("AreaDataCacheSize: ")+
                osmscout::NumberToString(parameter.GetAreaDataCacheSize()));

  progress.Info(std::string("WayDataMemoryMaped: ")+
                (parameter.GetWayDataMemoryMaped() ? "true" : "false"));
  progress.Info(std::string("WayDataCacheSize: ")+
                osmscout::NumberToString(parameter.GetWayDataCacheSize()));

  progress.Info(std::string("RouteNodeBlockSize: ")+
                osmscout::NumberToString(parameter.GetRouteNodeBlockSize()));

  bool result=osmscout::Import(parameter,
                               progress);

  progress.SetStep("Summary");

  if (result) {

    double dataSize=0;

    if (!CountDataSize(parameter,
                       progress,
                       dataSize)) {
      progress.Error("Error while retrieving data size");
    }
    else {
      progress.Info(std::string("Resulting data size: ")+osmscout::ByteSizeToString(dataSize));
    }

    progress.Info("Import OK!");
  }
  else {
    progress.Error("Import failed!");
  }

  return 0;
}
示例#3
0
//Assumption: All inputs are initialized to default or real value.  we'll just set the stuff we see on the command line.
//Assumption: Single byte names are passed in.. mb stuff doesnt cause an obvious problem... but it might have issues...
//Assumption: Values larger than 2^31 aren't expressible from the commandline.... (atoi) Unless you pass in negatives.. :-|
bool CommandLine::Parse(int argc, char* argv[], /* OUT */ Options* o)
{
    size_t argLen = 0;
    size_t tempLen = 0;
    bool foundJit = false;
    bool foundFile = false;

    if (argc == 1) //Print help when no args are passed
    {
        DumpHelp(argv[0]);
        return false;
    }

    for (int i = 1; i<argc; i++)
    {
        bool isASwitch = (argv[i][0] == '-');
#ifndef FEATURE_PAL
        if (argv[i][0] == '/') // Also accept "/" on Windows
        {
            isASwitch = true;
        }
#endif // !FEATURE_PAL

        //Process a switch
        if (isASwitch)
        {
            argLen = strlen(argv[i]);

            if (argLen >1)
                argLen--; //adjust for leading switch
            else
            {
                DumpHelp(argv[0]);
                return false;
            }

            if ((_strnicmp(&argv[i][1], "help", argLen) == 0) ||
                (_strnicmp(&argv[i][1], "HELP", argLen) == 0) ||
                (_strnicmp(&argv[i][1], "?", argLen) == 0))
            {
                DumpHelp(argv[0]);
                return false;
            }
            else if ((_strnicmp(&argv[i][1], "load", argLen) == 0))
            {
                if (++i >= argc)
                {
                    DumpHelp(argv[0]);
                    return false;
                }

            processMethodContext:

                tempLen = strlen(argv[i]);
                if (tempLen == 0)
                {
                    LogError("Arg '%s' is invalid, name of file missing.", argv[i]);
                    DumpHelp(argv[0]);
                    return false;
                }
                o->nameOfInputMethodContextFile = new char[tempLen + 1];
                strcpy_s(o->nameOfInputMethodContextFile, tempLen + 1, argv[i]);
                foundFile = true;
            }
            else if ((_strnicmp(&argv[i][1], "jit", argLen) == 0))
            {
                if (++i >= argc)
                {
                    DumpHelp(argv[0]);
                    return false;
                }

            processJit:

                tempLen = strlen(argv[i]);
                if (tempLen == 0)
                {
                    LogError("Arg '%s' is invalid, name of jit missing.", argv[i]);
                    DumpHelp(argv[0]);
                    return false;
                }
                char *tempStr = new char[tempLen + 1];
                strcpy_s(tempStr, tempLen + 1, argv[i]);
                if (!foundJit)
                {
                    o->nameOfJit = tempStr;
                    foundJit = true;
                }
                else
                {
                    o->nameOfJit2 = tempStr;
                }
            }
            else if ((_strnicmp(&argv[i][1], "reproName", argLen) == 0))
            {
                if (++i >= argc)
                {
                    DumpHelp(argv[0]);
                    return false;
                }

                tempLen = strlen(argv[i]);
                if (tempLen == 0)
                {
                    LogError("Arg '%s' is invalid, name of prefix missing.", argv[i]);
                    DumpHelp(argv[0]);
                    return false;
                }
                char *tempStr = new char[tempLen + 1];
                strcpy_s(tempStr, tempLen + 1, argv[i]);
                o->reproName = tempStr;
            }
            else if ((_strnicmp(&argv[i][1], "failingMCList", argLen) == 0))
            {
                if (++i >= argc)
                {
                    DumpHelp(argv[0]);
                    return false;
                }

                o->mclFilename = argv[i];
            }
            else if ((_strnicmp(&argv[i][1], "diffMCList", 10) == 0))
            {
                if (++i >= argc)
                {
                    DumpHelp(argv[0]);
                    return false;
                }

                o->diffMCLFilename = argv[i];
            }
            else if ((_strnicmp(&argv[i][1], "target", 6) == 0))
            {
                if (++i >= argc)
                {
                    DumpHelp(argv[0]);
                    return false;
                }

                o->targetArchitecture = argv[i];
            }
            else if ((_strnicmp(&argv[i][1], "boe", 3) == 0))
            {
                o->breakOnError = true;
            }
            else if ((_strnicmp(&argv[i][1], "boa", 3) == 0))
            {
                o->breakOnAssert = true;
            }
            else if ((_strnicmp(&argv[i][1], "verbosity", argLen) == 0))
            {
                if (++i >= argc)
                {
                    DumpHelp(argv[0]);
                    return false;
                }

                Logger::SetLogLevel(Logger::ParseLogLevelString(argv[i]));
            }
            else if ((_strnicmp(&argv[i][1], "writeLogFile", argLen) == 0))
            {
                if (++i >= argc)
                {
                    DumpHelp(argv[0]);
                    return false;
                }

                o->writeLogFile = argv[i];
                Logger::OpenLogFile(argv[i]);
            }
            else if ((_strnicmp(&argv[i][1], "emitMethodStats", argLen) == 0))
            {
                if (++i >= argc)
                {
                    DumpHelp(argv[0]);
                    return false;
                }

                o->methodStatsTypes = argv[i];
            }
            else if ((_strnicmp(&argv[i][1], "applyDiff", argLen) == 0))
            {
                o->applyDiff = true;
            }
            else if ((_strnicmp(&argv[i][1], "compile", argLen) == 0))
            {
                if (++i >= argc)
                {
                    DumpHelp(argv[0]);
                    return false;
                }

                bool isValidList = MCList::processArgAsMCL(argv[i], &o->indexCount, &o->indexes);
                if (!isValidList)
                {
                    LogError("Arg '%s' is invalid, needed method context list.", argv[i]);
                    DumpHelp(argv[0]);
                    return false;
                }
                if (o->hash != nullptr)
                {
                    LogError("Cannot use both method context list and method context hash.");
                    DumpHelp(argv[0]);
                    return false;
                }
                if (o->offset > 0 && o->increment > 0)
                {
                    LogError("Cannot use method context list in parallel mode.");
                    DumpHelp(argv[0]);
                    return false;
                }

                o->compileList = argv[i]; // Save this in case we need it for -parallel.
            }
#ifdef USE_COREDISTOOLS
            else if ((_strnicmp(&argv[i][1], "coredistools", argLen) == 0)) {
                o->useCoreDisTools = true;
            }
#endif // USE_COREDISTOOLS
            else if ((_strnicmp(&argv[i][1], "matchHash", argLen) == 0))
            {
                if (++i >= argc)
                {
                    DumpHelp(argv[0]);
                    return false;
                }

                if (strlen(argv[i]) != (MD5_HASH_BUFFER_SIZE - 1))
                {
                    LogError("Arg '%s' is invalid, needed a valid method context hash.", argv[i]);
                    DumpHelp(argv[0]);
                    return false;
                }
                if (o->indexCount > 0)
                {
                    LogError("Cannot use both method context list and method context hash.");
                    DumpHelp(argv[0]);
                    return false;
                }
                if (o->offset > 0 && o->increment > 0)
                {
                    LogError("Cannot use method context hash in parallel mode.");
                    DumpHelp(argv[0]);
                    return false;
                }
                o->hash = argv[i];
            }
            else if ((_strnicmp(&argv[i][1], "parallel", argLen) == 0))
            {
                o->parallel = true;

                // Is there another argument?
                if (i + 1 < argc)
                {
                    // If so, does it look like a worker count?
                    bool isWorkerCount = true;
                    size_t nextlen = strlen(argv[i + 1]);
                    for (size_t j = 0; j < nextlen; j++)
                    {
                        if (!isdigit(argv[i + 1][j]))
                        {
                            isWorkerCount = false; // Doesn't look like a worker count; bail out and let someone else handle it.
                            break;
                        }
                    }
                    if (isWorkerCount)
                    {
                        ++i;
                        o->workerCount = atoi(argv[i]);

                        if (o->workerCount < 1)
                        {
                            LogError("Invalid workers count specified, workers count must be at least 1.");
                            DumpHelp(argv[0]);
                            return false;
                        }
                        if (o->workerCount > MAXIMUM_WAIT_OBJECTS)
                        {
                            LogError("Invalid workers count specified, workers count cannot be more than %d.", MAXIMUM_WAIT_OBJECTS);
                            DumpHelp(argv[0]);
                            return false;
                        }
                    }
                }
            }
            else if ((_stricmp(&argv[i][1], "skipCleanup") == 0))
            {
                o->skipCleanup = true;
            }
            else if ((_strnicmp(&argv[i][1], "stride", argLen) == 0))
            {
                // "-stride" is an internal switch used by -parallel. Usage is:
                //
                // -stride offset increment
                //
                // It compiles methods in this series until end-of-file:
                //      offset, offset+increment, offset+2*increment, offset+3*increment, ...

                if (++i >= argc)
                {
                    DumpHelp(argv[0]);
                    return false;
                }

                o->offset = atoi(argv[i]);

                if (++i >= argc)
                {
                    DumpHelp(argv[0]);
                    return false;
                }

                o->increment = atoi(argv[i]);

                if (o->offset < 1 || o->increment < 1)
                {
                    LogError("Incorrect offset/increment specified for -stride. Offset and increment both must be > 0.");
                    DumpHelp(argv[0]);
                    return false;
                }
                if (o->indexCount > 0)
                {
                    LogError("Cannot use method context list in parallel mode.");
                    DumpHelp(argv[0]);
                    return false;
                }
                if (o->hash != nullptr)
                {
                    LogError("Cannot use method context hash in parallel mode.");
                    DumpHelp(argv[0]);
                    return false;
                }
            }
            else
            {
                LogError("Unknown switch '%s' passed as argument.", argv[i]);
                DumpHelp(argv[0]);
                return false;
            }
        }
        //Process an input filename
        //String comparisons on file extensions must be case-insensitive since we run on Windows
        else
        {
            char *lastdot = strrchr(argv[i], '.');
            if (lastdot == nullptr)
            {
                DumpHelp(argv[0]);
                return false;
            }

            if (_stricmp(lastdot, PLATFORM_SHARED_LIB_SUFFIX_A) == 0)
                goto processJit;
            else if (_stricmp(lastdot, ".mc") == 0)
                goto processMethodContext;
            else if (_stricmp(lastdot, ".mch") == 0)
                goto processMethodContext;
            else if (_stricmp(lastdot, ".mct") == 0)
                goto processMethodContext;
            else
            {
                LogError("Unknown file type passed as argument, '%s'.", argv[i]);
                DumpHelp(argv[0]);
                return false;
            }
        }
    }

    // Do some argument validation.

    if (o->nameOfJit == nullptr)
    {
        LogError("Missing name of a Jit.");
        DumpHelp(argv[0]);
        return false;
    }
    if (o->nameOfInputMethodContextFile == nullptr)
    {
        LogError("Missing name of an input file.");
        DumpHelp(argv[0]);
        return false;
    }
    if (o->diffMCLFilename != nullptr && !o->applyDiff)
    {
        LogError("-diffMCList specified without -applyDiff.");
        DumpHelp(argv[0]);
        return false;
    }
    if (o->targetArchitecture != nullptr && (0 != _stricmp(o->targetArchitecture, "arm64")))
    {
        LogError("Illegal target architecture specified with -target (only arm64 is supported).");
        DumpHelp(argv[0]);
        return false;
    }
    if (o->skipCleanup && !o->parallel)
    {
        LogError("-skipCleanup requires -parallel.");
        DumpHelp(argv[0]);
        return false;
    }
    return true;
}
int main(int argc, char* argv[])
{
  std::string         map;
  std::string         style;
  size_t              width,height;
  std::vector<Action> actions;

  if (argc<5) {
    DumpHelp();
    return 1;
  }

  if ((argc-5)%3!=0) {
    DumpHelp();
    return 1;
  }

  map=argv[1];
  style=argv[2];

  if (!osmscout::StringToNumber(argv[3],width)) {
    std::cerr << "width is not numeric!" << std::endl;
    return 1;
  }

  if (!osmscout::StringToNumber(argv[4],height)) {
    std::cerr << "height is not numeric!" << std::endl;
    return 1;
  }

  int arg=5;

  while (arg<argc) {
    Action action;

    if (sscanf(argv[arg],"%lf",&action.lat)!=1) {
      std::cerr << "lat is not numeric!" << std::endl;
      return 1;
    }

    arg++;

    if (sscanf(argv[arg],"%lf",&action.lon)!=1) {
      std::cerr << "lon is not numeric!" << std::endl;
      return 1;
    }

    arg++;

    if (sscanf(argv[arg],"%lf",&action.magnification)!=1) {
      std::cerr << "zoom is not numeric!" << std::endl;
      return 1;
    }

    arg++;

    actions.push_back(action);
  }

  std::cout << "# General program resources initialized, press return to start rendering emulation!" << std::endl;

  std::cin.get();

  {
    osmscout::DatabaseParameter databaseParameter;

    databaseParameter.SetAreaAreaIndexCacheSize(0);
    databaseParameter.SetAreaNodeIndexCacheSize(0);

    osmscout::DatabaseRef database(new osmscout::Database(databaseParameter));
    osmscout::MapServiceRef mapService(new osmscout::MapService(database));

    if (!database->Open(map.c_str())) {
      std::cerr << "Cannot open database" << std::endl;

      return 1;
    }

    database->DumpStatistics();

    osmscout::StyleConfigRef styleConfig(new osmscout::StyleConfig(database->GetTypeConfig()));

    if (!styleConfig->Load(style)) {
      std::cerr << "Cannot open style" << std::endl;
    }

    for (std::vector<Action>::const_iterator action=actions.begin();
         action!=actions.end();
         ++action) {
      std::cout << "-------------------" << std::endl;
      std::cout << "# Rendering " << action->lat << "," << action->lon << " with zoom " << action->magnification << " and size " << width << "x" << height << std::endl;

      osmscout::MercatorProjection  projection;
      osmscout::AreaSearchParameter searchParameter;
      osmscout::MapData             data;

      projection.Set(osmscout::GeoCoord(action->lat,
                                        action->lon),
                     osmscout::Magnification(action->magnification),
                     96.0,
                     width,
                     height);

      osmscout::StopClock dbTimer;

      std::list<osmscout::TileRef> tiles;

      mapService->LookupTiles(projection,tiles);
      mapService->LoadMissingTileData(searchParameter,*styleConfig,tiles);
      mapService->ConvertTilesToMapData(tiles,data);

      dbTimer.Stop();

      std::cout << "# DB access time " << dbTimer << std::endl;
      database->DumpStatistics();
    }

    std::cout << "# Press return to close database" << std::endl;

    std::cin.get();

    database->Close();
  }

  std::cout << "# Press return to end application" << std::endl;

  std::cin.get();

  return 0;
}
int main(int argc, char* argv[])
{
  std::string         map;
  std::string         style;
  size_t              width,height;
  std::vector<Action> actions;

  if (argc<5) {
    DumpHelp();
    return 1;
  }

  if ((argc-5)%3!=0) {
    DumpHelp();
    return 1;
  }

  map=argv[1];
  style=argv[2];

  if (!osmscout::StringToNumber(argv[3],width)) {
    std::cerr << "width is not numeric!" << std::endl;
    return 1;
  }

  if (!osmscout::StringToNumber(argv[4],height)) {
    std::cerr << "height is not numeric!" << std::endl;
    return 1;
  }

  int arg=5;

  while (arg<argc) {
    Action action;

    if (sscanf(argv[arg],"%lf",&action.lat)!=1) {
      std::cerr << "lat is not numeric!" << std::endl;
      return 1;
    }

    arg++;

    if (sscanf(argv[arg],"%lf",&action.lon)!=1) {
      std::cerr << "lon is not numeric!" << std::endl;
      return 1;
    }

    arg++;

    if (sscanf(argv[arg],"%lf",&action.magnification)!=1) {
      std::cerr << "zoom is not numeric!" << std::endl;
      return 1;
    }

    arg++;

    actions.push_back(action);
  }

  std::cout << "# General program resources initialized, press return to start rendering emulation!" << std::endl;

  std::cin.get();

  {
    osmscout::DatabaseParameter databaseParameter;

    databaseParameter.SetAreaAreaIndexCacheSize(0);
    databaseParameter.SetAreaNodeIndexCacheSize(0);

    databaseParameter.SetNodeCacheSize(0);
    databaseParameter.SetWayCacheSize(0);
    databaseParameter.SetAreaCacheSize(0);

    osmscout::DatabaseRef database(new osmscout::Database(databaseParameter));
    osmscout::MapServiceRef mapService(new osmscout::MapService(database));

    if (!database->Open(map.c_str())) {
      std::cerr << "Cannot open database" << std::endl;

      return 1;
    }

    database->DumpStatistics();

    osmscout::StyleConfigRef styleConfig(new osmscout::StyleConfig(database->GetTypeConfig()));

    if (!styleConfig->Load(style)) {
      std::cerr << "Cannot open style" << std::endl;
    }

    for (std::vector<Action>::const_iterator action=actions.begin();
         action!=actions.end();
         ++action) {
      std::cout << "-------------------" << std::endl;
      std::cout << "# Rendering " << action->lat << "," << action->lon << " with zoom " << action->magnification << " and size " << width << "x" << height << std::endl;

      osmscout::MercatorProjection  projection;
      osmscout::AreaSearchParameter searchParameter;
      osmscout::MapData             data;

      projection.Set(action->lon,
                     action->lat,
                     action->magnification,
                     width,
                     height);

      osmscout::TypeSet              nodeTypes;
      std::vector<osmscout::TypeSet> wayTypes;
      osmscout::TypeSet              areaTypes;

      styleConfig->GetNodeTypesWithMaxMag(projection.GetMagnification(),
                                          nodeTypes);

      styleConfig->GetWayTypesByPrioWithMaxMag(projection.GetMagnification(),
                                               wayTypes);

      styleConfig->GetAreaTypesWithMaxMag(projection.GetMagnification(),
                                          areaTypes);

      osmscout::StopClock dbTimer;

      mapService->GetObjects(nodeTypes,
                             wayTypes,
                             areaTypes,
                             projection.GetLonMin(),
                             projection.GetLatMin(),
                             projection.GetLonMax(),
                             projection.GetLatMax(),
                             projection.GetMagnification(),
                             searchParameter,
                             data.nodes,
                             data.ways,
                             data.areas);

      dbTimer.Stop();

      std::cout << "# DB access time " << dbTimer << std::endl;
      database->DumpStatistics();
    }

    std::cout << "# Press return to flush caches" << std::endl;

    std::cin.get();

    database->FlushCache();

    std::cout << "# Press return to close database" << std::endl;

    std::cin.get();
  }

  std::cout << "# Press return to end application" << std::endl;

  std::cin.get();

  return 0;
}
示例#6
0
int main(int argc, char* argv[])
{
  osmscout::ImportParameter parameter;
  osmscout::ConsoleProgress progress;
  bool                      parameterError=false;

  std::string               mapfile=parameter.GetMapfile();
  std::string               typefile=parameter.GetTypefile();
  std::string               destinationDirectory=parameter.GetDestinationDirectory();

  size_t                    startStep=parameter.GetStartStep();
  size_t                    endStep=parameter.GetEndStep();

  bool                      strictAreas=parameter.GetStrictAreas();

  size_t                    numericIndexPageSize=parameter.GetNumericIndexPageSize();

  size_t                    sortBlockSize=parameter.GetSortBlockSize();

  bool                      coordDataMemoryMaped=parameter.GetCoordDataMemoryMaped();

  bool                      rawNodeDataMemoryMaped=parameter.GetRawNodeDataMemoryMaped();
  size_t                    rawNodeDataCacheSize=parameter.GetRawNodeDataCacheSize();

  bool                      rawWayIndexMemoryMaped=parameter.GetRawWayIndexMemoryMaped();
  bool                      rawWayDataMemoryMaped=parameter.GetRawWayDataMemoryMaped();
  size_t                    rawWayDataCacheSize=parameter.GetRawWayDataCacheSize();
  size_t                    rawWayIndexCacheSize=parameter.GetRawWayIndexCacheSize();
  size_t                    rawWayBlockSize=parameter.GetRawWayBlockSize();

  bool                      areaDataMemoryMaped=parameter.GetAreaDataMemoryMaped();
  size_t                    areaDataCacheSize=parameter.GetAreaDataCacheSize();

  bool                      wayDataMemoryMaped=parameter.GetWayDataMemoryMaped();
  size_t                    wayDataCacheSize=parameter.GetWayDataCacheSize();

  size_t                    routeNodeBlockSize=parameter.GetRouteNodeBlockSize();

  // Simple way to analyse command line parameters, but enough for now...
  int i=1;
  while (i<argc) {
    if (strcmp(argv[i],"-s")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         startStep);
    }
    else if (strcmp(argv[i],"-e")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         endStep);
    }
    else if (strcmp(argv[i],"-d")==0) {
      progress.SetOutputDebug(true);

      i++;
    }
    else if (strcmp(argv[i],"-h")==0) {
      DumpHelp(parameter);

      return 0;
    }
    else if (strcmp(argv[i],"--help")==0) {
      DumpHelp(parameter);

      return 0;
    }
    else if (strcmp(argv[i],"--typefile")==0) {
      parameterError=!ParseStringArgument(argc,
                                          argv,
                                          i,
                                          typefile);
    }
    else if (strcmp(argv[i],"--destinationDirectory")==0) {
      parameterError=!ParseStringArgument(argc,
                                          argv,
                                          i,
                                          destinationDirectory);
    }
    else if (strcmp(argv[i],"--strictAreas")==0) {
      parameterError=!ParseBoolArgument(argc,
                                        argv,
                                        i,
                                        strictAreas);
    }
    else if (strcmp(argv[i],"--numericIndexPageSize")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         numericIndexPageSize);
    }
    else if (strcmp(argv[i],"--coordDataMemoryMaped")==0) {
      parameterError=!ParseBoolArgument(argc,
                                        argv,
                                        i,
                                        coordDataMemoryMaped);
    }
    else if (strcmp(argv[i],"--rawNodeDataMemoryMaped")==0) {
      parameterError=!ParseBoolArgument(argc,
                                        argv,
                                        i,
                                        rawNodeDataMemoryMaped);
    }
    else if (strcmp(argv[i],"--rawNodeDataCacheSize")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         rawNodeDataCacheSize);
    }
    else if (strcmp(argv[i],"--rawWayIndexMemoryMaped")==0) {
      parameterError=!ParseBoolArgument(argc,
                                        argv,
                                        i,
                                        rawWayIndexMemoryMaped);
    }
    else if (strcmp(argv[i],"--rawWayDataMemoryMaped")==0) {
      parameterError=!ParseBoolArgument(argc,
                                        argv,
                                        i,
                                        rawWayDataMemoryMaped);
    }
    else if (strcmp(argv[i],"--rawWayDataCacheSize")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         rawWayDataCacheSize);
    }
    else if (strcmp(argv[i],"--rawWayIndexCacheSize")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         rawWayIndexCacheSize);
    }
    else if (strcmp(argv[i],"--rawWayBlockSize")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         rawWayBlockSize);
    }
    else if (strcmp(argv[i],"-noSort")==0) {
      parameter.SetSortObjects(false);

      i++;
    }
    else if (strcmp(argv[i],"--sortBlockSize")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         sortBlockSize);
    }
    else if (strcmp(argv[i],"--areaDataMemoryMaped")==0) {
      parameterError=!ParseBoolArgument(argc,
                                        argv,
                                        i,
                                        areaDataMemoryMaped);
    }
    else if (strcmp(argv[i],"--areaDataCacheSize")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         areaDataCacheSize);
    }
    else if (strcmp(argv[i],"--wayDataMemoryMaped")==0) {
      parameterError=!ParseBoolArgument(argc,
                                        argv,
                                        i,
                                        wayDataMemoryMaped);
    }
    else if (strcmp(argv[i],"--wayDataCacheSize")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         wayDataCacheSize);
    }
    else if (strcmp(argv[i],"--routeNodeBlockSize")==0) {
      parameterError=!ParseSizeTArgument(argc,
                                         argv,
                                         i,
                                         routeNodeBlockSize);
    }
    else if (mapfile.empty()) {
      mapfile=argv[i];

      i++;
    }
    else {
      std::cerr << "Unknown option: " << argv[i] << std::endl;

      parameterError=true;
      i++;
    }
  }

  if (startStep==1 &&
      mapfile.empty()) {
    parameterError=true;
  }

  if (parameterError) {
    DumpHelp(parameter);
    return 1;
  }

  parameter.SetMapfile(mapfile);
  parameter.SetTypefile(typefile);
  parameter.SetDestinationDirectory(destinationDirectory);
  parameter.SetSteps(startStep,endStep);

  parameter.SetStrictAreas(strictAreas);

  parameter.SetNumericIndexPageSize(numericIndexPageSize);

  parameter.SetSortBlockSize(sortBlockSize);

  parameter.SetCoordDataMemoryMaped(coordDataMemoryMaped);

  parameter.SetRawNodeDataMemoryMaped(rawNodeDataMemoryMaped);
  parameter.SetRawNodeDataCacheSize(rawNodeDataCacheSize);

  parameter.SetRawWayIndexMemoryMaped(rawWayIndexMemoryMaped);
  parameter.SetRawWayDataMemoryMaped(rawWayDataMemoryMaped);
  parameter.SetRawWayDataCacheSize(rawWayDataCacheSize);
  parameter.SetRawWayIndexCacheSize(rawWayIndexCacheSize);
  parameter.SetRawWayBlockSize(rawWayBlockSize);

  parameter.SetAreaDataMemoryMaped(areaDataMemoryMaped);
  parameter.SetAreaDataCacheSize(areaDataCacheSize);

  parameter.SetWayDataMemoryMaped(wayDataMemoryMaped);
  parameter.SetWayDataCacheSize(wayDataCacheSize);

  parameter.SetRouteNodeBlockSize(routeNodeBlockSize);

  parameter.SetOptimizationWayMethod(osmscout::TransPolygon::quality);

  progress.SetStep("Dump parameter");
  progress.Info(std::string("Mapfile: ")+parameter.GetMapfile());
  progress.Info(std::string("typefile: ")+parameter.GetTypefile());
  progress.Info(std::string("Destination directory: ")+parameter.GetDestinationDirectory());
  progress.Info(std::string("Steps: ")+
                osmscout::NumberToString(parameter.GetStartStep())+
                " - "+
                osmscout::NumberToString(parameter.GetEndStep()));

  progress.Info(std::string("StrictAreas: ")+
                (parameter.GetStrictAreas() ? "true" : "false"));

  progress.Info(std::string("NumericIndexPageSize: ")+
                osmscout::NumberToString(parameter.GetNumericIndexPageSize()));

  progress.Info(std::string("CoordDataMemoryMaped: ")+
                (parameter.GetCoordDataMemoryMaped() ? "true" : "false"));

  progress.Info(std::string("RawNodeDataMemoryMaped: ")+
                (parameter.GetRawNodeDataMemoryMaped() ? "true" : "false"));
  progress.Info(std::string("RawNodeDataCacheSize: ")+
                osmscout::NumberToString(parameter.GetRawNodeDataCacheSize()));

  progress.Info(std::string("RawWayIndexMemoryMaped: ")+
                (parameter.GetRawWayIndexMemoryMaped() ? "true" : "false"));
  progress.Info(std::string("RawWayDataMemoryMaped: ")+
                (parameter.GetRawWayDataMemoryMaped() ? "true" : "false"));
  progress.Info(std::string("RawWayDataCacheSize: ")+
                osmscout::NumberToString(parameter.GetRawWayDataCacheSize()));
  progress.Info(std::string("RawWayIndexCacheSize: ")+
                osmscout::NumberToString(parameter.GetRawWayIndexCacheSize()));
  progress.Info(std::string("RawWayBlockSize: ")+
                osmscout::NumberToString(parameter.GetRawWayBlockSize()));


  progress.Info(std::string("SortObjects: ")+
                (parameter.GetSortObjects() ? "true" : "false"));
  progress.Info(std::string("SortBlockSize: ")+
                osmscout::NumberToString(parameter.GetSortBlockSize()));

  progress.Info(std::string("AreaDataMemoryMaped: ")+
                (parameter.GetAreaDataMemoryMaped() ? "true" : "false"));
  progress.Info(std::string("AreaDataCacheSize: ")+
                osmscout::NumberToString(parameter.GetAreaDataCacheSize()));

  progress.Info(std::string("WayDataMemoryMaped: ")+
                (parameter.GetWayDataMemoryMaped() ? "true" : "false"));
  progress.Info(std::string("WayDataCacheSize: ")+
                osmscout::NumberToString(parameter.GetWayDataCacheSize()));

  progress.Info(std::string("RouteNodeBlockSize: ")+
                osmscout::NumberToString(parameter.GetRouteNodeBlockSize()));

  if (osmscout::Import(parameter,progress)) {
    std::cout << "Import OK!" << std::endl;
  }
  else {
    std::cerr << "Import failed!" << std::endl;
  }

  return 0;
}