本文整理汇总了C++中array::Ptr类的典型用法代码示例。如果您正苦于以下问题:C++ Ptr类的具体用法?C++ Ptr怎么用?C++ Ptr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ptr类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: testStringElement
void JSONTest::testStringElement()
{
std::string json = "[ \"value\" ]";
Parser parser;
Var result;
try
{
DefaultHandler handler;
parser.setHandler(&handler);
parser.parse(json);
result = handler.result();
}
catch(JSONException& jsone)
{
std::cout << jsone.message() << std::endl;
assert(false);
}
assert(result.type() == typeid(Array::Ptr));
Array::Ptr array = result.extract<Array::Ptr>();
Var test = array->get(0);
assert(test.isString());
std::string value = test.convert<std::string>();
assert(value.compare("value") == 0);
}
开发者ID:RageStormers,项目名称:poco,代码行数:27,代码来源:JSONTest.cpp
示例2: 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."));
}
}
开发者ID:TheFlyingCorpse,项目名称:icinga2,代码行数:30,代码来源:value.cpp
示例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;
}
开发者ID:dupondje,项目名称:icinga2,代码行数:30,代码来源:hostgroup.cpp
示例4: PurgeSegments
void TimePeriod::PurgeSegments(double end)
{
ASSERT(OwnsLock());
Log(LogDebug, "TimePeriod")
<< "Purging segments older than '" << Utility::FormatDateTime("%c", end)
<< "' from TimePeriod '" << GetName() << "'";
if (GetValidBegin().IsEmpty() || end < GetValidBegin())
return;
SetValidBegin(end);
Array::Ptr segments = GetSegments();
if (!segments)
return;
Array::Ptr newSegments = new Array();
/* Remove old segments. */
ObjectLock dlock(segments);
for (const Dictionary::Ptr& segment : segments) {
if (segment->Get("end") >= end)
newSegments->Add(segment);
}
SetSegments(newSegments);
}
开发者ID:TheFlyingCorpse,项目名称:icinga2,代码行数:29,代码来源:timeperiod.cpp
示例5: testNullElement
void JSONTest::testNullElement()
{
std::string json = "[ null ]";
Parser parser;
Var result;
try
{
DefaultHandler handler;
parser.setHandler(&handler);
parser.parse(json);
result = handler.result();
}
catch(JSONException& jsone)
{
std::cout << jsone.message() << std::endl;
assert(false);
}
assert(result.type() == typeid(Array::Ptr));
Array::Ptr array = result.extract<Array::Ptr>();
assert(array->isNull(0));
Var test = array->get(0);
assert(test.isEmpty());
}
开发者ID:RageStormers,项目名称:poco,代码行数:26,代码来源:JSONTest.cpp
示例6: testEmptyObjectElement
void JSONTest::testEmptyObjectElement()
{
std::string json = "[{}]";
Parser parser;
Var result;
try
{
DefaultHandler handler;
parser.setHandler(&handler);
parser.parse(json);
result = handler.result();
}
catch(JSONException& jsone)
{
std::cout << jsone.message() << std::endl;
assert(false);
}
assert(result.type() == typeid(Array::Ptr));
Array::Ptr array = result.extract<Array::Ptr>();
Object::Ptr object = array->getObject(0);
assert(object->size() == 0);
}
开发者ID:RageStormers,项目名称:poco,代码行数:25,代码来源:JSONTest.cpp
示例7: Range
Array::Ptr ScriptUtils::Range(const std::vector<Value>& arguments)
{
double start, end, increment;
switch (arguments.size()) {
case 1:
start = 0;
end = arguments[0];
increment = 1;
break;
case 2:
start = arguments[0];
end = arguments[1];
increment = 1;
break;
case 3:
start = arguments[0];
end = arguments[1];
increment = arguments[2];
break;
default:
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid number of arguments for range()"));
}
Array::Ptr result = new Array();
if ((start < end && increment <= 0) ||
(start > end && increment >= 0))
return result;
for (double i = start; (increment > 0 ? i < end : i > end); i += increment)
result->Add(i);
return result;
}
开发者ID:TheFlyingCorpse,项目名称:icinga2,代码行数:35,代码来源:scriptutils.cpp
示例8: 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;
}
开发者ID:Icinga,项目名称:icinga2,代码行数:38,代码来源:consolecommand.cpp
示例9: testDoubleElement
void JSONTest::testDoubleElement()
{
std::string json = "[ 123.45 ]";
Parser parser;
Var result;
try
{
DefaultHandler handler;
parser.setHandler(&handler);
parser.parse(json);
result = handler.result();
}
catch(JSONException& jsone)
{
std::cout << jsone.message() << std::endl;
assert(false);
}
assert(result.type() == typeid(Array::Ptr));
Array::Ptr array = result.extract<Array::Ptr>();
Var test = array->get(0);
assert(test.isNumeric());
double value = test;
assert(value == 123.45);
}
开发者ID:RageStormers,项目名称:poco,代码行数:27,代码来源:JSONTest.cpp
示例10: olock
char *ConsoleCommand::ConsoleCompleteHelper(const char *word, int state)
{
static std::vector<String> matches;
if (state == 0) {
if (!l_Url)
matches = ConsoleHandler::GetAutocompletionSuggestions(word, *l_ScriptFrame);
else {
Array::Ptr suggestions;
/* Remote debug console. */
try {
suggestions = AutoCompleteScript(l_Session, word, l_ScriptFrame->Sandboxed);
} catch (...) {
return nullptr; //Errors are just ignored here.
}
matches.clear();
ObjectLock olock(suggestions);
std::copy(suggestions->Begin(), suggestions->End(), std::back_inserter(matches));
}
}
if (state >= static_cast<int>(matches.size()))
return nullptr;
return strdup(matches[state].CStr());
}
开发者ID:Icinga,项目名称:icinga2,代码行数:29,代码来源:consolecommand.cpp
示例11: startArray
void ParseHandler::startArray()
{
Array::Ptr newArr = new Array();
if ( _stack.empty() ) // The first array
{
_result = newArr;
}
else
{
Var parent = _stack.top();
if ( parent.type() == typeid(Array::Ptr) )
{
Array::Ptr arr = parent.extract<Array::Ptr>();
arr->add(newArr);
}
else if ( parent.type() == typeid(Object::Ptr) )
{
poco_assert_dbg(!_key.empty());
Object::Ptr obj = parent.extract<Object::Ptr>();
obj->set(_key, newArr);
_key.clear();
}
}
_stack.push(newArr);
}
开发者ID:12307,项目名称:poco,代码行数:28,代码来源:ParseHandler.cpp
示例12: CheckResultAPIHandler
Value ApiEvents::CheckResultAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params)
{
if (!origin.FromClient->GetEndpoint())
return Empty;
if (!params)
return Empty;
CheckResult::Ptr cr = make_shared<CheckResult>();
Dictionary::Ptr vcr = params->Get("cr");
Array::Ptr vperf = vcr->Get("performance_data");
vcr->Remove("performance_data");
Deserialize(cr, params->Get("cr"), true);
Array::Ptr rperf = make_shared<Array>();
ObjectLock olock(vperf);
BOOST_FOREACH(const Value& vp, vperf) {
Value p;
if (vp.IsObjectType<Dictionary>()) {
PerfdataValue::Ptr val = make_shared<PerfdataValue>();
Deserialize(val, vp, true);
rperf->Add(val);
} else
rperf->Add(vp);
}
开发者ID:Freeaqingme,项目名称:icinga2,代码行数:29,代码来源:apievents.cpp
示例13: AutocompleteScriptHelper
bool ConsoleHandler::AutocompleteScriptHelper(HttpRequest& request, HttpResponse& response,
const String& command, const String& session, bool sandboxed)
{
Log(LogInformation, "Console")
<< "Auto-completing expression: " << command;
ApiScriptFrame& lsf = l_ApiScriptFrames[session];
lsf.Seen = Utility::GetTime();
if (!lsf.Locals)
lsf.Locals = new Dictionary();
Array::Ptr results = new Array();
Dictionary::Ptr resultInfo = new Dictionary();
ScriptFrame frame;
frame.Locals = lsf.Locals;
frame.Self = lsf.Locals;
frame.Sandboxed = sandboxed;
resultInfo->Set("code", 200);
resultInfo->Set("status", "Auto-completed successfully.");
resultInfo->Set("suggestions", Array::FromVector(GetAutocompletionSuggestions(command, frame)));
results->Add(resultInfo);
Dictionary::Ptr result = new Dictionary();
result->Set("results", results);
response.SetStatus(200, "OK");
HttpUtility::SendJsonBody(response, result);
return true;
}
开发者ID:Thomas-Gelf,项目名称:icinga2,代码行数:34,代码来源:consolehandler.cpp
示例14: Compile
ConfigItem::Ptr ConfigItemBuilder::Compile(void)
{
if (m_Type.IsEmpty()) {
std::ostringstream msgbuf;
msgbuf << "The type name of an object may not be empty: " << m_DebugInfo;
BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str()));
}
if (!DynamicType::GetByName(m_Type)) {
std::ostringstream msgbuf;
msgbuf << "The type '" + m_Type + "' is unknown: " << m_DebugInfo;
BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str()));
}
std::vector<Expression *> exprs;
Array::Ptr templateArray = new Array();
templateArray->Add(m_Name);
exprs.push_back(new SetExpression(MakeIndexer(ScopeThis, "templates"), OpSetAdd,
new LiteralExpression(templateArray), m_DebugInfo));
DictExpression *dexpr = new DictExpression(m_Expressions, m_DebugInfo);
dexpr->MakeInline();
exprs.push_back(dexpr);
boost::shared_ptr<DictExpression> exprl = boost::make_shared<DictExpression>(exprs, m_DebugInfo);
exprl->MakeInline();
return new ConfigItem(m_Type, m_Name, m_Abstract, exprl, m_Filter,
m_DebugInfo, m_Scope, m_Zone);
}
开发者ID:annafw,项目名称:icinga2,代码行数:32,代码来源:configitembuilder.cpp
示例15: EvaluateObjectRule
bool ServiceGroup::EvaluateObjectRule(const Service::Ptr& service, const ConfigItem::Ptr& group)
{
String group_name = group->GetName();
CONTEXT("Evaluating rule for group '" + group_name + "'");
Host::Ptr host = service->GetHost();
ScriptFrame frame;
if (group->GetScope())
group->GetScope()->CopyTo(frame.Locals);
frame.Locals->Set("host", host);
frame.Locals->Set("service", service);
if (!group->GetFilter()->Evaluate(frame).GetValue().ToBool())
return false;
Log(LogDebug, "ServiceGroup")
<< "Assigning membership for group '" << group_name << "' to service '" << service->GetName() << "'";
Array::Ptr groups = service->GetGroups();
groups->Add(group_name);
return true;
}
开发者ID:LMNetworks,项目名称:icinga2,代码行数:25,代码来源:servicegroup.cpp
示例16: CustomVariableNamesAccessor
Value CommandsTable::CustomVariableNamesAccessor(const Value& row)
{
Command::Ptr command = static_cast<Command::Ptr>(row);
if (!command)
return Empty;
Dictionary::Ptr vars;
{
ObjectLock olock(command);
vars = CompatUtility::GetCustomAttributeConfig(command);
}
if (!vars)
return Empty;
Array::Ptr cv = new Array();
String key;
Value value;
ObjectLock xlock(vars);
BOOST_FOREACH(tie(key, value), vars) {
cv->Add(key);
}
开发者ID:andrewmeyer,项目名称:icinga2,代码行数:26,代码来源:commandstable.cpp
示例17: 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);
}
开发者ID:Nadahar,项目名称:icinga2,代码行数:33,代码来源:vmops.hpp
示例18: PurgeSegments
void TimePeriod::PurgeSegments(double end)
{
ASSERT(OwnsLock());
Log(LogDebug, "icinga", "Purging segments older than '" + Utility::FormatDateTime("%c", end) + "' from TimePeriod '" + GetName() + "'");
if (GetValidBegin().IsEmpty() || end < GetValidBegin())
return;
SetValidBegin(end);
Array::Ptr segments = GetSegments();
if (!segments)
return;
Array::Ptr newSegments = make_shared<Array>();
/* Remove old segments. */
ObjectLock dlock(segments);
BOOST_FOREACH(const Dictionary::Ptr& segment, segments) {
if (segment->Get("end") >= end)
newSegments->Add(segment);
}
SetSegments(newSegments);
}
开发者ID:nv1r,项目名称:icinga2,代码行数:27,代码来源:timeperiod.cpp
示例19: find
Var Query::find(const std::string& path) const
{
Var result = _source;
StringTokenizer tokenizer(path, ".");
for(StringTokenizer::Iterator token = tokenizer.begin(); token != tokenizer.end(); token++)
{
if ( !result.isEmpty() )
{
std::vector<int> indexes;
RegularExpression::MatchVec matches;
int firstOffset = -1;
int offset = 0;
RegularExpression regex("\\[([0-9]+)\\]");
while(regex.match(*token, offset, matches) > 0 )
{
if ( firstOffset == -1 )
{
firstOffset = static_cast<int>(matches[0].offset);
}
std::string num = token->substr(matches[1].offset, matches[1].length);
indexes.push_back(NumberParser::parse(num));
offset = static_cast<int>(matches[0].offset + matches[0].length);
}
std::string name(*token);
if ( firstOffset != -1 )
{
name = name.substr(0, firstOffset);
}
if ( name.length() > 0 )
{
if ( result.type() == typeid(Object::Ptr) )
{
Object::Ptr o = result.extract<Object::Ptr>();
result = o->get(name);
}
}
if ( !result.isEmpty()
&& !indexes.empty() )
{
for(std::vector<int>::iterator it = indexes.begin(); it != indexes.end(); ++it )
{
if ( result.type() == typeid(Array::Ptr) )
{
Array::Ptr array = result.extract<Array::Ptr>();
result = array->get(*it);
if ( result.isEmpty() )
{
break;
}
}
}
}
}
}
return result;
}
开发者ID:babafall,项目名称:Sogeti-MasterThesis-CrossPlatformMobileDevelopment,代码行数:59,代码来源:Query.cpp
示例20: Clone
/**
* Makes a deep clone of an array
* and its elements.
*
* @returns a copy of the array.
*/
Object::Ptr Array::Clone(void) const
{
Array::Ptr arr = new Array();
ObjectLock olock(this);
BOOST_FOREACH(const Value& val, m_Data) {
arr->Add(val.Clone());
}
开发者ID:hannesbe,项目名称:icinga2,代码行数:14,代码来源:array.cpp
注:本文中的array::Ptr类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论