// ----------------------------------------------------------------------------- TEST_F(TestCollectionFixture, int_vector) { TestCollectionObject subject; IntVector test1; test1.push_back(1); test1.push_back(2); test1.push_back(4); test1.push_back(8); test1.push_back(16); test1.push_back(32); IntVector test2; test2.push_back(-1); test2.push_back(-2); test2.push_back(-4); test2.push_back(-8); test2.push_back(-16); test2.push_back(-32); test2.push_back(-64); test2.push_back(-128); // Verify initial size & types CHECK_EQUAL(0, subject.int_vector_.size()); ObjectHandle provider( &subject ); Variant vIntVector = intVectorProperty_.get( provider, getDefinitionManager() ); Collection collection; vIntVector.tryCast( collection ); CHECK_EQUAL(0, collection.size()); // Verify initial iterator properties { CHECK_EQUAL(collection.begin(), collection.end()); const size_t index = 0; CHECK_EQUAL(collection.end(), collection.find(index)); } { subject.int_vector_ = test1; CHECK_EQUAL( Collection( subject.int_vector_), collection ); CHECK_EQUAL(test1.size(), collection.size()); } // Verify iteration { IntVector result; for (auto iter = collection.begin(), end = collection.end(); iter != end; ++iter) { int value; iter.value().tryCast( value ); result.push_back(value); } CHECK(test1 == result); } // Verify iterator access { size_t index = 3, 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[3], value); index = 0; iter = collection.find( index ); iter.key().tryCast( test_index ); CHECK_EQUAL(index, test_index); iter.value().tryCast( value ); CHECK_EQUAL(test1[0], value); index = 1000; iter = collection.find( index ); CHECK_EQUAL(collection.end(), iter); } { IntVector value = test2; intVectorProperty_.set( provider, value, getDefinitionManager() ); CHECK(test2 == value); CHECK(test2 == subject.int_vector_); CHECK_EQUAL(test2.size(), collection.size()); } auto definition = getDefinitionManager().getDefinition< TestCollectionObject >(); CHECK( definition ); { auto pa = definition->bindProperty( "int vector[0]", provider ); CHECK( pa.isValid() ); int i = 0; CHECK( pa.getValue().tryCast( i ) ); CHECK_EQUAL( -1, i ); // not Variant // not Variant::traits< int >::storage_type CHECK( pa.getType() == TypeId::getType< int >() ); } }
// ----------------------------------------------------------------------------- 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()); } }
serialnumber_string, interface_string, configuration_string }; static const uint8_t datapipereport_descriptor[] = { // 0x06, 0x00, 0xff, // HUT chap 3 table 1 // Vendor specific value 0xff00 UsagePageVendor(0xff00), // 0x09, 0x01, // Arbitrary number as we are vendor specific Usage(0x01), // 0xa1, 0x01, Collection(USB_HID_APPLICATION), // 0x85, 0x3f, // Vendor specific. Appears arbitrary. // ID can be left undefined if only one report type is created // 0x95, 0x3f, // The number of items in the report ReportCount(HID_PACKET_SIZE), // 0x75, 0x08, // As this is just generic data, 8 bits in a byte ReportSize(0x08), 0x26, 0xff, 0x00, // LogicalMaximum(0xff00), // 0x15, 0x01, LogicalMinimum(0), // 0x09, 0x80,
Collection EDS::collection(const std::string &aCollectionName) { return Collection(*this, aCollectionName); }
// //! \addtogroup hid_mouse_device_class_api //! @{ // //***************************************************************************** //***************************************************************************** // // The report descriptor for the mouse class device. // //***************************************************************************** static const unsigned char g_pucMouseReportDescriptor[]= { UsagePage(USB_HID_GENERIC_DESKTOP), Usage(USB_HID_MOUSE), Collection(USB_HID_APPLICATION), Usage(USB_HID_POINTER), Collection(USB_HID_PHYSICAL), // // The buttons. // UsagePage(USB_HID_BUTTONS), UsageMinimum(1), UsageMaximum(3), LogicalMinimum(0), LogicalMaximum(1), // // 3 - 1 bit values for the buttons. //
//============================================================================== Collection CommandInstance::getChildren() const { return Collection(children_); }
CurveEditor::CurveEditor() : impl_(new Impl) { impl_->curves_.setSource(Collection(impl_->storage_)); }
/** * Get state from rows/columns and save it into a struct. */ void extractRows(const AbstractItemModel& model, const AbstractItemModel::ItemIndex& startIndex, RemoveRowsCommandArgument::Type type, int count, RemoveRowsCommandArgument::ExtractedRowsStorage& o_data) { std::vector<ItemRole::Id> roleIds; { const auto roleNames = model.roles(); roleIds.reserve(roleNames.size()); for (const auto& roleName : roleNames) { roleIds.emplace_back(ItemRole::compute(roleName.c_str())); } } AbstractItemModel::ItemIndex index(startIndex); // Iterate through given range of rows (RemoveType::ROW) // otherwise iterating columns for (int row = 0; row < count; ++row) { // Iterate through all columns for the row (RemoveType::ROW) // otherwise iterating rows int columnCount = 0; if (type == RemoveRowsCommandArgument::Type::ROW) { columnCount = model.columnCount(startIndex.parent_); } else { columnCount = model.rowCount(startIndex.parent_); } for (int column = 0; column < columnCount; ++column) { const auto pItem = model.item(index); TF_ASSERT(pItem != nullptr); for (const auto& roleId : roleIds) { RemoveRowsCommandArgument::ExtractedRows extractedRows; extractedRows.data_ = pItem->getData(index.row_, index.column_, roleId); if (!extractedRows.data_.isVoid()) { ObjectHandle handle; extractedRows.data_.tryCast(handle); auto pInnerModel = handle.getBase<AbstractItemModel>(); if (pInnerModel != nullptr) { // Recursively extract const int innerRow = 0; const int innerColumn = 0; const AbstractItem* pInnerParent = nullptr; const AbstractItemModel::ItemIndex innerStartIndex(innerRow, innerColumn, pInnerParent); const int innerCount = pInnerModel->rowCount(pInnerParent); // Need to create a CollectionHolder, otherwise // extractedRows.data_ = innerData; // is unsafe, because it takes a reference // which will be deleted when innerData goes out of scope auto collectionHolder = std::make_shared<CollectionHolder<RemoveRowsCommandArgument::ExtractedRowsStorage>>(); auto& innerData = collectionHolder->storage(); innerData.reserve(innerCount); extractRows((*pInnerModel), innerStartIndex, type, innerCount, innerData); extractedRows.data_ = Collection(collectionHolder); } extractedRows.index_ = index; extractedRows.roleId_ = roleId; o_data.emplace_back(extractedRows); } } if (type == RemoveRowsCommandArgument::Type::ROW) { ++index.column_; } else { ++index.row_; } } if (type == RemoveRowsCommandArgument::Type::ROW) { ++index.row_; } else { ++index.column_; } } }
Collection RobotsCollection() { return Collection( KeyName( "robots" ), KeyName( "robot" ) ); }