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


C++ Option::isNone方法代码示例

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


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

示例1: main

int main(int argc, char** argv)
{
  if (argc != 2) {
    cerr << "Usage: " << argv[0] << " <master>" << endl;
    return -1;
  }

  DockerNoExecutorScheduler scheduler;

  FrameworkInfo framework;
  framework.set_user(""); // Have Mesos fill in the current user.
  framework.set_name("Docker No Executor Framework (C++)");
  framework.set_checkpoint(true);

  MesosSchedulerDriver* driver;
  if (os::getenv("MESOS_AUTHENTICATE_FRAMEWORKS").isSome()) {
    cout << "Enabling authentication for the framework" << endl;

    Option<string> value = os::getenv("DEFAULT_PRINCIPAL");
    if (value.isNone()) {
      EXIT(EXIT_FAILURE)
        << "Expecting authentication principal in the environment";
    }

    Credential credential;
    credential.set_principal(value.get());

    framework.set_principal(value.get());

    value = os::getenv("DEFAULT_SECRET");
    if (value.isNone()) {
      EXIT(EXIT_FAILURE)
        << "Expecting authentication secret in the environment";
    }

    credential.set_secret(value.get());

    driver = new MesosSchedulerDriver(
        &scheduler, framework, argv[1], credential);
  } else {
    framework.set_principal("no-executor-framework-cpp");

    driver = new MesosSchedulerDriver(
        &scheduler, framework, argv[1]);
  }

  int status = driver->run() == DRIVER_STOPPED ? 0 : 1;

  // Ensure that the driver process terminates.
  driver->stop();

  delete driver;
  return status;
}
开发者ID:BonnieTang,项目名称:mesos,代码行数:54,代码来源:docker_no_executor_framework.cpp

示例2: None

Try<Option<Entry> > LevelDBStorageProcess::read(const string& name)
{
  CHECK(error.isNone());

  leveldb::ReadOptions options;

  string value;

  leveldb::Status status = db->Get(options, name, &value);

  if (status.IsNotFound()) {
    return None();
  } else if (!status.ok()) {
    return Error(status.ToString());
  }

  google::protobuf::io::ArrayInputStream stream(value.data(), value.size());

  Entry entry;

  if (!entry.ParseFromZeroCopyStream(&stream)) {
    return Error("Failed to deserialize Entry");
  }

  return Some(entry);
}
开发者ID:evanv,项目名称:mesos,代码行数:26,代码来源:leveldb.cpp

示例3: CreateSlaveFlags

Try<PID<slave::Slave> > MesosTest::StartSlave(
    MasterDetector* detector,
    const Option<slave::Flags>& flags)
{
  return cluster.slaves.start(
      detector, flags.isNone() ? CreateSlaveFlags() : flags.get());
}
开发者ID:Guavus,项目名称:mesos,代码行数:7,代码来源:mesos.cpp

示例4: Some

Option<std::string> _check(const Option<T>& o)
{
  if (o.isNone()) {
    return Some("is NONE");
  }
  return None();
}
开发者ID:Bbarrett,项目名称:mesos,代码行数:7,代码来源:check.hpp

示例5: Error

Try<bool> create(
    const string& veth,
    const string& peer,
    const Option<pid_t>& pid)
{
  Try<Netlink<struct nl_sock> > sock = routing::socket();
  if (sock.isError()) {
    return Error(sock.error());
  }

  int err = rtnl_link_veth_add(
      sock.get().get(),
      veth.c_str(),
      peer.c_str(),
      (pid.isNone() ? getpid() : pid.get()));

  if (err != 0) {
    if (err == -NLE_EXIST) {
      return false;
    }
    return Error(nl_geterror(err));
  }

  return true;
}
开发者ID:Guavus,项目名称:mesos,代码行数:25,代码来源:link.cpp

示例6: CHECK

Future<bool> LeaderContenderProcess::withdraw()
{
  if (contending.isNone()) {
    // Nothing to withdraw because the contender has not contended.
    return false;
  }

  if (withdrawing.isSome()) {
    // Repeated calls to withdraw get the same result.
    return withdrawing.get();
  }

  withdrawing = new Promise<bool>();

  CHECK(!candidacy.isDiscarded());

  if (candidacy.isPending()) {
    // If we have not obtained the candidacy yet, we withdraw after
    // it is obtained.
    LOG(INFO) << "Withdraw requested before the candidacy is obtained; will "
              << "withdraw after it happens";
    candidacy.onAny(defer(self(), &Self::cancel));
  } else if (candidacy.isReady()) {
    cancel();
  } else {
    // We have failed to obtain the candidacy so we do not need to
    // cancel it.
    return false;
  }

  return withdrawing.get()->future();
}
开发者ID:GrovoLearning,项目名称:mesos,代码行数:32,代码来源:contender.cpp

示例7: Error

Try<ContainerLogger*> ContainerLogger::create(const Option<string>& type)
{
  ContainerLogger* logger = nullptr;

  if (type.isNone()) {
    logger = new internal::slave::SandboxContainerLogger();
  } else {
    // Try to load container logger from module.
    Try<ContainerLogger*> module =
      modules::ModuleManager::create<ContainerLogger>(type.get());

    if (module.isError()) {
      return Error(
          "Failed to create container logger module '" + type.get() +
          "': " + module.error());
    }

    logger = module.get();
  }

  // Initialize the module.
  Try<Nothing> initialize = logger->initialize();
  if (initialize.isError()) {
    delete logger;

    return Error(
        "Failed to initialize container logger module: " + initialize.error());
  }

  return logger;
}
开发者ID:ChrisPaprocki,项目名称:mesos,代码行数:31,代码来源:container_logger.cpp

示例8: AwaitAssertResponseHeaderEq

inline ::testing::AssertionResult AwaitAssertResponseHeaderEq(
    const char* expectedExpr,
    const char* keyExpr,
    const char* actualExpr,
    const char* durationExpr,
    const std::string& expected,
    const std::string& key,
    const process::Future<process::http::Response>& actual,
    const Duration& duration)
{
  const ::testing::AssertionResult result =
    AwaitAssertReady(actualExpr, durationExpr, actual, duration);

  if (result) {
    const Option<std::string> value = actual.get().headers.get(key);
    if (value.isNone()) {
      return ::testing::AssertionFailure()
        << "Response does not contain header '" << key << "'";
    } else if (expected == value.get()) {
      return ::testing::AssertionSuccess();
    } else {
      return ::testing::AssertionFailure()
        << "Value of: (" << actualExpr << ").get().headers[" << keyExpr << "]\n"
        << "  Actual: " << ::testing::PrintToString(value.get()) << "\n"
        << "Expected: " << expectedExpr << "\n"
        << "Which is: " << ::testing::PrintToString(expected);
    }
  }

  return result;
}
开发者ID:vanloswang,项目名称:mesos,代码行数:31,代码来源:gtest.hpp

示例9: calculateShare

double DRFSorter::calculateShare(const string& name)
{
  double share = 0;

  // TODO(benh): This implementation of "dominant resource fairness"
  // currently does not take into account resources that are not
  // scalars.

  // Scalar resources may be spread across multiple 'Resource'
  // objects. E.g. persistent volumes. So we first collect the names
  // of the scalar resources, before computing the totals.
  hashset<string> scalars;
  foreach (const Resource& resource, resources) {
    if (resource.type() == Value::SCALAR) {
      scalars.insert(resource.name());
    }
  }

  foreach (const string& scalar, scalars) {
    Option<Value::Scalar> total = resources.get<Value::Scalar>(scalar);

    if (total.isSome() && total.get().value() > 0) {
      Option<Value::Scalar> allocation =
        allocations[name].get<Value::Scalar>(scalar);

      if (allocation.isNone()) {
        allocation = Value::Scalar();
      }

      share = std::max(share, allocation.get().value() / total.get().value());
    }
  }
开发者ID:Adyoulike,项目名称:mesos,代码行数:32,代码来源:sorter.cpp

示例10: None

inline Option<std::string> which(const std::string& command)
{
    Option<std::string> path = getenv("PATH");
    if (path.isNone()) {
        return None();
    }

    std::vector<std::string> tokens = strings::tokenize(path.get(), ":");
    foreach (const std::string& token, tokens) {
        const std::string commandPath = path::join(token, command);
        if (!os::exists(commandPath)) {
            continue;
        }

        Try<os::Permissions> permissions = os::permissions(commandPath);
        if (permissions.isError()) {
            continue;
        }

        if (!permissions.get().owner.x &&
                !permissions.get().group.x &&
                !permissions.get().others.x) {
            continue;
        }

        return commandPath;
    }

    return None();
}
开发者ID:chenqiangzhishen,项目名称:mesos,代码行数:30,代码来源:os.hpp

示例11: BadRequest

Future<http::Response> Help::help(const http::Request& request)
{
  // Split the path by '/'.
  vector<string> tokens = strings::tokenize(request.path, "/");

  Option<string> id = None();
  Option<string> name = None();

  if (tokens.size() > 3) {
    return http::BadRequest("Malformed URL, expecting '/help/id/name/'\n");
  } else if (tokens.size() == 3) {
    id = tokens[1];
    name = tokens[2];
  } else if (tokens.size() > 1) {
    id = tokens[1];
  }

  string document;
  string references;

  if (id.isNone()) {             // http://ip:port/help
    document += "## HELP\n";
    foreachkey (const string& id, helps) {
      document += "> [/" + id + "][" + id + "]\n";
      references += "[" + id + "]: help/" + id + "\n";
    }
开发者ID:ConnorDoyle,项目名称:mesos,代码行数:26,代码来源:help.cpp

示例12: Failure

// Wait for a subprocess and test the status code for the following
// conditions of 'expected_status':
//   1. 'None' = Anything but '0'.
//   2. 'Some' = the value of 'expected_status'.
// Returns Nothing if the resulting status code matches the
// expectation otherwise a Failure with the output of the subprocess.
// TODO(jmlvanre): Turn this into a generally useful abstraction for
// gtest where we can have a more straigtforward 'expected_status'.
Future<Nothing> await_subprocess(
    const Subprocess& subprocess,
    const Option<int>& expected_status = None())
{
  // Dup the pipe fd of the subprocess so we can read the output if
  // needed.
  int out = dup(subprocess.out().get());

  // Once we get the status of the process.
  return subprocess.status()
    .then([=](const Option<int>& status) -> Future<Nothing> {
      // If the status is not set, fail out.
      if (status.isNone()) {
        return Failure("Subprocess status is none");
      }

      // If the status is not what we expect then fail out with the
      // output of the subprocess. The failure message will include
      // the assertion failures of the subprocess.
      if ((expected_status.isSome() && status.get() != expected_status.get()) ||
          (expected_status.isNone() && status.get() == 0)) {
        return io::read(out)
          .then([](const string& output) -> Future<Nothing> {
            return Failure("\n[++++++++++] Subprocess output.\n" + output +
                           "[++++++++++]\n");
          });
      }

      // If the subprocess ran successfully then return nothing.
      return Nothing();
    }).onAny([=]() {
      os::close(out);
    });
}
开发者ID:fin09pcap,项目名称:mesos,代码行数:42,代码来源:ssl_tests.cpp

示例13: None

// Creates a null-terminated array of null-terminated strings that will be
// passed to `CreateProcess` as the `lpEnvironment` argument, as described by
// MSDN[1]. This array needs to be sorted in alphabetical order, but the `map`
// already takes care of that. Note that this function does not handle Unicode
// environments, so it should not be used in conjunction with the
// `CREATE_UNICODE_ENVIRONMENT` flag.
//
// NOTE: This function will add the system's environment variables into
// the returned string. These variables take precedence over the provided
// `env` and are generally necessary in order to launch things on Windows.
//
// [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx
inline Option<std::string> createProcessEnvironment(
    const Option<std::map<std::string, std::string>>& env)
{
  if (env.isNone() || (env.isSome() && env.get().size() == 0)) {
    return None();
  }

  Option<std::map<std::string, std::string>> systemEnvironment =
    getSystemEnvironment();

  // The system environment must be non-empty.
  // No subprocesses will be able to launch if the system environment is blank.
  CHECK(systemEnvironment.isSome() && systemEnvironment.get().size() > 0);

  std::map<std::string, std::string> combinedEnvironment = env.get();

  foreachpair (const std::string& key,
               const std::string& value,
               systemEnvironment.get()) {
    combinedEnvironment[key] = value;
  }

  std::string environmentString;
  foreachpair (const std::string& key,
               const std::string& value,
               combinedEnvironment) {
    environmentString += key + '=' + value + '\0';
  }
开发者ID:OvertimeDog,项目名称:mesos,代码行数:40,代码来源:subprocess.hpp

示例14: split

// Splits the string using the provided delimiters.
// The string is split each time at the first character
// that matches any of the characters specified in delims.
// Empty tokens are allowed in the result.
// Optionally, maximum number of tokens to be returned
// can be specified.
inline std::vector<std::string> split(
    const std::string& s,
    const std::string& delims,
    const Option<size_t>& maxTokens = None())
{
  size_t offset = 0;
  std::vector<std::string> tokens;

  while (maxTokens.isNone() || maxTokens.get() > 0) {
    size_t next = s.find_first_of(delims, offset);

    // Finish splitting if this is the last token,
    // or we've found enough tokens.
    if (next == std::string::npos ||
        (maxTokens.isSome() && tokens.size() == maxTokens.get() - 1)) {
      tokens.push_back(s.substr(offset));
      break;
    }

    tokens.push_back(s.substr(offset, next - offset));
    offset = next + 1;
  }

  return tokens;
}
开发者ID:EronWright,项目名称:mesos,代码行数:31,代码来源:strings.hpp

示例15: calculateShare

double DRFSorter::calculateShare(const string& name)
{
  double share = 0;

  // TODO(benh): This implementaion of "dominant resource fairness"
  // currently does not take into account resources that are not
  // scalars.

  foreach (const Resource& resource, resources) {
    if (resource.type() == Value::SCALAR) {
      double total = resource.scalar().value();

      if (total > 0) {
        Option<Value::Scalar> scalar =
          allocations[name].get<Value::Scalar>(resource.name());

        if (scalar.isNone()) {
          scalar = Value::Scalar();
        }

        share = std::max(share, scalar.get().value() / total);
      }
    }
  }

  return share / weights[name];
}
开发者ID:Benguang,项目名称:mesos,代码行数:27,代码来源:drf_sorter.cpp


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