本文整理汇总了C++中Nothing函数的典型用法代码示例。如果您正苦于以下问题:C++ Nothing函数的具体用法?C++ Nothing怎么用?C++ Nothing使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Nothing函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: initialize
Try<Nothing> initialize(const mesos::Parameters& parameters)
{
foreach (const mesos::Parameter& parameter, parameters.parameter()) {
if (parameter.has_key() && parameter.has_value()) {
flags[parameter.key()] = parameter.value();
} else {
return Error("Invalid key-value parameters");
}
}
// We expect that when specifying the module, a module parameter
// was also specified, i.e.:
// "modules": [{"name": "org_apache_mesos_TestModule",
// "flags": [{"key": "operation", "value": "sum"}]}]
// The expected value for the key "operation" is "sum".
if (flags.contains("operation") && flags["operation"] != "sum") {
return Error("Invalid 'operation'");
}
return Nothing();
}
开发者ID:abhishekamralkar,项目名称:mesos,代码行数:21,代码来源:example_module_impl.cpp
示例17: write
// Write out the given protobuf to the specified file descriptor by
// first writing out the length of the protobuf followed by the contents.
// NOTE: On error, this may have written partial data to the file.
inline Try<Nothing> write(int fd, const google::protobuf::Message& message)
{
if (!message.IsInitialized()) {
return Error("Uninitialized protocol buffer");
}
// First write the size of the protobuf.
uint32_t size = message.ByteSize();
std::string bytes = std::string((char*) &size, sizeof(size));
Try<Nothing> result = os::write(fd, bytes);
if (result.isError()) {
return Error("Failed to write size: " + result.error());
}
if (!message.SerializeToFileDescriptor(fd)) {
return Error("Failed to write/serialize message");
}
return Nothing();
}
开发者ID:WuErPing,项目名称:mesos,代码行数:24,代码来源:protobuf.hpp
示例18: write
// Write out the string to the file at the current fd position.
inline Try<Nothing> write(int fd, const std::string& message)
{
size_t offset = 0;
while (offset < message.length()) {
ssize_t length =
::write(fd, message.data() + offset, message.length() - offset);
if (length < 0) {
// TODO(benh): Handle a non-blocking fd? (EAGAIN, EWOULDBLOCK)
if (errno == EINTR) {
continue;
}
return ErrnoError();
}
offset += length;
}
return Nothing();
}
开发者ID:dhardy92,项目名称:mesos,代码行数:22,代码来源:os.hpp
示例19: tar
Future<Nothing> tar(
const Path& input,
const Path& output,
const Option<Path>& directory,
const Option<Compression>& compression)
{
vector<string> argv = {
"tar",
"-c", // Create archive.
"-f", // Output file.
output
};
// Add additional flags.
if (directory.isSome()) {
argv.emplace_back("-C");
argv.emplace_back(directory.get());
}
if (compression.isSome()) {
switch (compression.get()) {
case Compression::GZIP:
argv.emplace_back("-z");
break;
case Compression::BZIP2:
argv.emplace_back("-j");
break;
case Compression::XZ:
argv.emplace_back("-J");
break;
default:
UNREACHABLE();
}
}
argv.emplace_back(input);
return launch("tar", argv)
.then([] () {return Nothing();});
}
开发者ID:LastRitter,项目名称:mesos,代码行数:40,代码来源:command_utils.cpp
示例20: copyToLocal
Try<Nothing> copyToLocal(
const std::string& from,
const std::string& to)
{
// Copy from HDFS.
Try<std::string> command = strings::format(
"%s fs -copyToLocal '%s' '%s'", hadoop, from, to);
CHECK_SOME(command);
std::ostringstream output;
Try<int> status = os::shell(&output, command.get() + " 2>&1");
if (status.isError()) {
return Error(status.error());
} else if (status.get() != 0) {
return Error(command.get() + "\n" + output.str());
}
return Nothing();
}
开发者ID:Bbarrett,项目名称:mesos,代码行数:22,代码来源:hdfs.hpp
注:本文中的Nothing函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论