Extensions3DOpenGLCommon::Extensions3DOpenGLCommon(GraphicsContext3D* context)
    : m_initializedAvailableExtensions(false)
    , m_context(context)
    , m_isNVIDIA(false)
    , m_isAMD(false)
    , m_isIntel(false)
    , m_isImagination(false)
    , m_requiresBuiltInFunctionEmulation(false)
    , m_requiresRestrictedMaximumTextureSize(false)
{
    m_vendor = String(reinterpret_cast<const char*>(::glGetString(GL_VENDOR)));
    m_renderer = String(reinterpret_cast<const char*>(::glGetString(GL_RENDERER)));

    Vector<String> vendorComponents;
    m_vendor.lower().split(' ', vendorComponents);
    if (vendorComponents.contains("nvidia"))
        m_isNVIDIA = true;
    if (vendorComponents.contains("ati") || vendorComponents.contains("amd"))
        m_isAMD = true;
    if (vendorComponents.contains("intel"))
        m_isIntel = true;
    if (vendorComponents.contains("imagination"))
        m_isImagination = true;

#if PLATFORM(MAC)
    if (m_isAMD || m_isIntel)
        m_requiresBuiltInFunctionEmulation = true;

    // Intel HD 3000 devices have problems with large textures. <rdar://problem/16649140>
    m_requiresRestrictedMaximumTextureSize = m_renderer.startsWith("Intel HD Graphics 3000");
#endif
}
Example #2
0
static PassRefPtr<DocumentFragment> createFragmentFromPasteboardData(Pasteboard& pasteboard, Frame& frame, Range& range, bool allowPlainText, bool& chosePlainText)
{
    chosePlainText = false;

    Vector<String> types = pasteboard.types();
    if (types.isEmpty())
        return nullptr;

    if (types.contains("text/html;charset=utf-8") && frame.document()) {
        String markup = pasteboard.readString("text/html;charset=utf-8");
        if (RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(*frame.document(), markup, emptyString(), DisallowScriptingAndPluginContent))
            return fragment.release();
    }

    if (!allowPlainText)
        return nullptr;

    if (types.contains("text/plain;charset=utf-8")) {
        chosePlainText = true;
        if (RefPtr<DocumentFragment> fragment = createFragmentFromText(range, pasteboard.readString("text/plain;charset=utf-8")))
            return fragment.release();
    }

    return nullptr;
}
bool MediaConstraintsImpl::initialize(const Dictionary& constraints)
{
    if (constraints.isUndefinedOrNull())
        return true;

    Vector<String> names;
    constraints.getOwnPropertyNames(names);

    String mandatory = ASCIILiteral("mandatory");
    String optional = ASCIILiteral("optional");

    for (Vector<String>::iterator it = names.begin(); it != names.end(); ++it) {
        if (*it != mandatory && *it != optional)
            return false;
    }

    if (names.contains(mandatory)) {
        Dictionary mandatoryConstraints;
        bool ok = constraints.get(mandatory, mandatoryConstraints);
        if (!ok || mandatoryConstraints.isUndefinedOrNull())
            return false;

        ok = mandatoryConstraints.getOwnPropertiesAsStringHashMap(m_mandatoryConstraints);
        if (!ok)
            return false;
    }

    if (names.contains(optional)) {
        ArrayValue optionalConstraints;
        bool ok = constraints.get(optional, optionalConstraints);
        if (!ok || optionalConstraints.isUndefinedOrNull())
            return false;

        size_t numberOfConstraints;
        ok = optionalConstraints.length(numberOfConstraints);
        if (!ok)
            return false;

        for (size_t i = 0; i < numberOfConstraints; ++i) {
            Dictionary constraint;
            ok = optionalConstraints.get(i, constraint);
            if (!ok || constraint.isUndefinedOrNull())
                return false;
            Vector<String> localNames;
            constraint.getOwnPropertyNames(localNames);
            if (localNames.size() != 1)
                return false;
            String key = localNames[0];
            String value;
            ok = constraint.get(key, value);
            if (!ok)
                return false;
            m_optionalConstraints.append(MediaConstraint(key, value));
        }
    }

    return true;
}
// Old style parser. Deprecated.
static bool parse(const Dictionary& constraintsDictionary, WebVector<WebMediaConstraint>& optional, WebVector<WebMediaConstraint>& mandatory)
{
    if (constraintsDictionary.isUndefinedOrNull())
        return true;

    Vector<String> names;
    bool ok = constraintsDictionary.getPropertyNames(names);
    if (!ok)
        return false;

    String mandatoryName("mandatory");
    String optionalName("optional");

    for (Vector<String>::iterator it = names.begin(); it != names.end(); ++it) {
        if (*it != mandatoryName && *it != optionalName)
            return false;
    }

    if (names.contains(mandatoryName)) {
        Dictionary mandatoryConstraintsDictionary;
        bool ok = constraintsDictionary.get(mandatoryName, mandatoryConstraintsDictionary);
        if (!ok || mandatoryConstraintsDictionary.isUndefinedOrNull())
            return false;
        ok = parseMandatoryConstraintsDictionary(mandatoryConstraintsDictionary, mandatory);
        if (!ok)
            return false;
    }

    Vector<WebMediaConstraint> optionalConstraintsVector;
    if (names.contains(optionalName)) {
        ArrayValue optionalConstraints;
        bool ok = DictionaryHelper::get(constraintsDictionary, optionalName, optionalConstraints);
        if (!ok || optionalConstraints.isUndefinedOrNull())
            return false;

        size_t numberOfConstraints;
        ok = optionalConstraints.length(numberOfConstraints);
        if (!ok)
            return false;

        for (size_t i = 0; i < numberOfConstraints; ++i) {
            Dictionary constraint;
            ok = optionalConstraints.get(i, constraint);
            if (!ok || constraint.isUndefinedOrNull())
                return false;
            ok = parseOptionalConstraintsVectorElement(constraint, optionalConstraintsVector);
            if (!ok)
                return false;
        }
        optional.assign(optionalConstraintsVector);
    }

    return true;
}
String NameManager::generateUniqueName(NameData* nameData, NameRules* rules) {
	String pattern = nameData->getRandomUniquePattern();
	String result = "";
	Vector<String> usedRoots;

	for (int i = 0; i < pattern.length(); i++) {
		String patType = pattern.subString(i, i + 1);

		if (patType == "*") {
			result = appendSyllable(result, generateRandomizedName(nameData, rules), nameData);
		} else {
			for (;;) {
				String root = "";
				String unique = nameData->getRandomUnique(patType, root);

				if (root != "" && usedRoots.contains(root))
					continue;

				result += unique;

				if (root != "")
					usedRoots.add(root);

				break;
			}
		}
	}

	return result;
}
void MediaPlayerPrivateAVFoundation::processNewAndRemovedTextTracks(const Vector<RefPtr<InbandTextTrackPrivateAVF>>& removedTextTracks)
{
    if (removedTextTracks.size()) {
        for (unsigned i = 0; i < m_textTracks.size(); ++i) {
            if (!removedTextTracks.contains(m_textTracks[i]))
                continue;
            
            player()->removeTextTrack(removedTextTracks[i].get());
            m_textTracks.remove(i);
        }
    }

    unsigned inBandCount = 0;
    for (unsigned i = 0; i < m_textTracks.size(); ++i) {
        RefPtr<InbandTextTrackPrivateAVF> track = m_textTracks[i];

#if ENABLE(AVF_CAPTIONS)
        if (track->textTrackCategory() == InbandTextTrackPrivateAVF::OutOfBand)
            continue;
#endif

        track->setTextTrackIndex(inBandCount);
        ++inBandCount;
        if (track->hasBeenReported())
            continue;
        
        track->setHasBeenReported(true);
        player()->addTextTrack(track.get());
    }
    LOG(Media, "MediaPlayerPrivateAVFoundation::processNewAndRemovedTextTracks(%p) - found %lu text tracks", this, m_textTracks.size());
}
Example #7
0
void VectorTest::test_contains(void)
{
   message += "test_contains\n";

   Vector<int> v;

   // Test

   assert_true(v.contains(0) == false, LOG);

   //Test

   v.set(5, -1);

   assert_true(v.contains(0) == false, LOG);
}
Example #8
0
int main()
{
	Vector vector;
	printVector(vector);

	vector.set(0, 13);
	vector.set(1, 5);
	vector.set(2, 5);
	vector.set(3, 7);
	vector.set(4, 19);
	vector.set(5, 3);
	vector.set(6, 10);
	vector.set(7, 23);
	vector.set(8, 30);
	vector.set(9, 1);

	printVector(vector);

	cout << "Indeholder 10: " << (vector.contains(10) ? "true" : "false") << endl;
	cout << "Indeholder 11: " << (vector.contains(11) ? "true" : "false") << endl;

	cout << "Antal forkomster af 5: " << vector.howMany(5) << endl;
	cout << "Antal forkomster af 10: " << vector.howMany(10) << endl;
	cout << "Antal forkomster af 50: " << vector.howMany(50) << endl;

	cout << "Alle unikke: " << (vector.allUnique() ? "true" : "false") << endl;
	vector.set(1, 14);
	printVector(vector);
	cout << "Alle unikke: " << (vector.allUnique() ? "true" : "false") << endl;

	return 0;
}
static PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value> value, Vector<v8::Handle<v8::Array> >& stack, v8::Isolate* isolate)
{
    if (value->IsNumber() && !std::isnan(value->NumberValue()))
        return IDBKey::createNumber(value->NumberValue());
    if (value->IsString())
        return IDBKey::createString(toCoreString(value.As<v8::String>()));
    if (value->IsDate() && !std::isnan(value->NumberValue()))
        return IDBKey::createDate(value->NumberValue());
    if (value->IsArray()) {
        v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value);

        if (stack.contains(array))
            return 0;
        if (stack.size() >= maximumDepth)
            return 0;
        stack.append(array);

        IDBKey::KeyArray subkeys;
        uint32_t length = array->Length();
        for (uint32_t i = 0; i < length; ++i) {
            v8::Local<v8::Value> item = array->Get(v8::Int32::New(i, isolate));
            RefPtr<IDBKey> subkey = createIDBKeyFromValue(item, stack, isolate);
            if (!subkey)
                subkeys.append(IDBKey::createInvalid());
            else
                subkeys.append(subkey);
        }

        stack.removeLast();
        return IDBKey::createArray(subkeys);
    }
    return 0;
}
void SupervoxelGeneratorRegionGrowing::recenterSupervoxels(const AppParameters &parameters, const Video &v)
{
	const UINT clusterMinSizeCutoff = 20;

	UINT teleportCount = 0;
	Vector<vec3i> seeds;
	for(Supervoxel &p : _supervoxels)
	{
		vec3i newSeed;
		if(p.voxels.size() < clusterMinSizeCutoff)
		{
			newSeed = vec3i(rand() % _dimensions.x, rand() % _dimensions.y, rand() % _dimensions.z);
			while(seeds.contains(newSeed))
				newSeed = vec3i(rand() % _dimensions.x, rand() % _dimensions.y, rand() % _dimensions.z);
			
			teleportCount++;
			p.resetColor(v.frames[newSeed.z](newSeed.y, newSeed.x));
		}
		else
		{
			newSeed = p.massCentroid();
			p.computeColor(v);
		}
		p.reset(v, newSeed);
		seeds.pushBack(newSeed);
	}
}
Example #11
0
void QNetworkReplyHandler::sendResponseIfNeeded()
{
    ASSERT(m_replyWrapper && m_replyWrapper->reply() && !wasAborted());

    if (m_replyWrapper->reply()->error() && m_replyWrapper->reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).isNull())
        return;

    ResourceHandleClient* client = m_resourceHandle->client();
    if (!client)
        return;

    WTF::String mimeType = m_replyWrapper->mimeType();

    if (mimeType.isEmpty()) {
        // let's try to guess from the extension
        mimeType = MIMETypeRegistry::getMIMETypeForPath(m_replyWrapper->reply()->url().path());
    }

    KURL url(m_replyWrapper->reply()->url());
    ResourceResponse response(url, mimeType.lower(),
                              m_replyWrapper->reply()->header(QNetworkRequest::ContentLengthHeader).toLongLong(),
                              m_replyWrapper->encoding(), String());

    if (url.isLocalFile()) {
        client->didReceiveResponse(m_resourceHandle, response);
        return;
    }

    // The status code is equal to 0 for protocols not in the HTTP family.
    int statusCode = m_replyWrapper->reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();

    if (url.protocolIsInHTTPFamily()) {
        String suggestedFilename = filenameFromHTTPContentDisposition(QString::fromLatin1(m_replyWrapper->reply()->rawHeader("Content-Disposition")));

        if (!suggestedFilename.isEmpty())
            response.setSuggestedFilename(suggestedFilename);
        else {
            Vector<String> extensions = MIMETypeRegistry::getExtensionsForMIMEType(mimeType);
            if (extensions.isEmpty())
                response.setSuggestedFilename(url.lastPathComponent());
            else {
                // If the suffix doesn't match the MIME type, correct the suffix.
                QString filename = url.lastPathComponent();
                const String suffix = QMimeDatabase().suffixForFileName(filename);
                if (!extensions.contains(suffix)) {
                    filename.chop(suffix.length());
                    filename += MIMETypeRegistry::getPreferredExtensionForMIMEType(mimeType);
                }
                response.setSuggestedFilename(filename);
            }
        }

        response.setHTTPStatusCode(statusCode);
        response.setHTTPStatusText(m_replyWrapper->reply()->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toByteArray().constData());

        // Add remaining headers.
        foreach (const QNetworkReply::RawHeaderPair& pair, m_replyWrapper->reply()->rawHeaderPairs())
            response.setHTTPHeaderField(QString::fromLatin1(pair.first), QString::fromLatin1(pair.second));
    }
Example #12
0
void InfoScreens::handleUpdateTimer() {
//		debugf("can updatedisplay=%i", canUpdateDisplay());

	if(canUpdateDisplay() && internalCanUpdateDisplay) {
		if (mChildern.size() == 0) {
			debugf("I cannot print anything, no Pages declared, setting to NOT update display");
			setCanUpdateDisplay(false);
			return;
		}

		if (paramValueMap["currentPage"].dirty) {
//				debugf("currentPage = %i, paramValueMap['currentPage'].dirty= %d",paramValueMap["currentPage"].val.toInt(), (int)paramValueMap["currentPage"].dirty);
			display->clearDisplay();
			display->setCursor(0,0);
			print(paramValueMap["currentPage"].val.toInt());
			paramValueMap["currentPage"].clearDirty();
		}
		else {
			internalCanUpdateDisplay = false;
			Vector<paramStruct*> params(getCurrent()->getAllParamsInPage());
//				debugf("params in page = %i", params.size());
			boolean updated = false;

			//need localcopy of params
			Vector<String> tempIds;
			for (int i = 0; i < params.size(); ++i) {
				paramStruct* param = params.get(i);
				if(paramValueMap[param->id].dirty) {
					tempIds.add(param->id);
					paramValueMap[param->id].clearDirty();
				}
			}

			for (int i = 0; i < params.size(); ++i) {
				paramStruct* param = params.get(i);
				if (tempIds.contains(param->id)) {
//						debugf("updating param %s", param->id.c_str());
					display->writeover(param->t, paramValueMap[param->id].val);
					updated = true;
				}
			}
			internalCanUpdateDisplay = true;
			if (updated) {
				display->display();
			}

			long current = millis();
			//in case of edit mode, flip every x mills the line (blink)
			if(viewMode == ViewMode::EDIT && current >= (lastEditModeBlinkTime + editModeBlinkTime)) {
				lastEditModeBlinkTime = current;
				blinkDrawn = !blinkDrawn;
	//			display->drawRect(0,0, 128, 64, blinkDrawn ? WHITE : BLACK);
//				display->drawPixel(127,0 , blinkDrawn ? WHITE : BLACK);
				display->fillRect(126, 0, 128, 2, blinkDrawn ? WHITE : BLACK);
//				display->display();
			}
		}
	}
}
bool CreatureManagerImplementation::addWearableItem(CreatureObject* creature, TangibleObject* clothing) {

	if (!clothing->isWearableObject() && !clothing->isWeaponObject())
		return false;

	ChatManager* chatMan = zoneServer->getChatManager();

	SharedTangibleObjectTemplate* tanoData = dynamic_cast<SharedTangibleObjectTemplate*>(clothing->getObjectTemplate());
	Vector<uint32>* races = tanoData->getPlayerRaces();
	String race = creature->getObjectTemplate()->getFullTemplateString();

	if(clothing->isWearableObject()) {
		if (!races->contains(race.hashCode())) {
			UnicodeString message;

			if(creature->getObjectTemplate()->getFullTemplateString().contains("ithorian"))
				message = "@player_structure:wear_not_ithorian";
			else
				message = "@player_structure:wear_no";

			chatMan->broadcastMessage(creature, message, clothing->getObjectID(), creature->getMoodID(), 0);

			return false;
		}
	}

	ManagedReference<SceneObject*> clothingParent = clothing->getParent();

	if (clothingParent == NULL)
		return false;

	for (int i = 0; i < clothing->getArrangementDescriptorSize(); ++i) {
		Vector<String> descriptors = clothing->getArrangementDescriptor(i);

		for (int j = 0; j < descriptors.size(); ++j) {
			ManagedReference<SceneObject*> slot = creature->getSlottedObject(descriptors.get(j));

			if (slot != NULL) {
				slot->destroyObjectFromWorld(true);
				slot->destroyObjectFromDatabase(true);
			}
		}
	}

	creature->transferObject(clothing, 4, false);
	creature->doAnimation("pose_proudly");
	creature->broadcastObject(clothing, true);

	UnicodeString message;
	if(clothing->isWeaponObject())
		message = "@player_structure:wear_yes_weapon";
	else
		message = "@player_structure:wear_yes";

	chatMan->broadcastMessage(creature, message, clothing->getObjectID(), creature->getMoodID(), 0);

	return true;
}
Example #14
0
Extensions3DOpenGLCommon::Extensions3DOpenGLCommon(GraphicsContext3D* context)
    : m_initializedAvailableExtensions(false)
    , m_context(context)
    , m_isNVIDIA(false)
    , m_isAMD(false)
    , m_isIntel(false)
    , m_maySupportMultisampling(true)
    , m_requiresBuiltInFunctionEmulation(false)
{
    m_vendor = String(reinterpret_cast<const char*>(::glGetString(GL_VENDOR)));

    Vector<String> vendorComponents;
    m_vendor.lower().split(' ', vendorComponents);
    if (vendorComponents.contains("nvidia"))
        m_isNVIDIA = true;
    if (vendorComponents.contains("ati") || vendorComponents.contains("amd"))
        m_isAMD = true;
    if (vendorComponents.contains("intel"))
        m_isIntel = true;

#if PLATFORM(MAC) && !PLATFORM(IOS)
    if (m_isAMD || m_isIntel)
        m_requiresBuiltInFunctionEmulation = true;

    // Currently in Mac we only allow multisampling if the vendor is NVIDIA,
    // or if the vendor is AMD/ATI and the system is 10.7.2 and above.

    bool systemSupportsMultisampling = true;
#if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED < 1080
    ASSERT(isMainThread());
    static SInt32 version;
    if (!version) {
        if (Gestalt(gestaltSystemVersion, &version) != noErr)
            systemSupportsMultisampling = false;
    }
    // See https://bugs.webkit.org/show_bug.cgi?id=77922 for more details
    if (systemSupportsMultisampling)
        systemSupportsMultisampling = version >= 0x1072;
#endif // SNOW_LEOPARD and LION

    if (m_isAMD && !systemSupportsMultisampling)
        m_maySupportMultisampling = false;
#endif
}
Example #15
0
void HTMLPropertiesCollection::findPropetiesOfAnItem(Node* root) const
{
    // 5.2.5 Associating names with items.
    Vector<Node*> memory;

    memory.append(root);

    Vector<Node*> pending;
    // Add the child elements of root, if any, to pending.
    for (Node* child = root->firstChild(); child; child = child->nextSibling())
        if (child->isHTMLElement())
            pending.append(child);

    // If root has an itemref attribute, split the value of that itemref attribute on spaces.
    // For each resulting token ID, if there is an element in the home subtree of root with the ID ID,
    // then add the first such element to pending.
    if (toHTMLElement(root)->fastHasAttribute(itemrefAttr)) {
        DOMSettableTokenList* itemRef = root->itemRef();

        for (size_t i = 0; i < itemRef->length(); ++i) {
            AtomicString id = itemRef->item(i);

            Element* element = root->document()->getElementById(id);
            if (element && element->isHTMLElement())
                pending.append(element);
        }
    }

    // Loop till we have processed all pending elements
    while (!pending.isEmpty()) {

        // Remove first element from pending and let current be that element.
        Node* current = pending[0];
        pending.remove(0);

        // If current is already in memory, there is a microdata error;
        if (memory.contains(current)) {
            // microdata error;
            continue;
        }

        memory.append(current);

        // If current does not have an itemscope attribute, then: add all the child elements of current to pending.
        HTMLElement* element = toHTMLElement(current);
        if (!element->fastHasAttribute(itemscopeAttr)) {
            for (Node* child = current->firstChild(); child; child = child->nextSibling())
                if (child->isHTMLElement())
                    pending.append(child);
        }

        // If current has an itemprop attribute specified, add it to results.
        if (element->fastHasAttribute(itempropAttr))
             m_properties.append(current);
    }
}
void SupervoxelGeneratorRegionGrowing::initializeSupervoxels(const AppParameters &parameters, const Video &v)
{
	Vector<vec3i> seeds;
	for(Supervoxel &p : _supervoxels)
	{
		vec3i randomSeed(rand() % _dimensions.x, rand() % _dimensions.y, rand() % _dimensions.z);
		while(seeds.contains(randomSeed))
			randomSeed = vec3i(rand() % _dimensions.x, rand() % _dimensions.y, rand() % _dimensions.z);

		p.resetColor(v.frames[randomSeed.z](randomSeed.y, randomSeed.x));
		p.reset(v, randomSeed);
		seeds.pushBack(randomSeed);
	}
}
bool WebSocketHandshake::checkResponseHeaders()
{
    const AtomicString& serverWebSocketProtocol = this->serverWebSocketProtocol();
    const AtomicString& serverUpgrade = this->serverUpgrade();
    const AtomicString& serverConnection = this->serverConnection();
    const AtomicString& serverWebSocketAccept = this->serverWebSocketAccept();

    if (serverUpgrade.isNull()) {
        m_failureReason = formatHandshakeFailureReason("'Upgrade' header is missing");
        return false;
    }
    if (serverConnection.isNull()) {
        m_failureReason = formatHandshakeFailureReason("'Connection' header is missing");
        return false;
    }
    if (serverWebSocketAccept.isNull()) {
        m_failureReason = formatHandshakeFailureReason("'Sec-WebSocket-Accept' header is missing");
        return false;
    }

    if (!equalIgnoringCase(serverUpgrade, "websocket")) {
        m_failureReason = formatHandshakeFailureReason("'Upgrade' header value is not 'WebSocket': " + serverUpgrade);
        return false;
    }
    if (!equalIgnoringCase(serverConnection, "upgrade")) {
        m_failureReason = formatHandshakeFailureReason("'Connection' header value is not 'Upgrade': " + serverConnection);
        return false;
    }

    if (serverWebSocketAccept != m_expectedAccept) {
        m_failureReason = formatHandshakeFailureReason("Incorrect 'Sec-WebSocket-Accept' header value");
        return false;
    }
    if (!serverWebSocketProtocol.isNull()) {
        if (m_clientProtocol.isEmpty()) {
            m_failureReason = formatHandshakeFailureReason("Response must not include 'Sec-WebSocket-Protocol' header if not present in request: " + serverWebSocketProtocol);
            return false;
        }
        Vector<String> result;
        m_clientProtocol.split(String(WebSocket::subprotocolSeperator()), result);
        if (!result.contains(serverWebSocketProtocol)) {
            m_failureReason = formatHandshakeFailureReason("'Sec-WebSocket-Protocol' header value '" + serverWebSocketProtocol + "' in response does not match any of sent values");
            return false;
        }
    } else if (!m_clientProtocol.isEmpty()) {
        m_failureReason = formatHandshakeFailureReason("Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received");
        return false;
    }
    return true;
}
static RefPtr<IDBKey> createIDBKeyFromValue(ExecState& exec, JSValue value, Vector<JSArray*>& stack)
{
    VM& vm = exec.vm();
    if (value.isNumber() && !std::isnan(value.toNumber(&exec)))
        return IDBKey::createNumber(value.toNumber(&exec));

    if (value.isString())
        return IDBKey::createString(asString(value)->value(&exec));

    if (value.inherits<DateInstance>(vm)) {
        auto dateValue = valueToDate(exec, value);
        if (!std::isnan(dateValue))
            return IDBKey::createDate(dateValue);
    }

    if (value.isObject()) {
        JSObject* object = asObject(value);
        if (auto* array = jsDynamicCast<JSArray*>(vm, object)) {
            size_t length = array->length();

            if (stack.contains(array))
                return nullptr;

            if (stack.size() >= maximumDepth)
                return nullptr;

            stack.append(array);

            Vector<RefPtr<IDBKey>> subkeys;
            for (size_t i = 0; i < length; i++) {
                JSValue item = array->getIndex(&exec, i);
                RefPtr<IDBKey> subkey = createIDBKeyFromValue(exec, item, stack);
                if (!subkey)
                    subkeys.append(IDBKey::createInvalid());
                else
                    subkeys.append(subkey);
            }

            stack.removeLast();
            return IDBKey::createArray(subkeys);
        }

        if (auto* arrayBuffer = jsDynamicCast<JSArrayBuffer*>(vm, value))
            return IDBKey::createBinary(*arrayBuffer);

        if (auto* arrayBufferView = jsDynamicCast<JSArrayBufferView*>(vm, value))
            return IDBKey::createBinary(*arrayBufferView);
    }
    return nullptr;
}
Example #19
0
// This returns an AtomicString because it is always passed as argument to
// setValue() and setValue() takes an AtomicString in argument.
AtomicString DOMTokenList::removeTokens(const AtomicString& input,
                                        const Vector<String>& tokens) {
  // Algorithm defined at
  // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#remove-a-token-from-a-string
  // New spec is at https://dom.spec.whatwg.org/#remove-a-token-from-a-string

  unsigned inputLength = input.length();
  StringBuilder output;  // 3
  output.reserveCapacity(inputLength);
  unsigned position = 0;  // 4

  // Step 5
  while (position < inputLength) {
    if (isHTMLSpace<UChar>(input[position])) {  // 6
      position++;
      continue;  // 6.3
    }

    // Step 7
    StringBuilder tokenBuilder;
    while (position < inputLength && isNotHTMLSpace<UChar>(input[position]))
      tokenBuilder.append(input[position++]);

    // Step 8
    String token = tokenBuilder.toString();
    if (tokens.contains(token)) {
      // Step 8.1
      while (position < inputLength && isHTMLSpace<UChar>(input[position]))
        ++position;

      // Step 8.2
      size_t j = output.length();
      while (j > 0 && isHTMLSpace<UChar>(output[j - 1]))
        --j;
      output.resize(j);
    } else {
      output.append(token);  // Step 9
    }

    if (position < inputLength && !output.isEmpty())
      output.append(' ');
  }

  size_t j = output.length();
  if (j > 0 && isHTMLSpace<UChar>(output[j - 1]))
    output.resize(j - 1);

  return output.toAtomicString();
}
Example #20
0
bool WebSocketHandshake::checkResponseHeaders()
{
    const String& serverWebSocketProtocol = this->serverWebSocketProtocol();
    const String& serverUpgrade = this->serverUpgrade();
    const String& serverConnection = this->serverConnection();
    const String& serverWebSocketAccept = this->serverWebSocketAccept();

    if (serverUpgrade.isNull()) {
        m_failureReason = "Error during WebSocket handshake: 'Upgrade' header is missing";
        return false;
    }
    if (serverConnection.isNull()) {
        m_failureReason = "Error during WebSocket handshake: 'Connection' header is missing";
        return false;
    }
    if (serverWebSocketAccept.isNull()) {
        m_failureReason = "Error during WebSocket handshake: 'Sec-WebSocket-Accept' header is missing";
        return false;
    }

    if (!equalIgnoringCase(serverUpgrade, "websocket")) {
        m_failureReason = "Error during WebSocket handshake: 'Upgrade' header value is not 'WebSocket'";
        return false;
    }
    if (!equalIgnoringCase(serverConnection, "upgrade")) {
        m_failureReason = "Error during WebSocket handshake: 'Connection' header value is not 'Upgrade'";
        return false;
    }

    if (serverWebSocketAccept != m_expectedAccept) {
        m_failureReason = "Error during WebSocket handshake: Sec-WebSocket-Accept mismatch";
        return false;
    }
    if (!serverWebSocketProtocol.isNull()) {
        if (m_clientProtocol.isEmpty()) {
            m_failureReason = "Error during WebSocket handshake: Sec-WebSocket-Protocol mismatch";
            return false;
        }
        Vector<String> result;
        m_clientProtocol.split(String(WebSocket::subProtocolSeperator()), result);
        if (!result.contains(serverWebSocketProtocol)) {
            m_failureReason = "Error during WebSocket handshake: Sec-WebSocket-Protocol mismatch";
            return false;
        }
    }
    return true;
}
Example #21
0
// Optimally, this should take a Vector<AtomicString> const ref in argument but
// the bindings generator does not handle that.
void DOMTokenList::add(const Vector<String>& tokens,
                       ExceptionState& exceptionState) {
  Vector<String> filteredTokens;
  filteredTokens.reserveCapacity(tokens.size());
  for (const auto& token : tokens) {
    if (!validateToken(token, exceptionState))
      return;
    if (containsInternal(AtomicString(token)))
      continue;
    if (filteredTokens.contains(token))
      continue;
    filteredTokens.append(token);
  }

  if (!filteredTokens.isEmpty())
    setValue(addTokens(value(), filteredTokens));
}
Example #22
0
inline void DOMTokenList::addInternal(const String* tokens, size_t length, ExceptionCode& ec)
{
    // This is usually called with a single token.
    Vector<AtomicString, 1> uniqueTokens;
    uniqueTokens.reserveInitialCapacity(length);

    for (size_t i = 0; i < length; ++i) {
        if (!validateToken(tokens[i], ec))
            return;
        if (!m_tokens.contains(tokens[i]) && !uniqueTokens.contains(tokens[i]))
            uniqueTokens.uncheckedAppend(tokens[i]);
    }

    if (!uniqueTokens.isEmpty())
        m_tokens.appendVector(uniqueTokens);

    updateAfterTokenChange();
}
Example #23
0
void initializeLogChannel(WTFLogChannel* channel)
{
    static Vector<WTFLogChannel*> activatedChannels;
    const static String logValue(g_getenv("WEBKIT_DEBUG"));

    if (logValue.isEmpty())
        return;

    // Fill activatedChannels vector only once based on names set in logValue.
    if (activatedChannels.isEmpty()) {
        static Vector<String> activatedNames;
        logValue.split(" ", activatedNames);
        for (unsigned int i = 0; i < activatedNames.size(); i++) {
            WTFLogChannel* activeChannel = getChannelFromName(activatedNames[i]);
            if (activeChannel)
                activatedChannels.append(activeChannel);
        }
    }

    if (activatedChannels.contains(channel))
        channel->state = WTFLogChannelOn;
}
static RefPtr<IDBKey> createIDBKeyFromValue(ExecState* exec, JSValue value, Vector<JSArray*>& stack)
{
    if (value.isNumber() && !std::isnan(value.toNumber(exec)))
        return IDBKey::createNumber(value.toNumber(exec));
    if (value.isString())
        return IDBKey::createString(value.toString(exec)->value(exec));
    if (value.inherits(DateInstance::info()) && !std::isnan(valueToDate(exec, value)))
        return IDBKey::createDate(valueToDate(exec, value));
    if (value.isObject()) {
        JSObject* object = asObject(value);
        if (isJSArray(object) || object->inherits(JSArray::info())) {
            JSArray* array = asArray(object);
            size_t length = array->length();

            if (stack.contains(array))
                return nullptr;
            if (stack.size() >= maximumDepth)
                return nullptr;
            stack.append(array);

            Vector<RefPtr<IDBKey>> subkeys;
            for (size_t i = 0; i < length; i++) {
                JSValue item = array->getIndex(exec, i);
                RefPtr<IDBKey> subkey = createIDBKeyFromValue(exec, item, stack);
                if (!subkey)
                    subkeys.append(IDBKey::createInvalid());
                else
                    subkeys.append(subkey);
            }

            stack.removeLast();
            return IDBKey::createArray(subkeys);
        }
    }
    return nullptr;
}
void MediaPlayerPrivateAVFoundation::processNewAndRemovedTextTracks(const Vector<RefPtr<InbandTextTrackPrivateAVF>>& removedTextTracks)
{
    if (removedTextTracks.size()) {
        for (unsigned i = 0; i < m_textTracks.size(); ++i) {
            if (!removedTextTracks.contains(m_textTracks[i]))
                continue;
            
            player()->removeTextTrack(removedTextTracks[i].get());
            m_textTracks.remove(i);
        }
    }
    
    for (unsigned i = 0; i < m_textTracks.size(); ++i) {
        RefPtr<InbandTextTrackPrivateAVF> track = m_textTracks[i];
        
        track->setTextTrackIndex(i);
        if (track->hasBeenReported())
            continue;
        
        track->setHasBeenReported(true);
        player()->addTextTrack(track.get());
    }
    LOG(Media, "MediaPlayerPrivateAVFoundation::processNewAndRemovedTextTracks(%p) - found %lu text tracks", this, m_textTracks.size());
}
Example #26
0
int main () {
	Vector v = Vector("4., 5., 6., 9., 8., 7.");
		
	v.print();
	v.print(" .... ");
	v.print(" @@ ", stdout);
	
	assert(v == v);
	assert(v == Vector(" 4., 5., 6., 9., 8., 7."));
	assert(v != Vector(" 3., 4., 5."));
	assert(v.size() == 6);
	assert(v.sum() == 4 + 5 + 6 + 9 + 8 + 7);
	assert(v.prod() == 4 * 5 * 6 * 9 * 8 * 7);
	assert(v.max() == 9);
	assert(v.min() == 4);
	assert(v.which_max() == 3);
	assert(v.which_min() == 0);
	Real v_max, v_min;
	long which_max, which_min;
	v.minmax(v_min, v_max);
	assert(v_min == 4 && v_max == 9);
	v.which_minmax(which_min, which_max);
	assert(which_min == 0 && which_max == 3);
	v += 1;
	assert(v == Vector("5., 6., 7., 10., 9., 8."));
	v *= 2;
	assert(v == Vector("10., 12., 14., 20., 18., 16."));
	v.sort();
	assert(v == Vector("10., 12., 14., 16., 18., 20."));
	
	assert(v.pop_back() == 20.);
	assert(v == Vector(" 10., 12., 14., 16., 18."));
	v.push_back(12.);
	assert(v == Vector(" 10., 12., 14., 16., 18., 12."));
	
	{
		Vector x = v * (3 + v + 2) * v;
		assert(v == Vector("10., 12., 14., 16., 18., 12."));
		assert(x == Vector("1500., 2448., 3724., 5376., 7452., 2448."));
	}
	assert(v == Vector("10., 12., 14., 16., 18., 12."));
	
	Real temp[] = {2, 3, 5, 7, 11};
	{
		Vector w = Vector::view(temp, 5);
		assert(w == Vector("2., 3., 5., 7., 11."));
	}
	assert(temp[0] == 2 && temp[1] == 3 && temp[2] == 5 && temp[3] == 7 && temp[4] == 11);
	
	v.append(Vector("6 7"));
	assert(v == Vector(" 10., 12., 14., 16., 18., 12., 6., 7."));
	assert(v.contains(16.) && v.contains(6.));
	assert(!v.contains(2.));
	long pos = -1;
	assert(v.search(18., 3, pos));
	assert(pos == 4);
	assert(!v.search(18., 5, pos));
	assert(!v.search(9., 0));
	assert(!v.search(10., 1));
	v.sort();
	assert(v.binsearch(16., pos));
	assert(pos == 6);
	assert(!v.binsearch(4.));
	
	v.null();
	assert(v == Vector(" 0., 0., 0., 0., 0., 0., 0., 0."));
	assert(v.isnull());
	v.fill(-12.);
	assert(v == Vector(" -12., -12., -12., -12., -12., -12., -12., -12."));
	assert(!v.isnull());
	
	Vector x = Vector::seq(4, 10);
	assert(x == Vector(" 4., 5., 6., 7., 8., 9., 10."));
	assert(x[2] == 6.);
	x[2] = 13.;
	assert(x[2] == 13.);
	assert(x[3] == 7.);
	assert(x == Vector(" 4., 5., 13., 7., 8., 9., 10."));
	assert(x.e(2) == 13.);
	x.set(3, 14.);
	assert(x == Vector(" 4., 5., 13., 14., 8., 9., 10."));
	assert(*x.e_ptr(3) == 14.);
	*x.e_ptr(4) = 15.;
	assert(x == Vector(" 4., 5., 13., 14., 15., 9., 10."));
	assert(x.tail() == 10.);
	
	Real c[7];
	x.copy_to(c);
	assert(c[0] == 4. && c[1] == 5. && c[2] == 13. && c[3] == 14. && c[4] == 15. && c[5] == 9. && c[6] == 10.);
	x.resize(4);
	assert(x == Vector("4., 5., 13., 14."));
	Vector y = x;
	x.reverse();
	assert(x == Vector(" 14., 13., 5., 4."));
	assert(y == Vector("4., 5., 13., 14."));
	x.swap(y);
	assert(y == Vector("14., 13., 5., 4."));
	assert(x == Vector("4., 5., 13., 14."));
	y.remove(2);
	assert(y == Vector("14., 13., 4."));
	y.swap_elements(0, 1);
	assert(y == Vector("13., 14., 4."));
	x.resize(2);
	assert(x == Vector("4., 5."));
	y.insert(2, 64.);
	y.insert(1, 89.);
	assert(y == Vector("13., 89., 14., 64., 4."));
	{
		Vector u = x;
		assert(x == u);
		u.update(y);
		assert(u == y);
		assert(u == Vector("13., 89., 14., 64., 4."));
	}
	assert(x == Vector("4 5"));
	assert(y == Vector("13., 89., 14., 64., 4."));
	y.remove_section(2, 4);
	assert(y == Vector("13., 89., 4."));
	y.clear();
	assert(y.size() == 0);
	
	{
		igraph_vector_t v6;
		igraph_vector_init(&v6, 7);
		Vector v7(&v6);
		Vector v8=v7;
	}
	
	std::vector<int> sv;
	sv.clear();
	sv.push_back(4);
	sv.push_back(14);
	sv.push_back(5);
	sv.push_back(7);
	
	Vector r = Vector(sv.begin(), sv.end());
	assert(r == Vector("4 14 5 7"));
	sv[1] = 22;
	assert(sv.size() == 4 && sv[0] == 4 && sv[1] == 22 && sv[2] == 5 && sv[3] == 7);
	assert(r == Vector("4 14 5 7"));
	sv = std::vector<int>(r.begin(), r.end());
	assert(sv.size() == 4 && sv[0] == 4 && sv[1] == 14 && sv[2] == 5 && sv[3] == 7);
	r[1] = 22;
	assert(sv.size() == 4 && sv[0] == 4 && sv[1] == 14 && sv[2] == 5 && sv[3] == 7);
	assert(r == Vector("4 22 5 7"));
	std::sort(r.begin(), r.end());
	assert(r == Vector("4 5 7 22"));
	assert(std::inner_product(sv.begin(), sv.end(), r.begin(), 0) == 4*4+14*5+5*7+7*22);
	
	Real d[] = {1., 4., 9., 16., 25., 49.};
	r = Vector(d, 6);
	assert(r == Vector("1 4 9 16 25 49"));
	d[5] = 36;
	assert(r == Vector("1 4 9 16 25 49"));
	r[5] = 81;
	assert(d[5] == 36);
	r = Vector::view(d, 6);
	d[4] = 121;
	assert(r == Vector("1 4 9 16 121 36"));
	r[3] = 144;
	assert(d[3] == 144);
	
#if XXINTRNL_CXX0X
	assert(Vector("2 -4 6 12") == Vector({2, -4, 6, 12}));
#endif
	
	assert(Vector("1 1 1 1 1; 2 2 2; 3; 4 4 4 4; 5 5 5").distribution() == Vector("0, 0.3125, 0.1875, 0.0625, 0.25, 0.1875"));
	
	{
		Vector r ("1 4 6 12 11 4");
		Vector s ("6 -2 5 8 6 4");
		assert(r.maxdifference(s) == 6);
		
		r = Vector("1 4 6 12 11 4 124 4");
		r.remove_first_matching(4);
		assert(r == Vector("1 6 12 11 4 124 4"));
		r.remove_all_matching(4);
		assert(r == Vector("1 6 12 11 124"));
		r.sort();
		assert(r == Vector("1 6 11 12 124"));
		r.remove_first_matching_assume_sorted(11);
		assert(r == Vector("1 6 12 124"));
		r.remove_first_matching(4);
		assert(r == Vector("1 6 12 124"));
		r.remove_first_matching_assume_sorted(9);
		assert(r == Vector("1 6 12 124"));
	}
	
	assert(Vector("1 2 3 4 5 6 7").intersect_sorted(Vector("4 5 7 9 11")) == Vector("4 5 7"));
	assert(Vector("1 1 1 1 1 6 7 8").intersect_sorted(Vector("1 1 1 6 7 7 7")) == Vector("1 6 7"));
	assert(Vector("1 1 1 1 1 6 7 8").intersect_sorted(Vector("1 1 1 6 7 7 7"), Vector::NotUnique) == Vector("1 1 1 1, 1 1 1 1; 6 6; 7 7 7 7"));

	{
		Vector t ("1 8 2 7 3 6 4 5");
		t.move_interval(2, 4, 0);
		assert(t == Vector("2 7 2 7 3 6 4 5"));
		t.move_interval(3, 6, 4);
		assert(t == Vector("2 7 2 7 7 3 6 5"));
		assert(t.isininterval(1, 8));
		assert(!t.isininterval(3, 8));
		assert(t.isininterval(2, 7));
		assert(!t.isininterval(1, 5));
		assert(t.any_smaller(3));
		assert(!t.any_smaller(2));
		
		t -= t / 4;
		assert(t == "1.5,5.25,1.5,5.25,5.25,2.25,4.5,3.75");
		t /= Vector("1 2 4 8 -1 -2 -4 -8");
		assert(t == "1.5,2.625,0.375,0.65625,-5.25,-1.125,-1.125,-0.46875");
		t += t * 31;
		assert(t == "48.,84.,12.,21.,-168.,-36.,-36.,-15.");
		
		
		Vector u (12);
		assert(u.isnull());
		assert(u.size() == 12);
		assert(!v.empty());
		Vector v = Vector::n();
		assert(v.isnull());
		assert(v.empty());
		assert(v.size() == 0);
	}
	
	printf("vector.hpp is correct.\n");

	return 0;
}
Example #27
0
void GameScene::checkPeng(float dt)
{
    //check peng !
    /*
     *1.enemy bullet -->player ship
     *2.player bullet -> enemy
     *3.playe ship  and enemy ship
     */
    auto config = Config::getInstance();
    if (config->getGameSatus()){
        Vector<Bullet *> temp;
        int canHurt = 0;
        int last = 0;
        for (auto bullet : *config->enemy_bullet_list)
        {
            
            if (temp.contains(bullet))
            {
                continue;
            }
            if (ship&&isPeng(bullet, ship) && ship->Hp() > 0)
            {
                //播放特效
                canHurt = bullet->hurt(canHurt);
                last = ship->hurt(canHurt);
                canHurt = 0;
                bullet->destory(this);
                temp.pushBack(bullet);//destroy bullet
                if (last <= 0)
                {
                    ship->destory();
                    ship = NULL;
                    shipReBorn();
                    return;
                }
            }
        }
        
        canHurt = 0;
        if (temp.size() != 0)
        {
            for (auto bullet : temp)
            {
                config->enemy_bullet_list->eraseObject(bullet);
            }
        }
        temp.clear();
        
        //检查ship bullet 和敌机碰撞
        Vector<Enemy *> tempEnemy;
        for (auto bullet : *config->player_bullet_list){
            if (temp.contains(bullet))//had destory  !!!
            {
                continue;
            }
            for (auto enemy : *config->enemy_list){
                
                if (tempEnemy.contains(enemy))
                {
                    continue;
                }
                
                if (isPeng(bullet, enemy) && enemy->Hp() > 0)
                {
                    //播放特效
                    canHurt = bullet->hurt(canHurt);
                    last = enemy->hurt(canHurt);
                    temp.pushBack(bullet);//destroy bullet
                    bullet->destory(this);
                    if (last <= 0)
                    {
                        //播放特效
                        enemy->destory();//
                        tempEnemy.pushBack(enemy);
                    }
                }
            }
        }
        if (tempEnemy.size() != 0)
        {
            for (auto enemy : tempEnemy)
            {
                config->enemy_list->eraseObject(enemy);
            }
        }
        tempEnemy.clear();
        if (temp.size() != 0)
        {
            for (auto bullet : temp)
            {
                config->player_bullet_list->eraseObject(bullet);
            }
        }
        temp.clear();
        
        
        //检查敌机和ship相碰撞
        canHurt = 5;//碰撞 固定伤害值 5点
        for (auto enemy : *config->enemy_list)
        {
            
            
            if (tempEnemy.contains(enemy))
            {
                continue;
            }
            if (ship&&isPeng(ship, enemy) && enemy->Hp() > 0 && ship->Hp() > 0)
            {
                
                last = enemy->hurt(canHurt);
                if (last <= 0)
                {
                    //播放特效
                    enemy->destory();
                    tempEnemy.pushBack(enemy);
                }
                
                last = ship->hurt(canHurt);
                if (last <= 0)
                {
                    ship->destory();
                    ship = NULL;
                    shipReBorn();
                    return;
                }
            }
        }
        
        if (tempEnemy.size() != 0)
        {
            for (auto enemy : tempEnemy)
            {
                
                config->enemy_list->eraseObject(enemy);
            }
        }
        tempEnemy.clear();
    }
}
static bool pageAndNotificationIDsMatch(uint64_t pageID, uint64_t pageNotificationID, uint64_t desiredPageID, const Vector<uint64_t>& desiredPageNotificationIDs)
{
    return pageID == desiredPageID && desiredPageNotificationIDs.contains(pageNotificationID);
}
static bool parse(const Dictionary& constraintsDictionary, blink::WebVector<blink::WebMediaConstraint>& optional, blink::WebVector<blink::WebMediaConstraint>& mandatory)
{
    if (constraintsDictionary.isUndefinedOrNull())
        return true;

    Vector<String> names;
    constraintsDictionary.getOwnPropertyNames(names);

    String mandatoryName("mandatory");
    String optionalName("optional");

    for (Vector<String>::iterator it = names.begin(); it != names.end(); ++it) {
        if (*it != mandatoryName && *it != optionalName)
            return false;
    }

    Vector<blink::WebMediaConstraint> mandatoryConstraintsVector;
    if (names.contains(mandatoryName)) {
        Dictionary mandatoryConstraintsDictionary;
        bool ok = constraintsDictionary.get(mandatoryName, mandatoryConstraintsDictionary);
        if (!ok || mandatoryConstraintsDictionary.isUndefinedOrNull())
            return false;

        HashMap<String, String> mandatoryConstraintsHashMap;
        ok = mandatoryConstraintsDictionary.getOwnPropertiesAsStringHashMap(mandatoryConstraintsHashMap);
        if (!ok)
            return false;

        HashMap<String, String>::const_iterator iter = mandatoryConstraintsHashMap.begin();
        for (; iter != mandatoryConstraintsHashMap.end(); ++iter)
            mandatoryConstraintsVector.append(blink::WebMediaConstraint(iter->key, iter->value));
    }

    Vector<blink::WebMediaConstraint> optionalConstraintsVector;
    if (names.contains(optionalName)) {
        ArrayValue optionalConstraints;
        bool ok = constraintsDictionary.get(optionalName, optionalConstraints);
        if (!ok || optionalConstraints.isUndefinedOrNull())
            return false;

        size_t numberOfConstraints;
        ok = optionalConstraints.length(numberOfConstraints);
        if (!ok)
            return false;

        for (size_t i = 0; i < numberOfConstraints; ++i) {
            Dictionary constraint;
            ok = optionalConstraints.get(i, constraint);
            if (!ok || constraint.isUndefinedOrNull())
                return false;
            Vector<String> localNames;
            constraint.getOwnPropertyNames(localNames);
            if (localNames.size() != 1)
                return false;
            String key = localNames[0];
            String value;
            ok = constraint.get(key, value);
            if (!ok)
                return false;
            optionalConstraintsVector.append(blink::WebMediaConstraint(key, value));
        }
    }

    optional.assign(optionalConstraintsVector);
    mandatory.assign(mandatoryConstraintsVector);
    return true;
}
int PlayerContainerComponent::canAddObject(SceneObject* sceneObject, SceneObject* object, int containmentType, String& errorDescription) {
	CreatureObject* creo = dynamic_cast<CreatureObject*>(sceneObject);

	if (object->isTangibleObject() && containmentType == 4) {
		TangibleObject* wearable = cast<TangibleObject*>( object);

		SharedTangibleObjectTemplate* tanoData = dynamic_cast<SharedTangibleObjectTemplate*>(wearable->getObjectTemplate());
		Vector<uint32>* races = tanoData->getPlayerRaces();
		String race = creo->getObjectTemplate()->getFullTemplateString();

		if (!races->contains(race.hashCode())) {
			errorDescription = "You lack the necessary requirements to wear this object";

			return TransferErrorCode::PLAYERUSEMASKERROR;
		}

		if (creo->isPlayerCreature()) {
			if (!wearable->isNeutral()) {
				ManagedReference<PlayerObject*> playerObject = creo->getPlayerObject();

				if (wearable->isImperial() && (playerObject->getFactionStatus() == FactionStatus::ONLEAVE || !creo->isImperial())) {
					errorDescription = "You lack the necessary requirements to wear this object";

					return TransferErrorCode::PLAYERUSEMASKERROR;
				}

				if (wearable->isRebel() && (playerObject->getFactionStatus() == FactionStatus::ONLEAVE || !creo->isRebel())) {
					errorDescription = "You lack the necessary requirements to wear this object";

					return TransferErrorCode::PLAYERUSEMASKERROR;
				}
			}
		}
	}

	if (object->isArmorObject() && containmentType == 4) {
		PlayerManager* playerManager = sceneObject->getZoneServer()->getPlayerManager();

		if (!playerManager->checkEncumbrancies(dynamic_cast<CreatureObject*>(sceneObject), cast<ArmorObject*>( object))) {
			errorDescription = "You lack the necessary secondary stats to equip this item";

			return TransferErrorCode::NOTENOUGHENCUMBRANCE;
		}
	}

	if (object->isRobeObject() && containmentType == 4) {
		ManagedReference<RobeObject*> robe = cast<RobeObject*>( object);
		String skillRequired = robe->getSkillRequired();

		if (!creo->hasSkill(skillRequired) && skillRequired != ""){
			errorDescription = "You are not eligible to wear this robe.";

			return TransferErrorCode::PLAYERUSEMASKERROR;
		}


	}

	if (object->isWeaponObject() && containmentType == 4) {
		ManagedReference<WeaponObject*> weapon = cast<WeaponObject*>( object);
		int bladeColor = weapon->getBladeColor();

		if (weapon->isJediWeapon()){
			if (bladeColor == 31) {
				errorDescription = "@jedi_spam:lightsaber_no_color";
				return TransferErrorCode::PLAYERUSEMASKERROR;
			}
			if (weapon->getCraftersName() != creo->getFirstName()) {
				errorDescription = "@jedi_spam:not_your_lightsaber";
				return TransferErrorCode::PLAYERUSEMASKERROR;
			}
		}
	}

	return ContainerComponent::canAddObject(sceneObject, object, containmentType, errorDescription);
}