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. void __fastcall Add(UnicodeString Option);
  15. void __fastcall Parse(const UnicodeString & CmdLine);
  16. bool __fastcall FindSwitch(const UnicodeString Switch);
  17. bool __fastcall FindSwitch(const UnicodeString Switch, UnicodeString & Value);
  18. bool __fastcall FindSwitch(const UnicodeString Switch, UnicodeString & Value, bool & ValueSet);
  19. bool __fastcall FindSwitch(const UnicodeString Switch, int & ParamsStart,
  20. int & ParamsCount);
  21. bool __fastcall FindSwitch(const UnicodeString Switch, TStrings * Params,
  22. int ParamsMax = -1);
  23. bool __fastcall FindSwitchCaseSensitive(const UnicodeString Switch);
  24. bool __fastcall FindSwitchCaseSensitive(const UnicodeString Switch, TStrings * Params,
  25. int ParamsMax = -1);
  26. void __fastcall ParamsProcessed(int Position, int Count);
  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. void __fastcall LogOptions(TLogOptionEvent OnEnumOption);
  33. __property int ParamCount = { read = FParamCount };
  34. __property UnicodeString Param[int Index] = { read = GetParam };
  35. __property bool Empty = { read = GetEmpty };
  36. protected:
  37. UnicodeString FSwitchMarks;
  38. UnicodeString FSwitchValueDelimiters;
  39. bool __fastcall FindSwitch(const UnicodeString Switch,
  40. UnicodeString & Value, int & ParamsStart, int & ParamsCount, bool CaseSensitive, bool & ValueSet);
  41. bool __fastcall DoFindSwitch(const UnicodeString Switch, TStrings * Params,
  42. int ParamsMax, bool CaseInsensitive);
  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