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


C++ Args::extract_switch方法代码示例

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


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

示例1: main

int main (int argc, char *argv[]) {
  printf("PROTO v%s%s (Kernel %s) (Developed by MIT Space-Time Programming Group 2005-2008)\n",
      PROTO_VERSION,
      "[opsim]",
      KERNEL_VERSION);
  Args *args = new Args(argc,argv); // set up the arg parser
  // define color palette
#ifdef WANT_GLUT
  palette = Palette::default_palette;
#endif //WANT_GLUT
  computer = new SpatialComputer(args,!test_mode); // then the computer
  int len = -1;
  if(args->argc <= 0)
     FATAL("Insufficient arguments");
  uint8_t* s = read_script(args->argv[args->argc-1],&len);
  if(len > 0 && s != NULL)
     computer->load_script(s,len);
  cout << "DONE load_script." << endl;
  // and start!
  bool headless = args->extract_switch("-headless") || DEFAULT_HEADLESS;
  if(args->extract_switch("-stop-after")) stop_time = args->pop_number();
  computer->is_dump = true;
  computer->is_debug = true;
  computer->dump_period = stop_time-1;
  if(headless) {
    if(stop_time==INFINITY) 
      uerror("Headless runs must set an end time with -stop-after N");
    while(1) idle();
  }
  cout << "Exiting OPSIM." << endl;
}
开发者ID:chazmatazz,项目名称:proto-mirror,代码行数:31,代码来源:opsim.cpp

示例2: main

int main (int argc, char *argv[]) {
  post("PROTO v%s%s (%s) (Developed by MIT Space-Time Programming Group 2005-2008)\n",
      PROTO_VERSION,
#if USE_NEOCOMPILER
      "[neo]",
#else
      "[paleo]",
#endif
      KERNEL_VERSION);
  Args *args = new Args(argc,argv); // set up the arg parser

  // initialize randomness  [JAH: fmod added for OS X bug]
  unsigned int seed = (unsigned int)
    (args->extract_switch("-seed") ? args->pop_number()
    : fmod(get_real_secs()*1000, RAND_MAX));
  post("Using random seed %d\n", seed);
  srand(seed);

  process_app_args(args);
  bool headless = args->extract_switch("-headless") || DEFAULT_HEADLESS;
  if(!headless) {
    vis = new Visualizer(args); // start visualizer
  } else {
#ifdef WANT_GLUT
    palette = Palette::default_palette;
#endif // WANT_GLUT
  }

  computer = new SpatialComputer(args,!test_mode);
  if(opcode_file != "") {
     post("reading opcodes from: %s\n", opcode_file.c_str());
     // read from file
     int len = -1;
     uint8_t* s = read_script(opcode_file,&len);
     //post("script[%d]=\n",len);
     //for(unsigned int i=0; i<len; ++i)
     //   post("%d\n", s[i]);
     if(len > 0 && s != NULL) {
        computer->load_script(s,len);
     }
     else
        uerror("Problem loading opcode file: %s", opcode_file.c_str());
     if(!headless) {
       vis->set_bounds(computer->vis_volume); // connect to computer
       register_app_colors();
     }
  } else {
     // use a compiler
#if USE_NEOCOMPILER
     compiler = new NeoCompiler(args);  // first the compiler
     compiler->emitter = new ProtoKernelEmitter(compiler,args);
#else
     compiler = new PaleoCompiler(args);  // first the compiler
#endif
     string defops;
     computer->appendDefops(defops);
     compiler->setDefops(defops);
     if(!headless) {
        vis->set_bounds(computer->vis_volume); // connect to computer
        register_app_colors();
     }
     // next the forwarder for the motes, if desired
     if(args->extract_switch("-motelink")) motelink = new MoteLink(args);
     // load the script
     int len;
     if(args->argc==1) {
        uerror("No program specified: all arguments consumed.");
     } else {
        uint8_t* s = compiler->compile(args->argv[args->argc-1],&len);
        computer->load_script(s,len);
        if(args->argc>2) {
           post("WARNING: %d unhandled arguments:",args->argc-2);
           for(int i=2;i<args->argc;i++) post(" '%s'",args->argv[i-1]);
           post("\n");
        }
     }
  }
  // if in test mode, swap the C++ file for a C file for the SpatialComputer
  if(test_mode) {
    delete cpout;
    computer->dump_file = fopen(dump_name,"a");
  }
  // and start!
  if(headless) {
    if(stop_time==INFINITY) 
      uerror("Headless runs must set an end time with -stop-after N");
    while(1) idle();
  } else {
#ifdef WANT_GLUT
    // set up callbacks for user interface and idle
    glutMouseFunc(on_mouse_button);
    glutMotionFunc(on_mouse_motion);
    glutPassiveMotionFunc(on_mouse_motion);
    glutDisplayFunc(render);
    glutReshapeFunc(resize);
    glutIdleFunc(idle);
    glutKeyboardFunc(keyboard_handler);
    glutSpecialFunc(special_handler);
    // finally, hand off control to the glut event-loop
    glutMainLoop(); 
//.........这里部分代码省略.........
开发者ID:chazmatazz,项目名称:proto-mirror,代码行数:101,代码来源:sim-app.cpp


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