C++ (Qt)bool USBID::operator ==(USBID &cmpId) const
C++ (Qt)USBID meow(vID);int foundIndex = m_ids->indexOf(&meow); // QList< USBID* > *m_ids;
C++ (Qt)bool operator ==( const QPointer< USBID > &cmpId, const QPointer< USBID > &cmpId2 ){ return *cmpId == *cmpId2;} USBID meow(vID);int foundIndex = m_ids->indexOf(&meow); // QList< QPointer< USBID > > *m_ids;
C++ (Qt)template <class T1, class T2>int IndexOfValue( const T1 & src, const T2 & match ){ for (int i = 0; i < src.size(); ++i) if (*src[i] == match) return i; return -1;}
C++ (Qt)class USBIDs{// ...public: bool findDevice(const QString &vID, const QString &pID); QString vendorName() const QString productName() const; private: QHash< QString, USBInfo > *m_ids; QString m_selectedKey;};
C++ (Qt)bool USBIDs::findDevice(const QString &vID, const QString &pID){ m_selectedKey = vID + pID; return m_ids->contains(m_selectedKey);} QString USBIDs::vendorName() const { return m_ids->value(m_selectedKey).vendorName; }QString USBIDs::productName() const { return m_ids->value(m_selectedKey).productName; }
C++ (Qt)struct USBIDs : public QList <USBInfo> { typedef QList <const USBInfo *> TUSBListPtr; TUSBListPtr Lookup( const QString * vendorName, const QString * productName, int options ) const; TUSBListPtr LookupByVendor( const QString & vendorName, int options = look_FullMatch ) const; { return Lookup(&vendorName, 0, options); } TUSBListPtr LookupByProduct( const QString & productName, int options = look_FullMatch ) const; { return Lookup(0, &productName, options); } enum { look_FullMatch = 0, look_StartsWith = 1, look_EndsWith = 2, };};
C++ (Qt)if (uids.findDevice(vendor, product)) { // а здесь что? return uids.vendorName(); // нет смысла, это тот самый vendor }
C++ (Qt) TUSBListPtr lst = uids.LookupByVendor(vendor); // теперь по каждому USB этого vendora for (int i = 0; i < lst.size(); ++i) // печатаем, выводим и.т.п.}
C++ (Qt)class USBID_Vendor{// ...private: QString _name QHash< QString, QString > _products; // ID, Name};
C++ (Qt)class USBIDs{// ...private: QHash< QString, USBID_Vendor > _ids};