MCPcopy Create free account
hub / github.com/adobe/hyde / check_object_array

Method check_object_array

emitters/yaml_base_emitter.cpp:841–981  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

839/**************************************************************************************************/
840
841bool yaml_base_emitter::check_object_array(const std::string& filepath,
842 const json& have_node,
843 const json& expected_node,
844 const std::string& nodepath,
845 json& merged_node,
846 const std::string& key,
847 const std::string& object_key,
848 const check_proc& proc) {
849 const auto notify = [&](const std::string& validate_message,
850 const std::string& update_message) {
851 check_notify(filepath, nodepath, key, validate_message, update_message);
852 };
853
854 const auto notify_fail = [&](const std::string& message) {
855 check_notify(filepath, nodepath, key, message, message);
856 };
857
858 if (!expected_node.count(key)) {
859 return check_removed(filepath, have_node, nodepath, key);
860 }
861
862 const json& expected = expected_node[key];
863
864 if (!expected.is_array()) {
865 notify_fail("expected type mismatch");
866 throw std::runtime_error("Merge object array failure");
867 }
868
869 json& result = merged_node[key];
870
871 if (!have_node.count(key)) {
872 notify("value missing", "value inserted");
873 result = expected;
874 return true;
875 }
876
877 if (!have_node[key].is_array()) {
878 notify("value not an array", "non-array value replaced");
879 result = expected;
880 return true;
881 }
882
883 const json& have = have_node[key];
884
885 // How does one merge an array of objects? The solution is to use one of the
886 // elements in each object as the object's "key", and treat the array like a
887 // dictionary. This does create the possibility that multiple objects will
888 // resolve to the same key, and/or the key value may not be a string, so we
889 // establish those requirements as function preconditions.
890 //
891 // As for the actual merge, we have a `have` array, and an `expected` array.
892 // The resulting merge will be built up in a resulting array, then moved
893 // into `result.`
894 //
895 // First we build up a sorted vector of key/position pairs of the `have`
896 // array. This will let us find elements in that array in log(N) time.
897 //
898 // Then we iterate the expected array from first to last. We pull out the

Callers

nothing calls this directly

Calls 1

to_stringFunction · 0.50

Tested by

no test coverage detected