Changeset 59733 in vbox for trunk/src/VBox/Main/include
- Timestamp:
- Feb 19, 2016 1:42:18 AM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 105597
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/USBIdDatabase.h
r58019 r59733 22 22 #include <iprt/stdint.h> 23 23 #include <iprt/cpp/ministring.h> 24 #include <iprt/bldprog-strtab.h> 24 25 25 26 … … 31 32 32 33 33 /** 34 * USB ID database string table reference. 35 */ 36 typedef struct USBIDDBSTR 37 { 38 /** Offset of the string in the string table. */ 39 uint32_t off : 22; 40 /** The length of the string. */ 41 uint32_t cch : 10; 42 } USBIDDBSTR; 43 AssertCompileSize(USBIDDBSTR, sizeof(uint32_t)); 34 AssertCompileSize(RTBLDPROGSTRREF, sizeof(uint32_t)); 44 35 45 36 … … 76 67 { 77 68 public: // For assertions and statis in the generator. 78 /** String table. */ 79 static const char s_achStrTab[]; 80 /** The size of the string table (for bounds checking). */ 81 static const size_t s_cchStrTab; 82 #ifdef USB_ID_DATABASE_WITH_COMPRESSION 83 /** Dictionary containing the 127 most used substrings (that we managed 84 * to detect without lousy word based searching). */ 85 static const USBIDDBSTR s_aCompDict[127]; 86 #endif 69 /** The compressed string table. */ 70 static RTBLDPROGSTRTAB const s_StrTab; 87 71 88 72 /** Number of vendors in the two parallel arrays. */ 89 static const size_t s_cVendors;73 static const size_t s_cVendors; 90 74 /** Vendor IDs lookup table. */ 91 static const USBIDDBVENDOR s_aVendors[];75 static const USBIDDBVENDOR s_aVendors[]; 92 76 /** Vendor names table running parallel to s_aVendors. */ 93 static const USBIDDBSTRs_aVendorNames[];77 static const RTBLDPROGSTRREF s_aVendorNames[]; 94 78 95 79 /** Number of products in the two parallel arrays. */ 96 static const size_t s_cProducts;80 static const size_t s_cProducts; 97 81 /** Vendor+Product keys for lookup purposes. */ 98 static const USBIDDBPROD s_aProducts[];82 static const USBIDDBPROD s_aProducts[]; 99 83 /** Product names table running parallel to s_aProducts. */ 100 static const USBIDDBSTRs_aProductNames[];84 static const RTBLDPROGSTRREF s_aProductNames[]; 101 85 102 86 public: 103 static RTCString returnString(USBIDDBSTR const *pStr) 104 { 105 Assert(pStr->cch < s_cchStrTab); 106 Assert(pStr->off < s_cchStrTab); 107 Assert(pStr->off + (size_t)pStr->cch < s_cchStrTab); 108 109 #ifdef USB_ID_DATABASE_WITH_COMPRESSION 110 char szTmp[USB_ID_DATABASE_MAX_STRING * 2]; 111 char *pchDst = &szTmp[0]; 112 size_t cchSrc = pStr->cch; 113 const char *pchSrc = &s_achStrTab[pStr->off]; 114 Assert(cchSrc <= USB_ID_DATABASE_MAX_STRING); 115 while (cchSrc-- > 0) 116 { 117 unsigned char uch = *pchSrc++; 118 if (!(uch & 0x80)) 119 { 120 *pchDst++ = (char)uch; 121 Assert(uch != 0); 122 Assert((uintptr_t)(pchDst - &szTmp[0]) < USB_ID_DATABASE_MAX_STRING); 123 } 124 else if (uch == 0xff) 125 { 126 RTUNICP uc = ' '; 127 int rc = RTStrGetCpNEx(&pchSrc, &cchSrc, &uc); 128 AssertStmt(RT_SUCCESS(rc), (uc = '?', pchSrc++, cchSrc--)); 129 pchDst = RTStrPutCp(pchDst, uc); 130 Assert((uintptr_t)(pchDst - &szTmp[0]) < USB_ID_DATABASE_MAX_STRING); 131 } 132 else 133 { 134 /* Dictionary reference. No unescaping necessary here. */ 135 const USBIDDBSTR *pStr2 = &s_aCompDict[uch & 0x7f]; 136 Assert(pStr2->cch < s_cchStrTab); 137 Assert(pStr2->off < s_cchStrTab); 138 Assert(pStr2->off + (size_t)pStr->cch < s_cchStrTab); 139 Assert((uintptr_t)(&pchDst[pStr2->cch] - &szTmp[0]) < USB_ID_DATABASE_MAX_STRING); 140 memcpy(pchDst, &s_achStrTab[pStr2->off], pStr2->cch); 141 pchDst += pStr2->cch; 142 } 143 } 144 *pchDst = '\0'; 145 return RTCString(szTmp, pchDst - &szTmp[0]); 146 #else /* !USB_ID_DATABASE_WITH_COMPRESSION */ 147 return RTCString(&s_achStrTab[pStr->off], pStr->cch); 148 #endif /* !USB_ID_DATABASE_WITH_COMPRESSION */ 87 static RTCString returnString(PCRTBLDPROGSTRREF pStr) 88 { 89 char szTmp[USB_ID_DATABASE_MAX_STRING * 2]; 90 ssize_t cchTmp = RTBldProgStrTabQueryString(&s_StrTab, pStr->off, pStr->cch, szTmp, sizeof(szTmp)); 91 return RTCString(szTmp, RT_MAX(cchTmp, 0)); 149 92 } 150 93
Note:
See TracChangeset
for help on using the changeset viewer.