示例#1
0
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."));
	}
}
void TroubleshootCommand::PrintLoggers(InfoLog& log, Dictionary::Ptr& logs)
{
	if (!logs->GetLength()) {
		InfoLogLine(log, 0, LogWarning)
			<< "No loggers found, check whether you enabled any logging features\n";
	} else {
		InfoLogLine(log)
			<< "Getting the last 20 lines of " << logs->GetLength() << " FileLogger objects.\n";

		ObjectLock ulock(logs);
		for (const Dictionary::Pair& kv : logs) {
			InfoLogLine(log)
				<< "Logger " << kv.first << " at path: " << kv.second << '\n';

			if (!Tail(kv.second, 20, log)) {
				InfoLogLine(log, 0, LogWarning)
					<< kv.second << " either does not exist or is empty\n";
			}
		}
	}
}
示例#3
0
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;
	}
}
示例#4
0
static double DictionaryLen(void)
{
	ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
	Dictionary::Ptr self = static_cast<Dictionary::Ptr>(vframe->Self);
	return self->GetLength();
}