本文整理汇总了C++中Local::WriteAscii方法的典型用法代码示例。如果您正苦于以下问题:C++ Local::WriteAscii方法的具体用法?C++ Local::WriteAscii怎么用?C++ Local::WriteAscii使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Local
的用法示例。
在下文中一共展示了Local::WriteAscii方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Undefined
Handle<Value> EnvWrap::open(const Arguments& args) {
HandleScope scope;
int rc;
int flags = 0;
// Get the wrapper
EnvWrap *ew = ObjectWrap::Unwrap<EnvWrap>(args.This());
if (!ew->env) {
ThrowException(Exception::Error(String::New("The environment is already closed.")));
return Undefined();
}
Local<Object> options = args[0]->ToObject();
Local<String> path = options->Get(String::NewSymbol("path"))->ToString();
rc = applyUint32Setting(&mdb_env_set_maxdbs, ew->env, options, 1, "maxDbs");
if (rc != 0) {
ThrowException(Exception::Error(String::New(mdb_strerror(rc))));
return Undefined();
}
rc = applyUint32Setting(&mdb_env_set_mapsize, ew->env, options, 10485760, "mapSize");
if (rc != 0) {
ThrowException(Exception::Error(String::New(mdb_strerror(rc))));
return Undefined();
}
// TODO: expose mdb_env_set_maxreaders
// NOTE: MDB_FIXEDMAP is not exposed here since it is "highly experimental" + it is irrelevant for this use case
// NOTE: MDB_NOTLS is not exposed here because it is irrelevant for this use case, as node will run all this on a single thread anyway
setFlagFromValue(&flags, MDB_NOSUBDIR, "noSubdir", false, options);
setFlagFromValue(&flags, MDB_RDONLY, "readOnly", false, options);
setFlagFromValue(&flags, MDB_WRITEMAP, "useWritemap", false, options);
setFlagFromValue(&flags, MDB_NOMETASYNC, "noMetaSync", false, options);
setFlagFromValue(&flags, MDB_NOSYNC, "noSync", false, options);
setFlagFromValue(&flags, MDB_MAPASYNC, "mapAsync", false, options);
int l = path->Length();
char *cpath = new char[l + 1];
path->WriteAscii(cpath);
cpath[l] = 0;
// TODO: make file attributes configurable
rc = mdb_env_open(ew->env, cpath, flags, 0664);
if (rc != 0) {
mdb_env_close(ew->env);
ew->env = NULL;
ThrowException(Exception::Error(String::New(mdb_strerror(rc))));
return Undefined();
}
return Undefined();
}
示例2: DecodeWrite
// Returns number of bytes written.
ssize_t DecodeWrite(char *buf,
size_t buflen,
Handle<Value> val,
enum encoding encoding) {
HandleScope scope;
// XXX
// A lot of improvement can be made here. See:
// http://code.google.com/p/v8/issues/detail?id=270
// http://groups.google.com/group/v8-dev/browse_thread/thread/dba28a81d9215291/ece2b50a3b4022c
// http://groups.google.com/group/v8-users/browse_thread/thread/1f83b0ba1f0a611
if (val->IsArray()) {
fprintf(stderr, "'raw' encoding (array of integers) has been removed. "
"Use 'binary'.\n");
assert(0);
return -1;
}
Local<String> str = val->ToString();
if (encoding == UTF8) {
str->WriteUtf8(buf, buflen, NULL, String::HINT_MANY_WRITES_EXPECTED);
return buflen;
}
if (encoding == ASCII) {
str->WriteAscii(buf, 0, buflen, String::HINT_MANY_WRITES_EXPECTED);
return buflen;
}
// THIS IS AWFUL!!! FIXME
assert(encoding == BINARY);
uint16_t * twobytebuf = new uint16_t[buflen];
str->Write(twobytebuf, 0, buflen, String::HINT_MANY_WRITES_EXPECTED);
for (size_t i = 0; i < buflen; i++) {
unsigned char *b = reinterpret_cast<unsigned char*>(&twobytebuf[i]);
buf[i] = b[0];
}
delete [] twobytebuf;
return buflen;
}
示例3: context_get_bin
// [[Rcpp::export]]
Rcpp::RawVector context_get_bin(std::string name, Rcpp::XPtr< v8::Persistent<v8::Context> > ctx) {
// Test if context still exists
if(!ctx)
throw std::runtime_error("Context has been disposed.");
// Create scope
HandleScope handle_scope;
Context::Scope context_scope(*ctx);
v8::Handle<v8::Object> global = (*ctx)->Global();
//find the string
Local<v8::String> mystring = global->Get(String::NewSymbol(name.c_str()))->ToString();
Rcpp::RawVector res(mystring->Length());
mystring->WriteAscii((char*) res.begin());
return res;
}