Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.6 KiB

  1. //=== RegistryParser.h - Linker-supported plugin registries -----*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // Defines a command-line parser for a registry.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_SUPPORT_REGISTRYPARSER_H
  14. #define LLVM_SUPPORT_REGISTRYPARSER_H
  15. #include "llvm/Support/CommandLine.h"
  16. #include "llvm/Support/Registry.h"
  17. namespace llvm {
  18. /// A command-line parser for a registry. Use like such:
  19. ///
  20. /// static cl::opt<Registry<Collector>::entry, false,
  21. /// RegistryParser<Collector> >
  22. /// GCOpt("gc", cl::desc("Garbage collector to use."),
  23. /// cl::value_desc());
  24. ///
  25. /// To make use of the value:
  26. ///
  27. /// Collector *TheCollector = GCOpt->instantiate();
  28. ///
  29. template <typename T, typename U = RegistryTraits<T> >
  30. class RegistryParser :
  31. public cl::parser<const typename U::entry*>,
  32. public Registry<T, U>::listener {
  33. typedef U traits;
  34. typedef typename U::entry entry;
  35. typedef typename Registry<T, U>::listener listener;
  36. protected:
  37. void registered(const entry &E) {
  38. addLiteralOption(traits::nameof(E), &E, traits::descof(E));
  39. }
  40. public:
  41. void initialize(cl::Option &O) {
  42. listener::init();
  43. cl::parser<const typename U::entry*>::initialize(O);
  44. }
  45. };
  46. }
  47. #endif // LLVM_SUPPORT_REGISTRYPARSER_H