The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

68 lines
2.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  19. /**
  20. A mini namespace to hold utility functions for working with juce::vars.
  21. @tags{Core}
  22. */
  23. struct JSONUtils
  24. {
  25. /** No constructor. */
  26. JSONUtils() = delete;
  27. /** Given a JSON array/object 'v', a string representing a JSON pointer,
  28. and a new property value 'newValue', returns a copy of 'v' where the
  29. property or array index referenced by the pointer has been set to 'newValue'.
  30. If the pointer cannot be followed, due to referencing missing array indices
  31. or fields, then this returns nullopt.
  32. For more details, check the JSON Pointer RFC 6901:
  33. https://datatracker.ietf.org/doc/html/rfc6901
  34. */
  35. static std::optional<var> setPointer (const var& v, String pointer, const var& newValue);
  36. /** Converts the provided key/value pairs into a JSON object. */
  37. static var makeObject (const std::map<Identifier, var>& source);
  38. /** Converts the provided key/value pairs into a JSON object with the provided
  39. key at the first position in the object.
  40. This is useful because the MIDI-CI spec requires that certain fields (e.g.
  41. status) should be placed at the beginning of a MIDI-CI header.
  42. */
  43. static var makeObjectWithKeyFirst (const std::map<Identifier, var>& source, Identifier key);
  44. /** Returns true if and only if the contents of a match the contents of b.
  45. Unlike var::operator==, this will recursively check that contained DynamicObject and Array
  46. instances compare equal.
  47. */
  48. static bool deepEqual (const var& a, const var& b);
  49. };
  50. } // namespace juce