summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2015-09-23 02:35:14 +0600
committerDaniil Baturin <daniil@baturin.org>2015-09-23 02:35:14 +0600
commit5b4deef7ca8916ebcc15062b32019b0488e039bc (patch)
treece80149d3d9c54548e8cf91b50e07dae9023adfa
parentc007e11142c605aaa8e8f3a0ff56b0fe657f8407 (diff)
downloadvyconf-5b4deef7ca8916ebcc15062b32019b0488e039bc.tar.gz
vyconf-5b4deef7ca8916ebcc15062b32019b0488e039bc.zip
Make Config_tree.set aware of valueless nodes.
-rw-r--r--src/config_tree.ml14
-rw-r--r--src/config_tree.mli2
2 files changed, 11 insertions, 5 deletions
diff --git a/src/config_tree.ml b/src/config_tree.ml
index 33af881..cdcbd1c 100644
--- a/src/config_tree.ml
+++ b/src/config_tree.ml
@@ -3,6 +3,7 @@ type value_behaviour = AddValue | ReplaceValue
exception Duplicate_value
exception Node_has_no_value
exception No_such_value
+exception Useless_set
type config_node_data = {
values: string list;
@@ -43,10 +44,15 @@ let set_value node path value behaviour =
| ReplaceValue -> replace_value node path value
let set node path value behaviour =
- if Vytree.exists node path then set_value node path value behaviour else
- let path_existing = Vytree.get_existent_path node path in
- let path_remaining = Vylist.complement path path_existing in
- Vytree.insert_multi_level default_data node path_existing path_remaining {default_data with values=[value]}
+ if (Vytree.exists node path) then
+ (match value with
+ | None -> raise Useless_set
+ | Some v -> set_value node path v behaviour)
+ else
+ let path_existing = Vytree.get_existent_path node path in
+ let path_remaining = Vylist.complement path path_existing in
+ let values = match value with None -> [] | Some v -> [v] in
+ Vytree.insert_multi_level default_data node path_existing path_remaining {default_data with values=values}
let get_values node path =
let node' = Vytree.get node path in
diff --git a/src/config_tree.mli b/src/config_tree.mli
index e4c91fc..27042f8 100644
--- a/src/config_tree.mli
+++ b/src/config_tree.mli
@@ -14,7 +14,7 @@ val default_data : config_node_data
val make : string -> t
-val set : t -> string list -> string -> value_behaviour -> t
+val set : t -> string list -> string option -> value_behaviour -> t
val delete : t -> string list -> string option -> t