ControlsIniParser.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include "..\..\common_h\core.h"
  3. #include "..\..\common_h\templates\string.h"
  4. class Controls;
  5. struct Token;
  6. // разбор ini-файлов контролов
  7. class ControlsIniParser
  8. {
  9. public:
  10. struct Table
  11. {
  12. Table() : items(__FILE__, __LINE__) {}
  13. Table(const string & name) : items(__FILE__, __LINE__), tableName(name) {}
  14. struct Item
  15. {
  16. string logName;
  17. string hwName;
  18. };
  19. string tableName;
  20. array<Item> items;
  21. };
  22. private:
  23. struct TokenOperation
  24. {
  25. string token; // токен
  26. bool addNext; // операция со следующим токеном ( "," = "ИЛИ" ; "+" = "И")
  27. };
  28. // таблицы маппинга
  29. array<Table> m_mappingTables;
  30. void MakeAlias(Controls& ctrls, const array<string>& tokens);
  31. void MakeMapping(const array<string>& strings, Table& mapping);
  32. void ParseToken(const char* token, Token& parsedToken);
  33. // void ParseAliases(Controls& ctrls, const array<string>& values);
  34. void ParseControls(Controls& ctrls, const array<string>& values);
  35. // static string GetToken(const char* str, unsigned int startPosition, const char* separators, char * separator = NULL);
  36. public:
  37. void ParseAliases(Controls& ctrls, const array<string>& values);
  38. static string GetToken(const char* str, unsigned int startPosition, const char* separators, char * separator = NULL);
  39. ControlsIniParser();
  40. void Parse(Controls& ctrls);
  41. void AddJoystickMappingTable(const char* name ) { m_mappingTables.Add(Table(name)); }
  42. void ParseJoystickMappings();
  43. const Table& GetMappingTable(const char* name) const;
  44. void ClearMappings();
  45. };