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


C++ BSONObj::end方法代码示例

本文整理汇总了C++中BSONObj::end方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONObj::end方法的具体用法?C++ BSONObj::end怎么用?C++ BSONObj::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BSONObj的用法示例。


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

示例1: BSONInputStream

/* 
 * Executes the migration of the indexes format that were saved before 0.3
 **/
void DBController::migrateIndex0_3(const char* db, const char* ns, InputStream* stream, IndexAlgorithm* impl) {
	long currentPos = stream->currentPos();
	stream->seek(0);

	int records = 0;
	BSONInputStream* bis = new BSONInputStream(stream);
	while (!stream->eof()) {
		BSONObj* obj = bis->readBSON();

		if (!impl) {
			std::set<std::string> skeys;
			for (BSONObj::const_iterator i = obj->begin(); i != obj->end(); i++) {
				std::string key = i->first;
				skeys.insert(key);
			}
		}
		long indexPos = stream->readLong();
		long posData = stream->readLong();
		if (obj->has("_id")) {
			insertIndex(db, ns, obj, posData);
			records++;
		}
		delete obj;
	}

	stream->close();

	if (_logger->isInfo()) _logger->info("db: %s, ns: %s, Index migrated to version 0.3. Records: %d", db, ns, records);

	delete bis;
}
开发者ID:FikiHafana,项目名称:djondb,代码行数:34,代码来源:dbcontroller.cpp

示例2: writeBSON

void BSONOutputStream::writeBSON(const BSONObj& bson) {
	Logger* log = getLogger(NULL);
	if (log->isDebug()) log->debug("BSONOutputStream::writeBSON bson elements: %d", bson.length());
    _outputStream->writeLong(bson.length());
    for (std::map<t_keytype, BSONContent* >::const_iterator i = bson.begin(); i != bson.end(); i++) {
        t_keytype key = i->first;
		  if (log->isDebug()) log->debug("BSONOutputStream::writeBSON name: %s", key.c_str());
        _outputStream->writeString(key);
        BSONContent* cont = i->second;
		  // If the type is PTRCHAR_TYPE change it to string_type, to remove this type in future
        _outputStream->writeLong(cont->type() != PTRCHAR_TYPE? cont->type(): STRING_TYPE);
        char* text;
		  BSONObj* inner;
        switch (cont->type()) {
            case BSON_TYPE:
                inner = (BSONObj*)cont->_element;
					 writeBSON(*inner); 
                break;
            case INT_TYPE:
                _outputStream->writeInt(*((int*)cont->_element));
                break;
            case LONG_TYPE:
                _outputStream->writeLong(*((long*)cont->_element));
                break;
            case DOUBLE_TYPE:
                _outputStream->writeDoubleIEEE(*((double*)cont->_element));
                break;
            case PTRCHAR_TYPE:
                text = (char*)cont->_element;
                _outputStream->writeString(std::string(text));
                break;
				case STRING_TYPE:
					 {
						 string* str = (string*)cont->_element;
						 _outputStream->writeString(*str);
						 break;
					 }
				case BSONARRAY_TYPE: 
					 {
						 BSONArrayObj* array = (BSONArrayObj*)cont->_element;
						 writeBSONArray(array);
						 break;
					 }
		  }
	 }
	 delete log;
}
开发者ID:hecogo,项目名称:djondb,代码行数:47,代码来源:bsonoutputstream.cpp


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