summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2015-09-21 05:52:44 +0600
committerDaniil Baturin <daniil@baturin.org>2015-09-21 05:52:44 +0600
commite16eed718dacb83e49fa72caecb82ba6820bcced (patch)
treea4c6615d0d9f1ea932f46a67ddd91ef9322a57ed /src
parentb367aa82bd2c11e312f0b0216ac369ed51d96bc7 (diff)
downloadvyconf-e16eed718dacb83e49fa72caecb82ba6820bcced.tar.gz
vyconf-e16eed718dacb83e49fa72caecb82ba6820bcced.zip
Remove metadata from the config tree data, rendering and the like requires
input from the reference tree anyway. Make value modification functions behaviour multi-value node aware.
Diffstat (limited to 'src')
-rw-r--r--src/config_tree.ml28
-rw-r--r--src/config_tree.mli19
2 files changed, 28 insertions, 19 deletions
diff --git a/src/config_tree.ml b/src/config_tree.ml
index e09761e..cd2eafd 100644
--- a/src/config_tree.ml
+++ b/src/config_tree.ml
@@ -1,10 +1,11 @@
+type value_behaviour = AddValue | ReplaceValue
+
exception Duplicate_value
+exception Node_has_no_value
type config_node_data = {
values: string list;
comment: string;
- node_type: Vytree.node_type;
- keep_order: bool;
}
type t = config_node_data Vytree.t
@@ -12,14 +13,12 @@ type t = config_node_data Vytree.t
let default_data = {
values = [];
comment = "";
- node_type = Vytree.Other;
- keep_order = false;
}
-let make = Vytree.make default_data
+let make name = Vytree.make default_data name
-let set_value node path value =
- let data = { default_data with values=[value] } in
+let replace_value node path value =
+ let data = {default_data with values=[value]} in
Vytree.update node path data
let add_value node path value =
@@ -32,7 +31,22 @@ let add_value node path value =
let values = values @ [value] in
Vytree.update node path ({data with values=values})
+let set_value node path value behaviour =
+ match behaviour with
+ | AddValue -> add_value node path value
+ | ReplaceValue -> replace_value node path value
+
+let set node path value position behaviour =
+ if Vytree.exists node path then set_value node path value behaviour
+ else Vytree.insert ~position:position node path {default_data with values=[value]}
+
let get_values node path =
let node' = Vytree.get node path in
let data = Vytree.data_of_node node' in
data.values
+
+let get_value node path =
+ let values = get_values node path in
+ match values with
+ | [] -> raise Node_has_no_value
+ | x :: _ -> x
diff --git a/src/config_tree.mli b/src/config_tree.mli
index 10fcdf6..1a807c2 100644
--- a/src/config_tree.mli
+++ b/src/config_tree.mli
@@ -1,26 +1,21 @@
+type value_behaviour = AddValue | ReplaceValue
+
exception Duplicate_value
+exception Node_has_no_value
type config_node_data = {
values : string list;
comment : string;
- node_type : Vytree.node_type;
- keep_order : bool;
}
type t = config_node_data Vytree.t
val default_data : config_node_data
-val make : string -> config_node_data Vytree.t
+val make : string -> t
-val set_value :
- config_node_data Vytree.t ->
- string list -> string -> config_node_data Vytree.t
+val set : t -> string list -> string -> Vytree.position -> value_behaviour -> t
-val add_value :
- config_node_data Vytree.t ->
- string list -> string -> config_node_data Vytree.t
+val get_values : t -> string list -> string list
-val get_values :
- config_node_data Vytree.t ->
- string list -> string list
+val get_value : t -> string list -> string