当前位置: 首页>>代码示例>>C++>>正文


C++ CommandLine::add_option方法代码示例

本文整理汇总了C++中CommandLine::add_option方法的典型用法代码示例。如果您正苦于以下问题:C++ CommandLine::add_option方法的具体用法?C++ CommandLine::add_option怎么用?C++ CommandLine::add_option使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CommandLine的用法示例。


在下文中一共展示了CommandLine::add_option方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char** argv)
{
  std::vector<Pathname> files;
  enum {
    kTitle       = (1<<0),
    kDescription = (1<<1),
    kLevels      = (1<<2),
    kFilename    = (1<<3)
  };

  unsigned int mode = 0;

  CommandLine argp;
  argp.add_usage("[OPTIONS]... [FILE]...");

  argp.add_option('h', "help",    "", "Displays this help");

  argp.add_option('t', "title", "", "Display title of the levelset");
  argp.add_option('d', "description", "", "Display description of the levelset");
  argp.add_option('l', "levels", "", "Display levels in this levelset");
  argp.add_option('f', "filename", "", "Display filename of the level");

  argp.parse_args(argc, argv);
  argp.set_help_indent(20);

  while (argp.next())
  {
    switch (argp.get_key())
    {
      case 'h':
        argp.print_help();
        exit(EXIT_SUCCESS);
        break;

      case 't':
        mode |= kTitle;
        break;

      case 'd':
        mode |= kDescription;
        break;

      case 'l':
        mode |= kLevels;
        break;

      case 'f':
        mode |= kFilename;
        break;

      case CommandLine::REST_ARG:
        files.push_back(Pathname(argp.get_argument(), Pathname::SYSTEM_PATH));
        break;
    }
  }

  if (files.empty())
  {
    argp.print_help();
    exit(EXIT_SUCCESS);
  }
  else
  {
    // FIXME: a little ugly that levelset loads sprites and savegames
    System::init_directories();
    g_path_manager.set_path("data/");
    SavegameManager savegame_manager("savegames/savegames.scm");
    StatManager stat_manager("savegames/variables.scm");
    Resource::init();

    Display::create_window(NULL_FRAMEBUFFER, Size(), false, false);

    for(auto it = files.begin(); it != files.end(); ++it)
    {
      const Pathname& path = *it;
      std::unique_ptr<Levelset> levelset = Levelset::from_file(path);

      if (mode == 0)
      {
        std::cout << "filename      : " << path << std::endl;
        std::cout << "title         : " << levelset->get_title() << std::endl;
        std::cout << "description   : " << levelset->get_description() << std::endl;
        std::cout << "levels        : " << std::endl;
        for(int i = 0; i < levelset->get_level_count(); ++i)
        {
          std::cout << "  " << levelset->get_level(i)->resname << std::endl;
        }
        std::cout << std::endl;
      }
      else
      {
        if (mode & kFilename)
        {
          std::cout << path << ": ";
        }

        if (mode & kTitle)
        {
          std::cout << levelset->get_title() << std::endl;
        }
//.........这里部分代码省略.........
开发者ID:bugdebugger,项目名称:pingus,代码行数:101,代码来源:pingus-levelset.cpp

示例2: main

int main(int argc, char** argv)
{
  std::vector<Pathname> files;
  bool crop = false;

  CommandLine argp;
  argp.add_usage("[OPTIONS]... LEVELFILE OUTPUTFILE");

  argp.add_option('h', "help",    "", "Displays this help");
  argp.add_option('b', "background",  "RRGGBBAA", "Set background color");
  argp.add_option('c', "crop", "", "crop output to the actual objects rendered, not levelsize ");

  argp.parse_args(argc, argv);

  while (argp.next())
  {
    switch (argp.get_key()) 
    {          
      case 'h':
        argp.print_help();
        exit(EXIT_SUCCESS);
        break;

      case 'c':
        crop = true;
        break;

      case 'b':
        // FIXME: not implemented
        break;

      case CommandLine::REST_ARG:
        files.push_back(Pathname(argp.get_argument(), Pathname::SYSTEM_PATH));
        break;
    }
  }
  
  if (files.size() != 2)
  {
    argp.print_help();
    exit(EXIT_SUCCESS);
  }
  else
  {
    g_path_manager.set_path("data/");
    Resource::init();

    // render all the objects
    WorldObjRenderer renderer;
    Size size;
    
    if (System::get_file_extension(files[0].get_raw_path()) == "prefab")
    {
      PrefabFile prefab = PrefabFile::from_path(files[0]);
      renderer.process(prefab.get_objects());
      crop = true;
    }
    else
    {
      PingusLevel plf(files[0]);
      renderer.process(plf.get_objects());
      size = plf.get_size();
    }

    Surface out_surface;

    if (crop)
    {
      Rect rect = renderer.get_clip_rect();
      
      out_surface = Surface(rect.get_width(), rect.get_height());
      
      // FIXME: alpha doesn't work, as the PNG saver can't handle that
      out_surface.fill(Color(255, 255, 255, 255));

      renderer.blit(out_surface, -rect.left, -rect.top);

      // create a .sprite file to handle the offset
      std::string outfile = System::cut_file_extension(files[1].get_sys_path()) + ".sprite";
      Vector2i offset(rect.left, rect.top);

      std::ostringstream out;
      SExprFileWriter writer(out);
      writer.begin_section("pingus-sprite");
      writer.write_string("image", System::cut_file_extension(System::basename(files[0].get_raw_path())) + ".png");
      writer.write_vector2i("offset", offset);
      writer.end_section();
      out << std::endl;
      log_info("writing: %1%", outfile);
      System::write_file(outfile, out.str());
    }
    else
    {
      out_surface = Surface(size.width, size.height);

      // FIXME: alpha doesn't work, as the PNG saver can't handle that
      out_surface.fill(Color(255, 255, 255, 255));

      renderer.blit(out_surface);
    }
//.........这里部分代码省略.........
开发者ID:AMDmi3,项目名称:pingus,代码行数:101,代码来源:pingus-level2png.cpp

示例3: main

int main(int argc, char** argv)
{
  std::vector<Pathname> files;
  enum { 
    kAuthor      = (1<<0),
    kName        = (1<<1),
    kChecksum    = (1<<2),
    kDescription = (1<<3),
    kMusic       = (1<<4),
    kFilename    = (1<<5),
    kSize        = (1<<6)
  };

  unsigned int mode = 0;

  CommandLine argp;
  argp.add_usage("[OPTIONS]... [FILE]...");

  argp.add_option('h', "help",    "", "Displays this help");

  argp.add_option('a', "author", "", "Display author name");
  argp.add_option('n', "name", "", "Display level name");
  argp.add_option('s', "size", "", "Display level size");
  argp.add_option('c', "checksum", "", "Display checksum of the level");
  argp.add_option('d', "description", "", "Display description of the level");
  argp.add_option('m', "music", "", "Display music of the level");
  argp.add_option('f', "filename", "", "Display filename of the level");

  argp.parse_args(argc, argv);
  argp.set_help_indent(20);

  while (argp.next())
  {
    switch (argp.get_key()) 
    {          
      case 'h':
        argp.print_help();
        exit(EXIT_SUCCESS);
        break;

      case 'a':
        mode |= kAuthor;
        break;

      case 'n':
        mode |= kName;
        break;

      case 'c':
        mode |= kChecksum;
        break;

      case 'd':
        mode |= kDescription;
        break;

      case 'm':
        mode |= kMusic;
        break;

      case 'f':
        mode |= kFilename;
        break;

      case 's':
        mode |= kSize;
        break;
        
      case CommandLine::REST_ARG:
        files.push_back(Pathname(argp.get_argument(), Pathname::SYSTEM_PATH));
        break;
    }
  }

  if (files.empty())
  {
    argp.print_help();
    exit(EXIT_SUCCESS);
  }
  else
  {
    for(auto it = files.begin(); it != files.end(); ++it)
    {
      const Pathname& path = *it;
      PingusLevel plf(path);

      if (mode == 0)
      {
        std::cout << "filename      : " << path << std::endl;
        std::cout << "name          : " << plf.get_levelname() << std::endl;
        std::cout << "checksum      : " << plf.get_checksum() << std::endl;
        std::cout << "description   : " << plf.get_description() << std::endl;
        std::cout << "author        : " << plf.get_author() << std::endl;
        std::cout << "music         : " << plf.get_music() << std::endl;
        std::cout << "ambient light : " 
                  << static_cast<int>(plf.get_ambient_light().r) << " "
                  << static_cast<int>(plf.get_ambient_light().g) << " " 
                  << static_cast<int>(plf.get_ambient_light().b) << " " 
                  << static_cast<int>(plf.get_ambient_light().a)
                  << std::endl;
//.........这里部分代码省略.........
开发者ID:jcs12311,项目名称:pingus,代码行数:101,代码来源:pingus-level.cpp

示例4: main

int main(int argc, char** argv)
{
  try {
    bool fullscreen = false;
    int screen_width  = 800;
    int screen_height = 600;
    int canvas_width  = 2048;
    int canvas_height = 2048;
    std::string hostname;
    std::string port     = "4711";
    int rest_arg_count = 0;
    std::string stylus;

    CommandLine argp;

    argp.add_usage("[OPTIONS] HOSTNAME PORT");
    argp.add_group("Display:");
    argp.add_option('g', "geometry",  "WIDTHxHEIGHT", "Set the windows size to WIDTHxHEIGHT");
    argp.add_option('c', "canvas",    "WIDTHxHEIGHT", "Set the size of the paintable canvas to WIDTHxHEIGHT");
    argp.add_option('f', "fullscreen", "",            "Start the application in fullscreen mode");
    argp.add_option('w', "window",     "",            "Start the application in window mode");
    argp.add_option('v', "version",    "",            "Display the netBrush version");
    argp.add_option('i', "input",      "NAME",        "Use XInput device NAME for drawing (tablet support)");
    argp.add_option('h', "help",       "",            "Show this help text");

    argp.parse_args(argc, argv);

    while(argp.next())
      {
        switch(argp.get_key())
          {
          case 'g':
            {
              if (sscanf(argp.get_argument().c_str(), "%dx%d",
                         &screen_width, &screen_height) == 2)
                {
                  std::cout << "Geometry: " << screen_width << "x" << screen_height << std::endl;
                }
              else
                {
                  throw std::runtime_error("Geometry option '-g' requires argument of type {WIDTH}x{HEIGHT}");
                }
            }
            break;

          case 'i':
            {
              stylus = argp.get_argument();
            }
            break;

          case 'c':
            {
              if (sscanf(argp.get_argument().c_str(), "%dx%d",
                         &canvas_width, &canvas_height) == 2)
                {
                  std::cout << "Geometry: " << canvas_width << "x" << canvas_height << std::endl;
                }
              else
                {
                  throw std::runtime_error("Canvas option '-c' requires argument of type {WIDTH}x{HEIGHT}");
                }
            }
            break;

          case 'f':
            fullscreen = true;
            break;

          case 'w':
            fullscreen = false;
            break;

          case 'h':
            argp.print_help();
            return 0;
            break;

          case 'v':
            std::cout << "netBrush 0.1.0" << std::endl;
            break;

          case CommandLine::REST_ARG:
            //std::cout << "Rest: " << argp.get_argument() << std::endl;
            if (rest_arg_count == 0)
              {
                hostname = argp.get_argument();
                rest_arg_count += 1;
              }
            else if (rest_arg_count == 1)
              {
                port = argp.get_argument();
                rest_arg_count += 1;
              }
            else
              {
                std::cout << "Invalide argument " << argp.get_argument() << std::endl;
                exit(EXIT_FAILURE);
              }
            break;
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:flexlay-svn,代码行数:101,代码来源:client.cpp

示例5: renderer

void
PingusMain::parse_args(int argc, char** argv)
{
  CommandLine argp;
  argp.add_usage(_("[OPTIONS]... [FILE]"));
  argp.add_doc(_("Pingus is a puzzle game where you need to guide a bunch of little penguins around the world."));

  argp.add_group(_("General Options:"));
  argp.add_option('h', "help", "", 
                  _("Displays this help"));
  argp.add_option('V', "version", "", 
                  _("Print version number and exit"));
  argp.add_option('v', "verbose", "",
                  _("Enable info level log output"));
  argp.add_option('D', "debug", "", 
                  _("Enable debug level log output"));
  argp.add_option('Q', "quiet", "", 
                  _("Disable all log output"));   

  argp.add_group(_("Display Options:"));
  argp.add_option('w', "window", "",
                  _("Start in Window Mode"));
  argp.add_option('f', "fullscreen", "",
                  _("Start in Fullscreen"));
  argp.add_option('r', "renderer", "RENDERER",
                  _("Use the given renderer (default: sdl)"));
  argp.add_option('g', "geometry", "{width}x{height}",  
                  _("Set the window resolution for pingus (default: 800x600)"));
  argp.add_option('R', "fullscreen-resolution", "{width}x{height}",  
                  _("Set the resolution used in fullscreen mode (default: 800x600)"));
  argp.add_option(346, "software-cursor", "",
                  _("Enable software cursor"));

  argp.add_group(_("Game Options:"));
  argp.add_option(337, "no-auto-scrolling", "",
                  _("Disable automatic scrolling"));
  argp.add_option(338, "drag-drop-scrolling", "",
                  _("Enable drag'n drop scrolling"));

  argp.add_group(_("Sound Options:"));
  argp.add_option('s', "disable-sound", "", 
                  _("Disable sound"));
  argp.add_option('m', "disable-music", "", 
                  _("Disable music"));

  argp.add_group("Language Options:");
  argp.add_option('l', "language", "LANG",
                  _("Select language to use with Pingus"));
  argp.add_option(365, "list-languages", "",
                  _("List all available languages"));

  argp.add_group("Editor Options:");
  argp.add_option('e', "editor", "",
                  _("Loads the level editor"));

  argp.add_group(_("Directory Options:"));
  argp.add_option('d', "datadir", _("DIR"),
                  _("Load game datafiles from DIR"));
  argp.add_option('u', "userdir", _("DIR"),
                  _("Load config files and store savegames in DIR"));
  argp.add_option('a', "addon", _("DIR"),
                  _("Load game modifications from DIR"));
  argp.add_option(342, "no-cfg-file", "",
                  _("Don't read ~/.pingus/config"));
  argp.add_option('c', "config", _("FILE"),
                  _("Read config options from FILE"));
  argp.add_option(360, "controller", "FILE",
                  _("Uses the controller given in FILE"));

  argp.add_group(_("Debug Options:"));
  argp.add_option(334, "developer-mode",  "",  
                  _("Enables some special features for developers"));
  argp.add_option('t', "speed", "SPEED",
                  _("Set the game speed (0=fastest, >0=slower)"));
  argp.add_option('k', "fps", "FPS",
                  _("Set the desired game framerate (frames per second)"));
  argp.add_option(344, "tile-size", "INT",
                  _("Set the size of the map tiles (default: 32)"));

  argp.parse_args(argc, argv);
  argp.set_help_indent(20);

  while (argp.next())
  {
    switch (argp.get_key()) 
    {          
      case 'r': // --renderer
        if (argp.get_argument() == "help")
        {
          std::cout << "Available renderers: " << std::endl;
          std::cout << "   delta: Software rendering with dirty-rectangles" << std::endl;
          std::cout << "     sdl: Software rendering" << std::endl;
          std::cout << "  opengl: Hardware accelerated graphics" << std::endl;
          std::cout << "    null: No rendering at all, for debugging" << std::endl;
          exit(EXIT_SUCCESS);
        }
        else
        {
          cmd_options.framebuffer_type.set(framebuffer_type_from_string(argp.get_argument()));

//.........这里部分代码省略.........
开发者ID:liushuyu,项目名称:aosc-os-abbs,代码行数:101,代码来源:pingus_main.cpp

示例6: main

int main(int argc, char** argv)
{
  std::vector<Pathname> files;

  CommandLine argp;
  argp.add_usage("[OPTIONS]... LEVELFILE OUTPUTFILE");

  argp.add_option('h', "help",    "", "Displays this help");
  argp.add_option('b', "background",  "RRGGBBAA", "Set background color");
  argp.add_option('c', "colmap", "", "Render collision map instead of graphic map");

  argp.parse_args(argc, argv);

  while (argp.next())
  {
    switch (argp.get_key()) 
    {          
      case 'h':
        argp.print_help();
        exit(EXIT_SUCCESS);
        break;

      case 'c':
        // FIXME: not implemented
        break;

      case 'b':
        // FIXME: not implemented
        break;

      case CommandLine::REST_ARG:
        files.push_back(Pathname(argp.get_argument(), Pathname::SYSTEM_PATH));
        break;
    }
  }
  
  if (files.size() != 2)
  {
    argp.print_help();
    exit(EXIT_SUCCESS);
  }
  else
  {
    g_path_manager.set_path("data/");
    Resource::init();
    PingusLevel plf(files[0]);

    Surface out_surface(plf.get_size().width, plf.get_size().height);

    // FIXME: alpha doesn't work, as the PNG saver can't handle that
    out_surface.fill(Color(255, 255, 255, 255));

    const std::vector<FileReader>& objects = plf.get_objects();
    
    for(auto it = objects.begin(); it != objects.end(); ++it)
    {
      const FileReader& reader = *it;

      Vector3f pos;
      ResDescriptor desc;

      // FIXME: does not handle sprite alignment
      // FIXME: does not handle remove groundpieces
      // FIXME: does not handle liquid

      if (reader.get_name() != "surface-background" && 
          reader.get_name() != "starfield-background" &&
          reader.get_name() != "solidcolor-background")
      {
        if (reader.read_vector("position", pos) &&
            reader.read_desc("surface", desc))
        {
          Surface surface = Resource::load_surface(desc);
          if (reader.get_name() == "exit")
          {
            // FIXME: hack, should take that info from the resource file
            out_surface.blit(surface, 
                             static_cast<int>(pos.x) - surface.get_width()/2, 
                             static_cast<int>(pos.y) - surface.get_height());
          }
          else if (reader.get_name() == "groundpiece")
          {
            std::string type;
            reader.read_string("type", type);
            if (type == "remove")
            {
              // FIXME: don't have blit_remove()
              out_surface.blit(surface, 
                               static_cast<int>(pos.x), 
                               static_cast<int>(pos.y));
            }
            else
            {
              out_surface.blit(surface, 
                               static_cast<int>(pos.x), 
                               static_cast<int>(pos.y));
            }
          }
          else
          {
//.........这里部分代码省略.........
开发者ID:jcs12311,项目名称:pingus,代码行数:101,代码来源:pingus-level2png.cpp

示例7: main

int main(int argc, char** argv)
{
  try {
    std::string port;
    CommandLine argp;

    argp.add_usage("[OPTIONS] PORT");
    argp.add_group("General:");
    argp.add_option('v', "version", "", "Print the netBrush server version");
    argp.add_option('h', "help", "", "Print this help");

    argp.parse_args(argc, argv);
    while(argp.next())
      {
        switch(argp.get_key())
          {
          case 'h':
            argp.print_help();
            return 0;
            break;

          case 'v':
            std::cout << "netBrush Server 0.1.0" << std::endl;
            return 0;
            break;

          case CommandLine::REST_ARG:
            if (!port.empty())
              {
                std::cout << "Invalid argument: " << argp.get_argument() << std::endl;
                return 1;
              }
            else
              {
                port = argp.get_argument();
              }
            break;
          }
      }

    if (port.empty())
      {
        argp.print_help();
        return 1;
      }

    if(SDL_Init(0)==-1) {
      printf("SDL_Init: %s\n", SDL_GetError());
      exit(1);
    }

    if(SDLNet_Init()==-1) {
      printf("SDLNet_Init: %s\n", SDLNet_GetError());
      exit(2);
    }

    atexit(SDL_Quit);
    atexit(SDLNet_Quit);

    std::ostringstream filename;
    filename << "sessions/session-" << time(NULL) << ".nbr";

    std::cout << "# writing log to " << filename.str() << std::endl;
    outfile = new std::ofstream(filename.str().c_str());

    if (argc == 2)
      {
        std::cout << "# listening on: " << port << std::endl;
        connect(atoi(port.c_str()));
      }
    else
      {
        std::cout << "Usage: " << argv[0] << " PORT" << std::endl;
      }

    outfile->close();
    delete outfile;
  } catch (std::exception& err) {
    std::cout << "Exception: " << err.what() << std::endl;
  }
  return 0;
}
开发者ID:Grumbel,项目名称:netbrush,代码行数:82,代码来源:server.cpp


注:本文中的CommandLine::add_option方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。