本文整理汇总了C++中type::Ptr类的典型用法代码示例。如果您正苦于以下问题:C++ Ptr类的具体用法?C++ Ptr怎么用?C++ Ptr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ptr类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: if
static inline Value ConstructorCall(const Type::Ptr& type, const DebugInfo& debugInfo = DebugInfo())
{
if (type->GetName() == "String")
return "";
else if (type->GetName() == "Number")
return 0;
else if (type->GetName() == "Boolean")
return false;
else {
Object::Ptr object = type->Instantiate();
if (!object)
BOOST_THROW_EXCEPTION(ScriptError("Failed to instantiate object of type '" + type->GetName() + "'", debugInfo));
return object;
}
}
开发者ID:zijam,项目名称:icinga2,代码行数:17,代码来源:vmops.hpp
示例2: GetObjectConfigPath
String ConfigObjectUtility::GetObjectConfigPath(const Type::Ptr& type, const String& fullName)
{
String typeDir = type->GetPluralName();
boost::algorithm::to_lower(typeDir);
return GetConfigDir() + "/conf.d/" + typeDir +
"/" + EscapeName(fullName) + ".conf";
}
开发者ID:spjmurray,项目名称:icinga2,代码行数:8,代码来源:configobjectutility.cpp
示例3: NewObject
static inline Value NewObject(ScriptFrame& frame, bool abstract, const String& type, const String& name, const boost::shared_ptr<Expression>& filter,
const String& zone, std::map<String, Expression *> *closedVars, const boost::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
{
ConfigItemBuilder::Ptr item = new ConfigItemBuilder(debugInfo);
String checkName = name;
if (!abstract) {
Type::Ptr ptype = Type::GetByName(type);
NameComposer *nc = dynamic_cast<NameComposer *>(ptype.get());
if (nc)
checkName = nc->MakeName(name, Dictionary::Ptr());
}
if (!checkName.IsEmpty()) {
ConfigItem::Ptr oldItem = ConfigItem::GetObject(type, checkName);
if (oldItem) {
std::ostringstream msgbuf;
msgbuf << "Object '" << name << "' of type '" << type << "' re-defined: " << debugInfo << "; previous definition: " << oldItem->GetDebugInfo();
BOOST_THROW_EXCEPTION(ScriptError(msgbuf.str(), debugInfo));
}
}
item->SetType(type);
if (name.FindFirstOf("!") != String::NPos) {
std::ostringstream msgbuf;
msgbuf << "Name for object '" << name << "' of type '" << type << "' is invalid: Object names may not contain '!'";
BOOST_THROW_EXCEPTION(ScriptError(msgbuf.str(), debugInfo));
}
item->SetName(name);
item->AddExpression(new OwnedExpression(expression));
item->SetAbstract(abstract);
item->SetScope(EvaluateClosedVars(frame, closedVars));
item->SetZone(zone);
item->SetFilter(filter);
item->Compile()->Register();
return Empty;
}
开发者ID:andrewmeyer,项目名称:icinga2,代码行数:45,代码来源:vmops.hpp
示例4: EvaluateFilter
bool FilterUtility::EvaluateFilter(ScriptFrame& frame, Expression *filter,
const Object::Ptr& target, const String& variableName)
{
if (!filter)
return true;
Type::Ptr type = target->GetReflectionType();
String varName;
if (variableName.IsEmpty())
varName = type->GetName().ToLower();
else
varName = variableName;
Namespace::Ptr frameNS;
if (frame.Self.IsEmpty()) {
frameNS = new Namespace();
frame.Self = frameNS;
} else {
/* Enforce a namespace object for 'frame.self'. */
ASSERT(frame.Self.IsObjectType<Namespace>());
frameNS = frame.Self;
}
frameNS->Set("obj", target);
frameNS->Set(varName, target);
for (int fid = 0; fid < type->GetFieldCount(); fid++) {
Field field = type->GetFieldInfo(fid);
if ((field.Attributes & FANavigation) == 0)
continue;
Object::Ptr joinedObj = target->NavigateField(fid);
if (field.NavigationName)
frameNS->Set(field.NavigationName, joinedObj);
else
frameNS->Set(field.Name, joinedObj);
}
return Convert::ToBool(filter->Evaluate(frame));
}
开发者ID:bebehei,项目名称:icinga2,代码行数:45,代码来源:filterutility.cpp
示例5: GetPrototypeField
Value icinga::GetPrototypeField(const Value& context, const String& field, bool not_found_error, const DebugInfo& debugInfo)
{
Type::Ptr ctype = context.GetReflectionType();
Type::Ptr type = ctype;
do {
Object::Ptr object = type->GetPrototype();
if (object && object->HasOwnField(field))
return object->GetFieldByName(field, false, debugInfo);
type = type->GetBaseType();
} while (type);
if (not_found_error)
BOOST_THROW_EXCEPTION(ScriptError("Invalid field access (for value of type '" + ctype->GetName() + "'): '" + field + "'", debugInfo));
else
return Empty;
}
开发者ID:LMNetworks,项目名称:icinga2,代码行数:19,代码来源:object.cpp
示例6: HandleRequest
bool StatusQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
{
if (request.RequestMethod != "GET")
return false;
if (request.RequestUrl->GetPath().size() < 2)
return false;
Type::Ptr type = FilterUtility::TypeFromPluralName(request.RequestUrl->GetPath()[1]);
if (!type)
return false;
QueryDescription qd;
qd.Types.insert(type);
std::vector<String> joinTypes;
joinTypes.push_back(type->GetName());
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
params->Set("type", type->GetName());
if (request.RequestUrl->GetPath().size() >= 3) {
String attr = type->GetName();
boost::algorithm::to_lower(attr);
params->Set(attr, request.RequestUrl->GetPath()[2]);
}
std::vector<ConfigObject::Ptr> objs = FilterUtility::GetFilterTargets(qd, params);
Array::Ptr results = new Array();
std::set<String> attrs;
Array::Ptr uattrs = params->Get("attrs");
if (uattrs) {
ObjectLock olock(uattrs);
BOOST_FOREACH(const String& uattr, uattrs) {
attrs.insert(uattr);
}
}
开发者ID:tomasdubec,项目名称:icinga2,代码行数:42,代码来源:statusqueryhandler.cpp
示例7:
ValidationError::ValidationError(const ConfigObject::Ptr& object, const std::vector<String>& attributePath, const String& message)
: m_Object(object), m_AttributePath(attributePath), m_Message(message)
{
String path;
BOOST_FOREACH(const String& attribute, attributePath) {
if (!path.IsEmpty())
path += " -> ";
path += "'" + attribute + "'";
}
Type::Ptr type = object->GetReflectionType();
m_What = "Validation failed for object '" + object->GetName() + "' of type '" + type->GetName() + "'";
if (!path.IsEmpty())
m_What += "; Attribute " + path;
m_What += ": " + message;
}
开发者ID:Nadahar,项目名称:icinga2,代码行数:20,代码来源:exception.cpp
示例8: EvaluateFilter
bool FilterUtility::EvaluateFilter(ScriptFrame& frame, Expression *filter,
const Object::Ptr& target, const String& variableName)
{
if (!filter)
return true;
Type::Ptr type = target->GetReflectionType();
String varName;
if (variableName.IsEmpty())
varName = type->GetName().ToLower();
else
varName = variableName;
Dictionary::Ptr vars;
if (frame.Self.IsEmpty()) {
vars = new Dictionary();
frame.Self = vars;
} else
vars = frame.Self;
vars->Set("obj", target);
vars->Set(varName, target);
for (int fid = 0; fid < type->GetFieldCount(); fid++) {
Field field = type->GetFieldInfo(fid);
if ((field.Attributes & FANavigation) == 0)
continue;
Object::Ptr joinedObj = target->NavigateField(fid);
if (field.NavigationName)
vars->Set(field.NavigationName, joinedObj);
else
vars->Set(field.Name, joinedObj);
}
return Convert::ToBool(filter->Evaluate(frame));
}
开发者ID:b0e,项目名称:icinga2,代码行数:41,代码来源:filterutility.cpp
示例9: GetFieldByName
Value Object::GetFieldByName(const String& field, bool sandboxed, const DebugInfo& debugInfo) const
{
Type::Ptr type = GetReflectionType();
if (!type)
return Empty;
int fid = type->GetFieldId(field);
if (fid == -1)
return GetPrototypeField(const_cast<Object *>(this), field, true, debugInfo);
if (sandboxed) {
Field fieldInfo = type->GetFieldInfo(fid);
if (fieldInfo.Attributes & FANoUserView)
BOOST_THROW_EXCEPTION(ScriptError("Accessing the field '" + field + "' for type '" + type->GetName() + "' is not allowed in sandbox mode.", debugInfo));
}
return GetField(fid);
}
开发者ID:LMNetworks,项目名称:icinga2,代码行数:21,代码来源:object.cpp
示例10: operator
void CCodeGenerator::operator()(Assignment* expr) {
// Handle all types of assignment, including member assignment
Expression::Ptr init = expr->initializer();
if (dynamic_cast<Empty*>(init.pointer())) {
return_ = Operand(env_->integer("0"));
} else {
return_ = emit(init);
}
String::Ptr id = expr->identifier();
Variable::Ptr var = variable(id);
Attribute::Ptr attr = class_ ? class_->attribute(id) : 0;
if (var) {
// Assignment to a local var that has already been initialized once in
// the current scope.
Type::Ptr type = var->type();
if (!type->is_value()) {
refcount_dec(Operand(var->name()));
}
line();
out_ << id->string() << " = " << return_ << ";\n";
if (!type->is_value()) {
refcount_inc(Operand(var->name()));
}
} else if (attr) {
// Assignment to an attribute within a class
/*
Type::Ptr type = expr->type();
Variable::Ptr self = variable(env_->name("__self"));
Operand addr = Operand::addr(, attr->slot());
Operand old = load(addr);
if (!type->is_value() && !attr->is_weak()) {
refcount_dec(old);
}
store(addr, return_);
if (!type->is_value() && !attr->is_weak()) {
refcount_inc(return_);
}
*/
assert(!"not impl");
} else {
// Assignment to a local var that has not yet been initialized in the
// current scope.
Type::Ptr declared = expr->declared_type();
if (declared->is_top()) {
declared = expr->type();
}
line();
brace();
operator()(declared);
out_ << " " << id->string() << " = " << return_ << "; ";
out_ << "(void)" << id->string() << ";\n";
variable(new Variable(id, declared));
if (!declared->is_value()) {
refcount_inc(return_);
}
}
}
开发者ID:mfichman,项目名称:jogo,代码行数:59,代码来源:CCodeGenerator.cpp
示例11: GetByName
ConfigType::Ptr ConfigType::GetByName(const String& name)
{
boost::mutex::scoped_lock lock(GetStaticMutex());
ConfigType::TypeMap::const_iterator tt = InternalGetTypeMap().find(name);
if (tt == InternalGetTypeMap().end()) {
Type::Ptr type = Type::GetByName(name);
if (!type || !ConfigObject::TypeInstance->IsAssignableFrom(type)
|| type->IsAbstract())
return ConfigType::Ptr();
ConfigType::Ptr dtype = new ConfigType(name);
InternalGetTypeMap()[type->GetName()] = dtype;
InternalGetTypeVector().push_back(dtype);
return dtype;
}
return tt->second;
}
开发者ID:sandeep-sidhu,项目名称:icinga2,代码行数:23,代码来源:configtype.cpp
示例12: HandleRequest
bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response)
{
if (request.RequestUrl->GetPath().size() < 3 || request.RequestUrl->GetPath().size() > 4)
return false;
if (request.RequestMethod != "GET")
return false;
Type::Ptr type = FilterUtility::TypeFromPluralName(request.RequestUrl->GetPath()[2]);
if (!type) {
HttpUtility::SendJsonError(response, 400, "Invalid type specified.");
return true;
}
QueryDescription qd;
qd.Types.insert(type->GetName());
qd.Permission = "objects/query/" + type->GetName();
std::vector<String> joinAttrs;
joinAttrs.push_back("");
for (int fid = 0; fid < type->GetFieldCount(); fid++) {
Field field = type->GetFieldInfo(fid);
if (field.Attributes & FANavigation)
joinAttrs.push_back(field.Name);
}
Dictionary::Ptr params = HttpUtility::FetchRequestParameters(request);
params->Set("type", type->GetName());
if (request.RequestUrl->GetPath().size() >= 4) {
String attr = type->GetName();
boost::algorithm::to_lower(attr);
params->Set(attr, request.RequestUrl->GetPath()[3]);
}
std::vector<Value> objs = FilterUtility::GetFilterTargets(qd, params, user);
Array::Ptr results = new Array();
std::set<String> attrs;
Array::Ptr uattrs = params->Get("attrs");
if (uattrs) {
ObjectLock olock(uattrs);
BOOST_FOREACH(const String& uattr, uattrs) {
attrs.insert(uattr);
}
}
开发者ID:jsabari,项目名称:icinga2,代码行数:52,代码来源:objectqueryhandler.cpp
示例13: strcmp
std::vector<String> icinga::GetFieldCompletionSuggestions(const Type::Ptr& type, const String& word)
{
std::vector<String> result;
for (int i = 0; i < type->GetFieldCount(); i++) {
Field field = type->GetFieldInfo(i);
if (!(field.Attributes & FAConfig) || field.Attributes & FAInternal)
continue;
if (strcmp(field.TypeName, "int") != 0 && strcmp(field.TypeName, "double") != 0
&& strcmp(field.TypeName, "bool") != 0 && strcmp(field.TypeName, "String") != 0)
continue;
String fname = field.Name;
String suggestion = fname + "=";
if (suggestion.Find(word) == 0)
result.push_back(suggestion);
}
return result;
}
开发者ID:abitduck,项目名称:icinga2,代码行数:24,代码来源:clicommand.cpp
示例14: TypeFromPluralName
Type::Ptr FilterUtility::TypeFromPluralName(const String& pluralName)
{
String uname = pluralName;
boost::algorithm::to_lower(uname);
{
Dictionary::Ptr globals = ScriptGlobal::GetGlobals();
ObjectLock olock(globals);
BOOST_FOREACH(const Dictionary::Pair& kv, globals) {
if (!kv.second.IsObjectType<Type>())
continue;
Type::Ptr type = kv.second;
String pname = type->GetPluralName();
boost::algorithm::to_lower(pname);
if (uname == pname)
return type;
}
}
return Type::Ptr();
}
开发者ID:b0e,项目名称:icinga2,代码行数:24,代码来源:filterutility.cpp
示例15: GetObjects
Array::Ptr ScriptUtils::GetObjects(const Type::Ptr& type)
{
if (!type)
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid type: Must not be null"));
ConfigType *ctype = dynamic_cast<ConfigType *>(type.get());
if (!ctype)
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid type: Type must inherit from 'ConfigObject'"));
Array::Ptr result = new Array();
for (const ConfigObject::Ptr& object : ctype->GetObjects())
result->Add(object);
return result;
}
开发者ID:TheFlyingCorpse,项目名称:icinga2,代码行数:17,代码来源:scriptutils.cpp
示例16: SetFieldByName
void Object::SetFieldByName(const String& field, const Value& value, const DebugInfo& debugInfo)
{
Type::Ptr type = GetReflectionType();
if (!type)
BOOST_THROW_EXCEPTION(ScriptError("Cannot set field on object.", debugInfo));
int fid = type->GetFieldId(field);
if (fid == -1)
BOOST_THROW_EXCEPTION(ScriptError("Attribute '" + field + "' does not exist.", debugInfo));
try {
SetField(fid, value);
} catch (const boost::bad_lexical_cast&) {
Field fieldInfo = type->GetFieldInfo(fid);
Type::Ptr ftype = Type::GetByName(fieldInfo.TypeName);
BOOST_THROW_EXCEPTION(ScriptError("Attribute '" + field + "' cannot be set to value of type '" + value.GetTypeName() + "', expected '" + ftype->GetName() + "'", debugInfo));
} catch (const std::bad_cast&) {
Field fieldInfo = type->GetFieldInfo(fid);
Type::Ptr ftype = Type::GetByName(fieldInfo.TypeName);
BOOST_THROW_EXCEPTION(ScriptError("Attribute '" + field + "' cannot be set to value of type '" + value.GetTypeName() + "', expected '" + ftype->GetName() + "'", debugInfo));
}
}
开发者ID:LMNetworks,项目名称:icinga2,代码行数:24,代码来源:object.cpp
示例17: CreateObject
bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& fullName,
const String& config, const Array::Ptr& errors, const Array::Ptr& diagnosticInformation)
{
{
boost::mutex::scoped_lock lock(ConfigPackageUtility::GetStaticMutex());
if (!ConfigPackageUtility::PackageExists("_api")) {
ConfigPackageUtility::CreatePackage("_api");
String stage = ConfigPackageUtility::CreateStage("_api");
ConfigPackageUtility::ActivateStage("_api", stage);
}
}
ConfigItem::Ptr item = ConfigItem::GetByTypeAndName(type, fullName);
if (item) {
errors->Add("Object '" + fullName + "' already exists.");
return false;
}
String path = GetObjectConfigPath(type, fullName);
Utility::MkDirP(Utility::DirName(path), 0700);
if (Utility::PathExists(path)) {
errors->Add("Cannot create object '" + fullName + "'. Configuration file '" + path + "' already exists.");
return false;
}
std::ofstream fp(path.CStr(), std::ofstream::out | std::ostream::trunc);
fp << config;
fp.close();
std::unique_ptr<Expression> expr = ConfigCompiler::CompileFile(path, String(), "_api");
try {
ActivationScope ascope;
ScriptFrame frame(true);
expr->Evaluate(frame);
expr.reset();
WorkQueue upq;
upq.SetName("ConfigObjectUtility::CreateObject");
std::vector<ConfigItem::Ptr> newItems;
/* Disable logging for object creation, but do so ourselves later on. */
if (!ConfigItem::CommitItems(ascope.GetContext(), upq, newItems, true) || !ConfigItem::ActivateItems(upq, newItems, true, true)) {
if (errors) {
if (unlink(path.CStr()) < 0 && errno != ENOENT) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("unlink")
<< boost::errinfo_errno(errno)
<< boost::errinfo_file_name(path));
}
for (const boost::exception_ptr& ex : upq.GetExceptions()) {
errors->Add(DiagnosticInformation(ex, false));
if (diagnosticInformation)
diagnosticInformation->Add(DiagnosticInformation(ex));
}
}
return false;
}
ApiListener::UpdateObjectAuthority();
Log(LogInformation, "ConfigObjectUtility")
<< "Created and activated object '" << fullName << "' of type '" << type->GetName() << "'.";
} catch (const std::exception& ex) {
if (unlink(path.CStr()) < 0 && errno != ENOENT) {
BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("unlink")
<< boost::errinfo_errno(errno)
<< boost::errinfo_file_name(path));
}
if (errors)
errors->Add(DiagnosticInformation(ex, false));
if (diagnosticInformation)
diagnosticInformation->Add(DiagnosticInformation(ex));
return false;
}
return true;
}
开发者ID:dupondje,项目名称:icinga2,代码行数:91,代码来源:configobjectutility.cpp
示例18: Commit
/**
* Commits the configuration item by creating a DynamicObject
* object.
*
* @returns The DynamicObject that was created/updated.
*/
DynamicObject::Ptr ConfigItem::Commit(bool discard)
{
ASSERT(!OwnsLock());
#ifdef _DEBUG
Log(LogDebug, "ConfigItem")
<< "Commit called for ConfigItem Type=" << GetType() << ", Name=" << GetName();
#endif /* _DEBUG */
/* Make sure the type is valid. */
Type::Ptr type = Type::GetByName(GetType());
ASSERT(type && Type::GetByName("DynamicObject")->IsAssignableFrom(type));
if (IsAbstract())
return DynamicObject::Ptr();
DynamicObject::Ptr dobj = static_pointer_cast<DynamicObject>(type->Instantiate());
dobj->SetDebugInfo(m_DebugInfo);
dobj->SetTypeName(m_Type);
dobj->SetZone(m_Zone);
Dictionary::Ptr locals = new Dictionary();
locals->Set("__parent", m_Scope);
m_Scope.reset();
dobj->SetParentScope(locals);
locals.reset();
dobj->SetName(m_Name);
DebugHint debugHints;
try {
m_Expression->Evaluate(dobj, &debugHints);
} catch (const ConfigError& ex) {
const DebugInfo *di = boost::get_error_info<errinfo_debuginfo>(ex);
ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo());
} catch (const std::exception& ex) {
ConfigCompilerContext::GetInstance()->AddMessage(true, DiagnosticInformation(ex));
}
if (discard)
m_Expression.reset();
dobj->SetParentScope(Object::Ptr());
String name = m_Name;
NameComposer *nc = dynamic_cast<NameComposer *>(type.get());
if (nc) {
name = nc->MakeName(m_Name, dobj);
if (name.IsEmpty())
BOOST_THROW_EXCEPTION(std::runtime_error("Could not determine name for object"));
}
if (name != m_Name)
dobj->SetShortName(m_Name);
dobj->SetName(name);
Dictionary::Ptr attrs = Serialize(dobj, FAConfig);
Dictionary::Ptr persistentItem = new Dictionary();
persistentItem->Set("type", GetType());
persistentItem->Set("name", GetName());
persistentItem->Set("properties", attrs);
persistentItem->Set("debug_hints", debugHints.ToDictionary());
ConfigCompilerContext::GetInstance()->WriteObject(persistentItem);
persistentItem.reset();
ConfigType::Ptr ctype = ConfigType::GetByName(GetType());
if (!ctype)
ConfigCompilerContext::GetInstance()->AddMessage(false, "No validation type found for object '" + GetName() + "' of type '" + GetType() + "'");
else {
TypeRuleUtilities utils;
try {
attrs->Remove("name");
ctype->ValidateItem(GetName(), attrs, GetDebugInfo(), &utils);
} catch (const ConfigError& ex) {
const DebugInfo *di = boost::get_error_info<errinfo_debuginfo>(ex);
ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo());
} catch (const std::exception& ex) {
ConfigCompilerContext::GetInstance()->AddMessage(true, DiagnosticInformation(ex));
}
}
dobj->Register();
//.........这里部分代码省略.........
开发者ID:CodeOps,项目名称:icinga2,代码行数:101,代码来源:configitem.cpp
示例19: Register
void Type::Register(const Type::Ptr& type)
{
VERIFY(GetByName(type->GetName()) == NULL);
GetTypes()[type->GetName()] = type;
}
开发者ID:CodeOps,项目名称:icinga2,代码行数:6,代码来源:type.cpp
示例20: HandleRequest
bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, HttpResponse& response, const Dictionary::Ptr& params)
{
if (request.RequestUrl->GetPath().size() < 3 || request.RequestUrl->GetPath().size() > 4)
return false;
if (request.RequestMethod != "GET")
return false;
Type::Ptr type = FilterUtility::TypeFromPluralName(request.RequestUrl->GetPath()[2]);
if (!type) {
HttpUtility::SendJsonError(response, params, 400, "Invalid type specified.");
return true;
}
QueryDescription qd;
qd.Types.insert(type->GetName());
qd.Permission = "objects/query/" + type->GetName();
Array::Ptr uattrs, ujoins, umetas;
try {
uattrs = params->Get("attrs");
} catch (const std::exception&) {
HttpUtility::SendJsonError(response, params, 400,
"Invalid type for 'attrs' attribute specified. Array type is required.");
return true;
}
try {
ujoins = params->Get("joins");
} catch (const std::exception&) {
HttpUtility::SendJsonError(response, params, 400,
"Invalid type for 'joins' attribute specified. Array type is required.");
return true;
}
try {
umetas = params->Get("meta");
} catch (const std::exception&) {
HttpUtility::SendJsonError(response, params, 400,
"Invalid type for 'meta' attribute specified. Array type is required.");
return true;
}
bool allJoins = HttpUtility::GetLastParameter(params, "all_joins");
params->Set("type", type->GetName());
if (request.RequestUrl->GetPath().size() >= 4) {
String attr = type->GetName();
boost::algorithm::to_lower(attr);
params->Set(attr, request.RequestUrl->GetPath()[3]);
}
std::vector<Value> objs;
try {
objs = FilterUtility::GetFilterTargets(qd, params, user);
} catch (const std::exception& ex) {
HttpUtility::SendJsonError(response, params, 404,
"No objects found.",
DiagnosticInformation(ex));
return true;
}
ArrayData results;
results.reserve(objs.size());
std::set<String> joinAttrs;
std::set<String> userJoinAttrs;
if (ujoins) {
ObjectLock olock(ujoins);
for (const String& ujoin : ujoins) {
userJoinAttrs.insert(ujoin.SubStr(0, ujoin.FindFirstOf(".")));
}
}
for (int fid = 0; fid < type->GetFieldCount(); fid++) {
Field field = type->GetFieldInfo(fid);
if (!(field.Attributes & FANavigation))
continue;
if (!allJoins && userJoinAttrs.find(field.NavigationName) == userJoinAttrs.end())
continue;
joinAttrs.insert(field.Name);
}
for (const ConfigObject::Ptr& obj : objs) {
DictionaryData result1{
{ "name", obj->GetName() },
{ "type", obj->GetReflectionType()->GetName() }
};
DictionaryData metaAttrs;
if (umetas) {
//.........这里部分代码省略.........
开发者ID:bebehei,项目名称:icinga2,代码行数:101,代码来源:objectqueryhandler.cpp
注:本文中的type::Ptr类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论