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


C++ Nothing函数代码示例

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


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

示例1: write_certificate_file

Try<Nothing> write_certificate_file(X509* x509, const Path& path)
{
  // We use 'FILE*' here because it is an API requirement by openssl.
  FILE* file = fopen(path.value.c_str(), "wb");
  if (file == nullptr) {
    return Error("Failed to open file '" + stringify(path) + "' for writing");
  }

  if (PEM_write_X509(file, x509) != 1) {
    fclose(file);
    return Error("Failed to write certificate to file '" + stringify(path) +
      "': PEM_write_X509");
  }

  fclose(file);

  return Nothing();
}
开发者ID:Sun-zhe,项目名称:mesos,代码行数:18,代码来源:utilities.cpp

示例2: typeid

void FlagsBase::add(
    Option<T>* option,
    const std::string& name,
    const std::string& help,
    F validate)
{
  // Don't bother adding anything if the pointer is NULL.
  if (option == NULL) {
    return;
  }

  Flag flag;
  flag.name = name;
  flag.help = help;
  flag.boolean = typeid(T) == typeid(bool);

  // NOTE: See comment above in T* overload of FlagsBase::add for why
  // we need to take the FlagsBase* parameter.

  flag.load = [option](FlagsBase*, const std::string& value) -> Try<Nothing> {
    // NOTE: 'fetch' "retrieves" the value if necessary and then
    // invokes 'parse'. See 'fetch' for more details.
    Try<T> t = fetch<T>(value);
    if (t.isSome()) {
      *option = Some(t.get());
    } else {
      return Error("Failed to load value '" + value + "': " + t.error());
    }
    return Nothing();
  };

  flag.stringify = [option](const FlagsBase&) -> Option<std::string> {
    if (option->isSome()) {
      return stringify(option->get());
    }
    return None();
  };

  flag.validate = [option, validate](const FlagsBase&) -> Option<Error> {
    return validate(*option);
  };

  add(flag);
}
开发者ID:AbheekG,项目名称:mesos,代码行数:44,代码来源:flags.hpp

示例3: open

  Try<Nothing> open(const std::string& path)
  {
    // Check if we've already opened a library.
    if (handle_ != NULL) {
      return Error("Library already opened");
    }

    handle_ = dlopen(path.c_str(), RTLD_NOW);

    if (handle_ == NULL) {
      return Error(
          "Could not load library '" + path +
          "': " + dlerror());
    }

    path_ = path;

    return Nothing();
  }
开发者ID:CodeTickler,项目名称:mesos,代码行数:19,代码来源:dynamiclibrary.hpp

示例4: checkpoint

Try<Nothing> checkpoint(const std::string& path, const T& t)
{
  // Create the base directory.
  std::string base = Path(path).dirname();

  Try<Nothing> mkdir = os::mkdir(base);
  if (mkdir.isError()) {
    return Error("Failed to create directory '" + base + "': " + mkdir.error());
  }

  // NOTE: We create the temporary file at 'base/XXXXXX' to make sure
  // rename below does not cross devices (MESOS-2319).
  //
  // TODO(jieyu): It's possible that the temporary file becomes
  // dangling if slave crashes or restarts while checkpointing.
  // Consider adding a way to garbage collect them.
  Try<std::string> temp = os::mktemp(path::join(base, "XXXXXX"));
  if (temp.isError()) {
    return Error("Failed to create temporary file: " + temp.error());
  }

  // Now checkpoint the instance of T to the temporary file.
  Try<Nothing> checkpoint = internal::checkpoint(temp.get(), t);
  if (checkpoint.isError()) {
    // Try removing the temporary file on error.
    os::rm(temp.get());

    return Error("Failed to write temporary file '" + temp.get() +
                 "': " + checkpoint.error());
  }

  // Rename the temporary file to the path.
  Try<Nothing> rename = os::rename(temp.get(), path);
  if (rename.isError()) {
    // Try removing the temporary file on error.
    os::rm(temp.get());

    return Error("Failed to rename '" + temp.get() + "' to '" +
                 path + "': " + rename.error());
  }

  return Nothing();
}
开发者ID:albertleecn,项目名称:mesos,代码行数:43,代码来源:state.hpp

示例5: TearDownMixin

  Try<Nothing> TearDownMixin()
  {
    // Return to previous working directory and cleanup the sandbox.
    Try<Nothing> chdir = os::chdir(cwd);

    if (chdir.isError()) {
      return Error("Failed to chdir into '" + cwd + "': " + chdir.error());
    }

    if (sandbox.isSome()) {
      Try<Nothing> rmdir = os::rmdir(sandbox.get());
      if (rmdir.isError()) {
        return Error("Failed to rmdir '" + sandbox.get() + "'"
                     ": " + rmdir.error());
      }
    }

    return Nothing();
  }
开发者ID:GrovoLearning,项目名称:mesos,代码行数:19,代码来源:utils.hpp

示例6: MOZ_ASSERT

void
VectorImage::OnSVGDocumentLoaded()
{
  MOZ_ASSERT(mSVGDocumentWrapper->GetRootSVGElem(),
             "Should have parsed successfully");
  MOZ_ASSERT(!mIsFullyLoaded && !mHaveAnimations,
             "These flags shouldn't get set until OnSVGDocumentLoaded. "
             "Duplicate calls to OnSVGDocumentLoaded?");

  CancelAllListeners();

  // XXX Flushing is wasteful if embedding frame hasn't had initial reflow.
  mSVGDocumentWrapper->FlushLayout();

  mIsFullyLoaded = true;
  mHaveAnimations = mSVGDocumentWrapper->IsAnimated();

  // Start listening to our image for rendering updates.
  mRenderingObserver = new SVGRootRenderingObserver(mSVGDocumentWrapper, this);

  // Tell *our* observers that we're done loading.
  if (mProgressTracker) {
    Progress progress = FLAG_SIZE_AVAILABLE |
                        FLAG_HAS_TRANSPARENCY |
                        FLAG_FRAME_COMPLETE |
                        FLAG_DECODE_COMPLETE |
                        FLAG_ONLOAD_UNBLOCKED;

    if (mHaveAnimations) {
      progress |= FLAG_IS_ANIMATED;
    }

    // Merge in any saved progress from OnImageDataComplete.
    if (mLoadProgress) {
      progress |= *mLoadProgress;
      mLoadProgress = Nothing();
    }

    mProgressTracker->SyncNotifyProgress(progress, GetMaxSizedIntRect());
  }

  EvaluateAnimation();
}
开发者ID:cstipkovic,项目名称:gecko-dev,代码行数:43,代码来源:VectorImage.cpp

示例7: write_key_file

Try<Nothing> write_key_file(EVP_PKEY* private_key, const Path& path)
{
  // We use 'FILE*' here because it is an API requirement by openssl.
  FILE* file = fopen(path.value.c_str(), "wb");
  if (file == nullptr) {
    return Error("Failed to open file '" + stringify(path) + "' for writing");
  }

  if (PEM_write_PrivateKey(
          file, private_key, nullptr, nullptr, 0, nullptr, nullptr) != 1) {
    fclose(file);
    return Error("Failed to write private key to file '" + stringify(path) +
      "': PEM_write_PrivateKey");
  }

  fclose(file);

  return Nothing();
}
开发者ID:Sun-zhe,项目名称:mesos,代码行数:19,代码来源:utilities.cpp

示例8: sizeof

Result<void> UdpLink::process()
{
    Frame frame;
    struct sockaddr_in6 sin6 = {0};
    struct iovec iov[2] = {{&frame, sizeof(Frame)}, {_buffer.data(), _buffer.size()}};
    struct msghdr msg = { &sin6, sizeof(sin6), iov, 2 };
    int r = recvmsg(_fd, &msg, MSG_DONTWAIT);

    if (r < 0)
        return Error(std::string("recvmsg failed: ") + strerror(errno));

    Message message;
    message.setSeq(frame.seq);
    ByteArray data(_buffer.data(), r - iov[0].iov_len);
    message.setData(data);

    processMessage(message);

    return Nothing();
}
开发者ID:ABBAPOH,项目名称:test-cpp2,代码行数:20,代码来源:udplink.cpp

示例9: copyToLocal

  Try<Nothing> copyToLocal(
      std::string from,
      const std::string& to)
  {
    from = absolutePath(from);

    // Copy from HDFS.
    Try<std::string> command = strings::format(
        "%s fs -copyToLocal '%s' '%s'", hadoop, from, to);

    CHECK_SOME(command);

    Try<std::string> out = os::shell(command.get());

    if (out.isError()) {
      return Error(out.error());
    }

    return Nothing();
  }
开发者ID:kamilchm,项目名称:mesos,代码行数:20,代码来源:hdfs.hpp

示例10: Error

// Send a request to the subprocess and wait for its signal that the
// work has been done.
Try<Nothing> MemoryTestHelper::requestAndWait(const string& request)
{
  if (s.isNone()) {
    return Error("The subprocess has not been spawned yet");
  }

  Try<Nothing> write = os::write(s->in().get(), request + "\n");
  if (write.isError()) {
    cleanup();
    return Error("Fail to sync with the subprocess: " + write.error());
  }

  Result<string> read = os::read(s->out().get(), sizeof(DONE));
  if (!read.isSome() || read.get() != string(sizeof(DONE), DONE)) {
    cleanup();
    return Error("Failed to sync with the subprocess");
  }

  return Nothing();
}
开发者ID:OvertimeDog,项目名称:mesos,代码行数:22,代码来源:memory_test_helper.cpp

示例11: checkpoint

Try<Nothing> checkpoint(
    const string& path,
    const google::protobuf::Message& message)
{
  // Create the base directory.
  Try<Nothing> result = os::mkdir(os::dirname(path).get());
  if (result.isError()) {
    return Error("Failed to create directory '" + os::dirname(path).get() +
                 "': " + result.error());
  }

  // Now checkpoint the protobuf to disk.
  result = ::protobuf::write(path, message);
  if (result.isError()) {
    return Error("Failed to checkpoint \n" + message.DebugString() +
                 "\n to '" + path + "': " + result.error());
  }

  return Nothing();
}
开发者ID:aelovikov,项目名称:mesos,代码行数:20,代码来源:state.cpp

示例12: check

Try<Nothing> check()
{
  // As advised in libnl, we use numeric values, instead of defined
  // macros (which creates compile time dependency), to check
  // capabilities.

  // Check NL_CAPABILITY_ROUTE_LINK_VETH_GET_PEER_OWN_REFERENCE.
  if (nl_has_capability(2) == 0) {
    return Error(
        "Capability ROUTE_LINK_VETH_GET_PEER_OWN_REFERENCE is not available");
  }

  // Check NL_CAPABILITY_ROUTE_LINK_CLS_ADD_ACT_OWN_REFERENCE.
  if (nl_has_capability(3) == 0) {
    return Error(
        "Capability ROUTE_LINK_CLS_ADD_ACT_OWN_REFERENCE is not available");
  }

  return Nothing();
}
开发者ID:Bbarrett,项目名称:mesos,代码行数:20,代码来源:utils.cpp

示例13: untar

Future<Nothing> untar(
    const Path& input,
    const Option<Path>& directory)
{
  vector<string> argv = {
    "tar",
    "-x",  // Extract/unarchive.
    "-f",  // Input file to extract/unarchive.
    input
  };

  // Add additional flags.
  if (directory.isSome()) {
    argv.emplace_back("-C");
    argv.emplace_back(directory.get());
  }

  return launch("tar", argv)
    .then([] () {return Nothing();});
}
开发者ID:LastRitter,项目名称:mesos,代码行数:20,代码来源:command_utils.cpp

示例14: CancelAllListeners

void
VectorImage::OnSVGDocumentError()
{
  CancelAllListeners();

  mError = true;

  if (mProgressTracker) {
    // Notify observers about the error and unblock page load.
    Progress progress = FLAG_ONLOAD_UNBLOCKED | FLAG_HAS_ERROR;

    // Merge in any saved progress from OnImageDataComplete.
    if (mLoadProgress) {
      progress |= *mLoadProgress;
      mLoadProgress = Nothing();
    }

    mProgressTracker->SyncNotifyProgress(progress);
  }
}
开发者ID:MekliCZ,项目名称:positron,代码行数:20,代码来源:VectorImage.cpp

示例15: checkpoint

Try<Nothing> checkpoint(const std::string& path, const std::string& message)
{
  std::cout << "Checkpointing '" << message << "' to '" << path << "'"
            << std::endl;

  // Create the base directory.
  Try<Nothing> result = os::mkdir(os::dirname(path).get());
  if (result.isError()) {
    return Error("Failed to create directory '" + os::dirname(path).get() +
                 "': " + result.error());
  }

  // Now checkpoint the message to disk.
  result = os::write(path, message);
  if (result.isError()) {
    return Error("Failed to checkpoint '" + message + "' to '" + path +
                 "': " + result.error());
  }

  return Nothing();
}
开发者ID:CommBank,项目名称:mesos,代码行数:21,代码来源:state.cpp


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