gcsx_config.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* GCSx
  2. ** CONFIG.H
  3. **
  4. ** Configuration loading and saving
  5. */
  6. /*****************************************************************************
  7. ** Copyright (C) 2003-2006 Janson
  8. **
  9. ** This program is free software; you can redistribute it and/or modify
  10. ** it under the terms of the GNU General Public License as published by
  11. ** the Free Software Foundation; either version 2 of the License, or
  12. ** (at your option) any later version.
  13. **
  14. ** This program is distributed in the hope that it will be useful,
  15. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ** GNU General Public License for more details.
  18. **
  19. ** You should have received a copy of the GNU General Public License
  20. ** along with this program; if not, write to the Free Software
  21. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  22. *****************************************************************************/
  23. #ifndef __GCSx_CONFIG_H_
  24. #define __GCSx_CONFIG_H_
  25. extern class Config {
  26. private:
  27. // String settings
  28. std::map<Uint16, std::string> configS;
  29. // Numeric settings
  30. std::map<Uint16, Sint32> configN;
  31. // Reverse shortcut key lookup
  32. typedef std::map<Sint32, std::vector<Uint16> > SKeyMap;
  33. SKeyMap configK;
  34. int configLoaded;
  35. int needsSaving;
  36. std::string configFile;
  37. void loadConfig();
  38. void saveConfig();
  39. void addKey(Sint32 key, Uint16 cmd);
  40. void delKey(Sint32 key, Uint16 cmd);
  41. public:
  42. Config();
  43. ~Config();
  44. // If config needs saving, save it (called on idle/exit)
  45. void performSave();
  46. // Read a setting; never assume setting is valid! Default values are
  47. // provided, however. Not designed for reading shortcut keys.
  48. Sint32 readNum(Uint16 key);
  49. const std::string& readStr(Uint16 key);
  50. // Looks up the cmd for a shortcut key, if any
  51. // pos 0 returns total # of possibilities
  52. // pos 1+ return those possibilities
  53. int readShortcut(Uint16 key, Uint16 mod, int pos = 1);
  54. // Return the default shortcut for a command
  55. Sint32 readShortcut(Uint16 cmd);
  56. // Write a setting (doesn't cache- so don't use in a time-critical situation)
  57. // Strings are limited to 255 characters in length or will be ignored
  58. // When writing shortcut keys, writing the first (non-alternate) removes
  59. // all alternates.
  60. // Use dontSave to not write config to file yet, when updating many settings
  61. void write(Uint16 key, Sint32 value);
  62. void write(Uint16 key, const std::string& value);
  63. // Reset to default shortcut keys
  64. // These don't save the config
  65. void clearShortcuts();
  66. void defaultShortcuts();
  67. } *config;
  68. #endif