本文整理汇总了C++中RepoBSON类的典型用法代码示例。如果您正苦于以下问题:C++ RepoBSON类的具体用法?C++ RepoBSON怎么用?C++ RepoBSON使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RepoBSON类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getObjectField
std::vector<repoUUID> RepoBSON::getUUIDFieldArray(const std::string &label) const{
std::vector<repoUUID> results;
if (hasField(label))
{
RepoBSON array = getObjectField(label);
if (!array.isEmpty())
{
std::set<std::string> fields;
array.getFieldNames(fields);
std::set<std::string>::iterator it;
for (it = fields.begin(); it != fields.end(); ++it)
results.push_back(array.getUUIDField(*it));
}
else
{
repoError << "getUUIDFieldArray: field " << label << " is an empty bson or wrong type!";
}
}
return results;
}
示例2: TEST
TEST(RepoBSONTest, GetFloatArray)
{
std::vector<float> floatArrIn;
size_t size = 10;
mongo::BSONObjBuilder builder, arrbuilder;
floatArrIn.reserve(size);
for (size_t i = 0; i < size; ++i)
{
floatArrIn.push_back((float)rand()/100.);
arrbuilder << std::to_string(i) << floatArrIn[i];
}
builder.appendArray("floatarr", arrbuilder.obj());
RepoBSON bson = builder.obj();
std::vector<float> floatArrOut = bson.getFloatArray("floatarr");
EXPECT_EQ(floatArrIn.size(), floatArrOut.size());
for (size_t i = 0; i < size; i++)
{
EXPECT_EQ(floatArrIn[i], floatArrOut[i]);
}
//Shouldn't fail if trying to get a uuid field that doesn't exist
EXPECT_EQ(0, bson.getFloatArray("hello").size());
EXPECT_EQ(0, testBson.getFloatArray("ice").size());
EXPECT_EQ(0, emptyBson.getFloatArray("ice").size());
}
示例3: getObjectField
MeshNode MeshNode::cloneAndUpdateMeshMapping(
const std::vector<repo_mesh_mapping_t> &vec,
const bool &overwrite)
{
RepoBSONBuilder builder, mapbuilder;
uint32_t index = 0;
std::vector<repo_mesh_mapping_t> mappings;
RepoBSON mapArray = getObjectField(REPO_NODE_MESH_LABEL_MERGE_MAP);
if (!overwrite && !mapArray.isEmpty())
{
//if map array isn't empty, find the next index it needs to slot in
std::set<std::string> fields;
mapArray.getFieldNames(fields);
index = fields.size();
}
for (uint32_t i = 0; i < vec.size(); ++i)
{
mapbuilder << std::to_string(index + i) << meshMappingAsBSON(vec[i]);
}
//append the rest of the array onto this new map bson
if (!overwrite) mapbuilder.appendElementsUnique(mapArray);
builder.appendArray(REPO_NODE_MESH_LABEL_MERGE_MAP, mapbuilder.obj());
//append the rest of the mesh onto this new bson
builder.appendElementsUnique(*this);
return MeshNode(builder.obj(), bigFiles);
}
示例4: BSON
bool RepoScene::commitProjectSettings(
repo::core::handler::AbstractDatabaseHandler *handler,
std::string &errMsg,
const std::string &userName)
{
RepoProjectSettings projectSettings =
RepoBSONFactory::makeRepoProjectSettings(projectName, userName);
bool success = handler->insertDocument(
databaseName, REPO_COLLECTION_SETTINGS, projectSettings, errMsg);
if (!success)
{
//check that the error occurred because of duplicated index (i.e. there's already an entry for projects)
RepoBSON criteria = BSON(REPO_LABEL_ID << projectName);
RepoBSON doc = handler->findOneByCriteria(databaseName, REPO_COLLECTION_SETTINGS, criteria);
//If it already exist, that's fine.
success = !doc.isEmpty();
if (success)
{
repoTrace << "This project already has a project settings entry, skipping project settings commit...";
errMsg.clear();
}
}
return success;
}
示例5: makeRepoProjectSettings
RepoProjectSettings RepoBSONFactory::makeRepoProjectSettings(
const std::string &uniqueProjectName,
const std::string &owner,
const std::string &type,
const std::string &description,
const double pinSize,
const double avatarHeight,
const double visibilityLimit,
const double speed,
const double zNear,
const double zFar)
{
RepoBSONBuilder builder;
//--------------------------------------------------------------------------
// Project name
if (!uniqueProjectName.empty())
builder << REPO_LABEL_ID << uniqueProjectName;
//--------------------------------------------------------------------------
// Owner
if (!owner.empty())
builder << REPO_LABEL_OWNER << owner;
//--------------------------------------------------------------------------
// Description
if (!description.empty())
builder << REPO_LABEL_DESCRIPTION << description;
//--------------------------------------------------------------------------
// Type
if (!type.empty())
builder << REPO_LABEL_TYPE << type;
//--------------------------------------------------------------------------
// Properties (embedded sub-bson)
RepoBSONBuilder propertiesBuilder;
if (pinSize != REPO_DEFAULT_PROJECT_PIN_SIZE)
propertiesBuilder << REPO_LABEL_PIN_SIZE << pinSize;
if (avatarHeight != REPO_DEFAULT_PROJECT_AVATAR_HEIGHT)
propertiesBuilder << REPO_LABEL_AVATAR_HEIGHT << avatarHeight;
if (visibilityLimit != REPO_DEFAULT_PROJECT_VISIBILITY_LIMIT)
propertiesBuilder << REPO_LABEL_VISIBILITY_LIMIT << visibilityLimit;
if (speed != REPO_DEFAULT_PROJECT_SPEED)
propertiesBuilder << REPO_LABEL_SPEED << speed;
if (zNear != REPO_DEFAULT_PROJECT_ZNEAR)
propertiesBuilder << REPO_LABEL_ZNEAR << zNear;
if (zFar != REPO_DEFAULT_PROJECT_ZFAR)
propertiesBuilder << REPO_LABEL_ZFAR << zFar;
RepoBSON propertiesBSON = propertiesBuilder.obj();
if (propertiesBSON.isValid() && !propertiesBSON.isEmpty())
builder << REPO_LABEL_PROPERTIES << propertiesBSON;
//--------------------------------------------------------------------------
// Add to the parent object
return RepoProjectSettings(builder.obj());
}
示例6: makeMetaDataNode
MetadataNode RepoBSONFactory::makeMetaDataNode(
RepoBSON &metadata,
const std::string &mimeType,
const std::string &name,
const std::vector<repoUUID> &parents,
const int &apiLevel)
{
RepoBSONBuilder builder;
// Compulsory fields such as _id, type, api as well as path
// and optional name
auto defaults = appendDefaults(REPO_NODE_TYPE_METADATA, apiLevel, generateUUID(), name, parents);
builder.appendElements(defaults);
//--------------------------------------------------------------------------
// Media type
if (!mimeType.empty())
builder << REPO_LABEL_MEDIA_TYPE << mimeType;
//--------------------------------------------------------------------------
// Add metadata subobject
if (!metadata.isEmpty())
builder << REPO_NODE_LABEL_METADATA << metadata;
return MetadataNode(builder.obj());
}
示例7: TEST
TEST(RepoBSONFactoryTest, MakeMetaDataNodeTest)
{
RepoBSON data = BSON("something" << "Something else" << "something2" << "somethingelse2");
std::string mimeType = "application/x-mswrite";
std::string name = "MetaTest";
MetadataNode metaNode = RepoBSONFactory::makeMetaDataNode(data, mimeType, name);
EXPECT_FALSE(metaNode.isEmpty());
EXPECT_EQ(name, metaNode.getName());
EXPECT_EQ(metaNode.getTypeAsEnum(), NodeType::METADATA);
EXPECT_EQ(mimeType, metaNode.getStringField(REPO_LABEL_MEDIA_TYPE));
EXPECT_EQ(data.toString(), metaNode.getObjectField(REPO_NODE_LABEL_METADATA).toString());
}
示例8: TEST
TEST(RepoBSONTest, GetUUIDField)
{
repoUUID uuid = generateUUID();
mongo::BSONObjBuilder builder;
builder.appendBinData("uuid", uuid.size(), mongo::bdtUUID, (char*)uuid.data);
RepoBSON test = RepoBSON(builder.obj());
EXPECT_EQ(uuid, test.getUUIDField("uuid"));
//Shouldn't fail if trying to get a uuid field that doesn't exist
EXPECT_NE(uuid, test.getUUIDField("hello"));
EXPECT_NE(uuid, testBson.getUUIDField("ice"));
EXPECT_NE(uuid, emptyBson.getUUIDField("ice"));
}
示例9: getObjectField
std::vector<std::string> RevisionNode::getOrgFiles() const
{
std::vector<std::string> fileList;
if (hasField(REPO_NODE_REVISION_LABEL_REF_FILE))
{
RepoBSON arraybson = getObjectField(REPO_NODE_REVISION_LABEL_REF_FILE);
std::set<std::string> fields;
arraybson.getFieldNames(fields);
for (const auto &field : fields)
{
fileList.push_back(arraybson.getStringField(field));
}
}
return fileList;
}
示例10:
std::vector<repo_vector_t> MeshNode::getBoundingBox(RepoBSON &bbArr)
{
std::vector<repo_vector_t> bbox;
if (!bbArr.isEmpty() && bbArr.couldBeArray())
{
size_t nVec = bbArr.nFields();
bbox.reserve(nVec);
for (uint32_t i = 0; i < nVec; ++i)
{
auto bbVectorBson = bbArr.getObjectField(std::to_string(i));
if (!bbVectorBson.isEmpty() && bbVectorBson.couldBeArray())
{
int32_t nFields = bbVectorBson.nFields();
if (nFields >= 3)
{
repo_vector_t vector;
vector.x = bbVectorBson.getField("0").Double();
vector.y = bbVectorBson.getField("1").Double();
vector.z = bbVectorBson.getField("2").Double();
bbox.push_back(vector);
}
else
{
repoError << "Insufficient amount of elements within bounding box! #fields: " << nFields;
}
}
else
{
repoError << "Failed to get a vector for bounding box!";
}
}
}
else
{
repoError << "Failed to fetch bounding box from Mesh Node!";
}
return bbox;
}
示例11: loadRevision
bool RepoScene::loadRevision(
repo::core::handler::AbstractDatabaseHandler *handler,
std::string &errMsg){
bool success = true;
if (!handler)
{
errMsg = "Cannot load revision with an empty database handler";
return false;
}
RepoBSON bson;
repoTrace << "loading revision : " << databaseName << "." << projectName << " head Revision: " << headRevision;
if (headRevision){
RepoBSONBuilder critBuilder;
critBuilder.append(REPO_NODE_LABEL_SHARED_ID, branch);
critBuilder << REPO_NODE_REVISION_LABEL_INCOMPLETE << BSON("$exists" << false);
bson = handler->findOneByCriteria(databaseName, projectName + "." +
revExt, critBuilder.obj(), REPO_NODE_REVISION_LABEL_TIMESTAMP);
repoTrace << "Fetching head of revision from branch " << UUIDtoString(branch);
}
else{
bson = handler->findOneByUniqueID(databaseName, projectName + "." + revExt, revision);
repoTrace << "Fetching revision using unique ID: " << UUIDtoString(revision);
}
if (bson.isEmpty()){
errMsg = "Failed: cannot find revision document from " + databaseName + "." + projectName + "." + revExt;
success = false;
}
else{
revNode = new RevisionNode(bson);
worldOffset = revNode->getCoordOffset();
}
return success;
}
示例12: rawFiles
RepoBSON RepoBSON::cloneAndShrink() const
{
std::set<std::string> fields;
std::unordered_map< std::string, std::pair<std::string, std::vector<uint8_t>>> rawFiles(bigFiles.begin(), bigFiles.end());
std::string uniqueIDStr = hasField(REPO_LABEL_ID) ? UUIDtoString(getUUIDField(REPO_LABEL_ID)) : UUIDtoString(generateUUID());
getFieldNames(fields);
RepoBSON resultBson = *this;
for (const std::string &field : fields)
{
if (getField(field).type() == ElementType::BINARY)
{
std::string fileName = uniqueIDStr + "_" + field;
rawFiles[field] = std::pair<std::string, std::vector<uint8_t>>(fileName, std::vector<uint8_t>());
getBinaryFieldAsVector(field, &rawFiles[field].second);
resultBson = resultBson.removeField(field);
}
}
return RepoBSON(resultBson, rawFiles);
}
示例13: RepoBSON
RepoNode::RepoNode(RepoBSON bson,
const std::unordered_map<std::string, std::pair<std::string, std::vector<uint8_t>>> &binMapping) : RepoBSON(bson, binMapping){
if (binMapping.size() == 0)
bigFiles = bson.getFilesMapping();
}
示例14: TransformationNode
bool RepoScene::populate(
const GraphType >ype,
repo::core::handler::AbstractDatabaseHandler *handler,
std::vector<RepoBSON> nodes,
std::string &errMsg)
{
bool success = true;
repoGraphInstance &g = gtype == GraphType::OPTIMIZED ? stashGraph : graph;
std::unordered_map<repoUUID, RepoNode *, RepoUUIDHasher> nodesBySharedID;
for (std::vector<RepoBSON>::const_iterator it = nodes.begin();
it != nodes.end(); ++it)
{
RepoBSON obj = *it;
RepoNode *node = NULL;
std::string nodeType = obj.getField(REPO_NODE_LABEL_TYPE).str();
if (REPO_NODE_TYPE_TRANSFORMATION == nodeType)
{
node = new TransformationNode(obj);
g.transformations.insert(node);
}
else if (REPO_NODE_TYPE_MESH == nodeType)
{
node = new MeshNode(obj);
g.meshes.insert(node);
}
else if (REPO_NODE_TYPE_MATERIAL == nodeType)
{
node = new MaterialNode(obj);
g.materials.insert(node);
}
else if (REPO_NODE_TYPE_TEXTURE == nodeType)
{
node = new TextureNode(obj);
g.textures.insert(node);
}
else if (REPO_NODE_TYPE_CAMERA == nodeType)
{
node = new CameraNode(obj);
g.cameras.insert(node);
}
else if (REPO_NODE_TYPE_REFERENCE == nodeType)
{
node = new ReferenceNode(obj);
g.references.insert(node);
}
else if (REPO_NODE_TYPE_METADATA == nodeType)
{
node = new MetadataNode(obj);
g.metadata.insert(node);
}
else{
//UNKNOWN TYPE - instantiate it with generic RepoNode
node = new RepoNode(obj);
g.unknowns.insert(node);
}
success &= addNodeToMaps(gtype, node, errMsg);
} //Node Iteration
//deal with References
RepoNodeSet::iterator refIt;
//Make sure it is propagated into the repoScene if it exists in revision node
if (g.references.size()) worldOffset.clear();
for (const auto &node : g.references)
{
ReferenceNode* reference = (ReferenceNode*)node;
//construct a new RepoScene with the information from reference node and append this g to the Scene
std::string spDbName = reference->getDatabaseName();
if (spDbName.empty()) spDbName = databaseName;
RepoScene *refg = new RepoScene(spDbName, reference->getProjectName(), sceneExt, revExt);
if (reference->useSpecificRevision())
refg->setRevision(reference->getRevisionID());
else
refg->setBranch(reference->getRevisionID());
//Try to load the stash first, if fail, try scene.
if (refg->loadStash(handler, errMsg) || refg->loadScene(handler, errMsg))
{
g.referenceToScene[reference->getSharedID()] = refg;
auto refOffset = refg->getWorldOffset();
if (!worldOffset.size())
{
worldOffset = refOffset;
}
}
else{
repoWarning << "Failed to load reference node for ref ID" << reference->getUniqueID() << ": " << errMsg;
}
}
repoTrace << "World Offset = [" << worldOffset[0] << " , " << worldOffset[1] << ", " << worldOffset[2] << " ]";
//Now that we know the world Offset, make sure the referenced scenes are shifted accordingly
for (const auto &node : g.references)
{
ReferenceNode* reference = (ReferenceNode*)node;
//.........这里部分代码省略.........