From 830e7c5d27d161b91402414e6ecd49f1ed818bfb Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Fri, 27 Mar 2026 08:48:05 +0100 Subject: Initial commit --- lib/model/content.ml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/model/content.ml (limited to 'lib/model/content.ml') diff --git a/lib/model/content.ml b/lib/model/content.ml new file mode 100644 index 0000000..2760715 --- /dev/null +++ b/lib/model/content.ml @@ -0,0 +1,30 @@ +open StdLabels + +type 'a t = { + id : string; + sections : 'a Section.t list; + subcontents : 'a t list; + parent : 'a t Weak.t; +} + +let v : string -> 'a Section.t list -> 'a t list -> 'a t = + fun id sections subcontents -> + let parent = Weak.create 1 in + let content = { id; sections; subcontents; parent } in + (* Fill the parent for all existing subcontent declared in the type + There is no need to repeat the same for the subcontents as they all are + already created in the same way. + *) + List.iter content.subcontents ~f:(fun v -> Weak.set v.parent 0 (Some content)); + content + +let id t = t.id +let sections t = t.sections +let subcontents t = t.subcontents +let parent t = Weak.get t.parent 0 +let rec root t = match parent t with None -> t | Some t -> root t + +let fields : 'a t -> 'a Field.t Seq.t = + fun t -> + List.to_seq t.sections + |> Seq.flat_map (fun section -> List.to_seq section.Section.fields) -- cgit v1.2.3