mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
better printing and doc
This commit is contained in:
parent
9e4627abfc
commit
397f41c4fa
2 changed files with 25 additions and 3 deletions
|
|
@ -186,15 +186,17 @@ module Make(X : EMPTY) : BITFIELD = struct
|
||||||
let pp out x =
|
let pp out x =
|
||||||
let ppf = Format.fprintf in
|
let ppf = Format.fprintf in
|
||||||
ppf out "{@[<hv>";
|
ppf out "{@[<hv>";
|
||||||
|
let first=ref true in
|
||||||
Queue.iter
|
Queue.iter
|
||||||
(fun (AnyField f) ->
|
(fun (AnyField f) ->
|
||||||
|
if !first then first := false else ppf out ",@ ";
|
||||||
match f.kind with
|
match f.kind with
|
||||||
| Bool ->
|
| Bool ->
|
||||||
let b = get f x in
|
let b = get f x in
|
||||||
ppf out "%s: %b,@ " f.name b
|
ppf out "%s=%b" f.name b
|
||||||
| Int ->
|
| Int ->
|
||||||
let i = get f x in
|
let i = get f x in
|
||||||
ppf out "%s: %ui@, " f.name i
|
ppf out "%s=%u" f.name i
|
||||||
) fields_;
|
) fields_;
|
||||||
ppf out "@]}"
|
ppf out "@]}"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,27 @@ module type BITFIELD = sig
|
||||||
(** Print the bitfield using the current list of fields *)
|
(** Print the bitfield using the current list of fields *)
|
||||||
end
|
end
|
||||||
|
|
||||||
(** Create a new bitfield type *)
|
(** Create a new bitfield type,
|
||||||
|
|
||||||
|
{[
|
||||||
|
module B = CCBitField.Make(struct end);;
|
||||||
|
|
||||||
|
#install_printer B.pp;;
|
||||||
|
|
||||||
|
let x = B.int ~name:"x" ~width:3;;
|
||||||
|
let y = B.int ~name:"y" ~width:2;;
|
||||||
|
let z = B.bool ~name:"z" ();;
|
||||||
|
|
||||||
|
let f = B.(empty |> set x 3 |> set y 1);;
|
||||||
|
|
||||||
|
B.get z f ;;
|
||||||
|
|
||||||
|
B.(f |> set z true |> get z) ;;
|
||||||
|
|
||||||
|
]}
|
||||||
|
|
||||||
|
|
||||||
|
*)
|
||||||
module Make(X : EMPTY) : BITFIELD
|
module Make(X : EMPTY) : BITFIELD
|
||||||
|
|
||||||
(*$R
|
(*$R
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue