VirtualBox

source: vbox/trunk/src/VBox/Main/include/USBIdDatabase.h@ 57437

Last change on this file since 57437 was 57358, checked in by vboxsync, 9 years ago

*: scm cleanup run.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.2 KB
Line 
1/*
2* Copyright (C) 2015 Oracle Corporation
3*
4* This file is part of VirtualBox Open Source Edition (OSE), as
5* available from http://www.virtualbox.org. This file is free software;
6* you can redistribute it and/or modify it under the terms of the GNU
7* General Public License (GPL) as published by the Free Software
8* Foundation, in version 2 as it comes in the "COPYING" file of the
9* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
10* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
11*/
12
13#pragma once
14
15#include <vector>
16#include <algorithm>
17#include <functional>
18#include <iprt/stdint.h>
19
20/**
21* Macros to make key of alias table
22*/
23#define USBKEY(vendorId, productId) (((uint32_t)(vendorId) << 16) | (productId))
24
25/**
26* Elements of Aliases table
27*/
28class Product
29{
30public:
31 uint32_t key;
32 const char* product;
33};
34
35/**
36* Element of Vendors table
37*/
38class Vendor
39{
40public:
41 unsigned short vendorID;
42 const char* vendor;
43};
44
45class ProductLess :
46 public std::binary_function<Product, Product, bool>
47{
48public:
49 bool operator () (const Product& left, const Product& right) const
50 {
51 return left.key < right.key;
52 }
53};
54
55class VendorLess :
56 public std::binary_function<Vendor, Vendor, bool>
57{
58public:
59 bool operator () (const Vendor& left, const Vendor& right) const
60 {
61 return left.vendorID < right.vendorID;
62 }
63};
64
65
66/**
67* Wrapper for static array of Aliases.
68*/
69class AliasDictionary
70{
71protected:
72 static Product productArray[];
73 static const size_t products_size;
74 static Vendor vendorArray[];
75 static const size_t vendors_size;
76
77public:
78 static const char* findProduct(unsigned short vendorId, unsigned short productId)
79 {
80 Product lookFor = { USBKEY(vendorId, productId) };
81 Product* it = std::lower_bound(productArray, productArray + products_size, lookFor, ProductLess());
82 return lookFor.key == it->key ? it->product : NULL;
83 }
84
85 static const char* findVendor(unsigned short vendorID)
86 {
87 Vendor lookFor = { vendorID };
88 Vendor* it = std::lower_bound(vendorArray, vendorArray + vendors_size, lookFor, VendorLess());
89 return lookFor.vendorID == it->vendorID ? it->vendor : NULL;
90 }
91};
Note: See TracBrowser for help on using the repository browser.

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