本文整理汇总了C++中ConfigVar::write方法的典型用法代码示例。如果您正苦于以下问题:C++ ConfigVar::write方法的具体用法?C++ ConfigVar::write怎么用?C++ ConfigVar::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigVar
的用法示例。
在下文中一共展示了ConfigVar::write方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toVar
ConfigVar ConfigReader::toVar() const {
// write everything to a ConfigVar, then output to disk
ConfigVar out;
out.writeInt(vars.size());
map<string, ConfigVar>::const_iterator it;
for (it = vars.begin(); it != vars.end(); ++it) {
out.writeInt(it->first.size());
out.write((unsigned char *)it->first.data(), it->first.size());
out.writeInt(it->second.size());
out.write((unsigned char *)it->second.buffer(), it->second.size());
}
return out;
}
示例2: load
// read the entire file into a ConfigVar instance and then use that to decode
// into mapped variables.
bool ConfigReader::load(const char *fileName) {
struct stat_st stbuf;
memset(&stbuf, 0, sizeof(struct stat_st));
if (unix::lstat(fileName, &stbuf) != 0) return false;
int size = stbuf.st_size;
int fd = unix::open(fileName, O_RDONLY);
if (fd < 0) return false;
char *buf = new char[size];
int res = ::_read(fd, buf, size);
close(fd);
if (res != size) {
rWarning("Partial read of config file, expecting %i bytes, got %i", size,
res);
delete[] buf;
return false;
}
ConfigVar in;
in.write((unsigned char *)buf, size);
delete[] buf;
return loadFromVar(in);
}
示例3: load
// read the entire file into a ConfigVar instance and then use that to decode
// into mapped variables.
bool ConfigReader::load(const char *fileName) {
struct stat stbuf;
memset(&stbuf, 0, sizeof(struct stat));
if (lstat(fileName, &stbuf) != 0) return false;
int size = stbuf.st_size;
int fd = open(fileName, O_RDONLY);
if (fd < 0) return false;
char *buf = new char[size];
int res = ::read(fd, buf, size);
close(fd);
if (res != size) {
RLOG(WARNING) << "Partial read of config file, expecting " << size
<< " bytes, got " << res;
delete[] buf;
return false;
}
ConfigVar in;
in.write((unsigned char *)buf, size);
delete[] buf;
return loadFromVar(in);
}