本文整理汇总了C++中mongo::BSONObj::hasField方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONObj::hasField方法的具体用法?C++ BSONObj::hasField怎么用?C++ BSONObj::hasField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongo::BSONObj
的用法示例。
在下文中一共展示了BSONObj::hasField方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DoHost
void Processer::DoHost(const std::string& grid,const std::string& cluster,mongo::BSONObj& host)
{
std::string host_id;
std::cout << host << std::endl;
if(host.hasField("host_ID") && host.hasField("heartbeat"))
{
//deal the record with host level
//do not need to cut it off
DBModules::iterator iter = db_modules_.begin();
for(;iter!=db_modules_.end();++iter)
{
iter->handler(host.objdata(),host.objsize(),NULL);
}
// host_id = host.getStringField("host_ID");
// std::vector<mongo::BSONElement> ele;
// host.elems(ele);
// for(int i=0;i<ele.size();i++)
// {
// if((!strcmp(ele[i].fieldName(),"host_ID")) ||
// (!strcmp(ele[i].fieldName(),"heartbeat")))
// {
// continue;
// }
// else
// {
// std::string ds_name = ele[i].fieldName();
// std::string path;
// if(grid!="")
// path = grid + '/' + cluster + '/' + host_id;
// else
// path = cluster + '/' + host_id;
// mongo::BSONObj obj = ele[i].wrap();
// std::cout << obj << std::endl;
// std::list<void(*)(const char*,int,const char*)>::iterator iter;
// iter = callback_[ds_name].begin();
// for(;iter!=callback_[ds_name].end();++iter)
// {
// (*iter)(obj.objdata(),obj.objsize(),path.c_str());
// }
// }
// }
}
else
{
std::stringstream oss;
oss << "This data is illegal! Drop!!";
LOG4CXX_WARN(log_,oss.str());
}
}
示例2:
RepoBSON::RepoBSON(
const mongo::BSONObj &obj,
const std::unordered_map<std::string, std::pair<std::string, std::vector<uint8_t>>> &binMapping)
: mongo::BSONObj(obj),
bigFiles(binMapping)
{
std::vector<std::pair<std::string, std::string>> existingFiles;
if (bigFiles.size() > 0)
{
mongo::BSONObjBuilder builder, arrbuilder;
for (const auto & pair : bigFiles)
{
//append field name :file name
arrbuilder << pair.first << pair.second.first;
}
if (obj.hasField(REPO_LABEL_OVERSIZED_FILES))
{
arrbuilder.appendElementsUnique(obj.getObjectField(REPO_LABEL_OVERSIZED_FILES));
}
builder.append(REPO_LABEL_OVERSIZED_FILES, arrbuilder.obj());
builder.appendElementsUnique(obj);
*this = builder.obj();
bigFiles = binMapping;
}
}
示例3: RepoNodeAbstract
repo::core::RepoNodeTexture::RepoNodeTexture(const mongo::BSONObj &obj)
: RepoNodeAbstract(obj)
, data(NULL)
{
//
// Width
//
if (obj.hasField(REPO_LABEL_WIDTH))
width = obj.getField(REPO_LABEL_WIDTH).numberInt();
//
// Height
//
if (obj.hasField(REPO_LABEL_HEIGHT))
height = obj.getField(REPO_LABEL_HEIGHT).numberInt();
//
// Format
//
if (obj.hasField(REPO_NODE_LABEL_EXTENSION)) {
extension = obj.getField(REPO_NODE_LABEL_EXTENSION).str();
name += "." + extension; // assimp needs full names with extension
}
//
// Bit depth
//
//if (obj.hasField(REPO_NODE_LABEL_BIT_DEPTH))
// bitDepth = obj.getField(REPO_NODE_LABEL_BIT_DEPTH).numberInt();
//
// Data
//
if (obj.hasField(REPO_LABEL_DATA) &&
obj.hasField(REPO_NODE_LABEL_DATA_BYTE_COUNT))
{
std::cerr << "Texture" << std::endl;
data = new std::vector<char>();
RepoTranscoderBSON::retrieve(
obj.getField(REPO_LABEL_DATA),
obj.getField(REPO_NODE_LABEL_DATA_BYTE_COUNT).numberInt(),
data);
}
}
示例4: Handle
void Processer::Handle(mongo::BSONObj& bson)
{
//handle the bson
//maybe grid-bosn;maybe cluster-bson
std::string grid_id;
if(bson.hasField("grid_ID") && bson.hasField("cluster_data"))
{
grid_id = bson.getStringField("grid_ID");
std::vector<mongo::BSONElement> c_ele = bson["cluster_data"].Array();
for(int i=0;i<c_ele.size();i++)
{
mongo::BSONObj obj = c_ele[i].Obj();
DoCluster(grid_id,obj);
}
}
else
{
grid_id = "";
DoCluster(grid_id,bson);
}
}
示例5: DoCluster
void Processer::DoCluster(const std::string& grid,mongo::BSONObj& cluster)
{
std::string cluster_id;
if(cluster.hasField("cluster_ID") && cluster.hasField("host_data"))
{
cluster_id = cluster.getStringField("cluster_ID");
std::vector<mongo::BSONElement> h_ele = cluster["host_data"].Array();
for(int i=0;i<h_ele.size();i++)
{
mongo::BSONObj obj = h_ele[i].Obj();
DoHost(grid,cluster_id,obj);
}
}
else
{
std::stringstream oss;
oss << "This data is illegal! Drop!!";
LOG4CXX_WARN(log_,oss.str());
std::cout << cluster << std::endl;
}
}
示例6: RepoNodeAbstract
repo::core::RepoNodeCamera::RepoNodeCamera(const mongo::BSONObj &obj)
: RepoNodeAbstract(obj)
{
//--------------------------------------------------------------------------
// Aspect ratio
if (obj.hasField(REPO_NODE_LABEL_ASPECT_RATIO))
aspectRatio = (float)
obj.getField(REPO_NODE_LABEL_ASPECT_RATIO).numberDouble();
//--------------------------------------------------------------------------
// Far clipping plane
if (obj.hasField(REPO_NODE_LABEL_FAR))
farClippingPlane = (float)
obj.getField(REPO_NODE_LABEL_FAR).numberDouble();
//--------------------------------------------------------------------------
// Near clipping plane
if (obj.hasField(REPO_NODE_LABEL_NEAR))
nearClippingPlane = (float)
obj.getField(REPO_NODE_LABEL_NEAR).numberDouble();
//--------------------------------------------------------------------------
// Field of view
if (obj.hasField(REPO_NODE_LABEL_FOV))
fieldOfView = (float)
obj.getField(REPO_NODE_LABEL_FOV).numberDouble();
//--------------------------------------------------------------------------
// Look at vector
if (obj.hasField(REPO_NODE_LABEL_LOOK_AT))
lookAt = RepoTranscoderBSON::retrieveVector3D(
obj.getField(REPO_NODE_LABEL_LOOK_AT));
//--------------------------------------------------------------------------
// Position vector
if (obj.hasField(REPO_NODE_LABEL_POSITION))
position = RepoTranscoderBSON::retrieveVector3D(
obj.getField(REPO_NODE_LABEL_POSITION));
//--------------------------------------------------------------------------
// Up vector
if (obj.hasField(REPO_NODE_LABEL_UP))
up = RepoTranscoderBSON::retrieveVector3D(
obj.getField(REPO_NODE_LABEL_UP));
}
示例7: getFieldF
/* ****************************************************************************
*
* ContextElementResponse::ContextElementResponse -
*
* This constructor builds the CER object based in a BSON object taken from the
* entities collection at DB.
*
* Note that statusCode is not touched by this constructor.
*/
ContextElementResponse::ContextElementResponse
(
const mongo::BSONObj& entityDoc,
const AttributeList& attrL,
bool includeEmpty,
const std::string& apiVersion
)
{
prune = false;
// Entity
BSONObj id = getFieldF(entityDoc, "_id").embeddedObject();
std::string entityId = getStringFieldF(id, ENT_ENTITY_ID);
std::string entityType = id.hasField(ENT_ENTITY_TYPE) ? getStringFieldF(id, ENT_ENTITY_TYPE) : "";
contextElement.entityId.fill(entityId, entityType, "false");
contextElement.entityId.servicePath = id.hasField(ENT_SERVICE_PATH) ? getStringFieldF(id, ENT_SERVICE_PATH) : "";
/* Get the location attribute (if it exists) */
std::string locAttr;
if (entityDoc.hasElement(ENT_LOCATION))
{
locAttr = getStringFieldF(getObjectFieldF(entityDoc, ENT_LOCATION), ENT_LOCATION_ATTRNAME);
}
//
// Attribute vector
// FIXME P5: constructor for BSONObj could be added to ContextAttributeVector/ContextAttribute classes, to make building more modular
//
BSONObj attrs = getObjectFieldF(entityDoc, ENT_ATTRS);
std::set<std::string> attrNames;
attrs.getFieldNames(attrNames);
for (std::set<std::string>::iterator i = attrNames.begin(); i != attrNames.end(); ++i)
{
std::string attrName = *i;
BSONObj attr = getObjectFieldF(attrs, attrName);
ContextAttribute* caP = NULL;
ContextAttribute ca;
// Name and type
ca.name = dbDotDecode(basePart(attrName));
std::string mdId = idPart(attrName);
ca.type = getStringFieldF(attr, ENT_ATTRS_TYPE);
// Skip attribute if the attribute is in the list (or attrL is empty or includes "*")
if (!includedAttribute(ca, attrL))
{
continue;
}
/* It could happen (although very rarely) that the value field is missing in the
* DB for the attribute. The following is a safety check measure to protect against that */
if (!attr.hasField(ENT_ATTRS_VALUE))
{
caP = new ContextAttribute(ca.name, ca.type, "");
}
else
{
switch(getFieldF(attr, ENT_ATTRS_VALUE).type())
{
case String:
ca.stringValue = getStringFieldF(attr, ENT_ATTRS_VALUE);
if (!includeEmpty && ca.stringValue.length() == 0)
{
continue;
}
caP = new ContextAttribute(ca.name, ca.type, ca.stringValue);
break;
case NumberDouble:
ca.numberValue = getNumberFieldF(attr, ENT_ATTRS_VALUE);
caP = new ContextAttribute(ca.name, ca.type, ca.numberValue);
break;
case NumberInt:
ca.numberValue = (double) getIntFieldF(attr, ENT_ATTRS_VALUE);
caP = new ContextAttribute(ca.name, ca.type, ca.numberValue);
break;
case Bool:
ca.boolValue = getBoolFieldF(attr, ENT_ATTRS_VALUE);
caP = new ContextAttribute(ca.name, ca.type, ca.boolValue);
break;
case jstNULL:
caP = new ContextAttribute(ca.name, ca.type, "");
caP->valueType = orion::ValueTypeNone;
break;
//.........这里部分代码省略.........
示例8: UpdateRackPDU
void CRackController::UpdateRackPDU(const mongo::BSONObj &boOldCIInfo, const mongo::BSONObj &boNewCIInfo, const mongo::BSONObj &boChangedFields)
{
CRackPDUModel objPDUModel;
CRackModel objRackModel;
BSONObj boRackPDUInfo;
BSONObj boPushPDU;
BSONObj boPullPDU;
string strOldRack, strOldSite, strNewRack, strNewSite;
string strOldName, strOldPMM;
Query qCond;
try
{
if (boChangedFields.hasField("rack") || boChangedFields.hasField("site")
|| boChangedFields.hasField("current")
|| boChangedFields.hasField("pmm")
|| boChangedFields.hasField("unit")
|| boChangedFields.hasField("name"))
{
strOldRack = CMongodbModel::GetStringFieldValue(boOldCIInfo, "rack", "");
strOldSite = CMongodbModel::GetStringFieldValue(boOldCIInfo, "site", "");
strOldName = CMongodbModel::GetStringFieldValue(boOldCIInfo, "name", "");
strOldPMM = CMongodbModel::GetStringFieldValue(boOldCIInfo, "pmm", "");
strNewRack = CMongodbModel::GetStringFieldValue(boNewCIInfo, "rack", "");
strNewSite = CMongodbModel::GetStringFieldValue(boNewCIInfo, "site", "");
// Load PDU info into CRackPDUModel
objPDUModel.Load(boNewCIInfo);
objPDUModel.Save(boRackPDUInfo);
if (strOldRack != "" && strOldSite != "")
{
boPullPDU = objRackModel.GetDeletePDURecord(strOldName, strOldPMM);
qCond = objRackModel.IsExistsRackQuery(strOldRack, strOldSite);
cout << "query:" << qCond.toString() << endl;
cout << "pull:" << boPullPDU.toString() << endl;
//Pull old Switch serial in rack
Update(boPullPDU, qCond);
}
if (strNewRack != "" && strNewRack != "")
{
boPushPDU = objRackModel.GetAddPDURecord(boRackPDUInfo);
qCond = objRackModel.IsExistsRackQuery(strNewRack, strNewSite);
cout << "query:" << qCond.toString() << endl;
cout << "push:" << boPushPDU.toString() << endl;
Update(boPushPDU, qCond);
}
}
}
catch(exception& ex)
{
stringstream strErrorMess;
string strLog;
strErrorMess << ex.what() << "][" << __FILE__ << "|" << __LINE__ ;
strLog = CUtilities::FormatLog(ERROR_MSG, "CRackController", "UpdateRackPDU","Exception:" + strErrorMess.str());
CUtilities::WriteErrorLog(ERROR_MSG, strLog);
}
}
示例9: RepoNodeAbstract
repo::core::RepoNodeMesh::RepoNodeMesh(
const mongo::BSONObj &obj) : RepoNodeAbstract(obj),
vertices(NULL),
faces(NULL),
normals(NULL),
outline(NULL),
uvChannels(NULL),
colors(NULL)
{
//--------------------------------------------------------------------------
// Vertices
if (obj.hasField(REPO_NODE_LABEL_VERTICES) &&
obj.hasField(REPO_NODE_LABEL_VERTICES_COUNT))
{
vertices = new std::vector<aiVector3t<float>>();
RepoTranscoderBSON::retrieve(
obj.getField(REPO_NODE_LABEL_VERTICES),
obj.getField(REPO_NODE_LABEL_VERTICES_COUNT).numberInt(),
vertices);
}
//--------------------------------------------------------------------------
// Faces
if (obj.hasField(REPO_NODE_LABEL_FACES) &&
obj.hasField(REPO_NODE_LABEL_FACES_COUNT) &&
obj.hasField(REPO_NODE_LABEL_FACES_BYTE_COUNT))
{
faces = new std::vector<aiFace>();
retrieveFacesArray(
obj.getField(REPO_NODE_LABEL_FACES),
api,
obj.getField(REPO_NODE_LABEL_FACES_BYTE_COUNT).numberInt(),
obj.getField(REPO_NODE_LABEL_FACES_COUNT).numberInt(),
faces);
}
//--------------------------------------------------------------------------
// Normals
if (obj.hasField(REPO_NODE_LABEL_NORMALS) &&
obj.hasField(REPO_NODE_LABEL_VERTICES_COUNT))
{
normals = new std::vector<aiVector3t<float> >();
RepoTranscoderBSON::retrieve(
obj.getField(REPO_NODE_LABEL_NORMALS),
obj.getField(REPO_NODE_LABEL_VERTICES_COUNT).numberInt(),
normals);
}
//--------------------------------------------------------------------------
// Polygon mesh outline (2D bounding rectangle in XY for the moment)
//
if (obj.hasField(REPO_NODE_LABEL_OUTLINE))
{
//outline = new std::vector<aiVector2D>();
// TODO: fill in
}
//--------------------------------------------------------------------------
// Bounding box
if (obj.hasField(REPO_NODE_LABEL_BOUNDING_BOX))
{
std::pair<aiVector3D, aiVector3D> min_max = RepoTranscoderBSON::retrieveBBox(
obj.getField(REPO_NODE_LABEL_BOUNDING_BOX));
this->boundingBox.setMin(min_max.first);
this->boundingBox.setMax(min_max.second);
}
//--------------------------------------------------------------------------
// SHA-256 hash
if (obj.hasField(REPO_NODE_LABEL_SHA256))
{
vertexHash = obj.getField(REPO_NODE_LABEL_SHA256).numberInt();
}
//--------------------------------------------------------------------------
// UV channels
if (obj.hasField(REPO_NODE_LABEL_UV_CHANNELS) &&
obj.hasField(REPO_NODE_LABEL_UV_CHANNELS_BYTE_COUNT) &&
obj.hasField(REPO_NODE_LABEL_UV_CHANNELS_COUNT))
{
unsigned int numberOfConcatenatedEntries =
obj.getField(REPO_NODE_LABEL_UV_CHANNELS_COUNT).numberInt() *
obj.getField(REPO_NODE_LABEL_VERTICES_COUNT).numberInt();
std::vector<aiVector2t<float>> concatenated;
RepoTranscoderBSON::retrieve(
obj.getField(REPO_NODE_LABEL_UV_CHANNELS),
numberOfConcatenatedEntries,
&concatenated);
unsigned int channelsCount =
obj.getField(REPO_NODE_LABEL_UV_CHANNELS_COUNT).numberInt();
unsigned int channelSize = (unsigned int) concatenated.size()/channelsCount;
uvChannels =
new std::vector<std::vector<aiVector3t<float>> *>(channelsCount);
//.........这里部分代码省略.........