Option.h 2.3 KB

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