VirtualBox

Changeset 58001 in vbox for trunk


Ignore:
Timestamp:
Oct 2, 2015 10:15:58 AM (9 years ago)
Author:
vboxsync
Message:

USBIdDatabase*: The product and vendor arrays should be const, just like the counts. If you're using hungarian for the element counts, use it for the arrays too. RT_ELEMENTS is a handy macro.

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/USBIdDatabase.h

    r58000 r58001  
    7676{
    7777protected:
    78     static Product productArray[];
    79     static const size_t cProducts;
    80     static Vendor vendorArray[];
    81     static const size_t cVendors;
     78    static Product const aProducts[];
     79    static const size_t  cProducts;
     80    static Vendor const  aVendors[];
     81    static const size_t  cVendors;
    8282
    8383public:
     
    8585    {
    8686        Product lookFor = { USBKEY(vendorId, productId) };
    87         Product* it = std::lower_bound(productArray, productArray + cProducts, lookFor, ProductLess());
     87        Product const *it = std::lower_bound(aProducts, aProducts + cProducts, lookFor, ProductLess());
    8888        return lookFor.key == it->key ? it->product : NULL;
    8989    }
     
    9292    {
    9393        Vendor lookFor = { vendorID };
    94         Vendor* it = std::lower_bound(vendorArray, vendorArray + cVendors, lookFor, VendorLess());
     94        Vendor const *it = std::lower_bound(aVendors, aVendors + cVendors, lookFor, VendorLess());
    9595        return lookFor.vendorID == it->vendorID ? it->vendor : NULL;
    9696    }
  • trunk/src/VBox/Main/src-server/USBIdDatabaseGenerator.cpp

    r58000 r58001  
    5656    " * The source of the list is http://www.linux-usb.org/usb.ids\n"
    5757    " */\n"
    58     "Product AliasDictionary::productArray[] =\n"
     58    "Product const AliasDictionary::aProducts[] =\n"
    5959    "{\n";
    6060
     
    6262    "};\n"
    6363    "\n"
    64     "const size_t AliasDictionary::cProducts = sizeof(AliasDictionary::productArray) / sizeof(Product);\n";
     64    "const size_t AliasDictionary::cProducts = RT_ELEMENTS(AliasDictionary::aProducts);\n";
    6565
    6666const char *vendor_header =
    67     "\nVendor AliasDictionary::vendorArray[] =\n"
     67    "\nVendor const AliasDictionary::aVendors[] =\n"
    6868    "{\n";
    6969const char *vendor_footer =
    7070    "};\n"
    7171    "\n"
    72     "const size_t AliasDictionary::cVendors = sizeof(AliasDictionary::vendorArray) / sizeof(Vendor);\n";
     72    "const size_t AliasDictionary::cVendors = RT_ELEMENTS(AliasDictionary::aVendors);\n";
    7373
    7474const char *start_block = "# Vendors, devices and interfaces. Please keep sorted.";
  • trunk/src/VBox/Main/src-server/USBIdDatabaseStub.cpp

    r58000 r58001  
    1818#include "USBIdDatabase.h"
    1919
    20 Product         AliasDictionary::productArray[] = {0};
    21 const size_t    AliasDictionary::products_size  = 0;
    22 Vendor          AliasDictionary::vendorArray[]  = {0};
    23 const size_t    AliasDictionary::vendors_size   = 0;
     20Product const   AliasDictionary::productArray[] = {0};
     21const size_t    AliasDictionary::cProducts      = 1; /* std::lower_bound cannot deal with empty array */
     22Vendor const    AliasDictionary::vendorArray[]  = {0};
     23const size_t    AliasDictionary::cVendors       = 1; /* std::lower_bound cannot deal with empty array */
    2424
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette