本文整理汇总了C++中Status::ToString方法的典型用法代码示例。如果您正苦于以下问题:C++ Status::ToString方法的具体用法?C++ Status::ToString怎么用?C++ Status::ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Status
的用法示例。
在下文中一共展示了Status::ToString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SaveError
static bool SaveError(char** errptr, const Status& s) {
assert(errptr != NULL);
if (s.ok()) {
return false;
} else if (*errptr == NULL) {
*errptr = strdup(s.ToString().c_str());
} else {
// TODO(sanjay): Merge with existing error?
free(*errptr);
*errptr = strdup(s.ToString().c_str());
}
return true;
}
示例2: main
int main(int argc, char** argv)
{
DB* db;
Options options;
options.create_if_missing = true;
Status status = DB::Open(options, "/tmp/leveldbtest", &db);
if (false == status.ok()) {
cerr << "Unable to open/create test database" << endl;
cerr << status.ToString() << endl;
return 1;
}
// write
WriteOptions writeOptions;
for (unsigned int i = 0; i < 256; ++i) {
ostringstream keyStream;
keyStream << "Key" << i;
ostringstream valueStream;
valueStream << "Test data value: " << i;
db->Put(writeOptions, keyStream.str(), valueStream.str());
this_thread::sleep_for(std::chrono::seconds(1));
}
// Close the database
delete db;
return 0;
}
示例3: main
int main(int argc, char** argv)
{
DB* db;
Options options;
options.create_if_missing = true;
Status status = DB::Open(options, "/tmp/leveldbtest", &db);
if (false == status.ok()) {
cerr << "Unable to open/create test database" << endl;
cerr << status.ToString() << endl;
return 1;
}
// read
int i = 0;
leveldb::Iterator* it = db->NewIterator(leveldb::ReadOptions());
for (it->SeekToFirst(); it->Valid(); it->Next()) {
i++;
cout << it->key().ToString() << " : " << it->value().ToString() << endl;
this_thread::sleep_for(std::chrono::seconds(1));
}
cout << "i=" << i << endl;
if (false == it->status().ok()) {
cerr << "An error was found during the scan" << endl;
cerr << it->status().ToString() << endl;
}
delete it;
// Close the database
delete db;
return 0;
}
示例4: open
void LevFormulaDb::open(const char* path) throw (runtime_error) {
Options options;
options.create_if_missing = false;
Status status = DB::Open(options, path, &mDatabase);
if (!status.ok()) {
throw runtime_error(status.ToString());
}
}
示例5: create_new
/** @throw runtime_error */
void LevCrawlDb::create_new(const char* path,
bool deleteIfExists) {
if (deleteIfExists) {
(void)DestroyDB(path, Options());
}
Options options;
options.error_if_exists = true;
options.create_if_missing = true;
Status status = DB::Open(options, path, &mDatabase);
if (!status.ok()) {
throw std::runtime_error(status.ToString());
}
}
示例6: fsck
int fsck(int argc, char** argv) {
const char* path;
if(argc == 2) {
path = argv[1];
} else {
path = "./harq.db";
}
std::cout << "Checking " << path << "...\n";
Options opts;
opts.paranoid_checks = true;
ReadOptions ro;
ro.verify_checksums = true;
DB* db;
Status s = DB::Open(opts, path, &db);
if(!s.ok()) {
std::cout << "Unable to open: " << s.ToString() << "\n";
return 1;
}
std::string val;
wire::QueueConfiguration cfg;
s = db->Get(ro, "!harq.config", &val);
if(!s.ok()) {
std::cout << "Unable to read configuration: " << s.ToString() << "\n";
return 1;
}
if(!cfg.ParseFromString(val)) {
std::cout << "Corrupt configuration detected.\n";
return 1;
}
std::cout << cfg.queues_size() << " queues detected.\n";
bool some_bad = false;
for(int i = 0; i < cfg.queues_size(); i++) {
const wire::QueueDeclaration& decl = cfg.queues(i);
std::cout << "name: " << decl.name() << "\n";
switch(decl.type()) {
case wire::QueueDeclaration::eBroadcast:
std::cout << " type: broadcast\n";
break;
case wire::QueueDeclaration::eTransient:
std::cout << " type: transient\n";
break;
case wire::QueueDeclaration::eDurable:
std::cout << " type: durable\n";
break;
default:
std::cout << " type: UNKNOWN(" << decl.type() << ")\n";
break;
}
s = db->Get(ro, decl.name(), &val);
if(!s.ok()) {
std::cout << " Unable to find queue on disk!\n";
} else {
wire::Queue qi;
if(!qi.ParseFromString(val)) {
std::cout << " Queue information corrupt on disk!\n";
} else {
std::cout << " total messages: " << qi.size() << "\n"
<< " ranges:\n";
for(int j = 0; j < qi.ranges_size(); j++) {
const wire::MessageRange& range = qi.ranges(j);
std::cout << " " << range.start() << " - "
<< range.start() + range.count() << "\n";
}
int valid = 0;
for(int j = 0; j < qi.ranges_size(); j++) {
const wire::MessageRange& range = qi.ranges(j);
int fin = range.start() + range.count();
for(int m = range.start(); m < fin; m++) {
std::stringstream tmp;
tmp << decl.name() << ":" << m;
s = db->Get(ro, tmp.str(), &val);
if(!s.ok()) {
std::cerr << "Missing message '" << tmp.str() << "'\n";
} else {
wire::Message msg;
if(!msg.ParseFromString(val)) {
some_bad = true;
std::cerr << "Corrupt message detected '" << tmp.str() << "'\n";
} else {
valid++;
//.........这里部分代码省略.........
示例7:
extern "C" void Java_com_sogou_leveldblib_LevelDB_test(JNIEnv* env, jobject thiz)
{
bool ret;
Status statue;
KvDB kvdb;
ret = kvdb.open("/sdcard/beijing/beijing.navi", "sdcard/beijing/beijing.index");
if(ret)
LOGI("kvdb open success");
else
{
LOGE("kvdb open failed, %s", statue.ToString().data());
return ;
}
LevelDB leveldb;
statue = leveldb.open("/sdcard/tmp/leveldb/", "beijing", false, true);
if(statue.ok())
LOGI("leveldb open success");
else
{
LOGE("leveldb open failed, %s", statue.ToString().data());
return ;
}
int index;
string data[] = {"Hello", "World", "NaviLink", "Sogou", "beijing", "Good"};
leveldb.atomReady();
for(int i = 0 ; i < sizeof(data)/sizeof(std::string) ; i++)
{
statue = leveldb.insert(LevelDB::KEY_HEAD_ROADNAME, i, data[i]);
if(!statue.ok())
{
LOGE("leveldb insert failed, %s", statue.ToString().data());
return ;
}
}
leveldb.atomCommit();
// leveldb.atomReady();
// while((index = kvdb.getRecord(data)) != 0)
// {
// statue = leveldb.insert(0x0001, index, data);
// if(!statue.ok())
// {
// LOGE("leveldb insert failed, %s", statue.ToString().data());
// return ;
// }
// }
// leveldb.atomCommit();
LOGE("leveldb insert %s", statue.ToString().data());
leveldb.close();
statue = leveldb.make();
if(statue.ok() == false)
{
LOGI("leveldb make error");
LOGI(statue.ToString().data());
}
else
{
LOGI("leveldb make success");
}
statue = leveldb.open("/sdcard/tmp/leveldb/", "beijing", true, false);
if(statue.ok())
LOGI("leveldb open success");
else
{
LOGE("leveldb open failed %s", statue.ToString().data());
return ;
}
string queryResult;
for(int i = 0 ; i < sizeof(data)/sizeof(std::string) ; i++)
{
statue = leveldb.query(LevelDB::KEY_HEAD_ROADNAME, i, queryResult);
if(!statue.ok())
{
LOGE("leveldb insert failed, %s", statue.ToString().data());
return ;
}
LOGE("query result %s", queryResult.data());
}
// std::string value;
//// LevelDB::makeKey(0x1122, 0x33445566778899aa, key);
// statue = leveldb.query(key, value);
// if(statue.ok())
// LOGI("leveldb query success, %s", value.data());
// else
// {
// LOGE("leveldb query failed, %s", statue.ToString().data());
//// return ;
// }
//.........这里部分代码省略.........
示例8: TmpDir
std::string TmpDir() {
std::string dir;
Status s = Env::Default()->GetTestDirectory(&dir);
ASSERT_TRUE(s.ok()) << s.ToString();
return dir;
}