You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.0 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
  5. * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software: you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation, either version 3 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef NESTED_SETTINGS_H_
  21. #define NESTED_SETTINGS_H_
  22. #include <settings/json_settings.h>
  23. /**
  24. * NESTED_SETTINGS is a JSON_SETTINGS that lives inside a JSON_SETTINGS.
  25. * Instead of being backed by a JSON file on disk, it loads and stores to its parent.
  26. */
  27. class NESTED_SETTINGS : public JSON_SETTINGS
  28. {
  29. public:
  30. NESTED_SETTINGS( const std::string& aName, int aSchemaVersion, JSON_SETTINGS* aParent,
  31. const std::string& aPath, nlohmann::json aDefault = nlohmann::json( {} ) );
  32. virtual ~NESTED_SETTINGS();
  33. /**
  34. * Loads the JSON document from the parent and then calls Load()
  35. * @param aDirectory
  36. */
  37. virtual void LoadFromFile( const std::string& aDirectory = "" ) override;
  38. /**
  39. * Calls Store() and then saves the JSON document contents into the parent JSON_SETTINGS
  40. * @param aDirectory is ignored
  41. */
  42. virtual void SaveToFile( const std::string& aDirectory = "" ) override;
  43. private:
  44. /// A pointer to the parent object to load and store from
  45. JSON_SETTINGS* m_parent;
  46. /// The path (in pointer format) of where to store this document in the parent
  47. std::string m_path;
  48. };
  49. #endif