usb_device_list.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. This software is subject to the license described in the License.txt file
  3. included with this software distribution. You may not use this file except
  4. in compliance with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2016
  6. All rights reserved.
  7. */
  8. #ifndef USB_DEVICE_LIST_HPP
  9. #define USB_DEVICE_LIST_HPP
  10. #include "types.h"
  11. #include <vector>
  12. #include <functional>
  13. //template <typename USBDeviceType, typename Container = std::vector<USBDeviceType> >
  14. template <typename USBDeviceType>
  15. class USBDeviceList
  16. {
  17. public:
  18. //CONSTRUCTORS//
  19. USBDeviceList() { return; }
  20. virtual ~USBDeviceList();
  21. USBDeviceList(const USBDeviceList& clDeviceList_);
  22. template<typename USBDeviceType_>
  23. USBDeviceList(const USBDeviceList<USBDeviceType_>& clDeviceList_);
  24. template <typename InputIterator>
  25. USBDeviceList(InputIterator tFirst_, InputIterator tLast_);
  26. //ASSIGNMENT OPERATOR//
  27. USBDeviceList& operator=(const USBDeviceList& clDeviceList_);
  28. template<typename USBDeviceType_>
  29. USBDeviceList& operator=(const USBDeviceList<USBDeviceType_>& clDeviceList_);
  30. //MUTATORS//
  31. void Add(const USBDeviceType& tDevice_);
  32. template<typename USBDeviceType_>
  33. void Add(const USBDeviceList<USBDeviceType_>& clDeviceList_);
  34. template<typename InputIterator>
  35. void Add(InputIterator tFirst_, InputIterator tLast_);
  36. void Clear();
  37. //ACCESSORS//
  38. typedef BOOL (*CompareFunc)(USBDeviceType const& tDevice_); //!!const USBDeviceType&
  39. //typedef std::unary_function<USBDeviceType, BOOL> CompareFunc; //!! unary_function<const USBDeviceType&,bool>
  40. USBDeviceList GetSubList(CompareFunc pfCompareFunc_) const; //!!Use unary_function instead! (scope, no bare pointer)
  41. const USBDeviceType& operator[](ULONG ulNum_) const;
  42. ULONG GetSize() const { return (ULONG)clDeviceList.size(); } //!!keep track of this so we can cache it ourselves?
  43. const USBDeviceType* GetAddress(ULONG ulNum_) const; //!!Don't want to have this
  44. private:
  45. //typedef std::vector<auto_ptr<USBDeviceType>> Container; //!!Do not use special container functions like sorting because we are holding auto_ptrs!
  46. typedef std::vector<USBDeviceType*> Container; //we hold on to pointers so that we can hold copies and still have polymorphism
  47. //we also hold on to pointers so that no matter where std::vector recopies stuff, we always have a constant place where our elements are
  48. Container clDeviceList;
  49. };
  50. #include "usb_device_list_template.hpp"
  51. /*
  52. //!!Could just be a normal class with a refresh function (but then we can't guarantee the list is const)
  53. class ANTDeviceList : public USBDeviceList<const USBDevice*>
  54. {
  55. public:
  56. static std::auto_ptr<const ANTDeviceList> GetDeviceList(ULONG ulDeviceTypeField_ = 0xFFFFFFFF); //this function keeps people from making a non-const instance of this class
  57. //static void FreeDeviceList(const USBDeviceList*& pclDeviceList_);
  58. protected:
  59. ANTDeviceList(ULONG ulDeviceTypeField_);
  60. virtual ~ANTDeviceList();
  61. private:
  62. friend std::auto_ptr<const ANTDeviceList>; //So that auto_ptr can be the only class to destroy an instance
  63. };
  64. */
  65. #endif //USB_DEVICE_LIST_HPP