better printing and doc

This commit is contained in:
Simon Cruanes 2015-08-11 21:10:03 +02:00
parent 9e4627abfc
commit 397f41c4fa
2 changed files with 25 additions and 3 deletions

View file

@ -186,15 +186,17 @@ module Make(X : EMPTY) : BITFIELD = struct
let pp out x =
let ppf = Format.fprintf in
ppf out "{@[<hv>";
let first=ref true in
Queue.iter
(fun (AnyField f) ->
if !first then first := false else ppf out ",@ ";
match f.kind with
| Bool ->
let b = get f x in
ppf out "%s: %b,@ " f.name b
ppf out "%s=%b" f.name b
| Int ->
let i = get f x in
ppf out "%s: %ui@, " f.name i
ppf out "%s=%u" f.name i
) fields_;
ppf out "@]}"
end

View file

@ -75,7 +75,27 @@ module type BITFIELD = sig
(** Print the bitfield using the current list of fields *)
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
(*$R