本文整理汇总了C++中mongo::BSONElement::valuestrsize方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONElement::valuestrsize方法的具体用法?C++ BSONElement::valuestrsize怎么用?C++ BSONElement::valuestrsize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongo::BSONElement
的用法示例。
在下文中一共展示了BSONElement::valuestrsize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: return_string
Datum convert_element<std::string>(PG_FUNCTION_ARGS, const mongo::BSONElement e)
{
std::stringstream ss;
switch(e.type())
{
case mongo::String:
case mongo::DBRef:
case mongo::Symbol:
return return_string(std::string(e.valuestr(), e.valuestrsize()-1));
case mongo::NumberDouble:
ss << e._numberDouble();
break;
case mongo::jstOID:
ss << e.__oid().str();
break;
case mongo::Bool:
ss << std::boolalpha << e.boolean();
break;
case mongo::Date:
return return_string(
to_iso_extended_string(
boost::posix_time::ptime(
boost::gregorian::date(1970, 1, 1),
boost::posix_time::milliseconds(e.date().millis)
)
)
);
case mongo::RegEx:
ss << e.regex();
break;
case mongo::NumberInt:
ss << e._numberInt();
break;
case mongo::NumberLong:
ss << e._numberLong();
break;
default:
throw convertion_error("text");
}
return return_string(ss.str());
}
示例2: buildJsonString
void buildJsonString(const mongo::BSONElement &elem,std::string &con, UUIDEncoding uuid, SupportedTimes tz)
{
switch (elem.type())
{
case NumberDouble:
{
char dob[32] = {0};
sprintf(dob, "%f", elem.Double());
con.append(dob);
}
break;
case String:
{
con.append(elem.valuestr(), elem.valuestrsize() - 1);
}
break;
case Object:
{
buildJsonString(elem.Obj(), con, uuid, tz);
}
break;
case Array:
{
buildJsonString(elem.Obj(), con, uuid, tz);
}
break;
case BinData:
{
mongo::BinDataType binType = elem.binDataType();
if (binType == mongo::newUUID || binType == mongo::bdtUUID) {
std::string uu = HexUtils::formatUuid(elem, uuid);
con.append(uu);
break;
}
con.append("<binary>");
}
break;
case Undefined:
con.append("<undefined>");
break;
case jstOID:
{
std::string idValue = elem.OID().toString();
char buff[256] = {0};
sprintf(buff, "ObjectId(\"%s\")", idValue.c_str());
con.append(buff);
}
break;
case Bool:
con.append(elem.Bool() ? "true" : "false");
break;
case Date:
{
long long ms = (long long) elem.Date().millis;
boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
boost::posix_time::time_duration diff = boost::posix_time::millisec(ms);
boost::posix_time::ptime time = epoch + diff;
std::string date = miutil::isotimeString(time,false,tz==LocalTime);
con.append(date);
break;
}
case jstNULL:
con.append("<null>");
break;
case RegEx:
{
con.append("/" + std::string(elem.regex()) + "/");
for ( const char *f = elem.regexFlags(); *f; ++f ) {
switch ( *f ) {
case 'g':
case 'i':
case 'm':
con+=*f;
default:
break;
}
}
}
break;
case DBRef:
break;
case Code:
con.append(elem._asCode());
break;
case Symbol:
con.append(elem.valuestr(), elem.valuestrsize() - 1);
break;
case CodeWScope:
{
mongo::BSONObj scope = elem.codeWScopeObject();
if (!scope.isEmpty() ) {
con.append(elem._asCode());
break;
}
}
//.........这里部分代码省略.........