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


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

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


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

示例1: 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

示例2: createDiskInfo

// NOTE: We only set the volume in DiskInfo if 'containerPath' is set.
// If volume mode is not specified, Volume::RW will be used (assuming
// 'containerPath' is set).
inline Resource::DiskInfo createDiskInfo(
    const Option<std::string>& persistenceId,
    const Option<std::string>& containerPath,
    const Option<Volume::Mode>& mode = None(),
    const Option<std::string>& hostPath = None())
{
  Resource::DiskInfo info;

  if (persistenceId.isSome()) {
    info.mutable_persistence()->set_id(persistenceId.get());
  }

  if (containerPath.isSome()) {
    Volume volume;
    volume.set_container_path(containerPath.get());
    volume.set_mode(mode.isSome() ? mode.get() : Volume::RW);

    if (hostPath.isSome()) {
      volume.set_host_path(hostPath.get());
    }

    info.mutable_volume()->CopyFrom(volume);
  }

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

示例3: createOperationStatus

OperationStatus createOperationStatus(
    const OperationState& state,
    const Option<OperationID>& operationId,
    const Option<string>& message,
    const Option<Resources>& convertedResources,
    const Option<id::UUID>& uuid)
{
  OperationStatus status;
  status.set_state(state);

  if (operationId.isSome()) {
    status.mutable_operation_id()->CopyFrom(operationId.get());
  }

  if (message.isSome()) {
    status.set_message(message.get());
  }

  if (convertedResources.isSome()) {
    status.mutable_converted_resources()->CopyFrom(convertedResources.get());
  }

  if (uuid.isSome()) {
    status.mutable_uuid()->set_value(uuid->toBytes());
  }

  return status;
}
开发者ID:ederst,项目名称:mesos,代码行数:28,代码来源:protobuf_utils.cpp

示例4: LOG

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

  LOG(INFO) << "Authorizing principal '"
            << (requestPrincipal.isSome() ? requestPrincipal.get() : "ANY")
            << "' to remove quota set by '"
            << (quotaPrincipal.isSome() ? quotaPrincipal.get() : "ANY")
            << "'";

  mesos::ACL::RemoveQuota request;

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

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

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

示例5: createContention

inline Contention createContention(
  Option<double_t> severity,
  const Contention_Type contentionType = Contention_Type_IPC,
  Option<WorkID> victim = None(),
  Option<double_t> timestamp = None(),
  Option<WorkID> aggressor = None()) {
  Contention contention;
  contention.set_type(contentionType);
  if (severity.isSome()) {
    contention.set_severity(severity.get());
  }

  if (timestamp.isSome()) {
    contention.set_timestamp(timestamp.get());
  }

  if (victim.isSome()) {
    contention.mutable_victim()->CopyFrom(victim.get());
  }

  if (aggressor.isSome())
    contention.mutable_aggressor()->CopyFrom(aggressor.get());

  return contention;
}
开发者ID:Bplotka,项目名称:serenity,代码行数:25,代码来源:serenity.hpp

示例6: createTaskStatus

TaskStatus createTaskStatus(
    TaskStatus status,
    const id::UUID& uuid,
    double timestamp,
    const Option<TaskState>& state,
    const Option<string>& message,
    const Option<TaskStatus::Source>& source,
    const Option<TaskStatus::Reason>& reason,
    const Option<string>& data,
    const Option<bool>& healthy,
    const Option<CheckStatusInfo>& checkStatus,
    const Option<Labels>& labels,
    const Option<ContainerStatus>& containerStatus,
    const Option<TimeInfo>& unreachableTime)
{
  status.set_uuid(uuid.toBytes());
  status.set_timestamp(timestamp);

  if (state.isSome()) {
    status.set_state(state.get());
  }

  if (message.isSome()) {
    status.set_message(message.get());
  }

  if (source.isSome()) {
    status.set_source(source.get());
  }

  if (reason.isSome()) {
    status.set_reason(reason.get());
  }

  if (data.isSome()) {
    status.set_data(data.get());
  }

  if (healthy.isSome()) {
    status.set_healthy(healthy.get());
  }

  if (checkStatus.isSome()) {
    status.mutable_check_status()->CopyFrom(checkStatus.get());
  }

  if (labels.isSome()) {
    status.mutable_labels()->CopyFrom(labels.get());
  }

  if (containerStatus.isSome()) {
    status.mutable_container_status()->CopyFrom(containerStatus.get());
  }

  if (unreachableTime.isSome()) {
    status.mutable_unreachable_time()->CopyFrom(unreachableTime.get());
  }

  return status;
}
开发者ID:ederst,项目名称:mesos,代码行数:60,代码来源:protobuf_utils.cpp

示例7: createStatusUpdate

// TODO(vinod): Make SlaveID optional because 'StatusUpdate.SlaveID'
// is optional.
StatusUpdate createStatusUpdate(
    const FrameworkID& frameworkId,
    const Option<SlaveID>& slaveId,
    const TaskID& taskId,
    const TaskState& state,
    const std::string& message = "",
    const Option<ExecutorID>& executorId = None())
{
  StatusUpdate update;

  update.set_timestamp(process::Clock::now().secs());
  update.set_uuid(UUID::random().toBytes());
  update.mutable_framework_id()->MergeFrom(frameworkId);

  if (slaveId.isSome()) {
    update.mutable_slave_id()->MergeFrom(slaveId.get());
  }

  if (executorId.isSome()) {
    update.mutable_executor_id()->MergeFrom(executorId.get());
  }

  TaskStatus* status = update.mutable_status();
  status->mutable_task_id()->MergeFrom(taskId);

  if (slaveId.isSome()) {
    status->mutable_slave_id()->MergeFrom(slaveId.get());
  }

  status->set_state(state);
  status->set_message(message);
  status->set_timestamp(update.timestamp());

  return update;
}
开发者ID:JianYuan1999,项目名称:mesos,代码行数:37,代码来源:protobuf_utils.cpp

示例8: max

Option<T> max(const Option<T>& left, const Option<T>& right)
{
  if (left.isSome() && right.isSome()) {
    return std::max(left.get(), right.get());
  } else if (left.isSome()) {
    return left.get();
  } else if (right.isSome()) {
    return right.get();
  } else {
    return Option<T>::none();
  }
}
开发者ID:447327642,项目名称:mesos,代码行数:12,代码来源:option.hpp

示例9: createDiskResource

  Resource createDiskResource(
      const string& value,
      const string& role,
      const Option<string>& persistenceID,
      const Option<string>& containerPath)
  {
    Resource resource = Resources::parse("disk", value, role).get();

    if (persistenceID.isSome() || containerPath.isSome()) {
      resource.mutable_disk()->CopyFrom(
          createDiskInfo(persistenceID, containerPath));
    }

    return resource;
  }
开发者ID:kmiku7,项目名称:mesos,代码行数:15,代码来源:resources_tests.cpp

示例10: 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

示例11: on_message_complete

  static int on_message_complete(http_parser* p)
  {
    DataDecoder* decoder = (DataDecoder*) p->data;
//     std::cout << "http::Request:" << std::endl;
//     std::cout << "  method: " << decoder->request->method << std::endl;
//     std::cout << "  path: " << decoder->request->path << std::endl;
    // Parse the query key/values.
    Try<std::string> decoded = http::decode(decoder->query);
    if (decoded.isError()) {
      return 1;
    }
    decoder->request->query = http::query::parse(decoded.get());

    Option<std::string> encoding =
      decoder->request->headers.get("Content-Encoding");
    if (encoding.isSome() && encoding.get() == "gzip") {
      Try<std::string> decompressed = gzip::decompress(decoder->request->body);
      if (decompressed.isError()) {
        return 1;
      }
      decoder->request->body = decompressed.get();
      decoder->request->headers["Content-Length"] =
        decoder->request->body.length();
    }

    decoder->requests.push_back(decoder->request);
    decoder->request = NULL;
    return 0;
  }
开发者ID:AsylumCorp,项目名称:mesos,代码行数:29,代码来源:decoder.hpp

示例12: LOG

void V0ToV1AdapterProcess::disconnected()
{
  // Upon noticing a disconnection with the master, we drain the pending
  // events in the queue that were waiting to be sent to the scheduler
  // upon receiving the subscribe call.
  // It's fine to do so because:
  // - Any outstanding offers are invalidated by the master upon a scheduler
  //   (re-)registration.
  // - Any task status updates could be reconciled by the scheduler.
  LOG(INFO) << "Dropping " << pending.size() << " pending event(s)"
            << " because master disconnected";

  pending = queue<Event>();
  subscribeCall = false;

  if (heartbeatTimer.isSome()) {
    Clock::cancel(heartbeatTimer.get());
    heartbeatTimer = None();
  }

  LOG(INFO) << "Disconnected with the Mesos master;"
            << " invoking disconnected callback";

  disconnect();
}
开发者ID:ederst,项目名称:mesos,代码行数:25,代码来源:org_apache_mesos_v1_scheduler_V0Mesos.cpp

示例13: BadRequest

Future<Response> FilesProcess::browse(const Request& request)
{
  Option<string> path = request.url.query.get("path");

  if (!path.isSome() || path.get().empty()) {
    return BadRequest("Expecting 'path=value' in query.\n");
  }

  Result<string> resolvedPath = resolve(path.get());

  if (resolvedPath.isError()) {
    return InternalServerError(resolvedPath.error() + ".\n");
  } else if (resolvedPath.isNone()) {
    return NotFound();
  }

  // The result will be a sorted (on path) array of files and dirs:
  // [{"name": "README", "path": "dir/README" "dir":False, "size":42}, ...]
  map<string, JSON::Object> files;
  Try<list<string> > entries = os::ls(resolvedPath.get());
  if (entries.isSome()) {
    foreach (const string& entry, entries.get()) {
      struct stat s;
      string fullPath = path::join(resolvedPath.get(), entry);

      if (stat(fullPath.c_str(), &s) < 0) {
        PLOG(WARNING) << "Found " << fullPath << " in ls but stat failed";
        continue;
      }

      files[fullPath] = jsonFileInfo(path::join(path.get(), entry), s);
    }
  }
开发者ID:Zhangwusheng,项目名称:mesos,代码行数:33,代码来源:files.cpp

示例14: on_message_complete

    static int on_message_complete(http_parser* p)
    {
        ResponseDecoder* decoder = (ResponseDecoder*) p->data;

        CHECK_NOTNULL(decoder->response);

        // Get the response status string.
        if (http::statuses.contains(decoder->parser.status_code)) {
            decoder->response->status = http::statuses[decoder->parser.status_code];
        } else {
            decoder->failure = true;
            return 1;
        }

        // We can only provide the gzip encoding.
        Option<std::string> encoding =
            decoder->response->headers.get("Content-Encoding");
        if (encoding.isSome() && encoding.get() == "gzip") {
            Try<std::string> decompressed = gzip::decompress(decoder->response->body);
            if (decompressed.isError()) {
                decoder->failure = true;
                return 1;
            }
            decoder->response->body = decompressed.get();
            decoder->response->headers["Content-Length"] =
                decoder->response->body.length();
        }

        decoder->responses.push_back(decoder->response);
        decoder->response = NULL;
        return 0;
    }
开发者ID:hcchen,项目名称:mesos,代码行数:32,代码来源:decoder.hpp

示例15: Failure

Future<bool> LevelDBStorageProcess::set(const Entry& entry, const UUID& uuid)
{
  if (error.isSome()) {
    return Failure(error.get());
  }

  // We do a read first to make sure the version has not changed. This
  // could be optimized in the future, for now it will probably hit
  // the cache anyway.
  Try<Option<Entry> > option = read(entry.name());

  if (option.isError()) {
    return Failure(option.error());
  }

  if (option.get().isSome()) {
    if (UUID::fromBytes(option.get().get().uuid()) != uuid) {
      return false;
    }
  }

  // Note that the read (i.e., DB::Get) and the write (i.e., DB::Put)
  // are inherently "atomic" because only one db can be opened at a
  // time, so there can not be any writes that occur concurrently.

  Try<bool> result = write(entry);

  if (result.isError()) {
    return Failure(result.error());
  }

  return result.get();
}
开发者ID:ankurcha,项目名称:mesos,代码行数:33,代码来源:leveldb.cpp


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