本文整理汇总了C++中array::Ptr::GetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::GetLength方法的具体用法?C++ Ptr::GetLength怎么用?C++ Ptr::GetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类array::Ptr
的用法示例。
在下文中一共展示了Ptr::GetLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Validate
void Notification::Validate(int types, const ValidationUtils& utils)
{
ObjectImpl<Notification>::Validate(types, utils);
if (!(types & FAConfig))
return;
Array::Ptr users = GetUsersRaw();
Array::Ptr groups = GetUserGroupsRaw();
if ((!users || users->GetLength() == 0) && (!groups || groups->GetLength() == 0))
BOOST_THROW_EXCEPTION(ValidationError(this, std::vector<String>(), "Validation failed: No users/user_groups specified."));
}
示例2: GetLastParameter
Value HttpUtility::GetLastParameter(const Dictionary::Ptr& params, const String& key)
{
Value varr = params->Get(key);
if (!varr.IsObjectType<Array>())
return varr;
Array::Ptr arr = varr;
if (arr->GetLength() == 0)
return Empty;
else
return arr->Get(arr->GetLength() - 1);
}
示例3: ResolveGroupMembership
bool HostGroup::ResolveGroupMembership(const Host::Ptr& host, bool add, int rstack) {
if (add && rstack > 20) {
Log(LogWarning, "HostGroup")
<< "Too many nested groups for group '" << GetName() << "': Host '"
<< host->GetName() << "' membership assignment failed.";
return false;
}
Array::Ptr groups = GetGroups();
if (groups && groups->GetLength() > 0) {
ObjectLock olock(groups);
for (const String& name : groups) {
HostGroup::Ptr group = HostGroup::GetByName(name);
if (group && !group->ResolveGroupMembership(host, add, rstack + 1))
return false;
}
}
if (add)
AddMember(host);
else
RemoveMember(host);
return true;
}
示例4: olock
static inline ExpressionResult For(ScriptFrame& frame, const String& fkvar, const String& fvvar, const Value& value, Expression *expression, const DebugInfo& debugInfo = DebugInfo())
{
if (value.IsObjectType<Array>()) {
if (!fvvar.IsEmpty())
BOOST_THROW_EXCEPTION(ScriptError("Cannot use dictionary iterator for array.", debugInfo));
Array::Ptr arr = value;
for (Array::SizeType i = 0; i < arr->GetLength(); i++) {
frame.Locals->Set(fkvar, arr->Get(i));
ExpressionResult res = expression->Evaluate(frame);
CHECK_RESULT_LOOP(res);
}
} else if (value.IsObjectType<Dictionary>()) {
if (fvvar.IsEmpty())
BOOST_THROW_EXCEPTION(ScriptError("Cannot use array iterator for dictionary.", debugInfo));
Dictionary::Ptr dict = value;
std::vector<String> keys;
{
ObjectLock olock(dict);
BOOST_FOREACH(const Dictionary::Pair& kv, dict) {
keys.push_back(kv.first);
}
}
BOOST_FOREACH(const String& key, keys) {
frame.Locals->Set(fkvar, key);
frame.Locals->Set(fvvar, dict->Get(key));
ExpressionResult res = expression->Evaluate(frame);
CHECK_RESULT_LOOP(res);
}
示例5: AutoCompleteScript
/**
* Executes the auto completion script via HTTP and returns HTTP and user errors.
*
* @param session Local session handler.
* @param command The auto completion string.
* @param sandboxed Whether to run this sandboxed.
* @return Result value, also contains user errors.
*/
Array::Ptr ConsoleCommand::AutoCompleteScript(const String& session, const String& command, bool sandboxed)
{
/* Extend the url parameters for the request. */
l_Url->SetPath({ "v1", "console", "auto-complete-script" });
l_Url->SetQuery({
{"session", session},
{"command", command},
{"sandboxed", sandboxed ? "1" : "0"}
});
Dictionary::Ptr jsonResponse = SendRequest();
/* Extract the result, and handle user input errors too. */
Array::Ptr results = jsonResponse->Get("results");
Array::Ptr suggestions;
if (results && results->GetLength() > 0) {
Dictionary::Ptr resultInfo = results->Get(0);
if (resultInfo->Get("code") >= 200 && resultInfo->Get("code") <= 299) {
suggestions = resultInfo->Get("suggestions");
} else {
String errorMessage = resultInfo->Get("status");
BOOST_THROW_EXCEPTION(ScriptError(errorMessage));
}
}
return suggestions;
}
示例6: ToBool
bool Value::ToBool(void) const
{
switch (GetType()) {
case ValueNumber:
return static_cast<bool>(boost::get<double>(m_Value));
case ValueBoolean:
return boost::get<bool>(m_Value);
case ValueString:
return !boost::get<String>(m_Value).IsEmpty();
case ValueObject:
if (IsObjectType<Dictionary>()) {
Dictionary::Ptr dictionary = *this;
return dictionary->GetLength() > 0;
} else if (IsObjectType<Array>()) {
Array::Ptr array = *this;
return array->GetLength() > 0;
} else {
return true;
}
case ValueEmpty:
return false;
default:
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid variant type."));
}
}
示例7: EmitScope
void ConfigWriter::EmitScope(std::ostream& fp, int indentLevel, const Dictionary::Ptr& val, const Array::Ptr& imports)
{
fp << "{";
if (imports && imports->GetLength() > 0) {
ObjectLock xlock(imports);
BOOST_FOREACH(const Value& import, imports) {
fp << "\n";
EmitIndent(fp, indentLevel);
fp << "import \"" << import << "\"";
}
示例8: ValidateEndpointsRaw
void Zone::ValidateEndpointsRaw(const Array::Ptr& value, const ValidationUtils& utils)
{
ObjectImpl<Zone>::ValidateEndpointsRaw(value, utils);
if (value && value->GetLength() > 2) {
Log(LogWarning, "Zone")
<< "The Zone object '" << GetName() << "' has more than two endpoints."
<< " Due to a known issue this type of configuration is strongly"
<< " discouraged and may cause Icinga to use excessive amounts of CPU time.";
}
}
示例9: ExecuteScriptHttpCompletionCallback
void ApiClient::ExecuteScriptHttpCompletionCallback(HttpRequest& request,
HttpResponse& response, const ExecuteScriptCompletionCallback& callback)
{
Dictionary::Ptr result;
String body;
char buffer[1024];
size_t count;
while ((count = response.ReadBody(buffer, sizeof(buffer))) > 0)
body += String(buffer, buffer + count);
try {
if (response.StatusCode < 200 || response.StatusCode > 299) {
std::string message = "HTTP request failed; Code: " + Convert::ToString(response.StatusCode) + "; Body: " + body;
BOOST_THROW_EXCEPTION(ScriptError(message));
}
result = JsonDecode(body);
Array::Ptr results = result->Get("results");
Value result;
String errorMessage = "Unexpected result from API.";
if (results && results->GetLength() > 0) {
Dictionary::Ptr resultInfo = results->Get(0);
errorMessage = resultInfo->Get("status");
if (resultInfo->Get("code") >= 200 && resultInfo->Get("code") <= 299) {
result = resultInfo->Get("result");
} else {
DebugInfo di;
Dictionary::Ptr debugInfo = resultInfo->Get("debug_info");
if (debugInfo) {
di.Path = debugInfo->Get("path");
di.FirstLine = debugInfo->Get("first_line");
di.FirstColumn = debugInfo->Get("first_column");
di.LastLine = debugInfo->Get("last_line");
di.LastColumn = debugInfo->Get("last_column");
}
bool incompleteExpression = resultInfo->Get("incomplete_expression");
BOOST_THROW_EXCEPTION(ScriptError(errorMessage, di, incompleteExpression));
}
}
callback(boost::exception_ptr(), result);
} catch (const std::exception&) {
callback(boost::current_exception(), Empty);
}
}
示例10: ArrayReduce
static Value ArrayReduce(const Function::Ptr& function)
{
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
if (vframe->Sandboxed && !function->IsSideEffectFree())
BOOST_THROW_EXCEPTION(ScriptError("Reduce function must be side-effect free."));
if (self->GetLength() == 0)
return Empty;
Value result = self->Get(0);
ObjectLock olock(self);
for (size_t i = 1; i < self->GetLength(); i++) {
std::vector<Value> args;
args.push_back(result);
args.push_back(self->Get(i));
result = function->Invoke(args);
}
return result;
}
示例11: Len
double ScriptUtils::Len(const Value& value)
{
if (value.IsObjectType<Dictionary>()) {
Dictionary::Ptr dict = value;
return dict->GetLength();
} else if (value.IsObjectType<Array>()) {
Array::Ptr array = value;
return array->GetLength();
} else if (value.IsString()) {
return Convert::ToString(value).GetLength();
} else {
return 0;
}
}
示例12: ExecuteScript
/**
* Executes the DSL script via HTTP and returns HTTP and user errors.
*
* @param session Local session handler.
* @param command The DSL string.
* @param sandboxed Whether to run this sandboxed.
* @return Result value, also contains user errors.
*/
Value ConsoleCommand::ExecuteScript(const String& session, const String& command, bool sandboxed)
{
/* Extend the url parameters for the request. */
l_Url->SetPath({"v1", "console", "execute-script"});
l_Url->SetQuery({
{"session", session},
{"command", command},
{"sandboxed", sandboxed ? "1" : "0"}
});
Dictionary::Ptr jsonResponse = SendRequest();
/* Extract the result, and handle user input errors too. */
Array::Ptr results = jsonResponse->Get("results");
Value result;
if (results && results->GetLength() > 0) {
Dictionary::Ptr resultInfo = results->Get(0);
if (resultInfo->Get("code") >= 200 && resultInfo->Get("code") <= 299) {
result = resultInfo->Get("result");
} else {
String errorMessage = resultInfo->Get("status");
DebugInfo di;
Dictionary::Ptr debugInfo = resultInfo->Get("debug_info");
if (debugInfo) {
di.Path = debugInfo->Get("path");
di.FirstLine = debugInfo->Get("first_line");
di.FirstColumn = debugInfo->Get("first_column");
di.LastLine = debugInfo->Get("last_line");
di.LastColumn = debugInfo->Get("last_column");
}
bool incompleteExpression = resultInfo->Get("incomplete_expression");
BOOST_THROW_EXCEPTION(ScriptError(errorMessage, di, incompleteExpression));
}
}
return result;
}
示例13: ScriptFunc
Array::Ptr LegacyTimePeriod::ScriptFunc(const TimePeriod::Ptr& tp, double begin, double end)
{
Array::Ptr segments = new Array();
Dictionary::Ptr ranges = tp->GetRanges();
if (ranges) {
for (int i = 0; i <= (end - begin) / (24 * 60 * 60); i++) {
time_t refts = begin + i * 24 * 60 * 60;
tm reference = Utility::LocalTime(refts);
#ifdef I2_DEBUG
Log(LogDebug, "LegacyTimePeriod")
<< "Checking reference time " << refts;
#endif /* I2_DEBUG */
ObjectLock olock(ranges);
for (const Dictionary::Pair& kv : ranges) {
if (!IsInDayDefinition(kv.first, &reference)) {
#ifdef I2_DEBUG
Log(LogDebug, "LegacyTimePeriod")
<< "Not in day definition '" << kv.first << "'.";
#endif /* I2_DEBUG */
continue;
}
#ifdef I2_DEBUG
Log(LogDebug, "LegacyTimePeriod")
<< "In day definition '" << kv.first << "'.";
#endif /* I2_DEBUG */
ProcessTimeRanges(kv.second, &reference, segments);
}
}
}
Log(LogDebug, "LegacyTimePeriod")
<< "Legacy timeperiod update returned " << segments->GetLength() << " segments.";
return segments;
}
示例14: AutocompleteScriptHttpCompletionCallback
void ApiClient::AutocompleteScriptHttpCompletionCallback(HttpRequest& request,
HttpResponse& response, const AutocompleteScriptCompletionCallback& callback)
{
Dictionary::Ptr result;
String body;
char buffer[1024];
size_t count;
while ((count = response.ReadBody(buffer, sizeof(buffer))) > 0)
body += String(buffer, buffer + count);
try {
if (response.StatusCode < 200 || response.StatusCode > 299) {
std::string message = "HTTP request failed; Code: " + Convert::ToString(response.StatusCode) + "; Body: " + body;
BOOST_THROW_EXCEPTION(ScriptError(message));
}
result = JsonDecode(body);
Array::Ptr results = result->Get("results");
Array::Ptr suggestions;
String errorMessage = "Unexpected result from API.";
if (results && results->GetLength() > 0) {
Dictionary::Ptr resultInfo = results->Get(0);
errorMessage = resultInfo->Get("status");
if (resultInfo->Get("code") >= 200 && resultInfo->Get("code") <= 299)
suggestions = resultInfo->Get("suggestions");
else
BOOST_THROW_EXCEPTION(ScriptError(errorMessage));
}
callback(boost::exception_ptr(), suggestions);
} catch (const std::exception&) {
callback(boost::current_exception(), nullptr);
}
}
示例15: IsSingleInstance
bool Zone::IsSingleInstance() const
{
Array::Ptr endpoints = GetEndpointsRaw();
return !endpoints || endpoints->GetLength() < 2;
}