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


C++ Options类代码示例

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


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

示例1: OptionsClear

 /* --------------------------------------------------------------------------------------------
  * Remove all the options from the options container.
 */
 void OptionsClear()
 {
     m_Options.clear();
 }
开发者ID:iSLC,项目名称:VCMP-SqMod,代码行数:7,代码来源:Account.hpp

示例2: opt

 forceinline
 Builder::Builder(const Options& opt0, bool b0)
   : opt(opt0.expand()), b(b0) {}
开发者ID:Gecode,项目名称:gecode,代码行数:3,代码来源:build.hpp

示例3: main

int main(int argc, char** argv) {

  int c;
  float col_r, col_g, col_b = -1.0f;
  Options opt;

  while ((c = getopt(argc, argv, "a:x:y:f:s:t:n:w:r:g:b:c:")) != -1) {
    switch(c) {

      /* color */
      /* ------------------------------------------------------- */
      case 'r': {
        col_r = convert_type<float>(optarg);
        break;
      }
      case 'g': {
        col_g = convert_type<float>(optarg);
        break;
      }
      case 'b': {
        col_b = convert_type<float>(optarg);
        break;
      }
      
      /* ------------------------------------------------------- */
      /* foreground */
      case 'c': {
        opt.foreground_file = convert_type<std::string>(optarg);
        break;
      }
      /* ------------------------------------------------------- */
      /* background */
      case 'x': {
        opt.background_x = convert_type<int>(optarg);
        break;
      }
      case 'y': {
        opt.background_y = convert_type<int>(optarg);
        break;
      }
      case 'f': {
        //printf("Got: %s", optarg);
        opt.background_file = convert_type<std::string>(optarg);
        break;
      }

      /* ------------------------------------------------------- */
      /* visible size */
      case 'a': {
        opt.visible_size = convert_type<float>(optarg);
        break;
      }

      /* ------------------------------------------------------- */
      /* name */
      case 'n': {
        opt.name = convert_type<std::string>(optarg);

        /* we expect that r,g,b has been set */
        if (0 > col_r) {
          printf("Error: you haven't set -r -g -b for the name.\n");
          exit(EXIT_FAILURE);
        }
        opt.name_r = col_r;
        opt.name_g = col_g;
        opt.name_b = col_b;
        break;
      }
      /* name x position */
      case 's': {
        opt.name_x = convert_type<int>(optarg);
        break;
      }
      /* name y position */
      case 't': {
        opt.name_y = convert_type<int>(optarg);
        break;
      }
      /* name font size */
      case 'w': {
        opt.name_font_size = convert_type<float>(optarg);
        break;
      }
      default: {
        printf("Unkown option\n");
        break;
      }
    }
  }
  
  if (false == opt.validate()) {
    printf("+ error: cannot validate the given options.\n");
    exit(EXIT_FAILURE);
  }

  opt.print();

  /* ------------------------------------------------------------------------------------ */

  Image img;
//.........这里部分代码省略.........
开发者ID:HellicarAndLewis,项目名称:Mosaic,代码行数:101,代码来源:test_cairo_png.cpp

示例4: spawn_command

static void spawn_command(
    const std::shared_ptr<w_root_t>& root,
    struct watchman_trigger_command* cmd,
    w_query_res* res,
    struct ClockSpec* since_spec) {
  long arg_max;
  size_t argspace_remaining;
  bool file_overflow = false;

#ifdef _WIN32
  arg_max = 32*1024;
#else
  arg_max = sysconf(_SC_ARG_MAX);
#endif

  if (arg_max <= 0) {
    argspace_remaining = UINT_MAX;
  } else {
    argspace_remaining = (uint32_t)arg_max;
  }

  // Allow some misc working overhead
  argspace_remaining -= 32;

  // Record an overflow before we call prepare_stdin(), which mutates
  // and resizes the results to fit the specified limit.
  if (cmd->max_files_stdin > 0 &&
      res->resultsArray.array().size() > cmd->max_files_stdin) {
    file_overflow = true;
  }

  auto stdin_file = prepare_stdin(cmd, res);
  if (!stdin_file) {
    w_log(
        W_LOG_ERR,
        "trigger %s:%s %s\n",
        root->root_path.c_str(),
        cmd->triggername.c_str(),
        strerror(errno));
    return;
  }

  // Assumption: that only one thread will be executing on a given
  // cmd instance so that mutation of cmd->env is safe.
  // This is guaranteed in the current architecture.

  // It is way too much of a hassle to try to recreate the clock value if it's
  // not a relative clock spec, and it's only going to happen on the first run
  // anyway, so just skip doing that entirely.
  if (since_spec && since_spec->tag == w_cs_clock) {
    cmd->env.set("WATCHMAN_SINCE", since_spec->clock.position.toClockString());
  } else {
    cmd->env.unset("WATCHMAN_SINCE");
  }

  cmd->env.set(
      "WATCHMAN_CLOCK", res->clockAtStartOfQuery.position().toClockString());

  if (cmd->query->relative_root) {
    cmd->env.set("WATCHMAN_RELATIVE_ROOT", cmd->query->relative_root);
  } else {
    cmd->env.unset("WATCHMAN_RELATIVE_ROOT");
  }

  // Compute args
  auto args = json_deep_copy(cmd->command);

  if (cmd->append_files) {
    // Measure how much space the base args take up
    for (size_t i = 0; i < json_array_size(args); i++) {
      const char *ele = json_string_value(json_array_get(args, i));

      argspace_remaining -= strlen(ele) + 1 + sizeof(char*);
    }

    // Dry run with env to compute space
    size_t env_size;
    cmd->env.asEnviron(&env_size);
    argspace_remaining -= env_size;

    for (const auto& item : res->dedupedFileNames) {
      // also: NUL terminator and entry in argv
      uint32_t size = item.size() + 1 + sizeof(char*);

      if (argspace_remaining < size) {
        file_overflow = true;
        break;
      }
      argspace_remaining -= size;

      json_array_append_new(args, w_string_to_json(item));
    }
  }

  cmd->env.set("WATCHMAN_FILES_OVERFLOW", file_overflow);

  Options opts;
  opts.environment() = cmd->env;
#ifndef _WIN32
  sigset_t mask;
//.........这里部分代码省略.........
开发者ID:Stevenzwzhai,项目名称:watchman,代码行数:101,代码来源:spawn.cpp

示例5: select_ostream

  void
  ScriptBase<Space>::runMeta(const Options& o, Script* s) {
    using namespace std;

    ofstream sol_file, log_file;

    ostream& s_out = select_ostream(o.out_file(), sol_file);
    ostream& l_out = select_ostream(o.log_file(), log_file);

    try {
      switch (o.mode()) {
      case SM_GIST:
#ifdef GECODE_HAS_GIST
        {
          Gist::Print<Script> pi(o.name());
          Gist::VarComparator<Script> vc(o.name());
          Gist::Options opt;
          opt.inspect.click(&pi);
          opt.inspect.compare(&vc);
          opt.clone = false;
          opt.c_d   = o.c_d();
          opt.a_d   = o.a_d();
          for (int i=0; o.inspect.click(i) != NULL; i++)
            opt.inspect.click(o.inspect.click(i));
          for (int i=0; o.inspect.solution(i) != NULL; i++)
            opt.inspect.solution(o.inspect.solution(i));
          for (int i=0; o.inspect.move(i) != NULL; i++)
            opt.inspect.move(o.inspect.move(i));
          for (int i=0; o.inspect.compare(i) != NULL; i++)
            opt.inspect.compare(o.inspect.compare(i));
          if (s == NULL)
            s = new Script(o);
          (void) GistEngine<Engine<Script> >::explore(s, opt);
        }
        break;
        // If Gist is not available, fall through
#endif
      case SM_SOLUTION:
        {
          l_out << o.name() << endl;
          Support::Timer t;
          int i = o.solutions();
          t.start();
          if (s == NULL)
            s = new Script(o);
          unsigned int n_p = s->propagators();
          unsigned int n_b = s->branchers();
          Search::Options so;
          so.threads = o.threads();
          so.c_d     = o.c_d();
          so.a_d     = o.a_d();
          so.stop    = CombinedStop::create(o.node(),o.fail(), o.time(), 
                                            o.interrupt());
          so.cutoff  = createCutoff(o);
          so.clone   = false;
          so.nogoods_limit = o.nogoods() ? o.nogoods_limit() : 0U;
          if (o.interrupt())
            CombinedStop::installCtrlHandler(true);
          {
            Meta<Engine,Script> e(s,so);
            if (o.print_last()) {
              Script* px = NULL;
              do {
                Script* ex = e.next();
                if (ex == NULL) {
                  if (px != NULL) {
                    px->print(s_out);
                    delete px;
                  }
                  break;
                } else {
                  delete px;
                  px = ex;
                }
              } while (--i != 0);
            } else {
              do {
                Script* ex = e.next();
                if (ex == NULL)
                  break;
                ex->print(s_out);
                delete ex;
              } while (--i != 0);
            }
            if (o.interrupt())
              CombinedStop::installCtrlHandler(false);
            Search::Statistics stat = e.statistics();
            s_out << endl;
            if (e.stopped()) {
              l_out << "Search engine stopped..." << endl
                    << "\treason: ";
              int r = static_cast<CombinedStop*>(so.stop)->reason(stat,so);
              if (r & CombinedStop::SR_INT)
                l_out << "user interrupt " << endl;
              else {
                if (r & CombinedStop::SR_NODE)
                  l_out << "node ";
                if (r & CombinedStop::SR_FAIL)
                  l_out << "fail ";
                if (r & CombinedStop::SR_TIME)
//.........这里部分代码省略.........
开发者ID:Wushaowei001,项目名称:gecode-clone,代码行数:101,代码来源:script.hpp

示例6: Alpha

  /// Actual model
  Alpha(const Options& opt) : le(*this,n,1,n) {
    IntVar
      a(le[ 0]), b(le[ 1]), c(le[ 2]), e(le[ 4]), f(le[ 5]),
      g(le[ 6]), h(le[ 7]), i(le[ 8]), j(le[ 9]), k(le[10]),
      l(le[11]), m(le[12]), n(le[13]), o(le[14]), p(le[15]),
      q(le[16]), r(le[17]), s(le[18]), t(le[19]), u(le[20]),
      v(le[21]), w(le[22]), x(le[23]), y(le[24]), z(le[25]);

    rel(*this, b+a+l+l+e+t       == 45,  opt.icl());
    rel(*this, c+e+l+l+o         == 43,  opt.icl());
    rel(*this, c+o+n+c+e+r+t     == 74,  opt.icl());
    rel(*this, f+l+u+t+e         == 30,  opt.icl());
    rel(*this, f+u+g+u+e         == 50,  opt.icl());
    rel(*this, g+l+e+e           == 66,  opt.icl());
    rel(*this, j+a+z+z           == 58,  opt.icl());
    rel(*this, l+y+r+e           == 47,  opt.icl());
    rel(*this, o+b+o+e           == 53,  opt.icl());
    rel(*this, o+p+e+r+a         == 65,  opt.icl());
    rel(*this, p+o+l+k+a         == 59,  opt.icl());
    rel(*this, q+u+a+r+t+e+t     == 50,  opt.icl());
    rel(*this, s+a+x+o+p+h+o+n+e == 134, opt.icl());
    rel(*this, s+c+a+l+e         == 51,  opt.icl());
    rel(*this, s+o+l+o           == 37,  opt.icl());
    rel(*this, s+o+n+g           == 61,  opt.icl());
    rel(*this, s+o+p+r+a+n+o     == 82,  opt.icl());
    rel(*this, t+h+e+m+e         == 72,  opt.icl());
    rel(*this, v+i+o+l+i+n       == 100, opt.icl());
    rel(*this, w+a+l+t+z         == 34,  opt.icl());

    distinct(*this, le, opt.icl());

    switch (opt.branching()) {
    case BRANCH_NONE:
      branch(*this, le, INT_VAR_NONE(), INT_VAL_MIN());
      break;
    case BRANCH_INVERSE:
      branch(*this, le.slice(le.size()-1,-1), INT_VAR_NONE(), INT_VAL_MIN());
      break;
    case BRANCH_SIZE:
      branch(*this, le, INT_VAR_SIZE_MIN(), INT_VAL_MIN());
      break;
    }
  }
开发者ID:tkelman,项目名称:gecode,代码行数:44,代码来源:alpha.cpp

示例7: curl_easy_setopt

void QtCUrl::setOptions(Options& opt) {
	Options defaults;
    //defaults[CURLOPT_FAILONERROR] = true;
	defaults[CURLOPT_ERRORBUFFER].setValue(_errorBuffer);

    if(FileName.isEmpty())
    {
        defaults[CURLOPT_WRITEFUNCTION].setValue(&writer);
        defaults[CURLOPT_WRITEDATA].setValue(&_buffer);
    }else
    {
        File.setFileName(FileName);

        defaults[CURLOPT_WRITEFUNCTION].setValue(&writer_file);
        defaults[CURLOPT_WRITEDATA].setValue(&File);
    }

    defaults[CURLOPT_PROGRESSFUNCTION].setValue(&progress_callback);
    defaults[CURLOPT_PROGRESSDATA].setValue(&AutoDelete);

    defaults[CURLOPT_NOPROGRESS].setValue(0);

    defaults[CURLOPT_SSL_VERIFYPEER].setValue(false);
    defaults[CURLOPT_SSL_VERIFYHOST].setValue(false);

    if(!Filter.isEmpty())
    {
        //defaults[CURLOPT_VERBOSE].setValue(1);
        defaults[CURLOPT_HEADERFUNCTION].setValue(&writer2);
        defaults[CURLOPT_WRITEHEADER].setValue(&_buffer_and_filter);
    }
    //defaults[CURLOPT_VERBOSE].setValue(1);



#ifdef QTCURL_DEBUG
	curl_easy_setopt(_curl, CURLOPT_VERBOSE, 1);
	curl_easy_setopt(_curl, CURLOPT_DEBUGFUNCTION, trace);
#endif

	OptionsIterator i(defaults);

	while (i.hasNext()) {
		i.next();

		if (! opt.contains(i.key())) {
			opt[i.key()] = i.value();
		}
	}

    if(opt.contains(CURLOPT_POSTFIELDSIZE))
    {
        int val = opt[CURLOPT_POSTFIELDSIZE].toInt();
        curl_easy_setopt(_curl, CURLOPT_POSTFIELDSIZE, (long)val);
    }

	i = opt;

	while (i.hasNext()) {
		i.next();
		QVariant value = i.value();


        if(i.key() == CURLOPT_POSTFIELDSIZE)
        {
            continue;
        }

		switch (value.type()) {
			case QVariant::Bool:
			case QVariant::Int: {
				int val = value.toInt();
				curl_easy_setopt(_curl, i.key(), val);
				break;
			}
			case QVariant::ByteArray: {
				QByteArray ba = value.toByteArray();
				curl_easy_setopt(_curl, i.key(), ba.constData());
				break;
			}
			case QVariant::Url: {
				QByteArray ba = value.toUrl().toEncoded();
				curl_easy_setopt(_curl, i.key(), ba.constData());
				break;
			}
			case QVariant::String: {
                curl_easy_setopt(_curl, i.key(), value.toString().toUtf8().data());
				break;
			}
			case QVariant::ULongLong: {
				qulonglong val = value.toULongLong();
				curl_easy_setopt(_curl, i.key(), (void*) val);
				break;
			}
			case QVariant::StringList: {
				struct curl_slist *slist = NULL;
				foreach (const QString &tmp, value.toStringList()) {
					 slist = curl_slist_append(slist, tmp.toUtf8().data());
				}
				_slist.append(slist);
//.........这里部分代码省略.........
开发者ID:bablosoft,项目名称:BAS,代码行数:101,代码来源:QtCUrl.cpp

示例8: run

void run () {
  size_t niter = 10000;
  float target_power = 2.0;

  Options opt = get_options ("power");
  if (opt.size())
    target_power = opt[0][0];

  opt = get_options ("niter");
  if (opt.size())
    niter = opt[0][0];

  ndirs = to<int> (argument[0]);

  if (get_options ("unipolar").size())
    bipolar = false;

  Math::RNG    rng;
  Math::Vector<double> v (2*ndirs);

  for (size_t n = 0; n < 2*ndirs; n+=2) {
    v[n] =  Math::pi * (2.0 * rng.uniform() - 1.0);
    v[n+1] = std::asin (2.0 * rng.uniform() - 1.0);
  }

  gsl_multimin_function_fdf fdf;

  fdf.f = energy_f;
  fdf.df = energy_df;
  fdf.fdf = energy_fdf;
  fdf.n = 2*ndirs;

  gsl_multimin_fdfminimizer* minimizer =
    gsl_multimin_fdfminimizer_alloc (gsl_multimin_fdfminimizer_conjugate_fr, 2*ndirs);


  {
    ProgressBar progress ("Optimising directions...");
    for (power = -1.0; power >= -target_power/2.0; power *= 2.0) {
      INFO ("setting power = " + str (-power*2.0));
      gsl_multimin_fdfminimizer_set (minimizer, &fdf, v.gsl(), 0.01, 1e-4);

      for (size_t iter = 0; iter < niter; iter++) {

        int status = gsl_multimin_fdfminimizer_iterate (minimizer);

        //for (size_t n = 0; n < 2*ndirs; ++n) 
          //std::cout << gsl_vector_get (minimizer->x, n) << " " << gsl_vector_get (minimizer->gradient, n) << "\n";

        if (iter%10 == 0)
          INFO ("[ " + str (iter) + " ] (pow = " + str (-power*2.0) + ") E = " + str (minimizer->f)
          + ", grad = " + str (gsl_blas_dnrm2 (minimizer->gradient)));

        if (status) {
          INFO (std::string ("iteration stopped: ") + gsl_strerror (status));
          break;
        }

        progress.update ([&]() { return "Optimising directions (power " + str(-2.0*power) + ", current energy: " + str(minimizer->f, 8) + ")..."; });
      }
      gsl_vector_memcpy (v.gsl(), minimizer->x);
    }
  }


  Math::Matrix<double> directions (ndirs, 2);
  for (size_t n = 0; n < ndirs; n++) {
    double az = gsl_vector_get (minimizer->x, 2*n);
    double el = gsl_vector_get (minimizer->x, 2*n+1);
    range (az, el);
    directions (n, 0) = az;
    directions (n, 1) = el;
  }

  gsl_multimin_fdfminimizer_free (minimizer);

  DWI::Directions::save (directions, argument[1], get_options ("cartesian").size());
}
开发者ID:chamberm,项目名称:mrtrix3,代码行数:78,代码来源:dirgen.cpp

示例9: verifyType

Expression::Ptr TypeChecker::verifyType(const Expression::Ptr &operand,
                                        const SequenceType::Ptr &reqSeqType,
                                        const StaticContext::Ptr &context,
                                        const ReportContext::ErrorCode code,
                                        const Options options)
{
    const ItemType::Ptr reqType(reqSeqType->itemType());
    const Expression::Properties props(operand->properties());

    /* If operand requires a focus, do the necessary type checking for that. */
    if(props.testFlag(Expression::RequiresFocus) && options.testFlag(CheckFocus))
    {
        const ItemType::Ptr contextType(context->contextItemType());
        if(contextType)
        {
            if(props.testFlag(Expression::RequiresContextItem))
            {
                Q_ASSERT_X(operand->expectedContextItemType(), Q_FUNC_INFO,
                           "When the Expression sets the RequiresContextItem property, it must "
                           "return a type in expectedContextItemType()");
                const ItemType::Ptr expectedContextType(operand->expectedContextItemType());

                /* Allow the empty sequence. We don't want to trigger XPTY0020 on ()/... . */
                if(!expectedContextType->xdtTypeMatches(contextType) && contextType != CommonSequenceTypes::Empty)
                {
                    context->error(wrongType(context->namePool(), operand->expectedContextItemType(), contextType),
                                            ReportContext::XPTY0020, operand.data());
                    return operand;
                }
            }
        }
        else
        {
            context->error(QtXmlPatterns::tr("The focus is undefined."), ReportContext::XPDY0002, operand.data());
            return operand;
        }
    }

    SequenceType::Ptr operandSeqType(operand->staticType());
    ItemType::Ptr operandType(operandSeqType->itemType());

    /* This returns the operand if the types are identical or if operandType
     * is a subtype of reqType. */
    if(reqType->xdtTypeMatches(operandType) || *operandType == *CommonSequenceTypes::Empty)
        return operand;

    /* Since we haven't exited yet, it means that the operandType is a super type
     * of reqType, and that there hence is a path down to it through the
     * type hierachy -- but that doesn't necessarily mean that a up-cast(down the
     * hierarchy) would succeed. */

    Expression::Ptr result(operand);

    if(reqType->isAtomicType())
    {
        const Expression::ID opID = operand->id();
        if((opID == Expression::IDArgumentReference ||
            (opID == Expression::IDCardinalityVerifier && operand->operands().first()->is(Expression::IDArgumentReference)))
           && *BuiltinTypes::item == *operandType)
            return Expression::Ptr(new ArgumentConverter(result, reqType));

        if(!operandType->isAtomicType())
        {
            result = Expression::Ptr(new Atomizer(result));
            /* The atomizer might know more about the type. */
            operandType = result->staticType()->itemType();
        }

        if(reqType->xdtTypeMatches(operandType))
        {
            /* Atomization was sufficient. Either the expected type is xs:anyAtomicType
             * or the type the Atomizer knows it returns, matches the required type. */
            return result;
        }

        const bool compatModeEnabled = context->compatModeEnabled();

        if((options.testFlag(AutomaticallyConvert) && BuiltinTypes::xsUntypedAtomic->xdtTypeMatches(operandType)) ||
           (compatModeEnabled && BuiltinTypes::xsString->xdtTypeMatches(reqType)))
        {
            if(*reqType == *BuiltinTypes::numeric)
            {
                result = typeCheck(new UntypedAtomicConverter(result, BuiltinTypes::xsDouble, code),
                                   context, reqSeqType);
            }
            else
                result = typeCheck(new UntypedAtomicConverter(result, reqType, code), context, reqSeqType);

            /* The UntypedAtomicConverter might know more about the type, so reload. */
            operandType = result->staticType()->itemType();
        }
        else if(compatModeEnabled && *reqType == *BuiltinTypes::xsDouble)
        {
            const FunctionFactory::Ptr functions(context->functionSignatures());
            Expression::List numberArgs;
            numberArgs.append(operand);

            result = functions->createFunctionCall(QXmlName(StandardNamespaces::fn, StandardLocalNames::number),
                                                   numberArgs,
                                                   context,
//.........这里部分代码省略.........
开发者ID:wpbest,项目名称:copperspice,代码行数:101,代码来源:qtypechecker.cpp

示例10: main

int main(int argc, char **argv) {
    if (!run_all_tests())
        return 1;

    _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
    _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);

    Options options = parseArgs(argc, argv);
    auto status = displayHelpIfNecessary(options, "0.0.1");

    if (status.first) {
        return status.second;
    }

    if (options.action == Options::Average) {
        vec3 average = exr_average(options.input0);
        std::cout << "[" << average.x << " " << average.y << " " << average.z << "]" << std::endl;
    }
    else if (options.action == Options::Errors) {
        return compute_errors(std::cout, options);
    }
    else if (options.action == Options::Strip) {
        strip_exr(options.output, options.input0);
    }
    else if (options.action == Options::Merge) {
        merge_exr(options.output, options.input0, options.input1);
    }
    else if (options.action == Options::Time) {
        std::cout << query_time(options.input0);
    }
    else if (options.action == Options::Statistics) {
      auto metadata = load_metadata(options.input0);
      print_records_tabular(std::cout, statistics_t(metadata));
    }
    else if (options.action == Options::Measurements) {
      auto metadata = load_metadata(options.input0);
      print_measurements_tabular(std::cout, statistics_t(metadata));
    }
    else if (options.action == Options::Traces) {
      auto metadata = load_metadata(options.input0);
      print_traces_tabular(std::cout, metadata);
    }
    else if (options.action == Options::Gnuplot) {
        auto error_message = gnuplot(argc, argv);

        options.displayHelp = !error_message.empty();
        options.displayMessage = error_message;

        auto status = displayHelpIfNecessary(options, "0.0.1");

        if (status.first) {
          return status.second;
        }
    }
    else if (options.action == Options::Bake) {
        return bake(argc, argv);
    }
    else if (options.action == Options::RelErr) {
        return compute_relative_error(options);
    }
    else {
        if (options.action == Options::Continue) {
            map<string, string> metadata = load_metadata(options.input0);
            auto output = options.input0;
            options = Options(metadata);
            options.output = output;
            options.action = Options::Continue;
            options.num_samples = atoi(metadata["statistics.num_samples"].c_str());
            options.num_seconds = atoi(metadata["statistics.total_time"].c_str());
            overrideArgs(options, argc, argv);

            auto status = displayHelpIfNecessary(options, "0.0.1");

            if (status.first) {
                return status.second;
            }
        }

        Application application(options);

        if (options.batch) {
            return application.runBatch(options.width, options.height);
        }
        else {
            return application.run(options.width, options.height, options.caption());
        }
    }

    return 0;
}
开发者ID:ciechowoj,项目名称:master,代码行数:90,代码来源:main.cpp

示例11: run

void run ()
{

  Image::Buffer<float> data_in (argument[0]);
  auto voxel_in = data_in.voxel();

  std::vector<std::vector<int> > bounds(data_in.ndim(), std::vector<int> (2) );
  for (size_t axis = 0; axis < data_in.ndim(); axis++) {
    bounds[axis][0] = 0;
    bounds[axis][1] = data_in.dim (axis) - 1;
  }

  Options opt = get_options ("mask");
  if (opt.size()) {

    Image::Buffer<bool> data_mask (opt[0][0]);

    Image::check_dimensions (data_in, data_mask, 0, 3);
    auto voxel_mask = data_mask.voxel();

    for (size_t axis = 0; axis != 3; ++axis) {
      bounds[axis][0] = data_in.dim (axis);
      bounds[axis][1] = 0;
    }

    // Note that even though only 3 dimensions are cropped when using a mask, the bounds
    // are computed by checking the extent for all dimensions (for example a 4D AFD mask)
    for (auto i = Image::Loop() (voxel_mask); i; ++i) {
      if (voxel_mask.value()) {
        for (size_t axis = 0; axis != 3; ++axis) {
          bounds[axis][0] = std::min (bounds[axis][0], int (voxel_mask[axis]));
          bounds[axis][1] = std::max (bounds[axis][1], int (voxel_mask[axis]));
        }
      }
    }

    for (size_t axis = 0; axis != 3; ++axis) {
      if (bounds[axis][0] > bounds[axis][1])
        throw Exception ("mask image is empty; can't use to crop image");
      if (bounds[axis][0])
        --bounds[axis][0];
      if (bounds[axis][1] < voxel_mask.dim (axis) - 1)
        ++bounds[axis][1];
    }

  }

  opt = get_options ("axis");
  for (size_t i = 0; i != opt.size(); ++i) {
    // Manual cropping of axis overrides mask image bounds
    const int axis  = opt[i][0];
    const int start = opt[i][1];
    const int end   = opt[i][2];
    bounds[axis][0] = start;
    bounds[axis][1] = end;
    if (bounds[axis][0] < 0 || bounds[axis][1] >= data_in.dim(axis))
      throw Exception ("Index supplied for axis " + str(axis) + " is out of bounds.");
  }

  std::vector<size_t> from(data_in.ndim());
  std::vector<size_t> size(data_in.ndim());
  for (size_t axis = 0; axis < data_in.ndim(); axis++) {
    from[axis] = bounds[axis][0];
    size[axis] = bounds[axis][1] - from[axis] + 1;
  }

  Image::Adapter::Subset<decltype(voxel_in)> cropped (voxel_in, from, size);

  Image::Header H_out (data_in);
  H_out.info() = cropped.info();
  Image::Buffer<float> data_out (argument[1], H_out);
  auto out = data_out.voxel();
  Image::copy_with_progress_message ("cropping image...", cropped, out);

}
开发者ID:JohnWangDataAnalyst,项目名称:mrtrix3,代码行数:75,代码来源:mrcrop.cpp

示例12: collect_attributes

Option PipelineReader::parseElement_Option(const ptree& tree)
{
    // cur is an option element, such as this:
    //     <option>
    //       <name>myname</name>
    //       <description>my descr</description>
    //       <value>17</value>
    //     </option>
    // this function will process the element and return an Option from it

    map_t attrs;
    collect_attributes(attrs, tree);

    std::string name = attrs["name"];
    std::string value = tree.get_value<std::string>();
    boost::algorithm::trim(value);
    Option option(name, value);

    boost::optional<ptree const&> moreOptions =
        tree.get_child_optional("Options");

    if (moreOptions)
    {
        ptree::const_iterator iter = moreOptions->begin();

        Options options;
        while (iter != moreOptions->end())
        {
            if (iter->first == "Option")
            {
                Option o2 = parseElement_Option(iter->second);
                options.add(o2);
            }
            ++iter;
        }
        option.setOptions(options);
    }

    // filenames in the XML are fixed up as follows:
    //   - if absolute path, leave it alone
    //   - if relative path, make it absolute using the XML file's directory
    // The toAbsolutePath function does exactly that magic for us.
    if (option.getName() == "filename")
    {
        std::string path = option.getValue<std::string>();
#ifndef PDAL_PLATFORM_WIN32
        wordexp_t result;
        if (wordexp(path.c_str(), &result, 0) == 0)
        {
            if (result.we_wordc == 1)
                path = result.we_wordv[0];
        }
        wordfree(&result);
#endif
        if (!FileUtils::isAbsolutePath(path))
        {
            std::string abspath = FileUtils::toAbsolutePath(m_inputXmlFile);
            std::string absdir = FileUtils::getDirectory(abspath);
            path = FileUtils::toAbsolutePath(path, absdir);

            assert(FileUtils::isAbsolutePath(path));
        }
        option.setValue(path);
    }
    return option;
}
开发者ID:rskelly,项目名称:PDAL,代码行数:66,代码来源:PipelineReader.cpp

示例13: main

int main(int argc, char * argv[])
{
    try
    {
        string resource;
        string type;
        string resourceEntity;
        string objectId;
        string outputPrefix;
        bool returnUrl;
        vector<string> resourceSets;
        bool ignoreMalformedHeaders;
        
        Options options;
        options.descriptions.add_options()
            ("resource,r", po::value<string>(&resource)
             ->default_value("Property"), "Object resource")
            ("type", po::value<string>(&type)
             ->default_value("Photo"), "Object type")
            ("output-prefix", po::value<string>(&outputPrefix)
             ->default_value(""), "Output file prefix")
            ("resource-set", po::value< vector<string> >(&resourceSets),
             "Resource sets (e.g. 'resource-id' or 'resource-id:#,#'))")
            ("return-url", po::value<bool>(&returnUrl)
             ->default_value(false), "Return the URL to the object (true or false)")
            ("ignore-malformed-headers", po::value<bool>(&ignoreMalformedHeaders)
             ->default_value(false), "Ignore malformed headers (true or false)")
            ;
        if (!options.ParseCommandLine(argc, argv))
        {
            return 1;
        }
        
        if (resourceSets.size() == 0)
        {
            resourceSets.push_back("1");
        }

        RetsSessionPtr session = options.RetsLogin();
        if (!session)
        {
            cout << "Login failed\n";
            return -1;
        }
    
        GetObjectRequest getObjectRequest(resource, type);
    
        vector<string>::const_iterator i;
        for (i = resourceSets.begin(); i != resourceSets.end(); i++)
        {
            vector<string> resourceSet;
            ba::split(resourceSet, *i, ba::is_any_of(":"));
            if (resourceSet.size() == 1)
            {
                getObjectRequest.AddAllObjects(resourceSet[0]);
            }
            else if (resourceSet.size() == 2)
            {
                vector<string> ids;
                ba::split(ids, resourceSet[1], ba::is_any_of(","));
                vector<string>::const_iterator idString;
                for (idString = ids.begin(); idString != ids.end();
                     idString++)
                {
                    int id  = lexical_cast<int>(*idString);
                    getObjectRequest.AddObject(resourceSet[0], id);
                }
            }
        }
        getObjectRequest.SetLocation(returnUrl);
        getObjectRequest.SetIgnoreMalformedHeaders(ignoreMalformedHeaders);
    
        GetObjectResponseAPtr getObjectResponse =
            session->GetObject(&getObjectRequest);
    
        StringMap contentTypeSuffixes;
        contentTypeSuffixes["image/jpeg"] = "jpg";
        contentTypeSuffixes["text/xml"] = "xml";
        ObjectDescriptor * objectDescriptor;
        while ((objectDescriptor = getObjectResponse->NextObject()))
        {
            int retsReplyCode = objectDescriptor->GetRetsReplyCode();
            string retsReplyText = objectDescriptor->GetRetsReplyText();
            
            string objectKey = objectDescriptor->GetObjectKey();
            int objectId = objectDescriptor->GetObjectId();
            string contentType = objectDescriptor->GetContentType();
            string description = objectDescriptor->GetDescription();
            string location = objectDescriptor->GetLocationUrl();
            
            if (objectDescriptor->GetWildIndicator())
                cout << objectKey << " object #: *";
            else
                cout << objectKey << " object #" << objectId;
            if (!description.empty())
                cout << ", description: " << description;
            if (!location.empty())
                cout << ", location: " << location;
            if (retsReplyCode)
                cout << ", **** " << retsReplyCode << ": " << retsReplyText;
//.........这里部分代码省略.........
开发者ID:NationalAssociationOfRealtors,项目名称:libRETS,代码行数:101,代码来源:get-object.cpp

示例14: checkOptions

void checkOptions(Options& opts) {
   opts.define("r|reverse=b", "Reverse the order of notes");

   opts.define("author=b",    "Author of the program");
   opts.define("version=b",   "Print version of the program");
   opts.define("example=b",   "Display example use of the program");
   opts.define("help=b",      "Dispay help for the program");
   opts.process();

   if (opts.getBoolean("author")) {
      cout << "Written by Craig Stuart Sapp, "
           << "[email protected], 2 December 1999" << endl;
      exit(0);
   }
   if (opts.getBoolean("version")) {
      cout << "midimixup version 2.0" << endl;
      cout << "compiled: " << __DATE__ << endl;
   }
   if (opts.getBoolean("help")) {
      usage(opts.getCommand().data());
      exit(0);
   }
   if (opts.getBoolean("example")) {
      example();
      exit(0);
   }

   reverseQ = opts.getBoolean("reverse");
}
开发者ID:bejado,项目名称:midifile,代码行数:29,代码来源:midimixup.cpp

示例15: checkOptions

void checkOptions(Options& opts) {
   opts.define("a|auto|automatic=b");
   opts.define("c|const|constant=b");
   opts.define("t|tempo|tempo-average=i:1");
   opts.define("m|max|max-amplitude=i:64");
   opts.define("p|port|out-port=i:0");
   opts.define("i|inport|in-port=i:0");
   opts.define("1|z|channel-collapse=b");
   opts.define("author=b");
   opts.define("version=b");
   opts.define("example=b");
   opts.define("help=b");
   opts.process();              

   if (opts.getBoolean("author")) {
      cout << "Written by Craig Stuart Sapp, "
           << "[email protected], Nov 1999" << endl;
      exit(0);
   }
   if (opts.getBoolean("version")) {
      cout << "midiplay version 1.0" << endl;
      cout << "compiled: " << __DATE__ << endl;
   }
   if (opts.getBoolean("help")) {
      usage(opts.getCommand().data());
      exit(0);
   }
   if (opts.getBoolean("example")) {
      example();
      exit(0);
   }               

   // can only have one output filename
   if (opts.getArgCount() != 1) {
      cout << "Error: need one input MIDI file for performance." << endl;
      usage(opts.getCommand().data());
      exit(1);
   } 

   // figure out the tempo performance method
   if (opts.getBoolean("automatic")) {
      tempoMethod = TEMPO_METHOD_AUTOMATIC;
   } else if (opts.getBoolean("constant")) {
      tempoMethod = TEMPO_METHOD_CONSTANT;
   } else {
      switch (opts.getInteger("tempo-average")) {
         case 1:  tempoMethod = TEMPO_METHOD_ONEBACK;   break;
         case 2:  tempoMethod = TEMPO_METHOD_TWOBACK;   break;
         case 3:  tempoMethod = TEMPO_METHOD_THREEBACK; break;
         case 4:  tempoMethod = TEMPO_METHOD_FOURBACK;  break;
         default: tempoMethod = TEMPO_METHOD_ONEBACK;   break;
      }
   }

   outport = opts.getInteger("out-port");
   inport = opts.getInteger("in-port");
   maxamp = opts.getInteger("max-amplitude");
   performance.channelCollapse(opts.getBoolean("channel-collapse"));
}
开发者ID:craigsapp,项目名称:improv,代码行数:59,代码来源:midiperform.cpp


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