本文整理汇总了C++中object::Ptr::GetField方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::GetField方法的具体用法?C++ Ptr::GetField怎么用?C++ Ptr::GetField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类object::Ptr
的用法示例。
在下文中一共展示了Ptr::GetField方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Dictionary
BOOST_FOREACH(const ConfigObject::Ptr& obj, objs) {
Dictionary::Ptr result1 = new Dictionary();
results->Add(result1);
Dictionary::Ptr resultAttrs = new Dictionary();
result1->Set("attrs", resultAttrs);
BOOST_FOREACH(const String& joinAttr, joinAttrs) {
Object::Ptr joinedObj;
String prefix;
if (joinAttr.IsEmpty()) {
joinedObj = obj;
prefix = type->GetName();
} else {
int fid = type->GetFieldId(joinAttr);
joinedObj = obj->NavigateField(fid);
if (!joinedObj)
continue;
Field field = type->GetFieldInfo(fid);
prefix = field.NavigationName;
}
boost::algorithm::to_lower(prefix);
Type::Ptr joinedType = joinedObj->GetReflectionType();
for (int fid = 0; fid < joinedType->GetFieldCount(); fid++) {
Field field = joinedType->GetFieldInfo(fid);
String aname = prefix + "." + field.Name;
if (!attrs.empty() && attrs.find(aname) == attrs.end())
continue;
Value val = joinedObj->GetField(fid);
/* hide internal navigation fields */
if (field.Attributes & FANavigation) {
Value nval = joinedObj->NavigateField(fid);
if (val == nval)
continue;
}
Value sval = Serialize(val, FAConfig | FAState);
resultAttrs->Set(aname, sval);
}
}
示例2: SerializeObjectAttrs
Dictionary::Ptr ObjectQueryHandler::SerializeObjectAttrs(const Object::Ptr& object,
const String& attrPrefix, const Array::Ptr& attrs, bool isJoin, bool allAttrs)
{
Type::Ptr type = object->GetReflectionType();
std::vector<int> fids;
if (isJoin && attrs) {
ObjectLock olock(attrs);
for (const String& attr : attrs) {
if (attr == attrPrefix) {
allAttrs = true;
break;
}
}
}
if (!isJoin && (!attrs || attrs->GetLength() == 0))
allAttrs = true;
if (allAttrs) {
for (int fid = 0; fid < type->GetFieldCount(); fid++) {
fids.push_back(fid);
}
} else if (attrs) {
ObjectLock olock(attrs);
for (const String& attr : attrs) {
String userAttr;
if (isJoin) {
String::SizeType dpos = attr.FindFirstOf(".");
if (dpos == String::NPos)
continue;
String userJoinAttr = attr.SubStr(0, dpos);
if (userJoinAttr != attrPrefix)
continue;
userAttr = attr.SubStr(dpos + 1);
} else
userAttr = attr;
int fid = type->GetFieldId(userAttr);
if (fid < 0)
BOOST_THROW_EXCEPTION(ScriptError("Invalid field specified: " + userAttr));
fids.push_back(fid);
}
}
DictionaryData resultAttrs;
resultAttrs.reserve(fids.size());
for (int fid : fids) {
Field field = type->GetFieldInfo(fid);
Value val = object->GetField(fid);
/* hide attributes which shouldn't be user-visible */
if (field.Attributes & FANoUserView)
continue;
/* hide internal navigation fields */
if (field.Attributes & FANavigation && !(field.Attributes & (FAConfig | FAState)))
continue;
Value sval = Serialize(val, FAConfig | FAState);
resultAttrs.emplace_back(field.Name, sval);
}
return new Dictionary(std::move(resultAttrs));
}