本文整理汇总了C++中BSONObj::getXpath方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONObj::getXpath方法的具体用法?C++ BSONObj::getXpath怎么用?C++ BSONObj::getXpath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONObj
的用法示例。
在下文中一共展示了BSONObj::getXpath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testParserRelation
void testParserRelation()
{
cout << "testParserRelation" << endl;
BSONObj* obj = BSONParser::parse("{age: 1, name: 'John', rel1: {innertext: 'inner text', salary: 150000, rent: 10000}}");
TEST_ASSERT(obj->has("age"));
TEST_ASSERT(obj->getInt("age") == 1);
TEST_ASSERT(obj->has("name"));
TEST_ASSERT(strcmp(obj->getString("name"), "John") == 0);
__int32 salary = *obj->getXpath("rel1.salary");
TEST_ASSERT(salary == 150000);
__int32 rent = *obj->getXpath("rel1.rent");
TEST_ASSERT(rent == 10000);
TEST_ASSERT(obj->getBSON("rel1") != NULL);
TEST_ASSERT(strcmp(obj->getBSON("rel1")->getString("innertext"), "inner text") == 0);
delete obj;
}
示例2: getXpath
BSONContent* BSONObj::getXpath(const std::string& xpath) const {
__int32 posDot = xpath.find('.');
BSONContent* result = NULL;
if (posDot == string::npos) {
result = getContent(xpath);
} else {
std::string path = xpath.substr(0, posDot);
result = getContent(path);
if ((result != NULL) && (result->type() == BSON_TYPE)) {
BSONContentBSON* bcontent = (BSONContentBSON*)result;
BSONObj* inner = (BSONObj*)*bcontent;
result = inner->getXpath(xpath.substr(posDot + 1));
}
}
if (result != NULL) {
return result->clone();
} else {
return NULL;
}
}