diff options
| author | John Estabrook <jestabro@vyos.io> | 2026-01-19 20:24:43 -0600 |
|---|---|---|
| committer | John Estabrook <jestabro@vyos.io> | 2026-02-06 14:42:47 -0600 |
| commit | 9186d3f1cfff21af08d64f94612967bfa5775c9c (patch) | |
| tree | 3661d9684df97014248d2049a98b856d718efc25 /src/reference_tree.ml | |
| parent | 03799d0a93e4a7eb5790836f50cb4a1188c360b6 (diff) | |
| download | vyos1x-config-9186d3f1cfff21af08d64f94612967bfa5775c9c.tar.gz vyos1x-config-9186d3f1cfff21af08d64f94612967bfa5775c9c.zip | |
T8232: add util get_subtree for reference_tree
This is the direct analogue of Config_tree.get_subtree, a safe wrapper
around Vytree.get. Note that the twin functions could easily have been
abstracted under Tree_alg, however, for such simple functions the
redundancy is preferable.
Diffstat (limited to 'src/reference_tree.ml')
| -rw-r--r-- | src/reference_tree.ml | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/reference_tree.ml b/src/reference_tree.ml index d76c480..10cc833 100644 --- a/src/reference_tree.ml +++ b/src/reference_tree.ml @@ -94,6 +94,8 @@ let default_data = { let default = Vytree.make default_data "" +let make name = Vytree.make default_data name + (* Loading from XML *) let node_type_of_string s = @@ -602,6 +604,22 @@ let get_default_value reftree path = let data = (Vytree.get_data[@alert "-exn"]) reftree path in data.default_value +let get_subtree ?(with_node=false) node path = + (* alert exn Vytree.get: + [Vytree.Empty_path] checked + [Vytree.Nonexistent_path] caught + *) + match path with + | [] -> node + | _ -> + try + let n = (Vytree.get[@alert "-exn"]) node path in + if with_node then + Vytree.make_full default_data "" [n] + else + Vytree.make_full default_data "" (Vytree.children_of_node n) + with Vytree.Nonexistent_path -> make "" + (* Convert from config path to reference tree path *) let refpath reftree path = let check_existence p = |
