Option.h 2.8 KB

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