Option.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //---------------------------------------------------------------------------
  2. #ifndef OptionH
  3. #define OptionH
  4. #include <vector>
  5. //---------------------------------------------------------------------------
  6. enum TOptionType { otParam, otSwitch };
  7. //---------------------------------------------------------------------------
  8. typedef void __fastcall (__closure *TLogOptionEvent)(const UnicodeString & LogStr);
  9. //---------------------------------------------------------------------------
  10. class TOptions
  11. {
  12. public:
  13. __fastcall TOptions();
  14. __fastcall TOptions(const TOptions & Source);
  15. void __fastcall Add(UnicodeString Option);
  16. void __fastcall Parse(const UnicodeString & CmdLine);
  17. bool __fastcall FindSwitch(const UnicodeString Switch);
  18. bool __fastcall FindSwitch(const UnicodeString Switch, UnicodeString & Value);
  19. bool __fastcall FindSwitch(const UnicodeString Switch, UnicodeString & Value, bool & ValueSet);
  20. bool __fastcall FindSwitch(const UnicodeString Switch, int & ParamsStart,
  21. int & ParamsCount);
  22. bool __fastcall FindSwitch(const UnicodeString Switch, TStrings * Params,
  23. int ParamsMax = -1);
  24. bool __fastcall FindSwitchCaseSensitive(const UnicodeString Switch);
  25. bool __fastcall FindSwitchCaseSensitive(const UnicodeString Switch, TStrings * Params,
  26. int ParamsMax = -1);
  27. UnicodeString __fastcall SwitchValue(const UnicodeString Switch, const UnicodeString Default = L"");
  28. bool __fastcall SwitchValue(const UnicodeString Switch, bool Default);
  29. bool __fastcall SwitchValue(const UnicodeString Switch, bool Default, bool DefaultOnNonExistence);
  30. bool __fastcall UnusedSwitch(UnicodeString & Switch);
  31. bool __fastcall WasSwitchAdded(UnicodeString & Switch, UnicodeString & Value, wchar_t & SwitchMark);
  32. UnicodeString ConsumeParam();
  33. void __fastcall LogOptions(TLogOptionEvent OnEnumOption);
  34. __property int ParamCount = { read = FParamCount };
  35. __property UnicodeString Param[int Index] = { read = GetParam };
  36. __property bool Empty = { read = GetEmpty };
  37. protected:
  38. UnicodeString FSwitchMarks;
  39. UnicodeString FSwitchValueDelimiters;
  40. bool __fastcall FindSwitch(const UnicodeString Switch,
  41. UnicodeString & Value, int & ParamsStart, int & ParamsCount, bool CaseSensitive, bool & ValueSet);
  42. bool __fastcall DoFindSwitch(const UnicodeString Switch, TStrings * Params,
  43. int ParamsMax, bool CaseInsensitive);
  44. void __fastcall ParamsProcessed(int Position, int Count);
  45. private:
  46. struct TOption
  47. {
  48. TOptionType Type;
  49. UnicodeString Name;
  50. UnicodeString Value;
  51. bool ValueSet;
  52. bool Used;
  53. wchar_t SwitchMark;
  54. };
  55. typedef std::vector<TOption> TOptionsVector;
  56. TOptionsVector FOptions;
  57. TOptionsVector FOriginalOptions;
  58. bool FNoMoreSwitches;
  59. int FParamCount;
  60. UnicodeString __fastcall GetParam(int Index);
  61. bool __fastcall GetEmpty();
  62. };
  63. //---------------------------------------------------------------------------
  64. #endif