HostConfigFlags.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. #include "Core/ICustomConfigFlags.h"
  7. class HostConfigFlags : public ICustomConfigFlags
  8. {
  9. public:
  10. #define FLAG(Type, Name, Desc, Default) \
  11. Type Name; \
  12. bool Name##IsEnabled;
  13. #include "HostConfigFlagsList.h"
  14. static HostConfigFlags flags;
  15. static LPWSTR* argsVal;
  16. static int argsCount;
  17. static void(__stdcall *pfnPrintUsage)();
  18. static void HandleArgsFlag(int& argc, _Inout_updates_to_(argc, argc) LPWSTR argv[]);
  19. static void RemoveArg(int& argc, _Inout_updates_to_(argc, argc) PWSTR argv[], int index);
  20. static int FindArg(int argc, _In_reads_(argc) PWSTR argv[], PCWSTR targetArg, size_t targetArgLen);
  21. template <class Func> static int FindArg(int argc, _In_reads_(argc) PWSTR argv[], Func func);
  22. template <int LEN> static int FindArg(int argc, _In_reads_(argc) PWSTR argv[], const char16(&targetArg)[LEN]);
  23. virtual bool ParseFlag(LPCWSTR flagsString, ICmdLineArgsParser * parser) override;
  24. virtual void PrintUsage() override;
  25. static void PrintUsageString();
  26. private:
  27. int nDummy;
  28. HostConfigFlags();
  29. template <typename T>
  30. void Parse(ICmdLineArgsParser * parser, T * value);
  31. };
  32. // Find an arg in the arg list that satisfies func. Return the arg index if found.
  33. template <class Func>
  34. int HostConfigFlags::FindArg(int argc, _In_reads_(argc) PWSTR argv[], Func func)
  35. {
  36. for (int i = 1; i < argc; ++i)
  37. {
  38. if (func(argv[i]))
  39. {
  40. return i;
  41. }
  42. }
  43. return -1;
  44. }
  45. template <int LEN>
  46. int HostConfigFlags::FindArg(int argc, _In_reads_(argc) PWSTR argv[], const char16(&targetArg)[LEN])
  47. {
  48. return FindArg(argc, argv, targetArg, LEN - 1); // -1 to exclude null terminator
  49. }