本文整理汇总了C++中dictionary::Ptr::Contains方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::Contains方法的具体用法?C++ Ptr::Contains怎么用?C++ Ptr::Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dictionary::Ptr
的用法示例。
在下文中一共展示了Ptr::Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddComment
Dictionary::Ptr ApiActions::AddComment(const ConfigObject::Ptr& object,
const Dictionary::Ptr& params)
{
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
if (!checkable)
return ApiActions::CreateResult(404, "Cannot add comment for non-existent object");
if (!params->Contains("author") || !params->Contains("comment"))
return ApiActions::CreateResult(403, "Comments require author and comment.");
String commentName = Comment::AddComment(checkable, CommentUser,
HttpUtility::GetLastParameter(params, "author"),
HttpUtility::GetLastParameter(params, "comment"), 0);
Comment::Ptr comment = Comment::GetByName(commentName);
Dictionary::Ptr additional = new Dictionary();
additional->Set("name", commentName);
additional->Set("legacy_id", comment->GetLegacyId());
return ApiActions::CreateResult(200, "Successfully added comment '"
+ commentName + "' for object '" + checkable->GetName()
+ "'.", additional);
}
示例2: UpdateConfigDir
bool ApiListener::UpdateConfigDir(const Dictionary::Ptr& oldConfig, const Dictionary::Ptr& newConfig, const String& configDir, bool authoritative)
{
bool configChange = false;
if (oldConfig->Contains(".timestamp") && newConfig->Contains(".timestamp")) {
double oldTS = Convert::ToDouble(oldConfig->Get(".timestamp"));
double newTS = Convert::ToDouble(newConfig->Get(".timestamp"));
/* skip update if our config is newer */
if (oldTS <= newTS)
return false;
}
{
ObjectLock olock(newConfig);
BOOST_FOREACH(const Dictionary::Pair& kv, newConfig) {
if (oldConfig->Get(kv.first) != kv.second) {
configChange = true;
String path = configDir + "/" + kv.first;
Log(LogInformation, "ApiListener")
<< "Updating configuration file: " << path;
//pass the directory and generate a dir tree, if not existing already
Utility::MkDirP(Utility::DirName(path), 0755);
std::ofstream fp(path.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
fp << kv.second;
fp.close();
}
}
}
ObjectLock xlock(oldConfig);
BOOST_FOREACH(const Dictionary::Pair& kv, oldConfig) {
if (!newConfig->Contains(kv.first)) {
configChange = true;
String path = configDir + "/" + kv.first;
(void) unlink(path.CStr());
}
}
String tsPath = configDir + "/.timestamp";
if (!Utility::PathExists(tsPath)) {
std::ofstream fp(tsPath.CStr(), std::ofstream::out | std::ostream::trunc);
fp << std::fixed << Utility::GetTime();
fp.close();
}
if (authoritative) {
String authPath = configDir + "/.authoritative";
if (!Utility::PathExists(authPath)) {
std::ofstream fp(authPath.CStr(), std::ofstream::out | std::ostream::trunc);
fp.close();
}
}
return configChange;
}
示例3: MessageHandler
void JsonRpcConnection::MessageHandler(const String& jsonString)
{
Dictionary::Ptr message = JsonRpc::DecodeMessage(jsonString);
m_Seen = Utility::GetTime();
if (m_HeartbeatTimeout != 0)
m_NextHeartbeat = Utility::GetTime() + m_HeartbeatTimeout;
if (m_Endpoint && message->Contains("ts")) {
double ts = message->Get("ts");
/* ignore old messages */
if (ts < m_Endpoint->GetRemoteLogPosition())
return;
m_Endpoint->SetRemoteLogPosition(ts);
}
MessageOrigin::Ptr origin = new MessageOrigin();
origin->FromClient = this;
if (m_Endpoint) {
if (m_Endpoint->GetZone() != Zone::GetLocalZone())
origin->FromZone = m_Endpoint->GetZone();
else
origin->FromZone = Zone::GetByName(message->Get("originZone"));
}
String method = message->Get("method");
Log(LogNotice, "JsonRpcConnection")
<< "Received '" << method << "' message from '" << m_Identity << "'";
Dictionary::Ptr resultMessage = new Dictionary();
try {
ApiFunction::Ptr afunc = ApiFunction::GetByName(method);
if (!afunc)
BOOST_THROW_EXCEPTION(std::invalid_argument("Function '" + method + "' does not exist."));
resultMessage->Set("result", afunc->Invoke(origin, message->Get("params")));
} catch (const std::exception& ex) {
/* TODO: Add a user readable error message for the remote caller */
resultMessage->Set("error", DiagnosticInformation(ex));
std::ostringstream info;
info << "Error while processing message for identity '" << m_Identity << "'";
Log(LogWarning, "JsonRpcConnection")
<< info.str() << "\n" << DiagnosticInformation(ex);
}
if (message->Contains("id")) {
resultMessage->Set("jsonrpc", "2.0");
resultMessage->Set("id", message->Get("id"));
SendMessage(resultMessage);
}
}
示例4: SendNotificationsAPIHandler
Value ClusterEvents::SendNotificationsAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
{
Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();
if (!endpoint) {
Log(LogNotice, "ClusterEvents")
<< "Discarding 'send notification' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
return Empty;
}
Host::Ptr host = Host::GetByName(params->Get("host"));
if (!host)
return Empty;
Checkable::Ptr checkable;
if (params->Contains("service"))
checkable = host->GetServiceByShortName(params->Get("service"));
else
checkable = host;
if (!checkable)
return Empty;
if (origin->FromZone && origin->FromZone != Zone::GetLocalZone()) {
Log(LogNotice, "ClusterEvents")
<< "Discarding 'send custom notification' message for checkable '" << checkable->GetName()
<< "' from '" << origin->FromClient->GetIdentity() << "': Unauthorized access.";
return Empty;
}
CheckResult::Ptr cr;
Array::Ptr vperf;
if (params->Contains("cr")) {
cr = new CheckResult();
Dictionary::Ptr vcr = params->Get("cr");
if (vcr && vcr->Contains("performance_data")) {
vperf = vcr->Get("performance_data");
if (vperf)
vcr->Remove("performance_data");
Deserialize(cr, vcr, true);
}
}
NotificationType type = static_cast<NotificationType>(static_cast<int>(params->Get("type")));
String author = params->Get("author");
String text = params->Get("text");
Checkable::OnNotificationsRequested(checkable, type, cr, author, text, origin);
return Empty;
}
示例5: Validate
void Command::Validate(int types, const ValidationUtils& utils)
{
ObjectImpl<Command>::Validate(types, utils);
Dictionary::Ptr arguments = GetArguments();
if (!(types & FAConfig))
return;
if (arguments) {
if (!GetCommandLine().IsObjectType<Array>())
BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("command"), "Attribute 'command' must be an array if the 'arguments' attribute is set."));
ObjectLock olock(arguments);
BOOST_FOREACH(const Dictionary::Pair& kv, arguments) {
const Value& arginfo = kv.second;
Value argval;
if (arginfo.IsObjectType<Dictionary>()) {
Dictionary::Ptr argdict = arginfo;
if (argdict->Contains("value")) {
Value argvalue = argdict->Get("value");
if (argvalue.IsString() && !MacroProcessor::ValidateMacroString(argvalue))
BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of<String>("arguments")(kv.first)("value"), "Validation failed: Closing $ not found in macro format string '" + argvalue + "'."));
}
if (argdict->Contains("set_if")) {
Value argsetif = argdict->Get("set_if");
if (argsetif.IsString() && !MacroProcessor::ValidateMacroString(argsetif))
BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of<String>("arguments")(kv.first)("set_if"), "Closing $ not found in macro format string '" + argsetif + "'."));
}
} else if (arginfo.IsString()) {
if (!MacroProcessor::ValidateMacroString(arginfo))
BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of<String>("arguments")(kv.first), "Closing $ not found in macro format string '" + arginfo + "'."));
}
}
}
Dictionary::Ptr env = GetEnv();
if (env) {
ObjectLock olock(env);
BOOST_FOREACH(const Dictionary::Pair& kv, env) {
const Value& envval = kv.second;
if (!envval.IsString() || envval.IsEmpty())
continue;
if (!MacroProcessor::ValidateMacroString(envval))
BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of<String>("env")(kv.first), "Closing $ not found in macro format string '" + envval + "'."));
}
}
}
示例6: ProcessCheckResult
Dictionary::Ptr ApiActions::ProcessCheckResult(const ConfigObject::Ptr& object,
const Dictionary::Ptr& params)
{
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
if (!checkable)
return ApiActions::CreateResult(404,
"Cannot process passive check result for non-existent object.");
if (!checkable->GetEnablePassiveChecks())
return ApiActions::CreateResult(403, "Passive checks are disabled for object '" + checkable->GetName() + "'.");
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
if (!params->Contains("exit_status"))
return ApiActions::CreateResult(403, "Parameter 'exit_status' is required.");
int exitStatus = HttpUtility::GetLastParameter(params, "exit_status");
ServiceState state;
if (!service) {
if (exitStatus == 0)
state = ServiceOK;
else if (exitStatus == 1)
state = ServiceCritical;
else
return ApiActions::CreateResult(403, "Invalid 'exit_status' for Host "
+ checkable->GetName() + ".");
} else {
state = PluginUtility::ExitStatusToState(exitStatus);
}
if (!params->Contains("plugin_output"))
return ApiActions::CreateResult(403, "Parameter 'plugin_output' is required");
CheckResult::Ptr cr = new CheckResult();
cr->SetOutput(HttpUtility::GetLastParameter(params, "plugin_output"));
cr->SetState(state);
cr->SetCheckSource(HttpUtility::GetLastParameter(params, "check_source"));
cr->SetPerformanceData(params->Get("performance_data"));
cr->SetCommand(params->Get("check_command"));
checkable->ProcessCheckResult(cr);
/* Reschedule the next check. The side effect of this is that for as long
* as we receive passive results for a service we won't execute any
* active checks. */
checkable->SetNextCheck(Utility::GetTime() + checkable->GetCheckInterval());
return ApiActions::CreateResult(200, "Successfully processed check result for object '" + checkable->GetName() + "'.");
}
示例7: OnConfigUpdate
void UserDbObject::OnConfigUpdate(void)
{
Dictionary::Ptr fields = new Dictionary();
User::Ptr user = static_pointer_cast<User>(GetObject());
/* contact addresses */
Log(LogDebug, "UserDbObject")
<< "contact addresses for '" << user->GetName() << "'";
Dictionary::Ptr vars = user->GetVars();
if (vars) { /* This is sparta. */
for (int i = 1; i <= 6; i++) {
String key = "address" + Convert::ToString(i);
if (!vars->Contains(key))
continue;
String val = vars->Get(key);
fields->Set("contact_id", DbValue::FromObjectInsertID(user));
fields->Set("address_number", i);
fields->Set("address", val);
fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
DbQuery query;
query.Type = DbQueryInsert;
query.Table = "contact_addresses";
query.Fields = fields;
OnQuery(query);
}
}
}
示例8: Run
/**
* The entry point for the "ca list" CLI command.
*
* @returns An exit status.
*/
int CAListCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
{
Dictionary::Ptr requests = PkiUtility::GetCertificateRequests();
if (vm.count("json"))
std::cout << JsonEncode(requests);
else {
ObjectLock olock(requests);
std::cout << "Fingerprint | Timestamp | Signed | Subject\n";
std::cout << "-----------------------------------------------------------------|--------------------------|--------|--------\n";
for (auto& kv : requests) {
Dictionary::Ptr request = kv.second;
std::cout << kv.first
<< " | "
/* << Utility::FormatDateTime("%Y/%m/%d %H:%M:%S", request->Get("timestamp")) */
<< request->Get("timestamp")
<< " | "
<< (request->Contains("cert_response") ? "*" : " ") << " "
<< " | "
<< request->Get("subject")
<< "\n";
}
}
return 0;
}
示例9: DumpModifiedAttributes
void ConfigObject::DumpModifiedAttributes(const std::function<void(const ConfigObject::Ptr&, const String&, const Value&)>& callback)
{
for (const Type::Ptr& type : Type::GetAllTypes()) {
auto *dtype = dynamic_cast<ConfigType *>(type.get());
if (!dtype)
continue;
for (const ConfigObject::Ptr& object : dtype->GetObjects()) {
Dictionary::Ptr originalAttributes = object->GetOriginalAttributes();
if (!originalAttributes)
continue;
ObjectLock olock(originalAttributes);
for (const Dictionary::Pair& kv : originalAttributes) {
String key = kv.first;
Type::Ptr type = object->GetReflectionType();
std::vector<String> tokens = key.Split(".");
String fieldName = tokens[0];
int fid = type->GetFieldId(fieldName);
Value currentValue = object->GetField(fid);
Value modifiedValue;
if (tokens.size() > 1) {
Value current = currentValue;
for (std::vector<String>::size_type i = 1; i < tokens.size() - 1; i++) {
if (!current.IsObjectType<Dictionary>())
BOOST_THROW_EXCEPTION(std::invalid_argument("Value must be a dictionary."));
Dictionary::Ptr dict = current;
const String& key = tokens[i];
if (!dict->Contains(key))
break;
current = dict->Get(key);
}
if (!current.IsObjectType<Dictionary>())
BOOST_THROW_EXCEPTION(std::invalid_argument("Value must be a dictionary."));
Dictionary::Ptr dict = current;
const String& key = tokens[tokens.size() - 1];
modifiedValue = dict->Get(key);
} else
modifiedValue = currentValue;
callback(object, key, modifiedValue);
}
}
}
}
示例10: olock
wxPGProperty *MainForm::ValueToProperty(const String& name, const Value& value)
{
wxPGProperty *prop;
if (value.IsNumber()) {
prop = new wxFloatProperty(name.GetData(), wxPG_LABEL, value);
prop->SetAttribute(wxPG_ATTR_UNITS, "Number");
return prop;
} else if (value.IsBoolean()) {
prop = new wxBoolProperty(name.GetData(), wxPG_LABEL, value);
prop->SetAttribute(wxPG_ATTR_UNITS, "Boolean");
return prop;
} else if (value.IsObjectType<Array>()) {
wxArrayString val;
Array::Ptr arr = value;
{
ObjectLock olock(arr);
for (const Value& aitem : arr) {
String val1 = aitem;
val.Add(val1.GetData());
}
}
prop = new wxArrayStringProperty(name.GetData(), wxPG_LABEL, val);
prop->SetAttribute(wxPG_ATTR_UNITS, "Array");
return prop;
} else if (value.IsObjectType<Dictionary>()) {
wxStringProperty *prop = new wxStringProperty(name.GetData(), wxPG_LABEL);
Dictionary::Ptr dict = value;
{
ObjectLock olock(dict);
for (const Dictionary::Pair& kv : dict) {
if (kv.first != "type")
prop->AppendChild(ValueToProperty(kv.first, kv.second));
}
}
String type = "Dictionary";
if (dict->Contains("type"))
type = dict->Get("type");
prop->SetAttribute(wxPG_ATTR_UNITS, type.GetData());
return prop;
} else if (value.IsEmpty() && !value.IsString()) {
prop = new wxStringProperty(name.GetData(), wxPG_LABEL, "");
prop->SetAttribute(wxPG_ATTR_UNITS, "Empty");
return prop;
} else {
String val = value;
prop = new wxStringProperty(name.GetData(), wxPG_LABEL, val.GetData());
prop->SetAttribute(wxPG_ATTR_UNITS, "String");
return prop;
}
}
示例11: HasAuthority
bool DynamicObject::HasAuthority(const String& type) const
{
Dictionary::Ptr authorityInfo = GetAuthorityInfo();
if (!authorityInfo || !authorityInfo->Contains(type))
return true;
return authorityInfo->Get(type);
}
示例12: AcknowledgeProblem
Dictionary::Ptr ApiActions::AcknowledgeProblem(const ConfigObject::Ptr& object,
const Dictionary::Ptr& params)
{
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
if (!checkable)
return ApiActions::CreateResult(404, "Cannot acknowledge problem for non-existent object.");
if (!params->Contains("author") || !params->Contains("comment"))
return ApiActions::CreateResult(403, "Acknowledgements require author and comment.");
AcknowledgementType sticky = AcknowledgementNormal;
bool notify = false;
double timestamp = 0.0;
if (params->Contains("sticky"))
sticky = AcknowledgementSticky;
if (params->Contains("notify"))
notify = true;
if (params->Contains("expiry"))
timestamp = HttpUtility::GetLastParameter(params, "expiry");
else
timestamp = 0;
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
if (!service) {
if (host->GetState() == HostUp)
return ApiActions::CreateResult(409, "Host " + checkable->GetName() + " is UP.");
} else {
if (service->GetState() == ServiceOK)
return ApiActions::CreateResult(409, "Service " + checkable->GetName() + " is OK.");
}
Comment::AddComment(checkable, CommentAcknowledgement, HttpUtility::GetLastParameter(params, "author"),
HttpUtility::GetLastParameter(params, "comment"), timestamp);
checkable->AcknowledgeProblem(HttpUtility::GetLastParameter(params, "author"),
HttpUtility::GetLastParameter(params, "comment"), sticky, notify, timestamp);
return ApiActions::CreateResult(200, "Successfully acknowledged problem for object '" + checkable->GetName() + "'.");
}
示例13: RemoveCommentByID
Dictionary::Ptr ApiActions::RemoveCommentByID(const ConfigObject::Ptr& object,
const Dictionary::Ptr& params)
{
if (!params->Contains("comment_id"))
return ApiActions::CreateResult(403, "Parameter 'comment_id' is required.");
String comment_id = HttpUtility::GetLastParameter(params, "comment_id");
Comment::RemoveComment(comment_id);
return ApiActions::CreateResult(200, "Successfully removed comment '" + comment_id + "'.");
}
示例14: RemoveDowntimeByID
Dictionary::Ptr ApiActions::RemoveDowntimeByID(const ConfigObject::Ptr& object,
const Dictionary::Ptr& params)
{
if (!params->Contains("downtime_id"))
return ApiActions::CreateResult(403, "Parameter 'downtime_id' is required.");
String downtime_id = HttpUtility::GetLastParameter(params, "downtime_id");
Downtime::RemoveDowntime(downtime_id, true);
return ApiActions::CreateResult(200, "Successfully removed downtime '" + downtime_id + "'.");
}
示例15: SendCustomNotification
Dictionary::Ptr ApiActions::SendCustomNotification(const ConfigObject::Ptr& object,
const Dictionary::Ptr& params)
{
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
if (!checkable)
return ApiActions::CreateResult(404, "Cannot send notification for non-existent object.");
if (!params->Contains("author"))
return ApiActions::CreateResult(403, "Parameter 'author' is required.");
if (!params->Contains("comment"))
return ApiActions::CreateResult(403, "Parameter 'comment' is required.");
if (Convert::ToBool(HttpUtility::GetLastParameter(params, "force")))
checkable->SetForceNextNotification(true);
Checkable::OnNotificationsRequested(checkable, NotificationCustom, checkable->GetLastCheckResult(),
HttpUtility::GetLastParameter(params, "author"), HttpUtility::GetLastParameter(params, "comment"), MessageOrigin::Ptr());
return ApiActions::CreateResult(200, "Successfully sent custom notification for object '" + checkable->GetName() + "'.");
}