ObjectHandle ReflectedCollectionEraseCommand::execute(const ObjectHandle& arguments) const
{
	auto commandArgs = arguments.getBase<ReflectedCollectionEraseCommandParameters>();

	auto objManager = definitionManager_.getObjectManager();
	assert(objManager != nullptr);
	auto object = objManager->getObject(commandArgs->id_);
	if (!object.isValid())
	{
		return CommandErrorCode::INVALID_ARGUMENTS;
	}

	auto property = object.getDefinition(definitionManager_)->bindProperty(commandArgs->path_.c_str(), object);
	if (property.isValid() == false)
	{
		return CommandErrorCode::INVALID_ARGUMENTS;
	}

	Collection collection;
	auto value = property.getValue();
	if (!value.tryCast(collection))
	{
		return CommandErrorCode::INVALID_ARGUMENTS;
	}

	auto it = collection.find(commandArgs->key_);
	if (it == collection.end())
	{
		return CommandErrorCode::INVALID_VALUE;
	}

	commandArgs->value_ = *it;

	commandArgs->erased_ = property.erase(commandArgs->key_);
	if (!commandArgs->erased_)
	{
		return CommandErrorCode::INVALID_VALUE;
	}

	return nullptr;
}
Esempio n. 2
0
// -----------------------------------------------------------------------------
TEST_F(TestCollectionFixture, int_map)
{
	TestCollectionObject subject;

	IntMap test1;
	test1[1] = 0;
	test1[2] = 1;
	test1[4] = 2;
	test1[8] = 3;
	test1[16] = 4;
	test1[32] = 5;

	IntMap test2;
	test2[-1] = 99;
	test2[-2] = 98;
	test2[-4] = 96;
	test2[-8] = 92;
	test2[-16] = 84;
	test2[-32] = 68;
	test2[-64] = 34;
	test2[-128] = -28;

	// Verify initial size & types
	CHECK_EQUAL(0, subject.int_map_.size());

	ObjectHandle provider(
		&subject,
		getDefinitionManager().getDefinition< TestCollectionObject >() );


	auto vCollection =
		intMapProperty_.get( provider, getDefinitionManager() );
	Collection collection;
	vCollection.tryCast( collection );
	CHECK_EQUAL(0, collection.size());

	// Verify initial iterator properties
	{
		CHECK_EQUAL(collection.begin(), collection.end());

		const int index = 0;
		CHECK_EQUAL(collection.end(), collection.find( index ) );
	}

	{
		subject.int_map_ = test1;

		CHECK_EQUAL( Collection( subject.int_map_ ) , collection);
		CHECK_EQUAL(test1.size(), collection.size());
	}

	// Verify iteration
	{
		IntMap result;
		for (auto iter = collection.begin(), 
			end = collection.end(); iter != end; ++iter)
		{
			int index, value;
			iter.key().tryCast( index );
			iter.value().tryCast( value );
			result[index] = value;
		}

		CHECK(test1 == result);
	}

	// Verify iterator access
	{
		int index = 32, test_index = 0;
		auto iter = collection.find( index );
		iter.key().tryCast( test_index );
		CHECK_EQUAL(index, test_index);

		int value = 0;
		iter.value().tryCast( value );
		CHECK_EQUAL(test1[32], value);

		index = 2;
		iter = collection.find( index );
		iter.key().tryCast( test_index );
		CHECK_EQUAL(index, test_index);

		iter.value().tryCast( value );
		CHECK_EQUAL(test1[2], value);

		index = 1000;
		iter = collection.find( index);
		CHECK_EQUAL(collection.end(), iter);
	}

	{
		IntMap value = test2;
		intMapProperty_.set( provider, value, getDefinitionManager() );

		CHECK(test2 == value);
		CHECK(test2 == subject.int_map_);

		CHECK_EQUAL(test2.size(), collection.size());
	}
}
Esempio n. 3
0
void BytecodeTranslatorVisitor::visitTyped(AstNode* node, VarType type) {
    VISIT(node);
    tryCast(type);
    popType(type);
}
Esempio n. 4
0
void TestUIContext::updateValues()
{
	if (selectedId_ == NO_ID)
	{
		return;
	}

	auto model = getTreeModel();

	const AbstractTreeModel::ItemIndex rootIndex(0, nullptr);
	auto pRoot = model->item(rootIndex);
	const AbstractTreeModel::ItemIndex simpleCasesIndex(0, pRoot);
	auto pSimpleCases = model->item(simpleCasesIndex);

	const AbstractTreeModel::ItemIndex boolIndex(0, pRoot);
	auto pBool = model->item(boolIndex);
	if (pBool != nullptr)
	{
		const auto oldVariant = pBool->getData(0, 0, ItemRole::valueId);
		bool oldBool = false;
		const auto castOk = oldVariant.tryCast(oldBool);
		assert(castOk);
		const auto setOk = pBool->setData(0, 0, ItemRole::valueId, !oldBool);
		assert(setOk);
	}

	const AbstractTreeModel::ItemIndex checkBoxIndex(1, pRoot);
	auto pCheckBox = model->item(checkBoxIndex);
	if (pCheckBox != nullptr)
	{
		const auto oldVariant = pCheckBox->getData(0, 0, ItemRole::valueId);
		bool oldBool = false;
		const auto castOk = oldVariant.tryCast(oldBool);
		assert(castOk);
		const auto setOk = pCheckBox->setData(0, 0, ItemRole::valueId, !oldBool);
		assert(setOk);
	}

	const AbstractTreeModel::ItemIndex slideIndex(3, pRoot);
	auto pSlide = model->item(slideIndex);
	if (pSlide != nullptr)
	{
		const auto oldVariant = pSlide->getData(0, 0, ItemRole::valueId);
		float oldfloat = -1.0f;
		const auto castOk = oldVariant.tryCast(oldfloat);
		assert(castOk);
		const auto setOk = pSlide->setData(0, 0, ItemRole::valueId, oldfloat + 1.0f);
		assert(setOk);
	}

	const AbstractTreeModel::ItemIndex numberIndex(4, pRoot);
	auto pNumber = model->item(numberIndex);
	if (pNumber != nullptr)
	{
		const auto oldVariant = pNumber->getData(0, 0, ItemRole::valueId);
		int oldInt = 1;
		const auto castOk = oldVariant.tryCast(oldInt);
		assert(castOk);
		const auto setOk = pNumber->setData(0, 0, ItemRole::valueId, oldInt + 1);
		assert(setOk);
	}

	const AbstractTreeModel::ItemIndex textFieldIndex(2, pRoot);
	auto pTextField = model->item(textFieldIndex);
	if ((pTextField != nullptr) && (pNumber != nullptr))
	{
		const auto oldVariant = pNumber->getData(0, 0, ItemRole::valueId);
		int newInt = 1;
		const auto castOk = oldVariant.tryCast(newInt);
		assert(castOk);
		std::string newString("Hello Test");
		newString.append(std::to_string(newInt));
		const auto setOk = pTextField->setData(0, 0, ItemRole::valueId, newString);
		assert(setOk);
	}
}