]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/bit_str.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / common / bit_str.cc
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2016 SUSE LINUX GmbH
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14#include "common/bit_str.h"
15#include "common/Formatter.h"
11fdf7f2 16#include "include/ceph_assert.h"
7c673cae
FG
17
18static void _dump_bit_str(
19 uint64_t bits,
20 std::ostream *out,
21 ceph::Formatter *f,
22 std::function<const char*(uint64_t)> func,
23 bool dump_bit_val)
24{
25 uint64_t b = bits;
26 int cnt = 0;
27 bool outted = false;
28
29 while (b && cnt < 64) {
30 uint64_t r = bits & (1ULL << cnt++);
31 if (r) {
32 if (out) {
33 if (outted)
34 *out << ",";
35 *out << func(r);
36 if (dump_bit_val) {
37 *out << "(" << r << ")";
38 }
39 } else {
11fdf7f2 40 ceph_assert(f != NULL);
7c673cae
FG
41 if (dump_bit_val) {
42 f->dump_stream("bit_flag") << func(r)
43 << "(" << r << ")";
44 } else {
45 f->dump_stream("bit_flag") << func(r);
46 }
47 }
48 outted = true;
49 }
50 b >>= 1;
51 }
52 if (!outted && out)
53 *out << "none";
54}
55
56void print_bit_str(
57 uint64_t bits,
58 std::ostream &out,
11fdf7f2 59 const std::function<const char*(uint64_t)> &func,
7c673cae
FG
60 bool dump_bit_val)
61{
62 _dump_bit_str(bits, &out, NULL, func, dump_bit_val);
63}
64
65void dump_bit_str(
66 uint64_t bits,
67 ceph::Formatter *f,
11fdf7f2 68 const std::function<const char*(uint64_t)> &func,
7c673cae
FG
69 bool dump_bit_val)
70{
71 _dump_bit_str(bits, NULL, f, func, dump_bit_val);
72}