PlistDictionary.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/XML/rapidxml.h>
  10. namespace ProjectSettingsTool
  11. {
  12. using XmlDocument = AZ::rapidxml::xml_document<char>;
  13. using XmlNode = AZ::rapidxml::xml_node<char>;
  14. // Wraps a plist dict node with a friendly api to allow lookups and other actions in it
  15. class PlistDictionary
  16. {
  17. public:
  18. // Constructs the dictionary wrapper
  19. PlistDictionary(XmlDocument* plist);
  20. // Allocates a new node with given name and value
  21. XmlNode* MakeNode(const char* name, const char* value);
  22. XmlNode* MakeNode();
  23. // Returns pointer to property data node
  24. XmlNode* GetPropertyValueNode(const char* key);
  25. // Creates a new property and returns pointer to its value node
  26. XmlNode* AddProperty(const char* key);
  27. // Removes property from dictionary
  28. void RemoveProperty(const char* key);
  29. // Returns pointer to property data value or nullptr if it is empty
  30. const char* GetPropertyValue(const char* key);
  31. const char* GetPropertyValue(XmlNode* node);
  32. // Returns pointer to property data name or nullptr if it is empty
  33. const char* GetPropertyValueName(const char* key);
  34. const char* GetPropertyValueName(XmlNode* node);
  35. // Changes value of property data and creates it if it doesn't exist
  36. XmlNode* SetPropertyValue(const char* key, const char* newValue);
  37. void SetPropertyValue(XmlNode* node, const char* newValue);
  38. // Changes name of property data and creates it if it doesn't exist
  39. XmlNode* SetPropertyValueName(const char* key, const char* newName);
  40. void SetPropertyValueName(XmlNode* node, const char* newName);
  41. // Checks to make sure a plist file has a valid dictionary
  42. static bool ContainsValidDict(XmlDocument* plist);
  43. protected:
  44. // Returns pointer to property key node
  45. XmlNode* GetPropertyKeyNode(const char* key);
  46. // pList dictionary is found in
  47. XmlDocument* m_document;
  48. // The dictionary of properties
  49. XmlNode* m_dict;
  50. };
  51. } // namespace ProjectSettingsTool