Beispiel #1
0
QVariant QJson::parseString(const QString &json, int &index, bool &success, QString *errorMessage)
{
	Q_ASSERT(json[index] == '"');
	index++;

	QString string;
	QChar ch;

	while (checkAvailable(json, index, success, errorMessage))
	{
		ch = json[index++];

		switch (ch.toLatin1())
		{
		case '\\':
			// Escaped character
			if (!checkAvailable(json, index, success, errorMessage))
				return QVariant();
			ch = json[index++];
			switch (ch.toLatin1())
			{
			case 'b':
				string.append('\b');
				break;
			case 'f':
				string.append('\f');
				break;
			case 'n':
				string.append('\n');
				break;
			case 'r':
				string.append('\r');
				break;
			case 't':
				string.append('\t');
				break;
			case 'u':
				if (!checkAvailable(json, index, success, errorMessage, 4))
					return QVariant();
				string.append(QChar(json.mid(index, 4).toInt(0, 16)));
				index += 4;
				break;
			default:
				string.append(ch);
			}
			break;

		case '"':
			// End of string
			return QVariant(string);

		default:
			string.append(ch);
		}
	}

	return QVariant();
}
Beispiel #2
0
QVariant QJson::parseArray(const QString &json, int &index, DecodeOptions options, bool &success, QString *errorMessage)
{
	Q_ASSERT(json[index] == '[');
	index++;
	skipWhitespace(json, index);

	QVariantList array;

	while (checkAvailable(json, index, success, errorMessage))
	{
		if (json[index] == QChar::fromLatin1(']'))
		{
			index++;
			return array;
		}
		else
		{
			QVariant value = QJson::parseValue(json, index, options, success, errorMessage);
			if (!success)
				return QVariant();

			// Add the value pair to the array
			array.append(value);

			int skippedWhitespaces = skipWhitespace(json, index);
			checkAvailable(json, index, success, errorMessage);

			switch (json[index].toLatin1())
			{
			case ',':
				index++;
				skipWhitespace(json, index);
				break;

			case ']':
				//']' will be processed in the next iteration
				break;

			default:
				// Only allow missing comma if there is at least one whitespace instead of the comma!
				if ((options & AllowMissingComma) && skippedWhitespaces > 0)
					break;
				else
				{
					success = false;
					if (errorMessage)
						*errorMessage = QString("Unexpected character at index %1").arg(index);
					return QVariant();
				}
			}
		}
	}

	return QVariant();
}
Beispiel #3
0
HRESULT BusAssignmentManager::State::autoAssign(const char* pszName, PCIBusAddress& Address)
{
    PCIRulesList matchingRules;

    addMatchingRules(pszName,  matchingRules);
    const char* pszAlias = findAlias(pszName);
    if (pszAlias)
        addMatchingRules(pszAlias, matchingRules);

    AssertMsg(matchingRules.size() > 0, ("No rule for %s(%s)\n", pszName, pszAlias));

    stable_sort(matchingRules.begin(), matchingRules.end(), RuleComparator);

    for (size_t iRule = 0; iRule < matchingRules.size(); iRule++)
    {
        const DeviceAssignmentRule* rule = matchingRules[iRule];

        Address.miBus = rule->iBus;
        Address.miDevice = rule->iDevice;
        Address.miFn = rule->iFn;

        if (checkAvailable(Address))
            return S_OK;
    }
    AssertMsgFailed(("All possible candidate positions for %s exhausted\n", pszName));

    return E_INVALIDARG;
}
Beispiel #4
0
bool cFixedAlloc::getFrame(uint32_t frame) {
	//Find first free
	uint32_t firstFree = findFirstOf(false, frames);
	if ( !checkAvailable(firstFree) )
		return false;

	frames.set(firstFree);
	--openFrames;
	printFrames();

	return true;
}
Beispiel #5
0
pair<bool,uint32_t> cFixedAlloc::getFrame() {
	//Find first free
	uint32_t firstFree = findFirstOf(false, frames);

	if ( !checkAvailable(firstFree) )
		return make_pair(false, 0);

	frames.set(firstFree);
	--openFrames;
	printFrames();

	return make_pair(true, firstFree);
}
Beispiel #6
0
	bool loadHardcodedWindowsExtension()
	{
		if(!glelp::checkAvailable("WGL_ARB_pixel_format")) return false;
			wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribivARB");
			wglGetPixelFormatAttribfvARB = (PFNWGLGETPIXELFORMATATTRIBFVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribfvARB");
			wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");

		if(!glelp::checkAvailable("WGL_ARB_create_context")) return false;
			wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");


		if(!checkAvailable("WGL_ARB_extensions_string")) return false;
			wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
	
		return true;
	}
void Genetic_AlgorithmApp::setupCapture()
{
    auto deviceList = cinder::Capture::getDevices();

    if (deviceList.size() > 0)
    {
        auto device = deviceList.front();
        
        if (device->checkAvailable())
        {
            m_capture = cinder::Capture::create(1920, 1080, device);

            m_videoCapture = Surface(m_capture->getSurface());

            m_capture->start();

            m_captureMode = true;
        }
    }
}
void CollationServiceTest::TestRegisterFactory(void)
{
#if !UCONFIG_NO_SERVICE
    int32_t n1, n2, n3;
    Locale fu_FU("fu", "FU", "");
    Locale fu_FU_FOO("fu", "FU", "FOO");

    UErrorCode status = U_ZERO_ERROR;

    Hashtable* fuFUNames = new Hashtable(FALSE, status);
    if (!fuFUNames) {
        errln("memory allocation error");
        return;
    }
    fuFUNames->setValueDeleter(uhash_deleteUnicodeString);

    fuFUNames->put(fu_FU.getName(), new UnicodeString("ze leetle bunny Fu-Fu"), status);
    fuFUNames->put(fu_FU_FOO.getName(), new UnicodeString("zee leetel bunny Foo-Foo"), status);
    fuFUNames->put(Locale::getDefault().getName(), new UnicodeString("little bunny Foo Foo"), status);

    Collator* frcol = Collator::createInstance(Locale::getFrance(), status);
    Collator* gecol = Collator::createInstance(Locale::getGermany(), status);
    Collator* jpcol = Collator::createInstance(Locale::getJapan(), status);
    if(U_FAILURE(status)) {
      errcheckln(status, "Failed to create collators with %s", u_errorName(status));
      delete frcol;
      delete gecol;
      delete jpcol;
      delete fuFUNames;
      return;
    }

    CollatorInfo** info = new CollatorInfo*[4];
    if (!info) {
        errln("memory allocation error");
        return;
    }

    info[0] = new CollatorInfo(Locale::getUS(), frcol, NULL);
    info[1] = new CollatorInfo(Locale::getFrance(), gecol, NULL);
    info[2] = new CollatorInfo(fu_FU, jpcol, fuFUNames);
    info[3] = NULL;

    TestFactory* factory = new TestFactory(info);
    if (!factory) {
        errln("memory allocation error");
        return;
    }

    Collator* uscol = Collator::createInstance(Locale::getUS(), status);
    Collator* fucol = Collator::createInstance(fu_FU, status);

    {
        n1 = checkAvailable("before registerFactory");

        URegistryKey key = Collator::registerFactory(factory, status);

        n2 = checkAvailable("after registerFactory");
        assertTrue("count after > count before", n2 > n1);

        Collator* ncol = Collator::createInstance(Locale::getUS(), status);
        if (*frcol != *ncol) {
            errln("frcoll for en_US failed");
        }
        delete ncol; ncol = NULL;

        ncol = Collator::createInstance(fu_FU_FOO, status);
        if (*jpcol != *ncol) {
            errln("jpcol for fu_FU_FOO failed");
        }

        Locale loc = ncol->getLocale(ULOC_REQUESTED_LOCALE, status);
        if (loc != fu_FU_FOO) {
            errln(UnicodeString("requested locale for fu_FU_FOO is not fu_FU_FOO but ") + loc.getName());
        }
        loc = ncol->getLocale(ULOC_VALID_LOCALE, status);
        if (loc != fu_FU) {
            errln(UnicodeString("valid locale for fu_FU_FOO is not fu_FU but ") + loc.getName());
        }
        delete ncol; ncol = NULL;

        UnicodeString locName = fu_FU.getName();
        StringEnumeration* localeEnum = Collator::getAvailableLocales();
        UBool found = FALSE;
        const UnicodeString* locStr;
        for (locStr = localeEnum->snext(status);
            !found && locStr != NULL;
            locStr = localeEnum->snext(status))
        {
            if (locName == *locStr) {
                found = TRUE;
            }
        }
        delete localeEnum;

        if (!found) {
            errln("new locale fu_FU not reported as supported locale");
        }

        UnicodeString name;
        Collator::getDisplayName(fu_FU, name);
        if (name != "little bunny Foo Foo") {
            errln(UnicodeString("found ") + name + " for fu_FU");
        }

        Collator::getDisplayName(fu_FU, fu_FU_FOO, name);
        if (name != "zee leetel bunny Foo-Foo") {
            errln(UnicodeString("found ") + name + " for fu_FU in fu_FU_FOO");
        }

        if (!Collator::unregister(key, status)) {
            errln("failed to unregister factory");
        }
        // ja, fr, ge collators no longer valid

        ncol = Collator::createInstance(fu_FU, status);
        if (*fucol != *ncol) {
            errln("collator after unregister does not match original fu_FU");
        }
        delete ncol;

        n3 = checkAvailable("after unregister");
        assertTrue("count after unregister == count before register", n3 == n1);
    }

    delete fucol;
    delete uscol;
#endif
}
Beispiel #9
0
bool QJson::checkToken(const QString &json, int &index, bool &success, QString *errorMessage, QString token)
{
	return checkAvailable(json, index, success, errorMessage, token.length())
		&& json.mid(index, token.length()) == token;
}
Beispiel #10
0
QVariant QJson::parseUnquotedString(const QString &json, int &index, bool &success, QString *errorMessage)
{
	QString string;
	QChar ch;

	bool end = false;
	while (!end && checkAvailable(json, index, success, errorMessage))
	{
		ch = json[index++];

		switch (ch.toLatin1())
		{
		case '\\':
			// Escaped character
			if (!checkAvailable(json, index, success, errorMessage))
				return QVariant();
			ch = json[index++];
			switch (ch.toLatin1())
			{
			case 'b':
				string.append('\b');
				break;
			case 'f':
				string.append('\f');
				break;
			case 'n':
				string.append('\n');
				break;
			case 'r':
				string.append('\r');
				break;
			case 't':
				string.append('\t');
				break;
			case 'u':
				if (!checkAvailable(json, index, success, errorMessage, 4))
					return QVariant();
				string.append(QChar(json.mid(index, 4).toInt(0, 16)));
				index += 4;
				break;
			default:
				string.append(ch);
			}
			break;

		case ':':
		case ',':
		case ']':
		case '}':
		case '\n':
			// End of string (was one character before this!)
			end = true;
			index--;
			break;

		default:
			string.append(ch);
		}
	}

	//trim string
	string = string.trimmed();

	//handle keywords
	if (string == "true")
		return QVariant(true);
	if (string == "false")
		return QVariant(false);
	if (string == "null")
		return QVariant();

	return QVariant(string);
}
Beispiel #11
0
QVariant QJson::parseObject(const QString &json, int &index, DecodeOptions options, bool &success, QString *errorMessage)
{
	Q_ASSERT(json[index] == '{');
	index++;
	skipWhitespace(json, index);

	ContainerType object;

	while (checkAvailable(json, index, success, errorMessage))
	{
		if (json[index] == QChar::fromLatin1('}'))
		{
			index++;
			return object;
		}
		else
		{
			QString key = QJson::parseValue(json, index, options, success, errorMessage).toString();
			if (!success)
				return QVariant();

			skipWhitespace(json, index);
			checkAvailable(json, index, success, errorMessage);

			if (json[index] == QChar::fromLatin1(':'))
				index++;
			else
			{
				success = false;
				if (errorMessage)
					*errorMessage = QString("Expected colon at position %1").arg(index);
				return QVariant();
			}

			skipWhitespace(json, index);

			QVariant value = QJson::parseValue(json, index, options, success, errorMessage);
			if (!success)
				return QVariant();

			// Add the key / value pair to the object
			object.insert(key, value);

			int skippedWhitespaces = skipWhitespace(json, index);
			checkAvailable(json, index, success, errorMessage);

			switch (json[index].toLatin1())
			{
			case ',':
				index++;
				skipWhitespace(json, index);
				break;

			case '}':
				//'}' will be processed in the next iteration
				break;

			default:
				// Only allow missing comma if there is at least one whitespace instead of the comma!
				if ((options & AllowMissingComma) && skippedWhitespaces > 0)
					break;
				else
				{
					success = false;
					if (errorMessage)
						*errorMessage = QString("Unexpected character at index %1").arg(index);
					return QVariant();
				}
			}
		}
	}

	return QVariant();
}
Beispiel #12
0
QVariant QJson::parseValue(const QString &json, int &index, DecodeOptions options, bool &success, QString *errorMessage)
{
	skipWhitespace(json, index);
	if (!checkAvailable(json, index, success, errorMessage))
	{
		success = false;
		if (errorMessage)
			*errorMessage = QString("Expected more input at position %1").arg(index);
		return QVariant();
	}

	switch (json[index].toLatin1())
	{
	case '"':
		return QJson::parseString(json, index, success, errorMessage);

	case '{':
		if (options & DecodeObjectsAsHash)
			return QJson::parseObject<QVariantHash>(json, index, options, success, errorMessage);
		else
			return QJson::parseObject<QVariantMap>(json, index, options, success, errorMessage);

	case '[':
		return QJson::parseArray(json, index, options, success, errorMessage);

	case 't':
	case 'f':
		if (options & AllowUnquotedStrings)
			return QJson::parseUnquotedString(json, index, success, errorMessage);
		else
			return QJson::parseBool(json, index, success, errorMessage);

	case 'n':
		if (options & AllowUnquotedStrings)
			return QJson::parseUnquotedString(json, index, success, errorMessage);
		else
			return QJson::parseNull(json, index, success, errorMessage);

	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':
	case '-':
		return QJson::parseNumber(json, index, success, errorMessage);

	default:
		if (options & AllowUnquotedStrings)
			return QJson::parseUnquotedString(json, index, success, errorMessage);
		else
		{
			success = false;
			if (errorMessage)
				*errorMessage = QString("Unexpected character at position %1").arg(index);
			return QVariant();
		}
	}
}