本文整理汇总了C++中type::Ptr类的典型用法代码示例。如果您正苦于以下问题:C++ Ptr类的具体用法?C++ Ptr怎么用?C++ Ptr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例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";
}
示例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;
}
示例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));
}
示例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;
}
示例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);
}
}
示例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;
}
示例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));
}
示例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);
}
示例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_);
}
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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();
}
示例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;
}