diff options
author | Daniil Baturin <daniil@baturin.org> | 2016-12-25 12:09:34 +0700 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2016-12-25 12:09:34 +0700 |
commit | e06d80ac105d49c18df3526e4aa0b70cc37a691a (patch) | |
tree | 945abaa9241e6d7154b8175c7a42733a0aef46ff /src/session.ml | |
parent | bf0bb2d35b145fa6556993c2f745edfa73a977d7 (diff) | |
download | vyconf-e06d80ac105d49c18df3526e4aa0b70cc37a691a.tar.gz vyconf-e06d80ac105d49c18df3526e4aa0b70cc37a691a.zip |
Add value retrieval functions to the session module.
Diffstat (limited to 'src/session.ml')
-rw-r--r-- | src/session.ml | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/session.ml b/src/session.ml index cc71116..b5492ea 100644 --- a/src/session.ml +++ b/src/session.ml @@ -2,6 +2,8 @@ module CT = Config_tree module RT = Reference_tree module D = Directories +exception Session_error of string + type cfg_op = | CfgSet of string list * string option * CT.value_behaviour | CfgDelete of string list * string option @@ -53,3 +55,29 @@ let delete w s path = let op = CfgDelete (path, value) in let config = apply_cfg_op op s.proposed_config in {s with proposed_config=config; changeset=(op :: s.changeset)} + +let get_value w s path = + let path, _ = RT.validate_path D.(w.dirs.validators) w.reference_tree path in + if RT.is_leaf w.reference_tree path then + if not ((RT.is_multi w.reference_tree path) || (RT.is_valueless w.reference_tree path)) + then CT.get_value s.proposed_config path + else raise (Session_error "This node can have more than one value") + else raise (Session_error "Cannot get a value of a non-leaf node") + +let get_values w s path = + let path, _ = RT.validate_path D.(w.dirs.validators) w.reference_tree path in + if RT.is_leaf w.reference_tree path then + if RT.is_multi w.reference_tree path + then CT.get_values s.proposed_config path + else raise (Session_error "This node can have only one value") + else raise (Session_error "Cannot get a value of a non-leaf node") + +let list_children w s path = + let path, _ = RT.validate_path D.(w.dirs.validators) w.reference_tree path in + if not (RT.is_leaf w.reference_tree path) + then Vytree.children_of_path s.proposed_config path + else raise (Session_error "Cannot list children of a leaf node") + +let exists w s path = + let path, _ = RT.validate_path D.(w.dirs.validators) w.reference_tree path in + Vytree.exists s.proposed_config path |