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


C++ Option类代码示例

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


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

示例1: TEST_F

TEST_F(FetcherEnvironmentTest, EmptyHadoop)
{
  CommandInfo commandInfo;
  CommandInfo::URI* uri = commandInfo.add_uris();
  uri->set_value("hdfs:///uri");
  uri->set_executable(false);

  string directory = "/tmp/directory";
  Option<string> user = "user";

  slave::Flags flags;
  flags.frameworks_home = "/tmp/frameworks";
  flags.hadoop_home = "";

  map<string, string> environment =
    fetcher::environment(commandInfo, directory, user, flags);

  EXPECT_EQ(4u, environment.size());
  EXPECT_EQ(stringify(JSON::Protobuf(commandInfo)),
            environment["MESOS_COMMAND_INFO"]);
  EXPECT_EQ(directory, environment["MESOS_WORK_DIRECTORY"]);
  EXPECT_EQ(user.get(), environment["MESOS_USER"]);
  EXPECT_EQ(flags.frameworks_home, environment["MESOS_FRAMEWORKS_HOME"]);
}
开发者ID:Mountain-Colt,项目名称:mesos_patch,代码行数:24,代码来源:fetcher_tests.cpp

示例2: ACTION_P5

// For use with a MockScheduler, for example:
// EXPECT_CALL(sched, resourceOffers(_, _))
//   .WillOnce(LaunchTasks(EXECUTOR, TASKS, CPUS, MEM, ROLE));
// Launches up to TASKS no-op tasks, if possible,
// each with CPUS cpus and MEM memory and EXECUTOR executor.
ACTION_P5(LaunchTasks, executor, tasks, cpus, mem, role)
{
  SchedulerDriver* driver = arg0;
  std::vector<Offer> offers = arg1;
  int numTasks = tasks;

  int launched = 0;
  for (size_t i = 0; i < offers.size(); i++) {
    const Offer& offer = offers[i];

    const Resources TASK_RESOURCES = Resources::parse(
        "cpus:" + stringify(cpus) + ";mem:" + stringify(mem)).get();

    int nextTaskId = 0;
    std::vector<TaskInfo> tasks;
    Resources remaining = offer.resources();

    while (TASK_RESOURCES <= remaining.flatten() && launched < numTasks) {
      TaskInfo task;
      task.set_name("TestTask");
      task.mutable_task_id()->set_value(stringify(nextTaskId++));
      task.mutable_slave_id()->MergeFrom(offer.slave_id());
      task.mutable_executor()->MergeFrom(executor);

      Option<Resources> resources = remaining.find(TASK_RESOURCES, role);
      CHECK_SOME(resources);
      task.mutable_resources()->MergeFrom(resources.get());
      remaining -= resources.get();

      tasks.push_back(task);
      launched++;
    }

    driver->launchTasks(offer.id(), tasks);
  }
}
开发者ID:Hadoyy,项目名称:mesos,代码行数:41,代码来源:mesos.hpp

示例3:

// parser<bool> implementation
//
bool parser<bool>::parse(Option &O, StringRef ArgName,
                         StringRef Arg, bool &Value) {
  if (Arg == "" || Arg == "true" || Arg == "TRUE" || Arg == "True" ||
      Arg == "1") {
    Value = true;
    return false;
  }

  if (Arg == "false" || Arg == "FALSE" || Arg == "False" || Arg == "0") {
    Value = false;
    return false;
  }
  return O.error("'" + Arg +
                 "' is invalid value for boolean argument! Try 0 or 1");
}
开发者ID:nikunjy,项目名称:parallelStuff,代码行数:17,代码来源:CommandLine.cpp

示例4: TestContainerizer

Try<PID<slave::Slave>> MesosTest::StartSlave(
    MockExecutor* executor,
    mesos::slave::ResourceEstimator* resourceEstimator,
    const Option<slave::Flags>& flags)
{
  slave::Containerizer* containerizer = new TestContainerizer(executor);

  Try<PID<slave::Slave>> pid = cluster.slaves.start(
      flags.isNone() ? CreateSlaveFlags() : flags.get(),
      containerizer,
      None(),
      None(),
      None(),
      resourceEstimator);

  if (pid.isError()) {
    delete containerizer;
    return pid;
  }

  containerizers[pid.get()] = containerizer;

  return pid;
}
开发者ID:ankurcha,项目名称:mesos,代码行数:24,代码来源:mesos.cpp

示例5: createOption

void Options::init(const Json::Value &array)
{
	for (Json::ValueIterator itr = array.begin(); itr != array.end(); itr++)
	{
		Json::Value value = (*itr);

		Json::Value &name = value["name"];
		Json::Value &type = value["type"];

		string typeString = type.asString();
		Option *option = createOption(typeString);

		if (option != NULL)
		{
			option->init(value);
			add(name.asString(), option);
		}
		else
		{
			cout << "Unknown data type: " << typeString << "\n";
			cout.flush();
		}
	}
}
开发者ID:FransMeerhoff,项目名称:jasp-desktop,代码行数:24,代码来源:options.cpp

示例6: process

Try<Owned<HealthChecker>> HealthChecker::create(
    const HealthCheck& check,
    const string& launcherDir,
    const UPID& executor,
    const TaskID& taskID,
    Option<pid_t> taskPid,
    const vector<string>& namespaces)
{
  // Validate the 'HealthCheck' protobuf.
  Option<Error> error = validation::healthCheck(check);
  if (error.isSome()) {
    return error.get();
  }

  Owned<HealthCheckerProcess> process(new HealthCheckerProcess(
      check,
      launcherDir,
      executor,
      taskID,
      taskPid,
      namespaces));

  return Owned<HealthChecker>(new HealthChecker(process));
}
开发者ID:liyubobj,项目名称:mesos,代码行数:24,代码来源:health_checker.cpp

示例7:

// parser<boolOrDefault> implementation
//
bool parser<boolOrDefault>::parse(Option &O, const string& ArgName,
                                  const string& Arg, boolOrDefault &Value) {
  if (Arg == "" || Arg == "true" || Arg == "TRUE" || Arg == "True" ||
      Arg == "1") {
    Value = BOU_TRUE;
    return false;
  }
  if (Arg == "false" || Arg == "FALSE" || Arg == "False" || Arg == "0") {
    Value = BOU_FALSE;
    return false;
  }

  return O.error("'" + Arg +
                 "' is invalid value for boolean argument! Try 0 or 1");
}
开发者ID:chengwang88,项目名称:smina,代码行数:17,代码来源:CommandLine.cpp

示例8: LOG

Future<bool> Master::QuotaHandler::authorizeSetQuota(
    const Option<string>& principal,
    const string& role) const
{
  if (master->authorizer.isNone()) {
    return true;
  }

  LOG(INFO) << "Authorizing principal '"
            << (principal.isSome() ? principal.get() : "ANY")
            << "' to request quota for role '" << role << "'";

  mesos::ACL::SetQuota request;

  if (principal.isSome()) {
    request.mutable_principals()->add_values(principal.get());
  } else {
    request.mutable_principals()->set_type(mesos::ACL::Entity::ANY);
  }

  request.mutable_roles()->add_values(role);

  return master->authorizer.get()->authorize(request);
}
开发者ID:lodejard,项目名称:mesoswin,代码行数:24,代码来源:quota_handler.cpp

示例9: TEST_F

TEST_F(MesosContainerizerProcessTest, Simple)
{
  CommandInfo commandInfo;
  CommandInfo::URI uri;
  uri.set_value("hdfs:///uri");
  uri.set_executable(false);
  commandInfo.add_uris()->MergeFrom(uri);

  string directory = "/tmp/directory";
  Option<string> user = "user";

  Flags flags;
  flags.frameworks_home = "/tmp/frameworks";
  flags.hadoop_home = "/tmp/hadoop";

  map<string, string> environment =
    fetcherEnvironment(commandInfo, directory, user, flags);
  EXPECT_EQ(5u, environment.size());
  EXPECT_EQ("hdfs:///uri+0X", environment["MESOS_EXECUTOR_URIS"]);
  EXPECT_EQ(directory, environment["MESOS_WORK_DIRECTORY"]);
  EXPECT_EQ(user.get(), environment["MESOS_USER"]);
  EXPECT_EQ(flags.frameworks_home, environment["MESOS_FRAMEWORKS_HOME"]);
  EXPECT_EQ(flags.hadoop_home, environment["HADOOP_HOME"]);
}
开发者ID:JianYuan1999,项目名称:mesos,代码行数:24,代码来源:containerizer_tests.cpp

示例10: OK

  OK(const JSON::Value& value, const Option<std::string>& jsonp = None())
  {
    type = BODY;

    status = "200 OK";

    std::ostringstream out;

    if (jsonp.isSome()) {
      out << jsonp.get() << "(";
    }

    out << value;

    if (jsonp.isSome()) {
      out << ");";
      headers["Content-Type"] = "text/javascript";
    } else {
      headers["Content-Type"] = "application/json";
    }

    headers["Content-Length"] = stringify(out.str().size());
    body = out.str().data();
  }
开发者ID:Razor87,项目名称:mesos,代码行数:24,代码来源:http.hpp

示例11: ProcessOptions

  int ListAdjacent::ProcessOptions(int argc, char** argv) {
 
    Option option;
    int argc_old=argc;


    while (*argv[0]=='-' && argc>1) {
      option.reset();
      switch (argv[0][1]) {
     
	
      default:
	EchoError(string("unknown option ")+argv[0]);
      } // switch

      if(!option.option.empty())
	addToSwitches(option);

      argc--;
      argv++; 
    } // while
    return argc_old-argc;
    
  }
开发者ID:aalto-cbir,项目名称:PicSOM,代码行数:24,代码来源:ListAdjacent.C

示例12: createTask

// TODO(bmahler): Refactor this to make the distinction between
// command tasks and executor tasks clearer.
inline TaskInfo createTask(
    const SlaveID& slaveId,
    const Resources& resources,
    const std::string& command,
    const Option<mesos::ExecutorID>& executorId = None(),
    const std::string& name = "test-task",
    const std::string& id = UUID::random().toString())
{
  TaskInfo task;
  task.set_name(name);
  task.mutable_task_id()->set_value(id);
  task.mutable_slave_id()->CopyFrom(slaveId);
  task.mutable_resources()->CopyFrom(resources);
  if (executorId.isSome()) {
    ExecutorInfo executor;
    executor.mutable_executor_id()->CopyFrom(executorId.get());
    executor.mutable_command()->set_value(command);
    task.mutable_executor()->CopyFrom(executor);
  } else {
    task.mutable_command()->set_value(command);
  }

  return task;
}
开发者ID:lodejard,项目名称:mesos,代码行数:26,代码来源:mesos.hpp

示例13: cmdline

inline Result<std::string> cmdline(const Option<pid_t>& pid = None())
{
  const std::string path = pid.isSome()
    ? "/proc/" + stringify(pid.get()) + "/cmdline"
    : "/proc/cmdline";

  std::ifstream file(path.c_str());

  if (!file.is_open()) {
    // Need to check if file exists AFTER we open it to guarantee
    // process hasn't terminated (or if it has, we at least have a
    // file which the kernel _should_ respect until a close).
    if (!os::exists(path)) {
      return None();
    }
    return Error("Failed to open '" + path + "'");
  }

  std::stringbuf buffer;

  do {
    // Read each argument in "argv", separated by null bytes.
    file.get(buffer, '\0');

    // Check for any read errors.
    if (file.fail() && !file.eof()) {
      file.close();
      return Error("Failed to read '" + path + "'");
    } else if (!file.eof()) {
      file.get(); // Read the null byte.
      buffer.sputc(' '); // Put a space between each command line argument.
    }
  } while (!file.eof());

  return buffer.str();
}
开发者ID:Adyoulike,项目名称:mesos,代码行数:36,代码来源:proc.hpp

示例14: while

void PawnShopChapter::Do(Character& character) const
{
  //Must be a copy, as the copy can get cleared
  std::vector<std::pair<Item,int>> items = this->GetItems();

  while (1)
  {
    std::vector<Option> options;
    options.push_back(CreateLeaveOption());

    for (const auto& item: items)
    {
      if (!character.HasItem(item.first)) continue;
      std::stringstream text;
      text
        << "Sell "
        << ToPrettyStr(item.first) << " for "
        << item.second << " gold pieces"
      ;
      Consequence consequence;
      consequence.AddItemToRemove(item.first);
      consequence.SetChangeGold(item.second);
      Option option(text.str(),consequence);
      options.push_back(option);
    }
    //Pawn shop
    const Option chosen{m_chapter->RequestOption(options)};
    if (chosen.GetConsequence().GetType() == ConsequenceType::leave) { break; }

    assert(!chosen.GetConsequence().GetItemsToRemove().empty());
    const Item item_sold{chosen.GetConsequence().GetItemsToRemove()[0]};

    m_chapter->ShowText("You sold " + ToPrettyStr(item_sold) + "\n");
    chosen.GetConsequence().Apply(character);
  }
}
开发者ID:richelbilderbeek,项目名称:CityOfThieves,代码行数:36,代码来源:pawnshopchapter.cpp

示例15: sprintf

 Expression toMicroSt::newDiscrete(Option<Expression> oe) const {
     char buff[1024];
     sprintf(buff,"d%d",disc_count++);
     Name name(buff);
     VarSymbolTable &syms=mmo_class.syms_ref();     
     if (oe) {
       ClassModification cm;
       cm.push_back(ElMod("start",ModEq(oe.get())));
       ModClass mc(cm);
       Modification m = mc;
       syms.insert(name,VarInfo(TypePrefixes(1,discrete) , "Real", Option<Comment>(), m));
     }  else
       syms.insert(name,VarInfo(TypePrefixes(1,discrete) , "Real"));
     mmo_class.variables_ref().push_back(name);
     return Reference(Ref(1,RefTuple(name,ExpList())));
 }
开发者ID:RexFuzzle,项目名称:ModelicaCC,代码行数:16,代码来源:to_micro_st.cpp


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