Option.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. void __fastcall ParamsProcessed(int Position, int Count);
  28. UnicodeString __fastcall SwitchValue(const UnicodeString Switch, const UnicodeString Default = L"");
  29. bool __fastcall SwitchValue(const UnicodeString Switch, bool Default);
  30. bool __fastcall SwitchValue(const UnicodeString Switch, bool Default, bool DefaultOnNonExistence);
  31. bool __fastcall UnusedSwitch(UnicodeString & Switch);
  32. bool __fastcall WasSwitchAdded(UnicodeString & Switch, UnicodeString & Value, wchar_t & SwitchMark);
  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. private:
  45. struct TOption
  46. {
  47. TOptionType Type;
  48. UnicodeString Name;
  49. UnicodeString Value;
  50. bool ValueSet;
  51. bool Used;
  52. wchar_t SwitchMark;
  53. };
  54. typedef std::vector<TOption> TOptionsVector;
  55. TOptionsVector FOptions;
  56. TOptionsVector FOriginalOptions;
  57. bool FNoMoreSwitches;
  58. int FParamCount;
  59. UnicodeString __fastcall GetParam(int Index);
  60. bool __fastcall GetEmpty();
  61. };
  62. //---------------------------------------------------------------------------
  63. #endif