Option.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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, TStrings * Params,
  21. int ParamsMax = -1);
  22. bool __fastcall FindSwitchCaseSensitive(const UnicodeString Switch);
  23. bool __fastcall FindSwitchCaseSensitive(const UnicodeString Switch, TStrings * Params,
  24. int ParamsMax = -1);
  25. UnicodeString __fastcall SwitchValue(const UnicodeString Switch, const UnicodeString Default = L"");
  26. bool __fastcall SwitchValue(const UnicodeString Switch, bool Default);
  27. bool __fastcall SwitchValue(const UnicodeString Switch, bool Default, bool DefaultOnNonExistence);
  28. bool __fastcall UnusedSwitch(UnicodeString & Switch);
  29. bool __fastcall WasSwitchAdded(UnicodeString & Switch, UnicodeString & Value, wchar_t & SwitchMark);
  30. UnicodeString ConsumeParam();
  31. void __fastcall LogOptions(TLogOptionEvent OnEnumOption);
  32. __property int ParamCount = { read = FParamCount };
  33. __property UnicodeString Param[int Index] = { read = GetParam };
  34. __property bool Empty = { read = GetEmpty };
  35. protected:
  36. UnicodeString FSwitchMarks;
  37. UnicodeString FSwitchValueDelimiters;
  38. bool __fastcall FindSwitch(const UnicodeString Switch,
  39. UnicodeString & Value, int & ParamsStart, int & ParamsCount, bool CaseSensitive, bool & ValueSet);
  40. bool __fastcall DoFindSwitch(const UnicodeString Switch, TStrings * Params,
  41. int ParamsMax, bool CaseInsensitive);
  42. void __fastcall ParamsProcessed(int Position, int Count);
  43. private:
  44. struct TOption
  45. {
  46. TOptionType Type;
  47. UnicodeString Name;
  48. UnicodeString Value;
  49. bool ValueSet;
  50. bool Used;
  51. wchar_t SwitchMark;
  52. };
  53. typedef std::vector<TOption> TOptionsVector;
  54. TOptionsVector FOptions;
  55. TOptionsVector FOriginalOptions;
  56. bool FNoMoreSwitches;
  57. int FParamCount;
  58. UnicodeString __fastcall GetParam(int Index);
  59. bool __fastcall GetEmpty();
  60. };
  61. //---------------------------------------------------------------------------
  62. #endif