本文整理汇总了C++中type::Ptr::GetName方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::GetName方法的具体用法?C++ Ptr::GetName怎么用?C++ Ptr::GetName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类type::Ptr
的用法示例。
在下文中一共展示了Ptr::GetName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
static inline Value ConstructorCall(const Type::Ptr& type, const std::vector<Value>& args, const DebugInfo& debugInfo = DebugInfo())
{
if (type->GetName() == "String") {
if (args.empty())
return "";
else if (args.size() == 1)
return Convert::ToString(args[0]);
else
BOOST_THROW_EXCEPTION(ScriptError("Too many arguments for constructor."));
} else if (type->GetName() == "Number") {
if (args.empty())
return 0;
else if (args.size() == 1)
return Convert::ToDouble(args[0]);
else
BOOST_THROW_EXCEPTION(ScriptError("Too many arguments for constructor."));
} else if (type->GetName() == "Boolean") {
if (args.empty())
return 0;
else if (args.size() == 1)
return Convert::ToBool(args[0]);
else
BOOST_THROW_EXCEPTION(ScriptError("Too many arguments for constructor."));
} else if (args.size() == 1 && type->IsAssignableFrom(args[0].GetReflectionType()))
return args[0];
else
return type->Instantiate(args);
}
示例2: 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);
}
}
示例3: ToString
static inline Value CopyConstructorCall(const Type::Ptr& type, const Value& value, const DebugInfo& debugInfo = DebugInfo())
{
if (type->GetName() == "String")
return Convert::ToString(value);
else if (type->GetName() == "Number")
return Convert::ToDouble(value);
else if (type->GetName() == "Boolean")
return Convert::ToBool(value);
else if (!type->IsAssignableFrom(value.GetReflectionType()))
BOOST_THROW_EXCEPTION(ScriptError("Invalid cast: Tried to cast object of type '" + value.GetReflectionType()->GetName() + "' to type '" + type->GetName() + "'", debugInfo));
else
return value;
}
示例4: CreateObject
bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& fullName,
const Array::Ptr& templates, const Dictionary::Ptr& attrs, const Array::Ptr& errors)
{
NameComposer *nc = dynamic_cast<NameComposer *>(type.get());
Dictionary::Ptr nameParts;
String name;
if (nc) {
nameParts = nc->ParseName(fullName);
name = nameParts->Get("name");
} else
name = fullName;
ConfigItemBuilder::Ptr builder = new ConfigItemBuilder();
builder->SetType(type->GetName());
builder->SetName(name);
builder->SetScope(ScriptGlobal::GetGlobals());
builder->SetPackage("_api");
if (templates) {
ObjectLock olock(templates);
BOOST_FOREACH(const String& tmpl, templates) {
ImportExpression *expr = new ImportExpression(MakeLiteral(tmpl));
builder->AddExpression(expr);
}
}
示例5: GetTypeName
String Value::GetTypeName(void) const
{
Type::Ptr t;
switch (GetType()) {
case ValueEmpty:
return "Empty";
case ValueNumber:
return "Number";
case ValueBoolean:
return "Boolean";
case ValueString:
return "String";
case ValueObject:
t = boost::get<Object::Ptr>(m_Value)->GetReflectionType();
if (!t) {
if (IsObjectType<Array>())
return "Array";
else if (IsObjectType<Dictionary>())
return "Dictionary";
else
return "Object";
} else
return t->GetName();
default:
return "Invalid";
}
}
示例6: 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;
}
}
示例7: DeleteObjectHelper
bool ConfigObjectUtility::DeleteObjectHelper(const ConfigObject::Ptr& object, bool cascade, const Array::Ptr& errors)
{
std::vector<Object::Ptr> parents = DependencyGraph::GetParents(object);
Type::Ptr type = object->GetReflectionType();
if (!parents.empty() && !cascade) {
if (errors)
errors->Add("Object '" + object->GetName() + "' of type '" + type->GetName() +
"' cannot be deleted because other objects depend on it. "
"Use cascading delete to delete it anyway.");
return false;
}
for (const Object::Ptr& pobj : parents) {
ConfigObject::Ptr parentObj = dynamic_pointer_cast<ConfigObject>(pobj);
if (!parentObj)
continue;
DeleteObjectHelper(parentObj, cascade, errors);
}
ConfigItem::Ptr item = ConfigItem::GetByTypeAndName(type, object->GetName());
try {
/* mark this object for cluster delete event */
object->SetExtension("ConfigObjectDeleted", true);
/* triggers signal for DB IDO and other interfaces */
object->Deactivate(true);
if (item)
item->Unregister();
else
object->Unregister();
} catch (const std::exception& ex) {
if (errors)
errors->Add(DiagnosticInformation(ex));
return false;
}
String path = GetObjectConfigPath(object->GetReflectionType(), object->GetName());
if (Utility::PathExists(path)) {
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));
}
}
return true;
}
示例8: 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);
}
}
示例9: CreateObjectConfig
String ConfigObjectUtility::CreateObjectConfig(const Type::Ptr& type, const String& fullName,
bool ignoreOnError, const Array::Ptr& templates, const Dictionary::Ptr& attrs)
{
NameComposer *nc = dynamic_cast<NameComposer *>(type.get());
Dictionary::Ptr nameParts;
String name;
if (nc) {
nameParts = nc->ParseName(fullName);
name = nameParts->Get("name");
} else
name = fullName;
Dictionary::Ptr allAttrs = new Dictionary();
if (attrs) {
attrs->CopyTo(allAttrs);
ObjectLock olock(attrs);
for (const Dictionary::Pair& kv : attrs) {
int fid = type->GetFieldId(kv.first.SubStr(0, kv.first.FindFirstOf(".")));
if (fid < 0)
BOOST_THROW_EXCEPTION(ScriptError("Invalid attribute specified: " + kv.first));
Field field = type->GetFieldInfo(fid);
if (!(field.Attributes & FAConfig) || kv.first == "name")
BOOST_THROW_EXCEPTION(ScriptError("Attribute is marked for internal use only and may not be set: " + kv.first));
}
}
if (nameParts)
nameParts->CopyTo(allAttrs);
allAttrs->Remove("name");
/* update the version for config sync */
allAttrs->Set("version", Utility::GetTime());
std::ostringstream config;
ConfigWriter::EmitConfigItem(config, type->GetName(), name, false, ignoreOnError, templates, allAttrs);
ConfigWriter::EmitRaw(config, "\n");
return config.str();
}
示例10: 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));
}
示例11: 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;
}
示例12:
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;
}
示例13: 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));
}
示例14: 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;
}
示例15: HandleRequest
bool ModifyObjectHandler::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 != "POST")
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/modify/" + type->GetName();
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, 404,
"No objects found.",
HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
return true;
}
Dictionary::Ptr attrs = params->Get("attrs");
Array::Ptr results = new Array();
for (const ConfigObject::Ptr& obj : objs) {
Dictionary::Ptr result1 = new Dictionary();
result1->Set("type", type->GetName());
result1->Set("name", obj->GetName());
String key;
try {
if (attrs) {
ObjectLock olock(attrs);
for (const Dictionary::Pair& kv : attrs) {
key = kv.first;
obj->ModifyAttribute(kv.first, kv.second);
}
}
result1->Set("code", 200);
result1->Set("status", "Attributes updated.");
} catch (const std::exception& ex) {
result1->Set("code", 500);
result1->Set("status", "Attribute '" + key + "' could not be set: " + DiagnosticInformation(ex));
}
results->Add(result1);
}
Dictionary::Ptr result = new Dictionary();
result->Set("results", results);
response.SetStatus(200, "OK");
HttpUtility::SendJsonBody(response, result);
return true;
}