Option.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //---------------------------------------------------------------------------
  2. #ifndef OptionH
  3. #define OptionH
  4. #include <vector>
  5. //---------------------------------------------------------------------------
  6. enum TOptionType { otParam, otSwitch };
  7. //---------------------------------------------------------------------------
  8. class TOptions
  9. {
  10. public:
  11. __fastcall TOptions();
  12. bool __fastcall FindSwitch(const AnsiString Switch);
  13. bool __fastcall FindSwitch(const AnsiString Switch, AnsiString & Value);
  14. bool __fastcall FindSwitch(const AnsiString Switch, int & ParamsStart,
  15. int & ParamsCount);
  16. bool __fastcall FindSwitch(const AnsiString Switch, TStrings * Params,
  17. int ParamsMax = -1);
  18. void __fastcall ParamsProcessed(int Position, int Count);
  19. AnsiString __fastcall SwitchValue(const AnsiString Switch, const AnsiString Default = "");
  20. bool __fastcall UnusedSwitch(AnsiString & Switch);
  21. __property int ParamCount = { read = FParamCount };
  22. __property AnsiString Param[int Index] = { read = GetParam };
  23. __property bool Empty = { read = GetEmpty };
  24. protected:
  25. AnsiString FSwitchMarks;
  26. AnsiString FSwitchValueDelimiters;
  27. void __fastcall Add(AnsiString Option);
  28. bool __fastcall FindSwitch(const AnsiString Switch,
  29. AnsiString & Value, int & ParamsStart, int & ParamsCount);
  30. private:
  31. struct TOption
  32. {
  33. TOptionType Type;
  34. AnsiString Name;
  35. AnsiString Value;
  36. bool Used;
  37. };
  38. std::vector<TOption> FOptions;
  39. bool FNoMoreSwitches;
  40. int FParamCount;
  41. AnsiString __fastcall GetParam(int Index);
  42. bool __fastcall GetEmpty();
  43. };
  44. //---------------------------------------------------------------------------
  45. #endif