--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+#include "types.h"
+
+#include <iomanip>
+
+namespace {
+inline std::ostream& format_u(std::ostream& out, const uint64_t v, const uint64_t n,
+ const int index, const uint64_t mult, const char* u)
+ {
+ char buffer[32];
+
+ if (index == 0) {
+ (void) snprintf(buffer, sizeof(buffer), "%" PRId64 "%s", n, u);
+ } else if ((v % mult) == 0) {
+ // If this is an even multiple of the base, always display
+ // without any decimal fraction.
+ (void) snprintf(buffer, sizeof(buffer), "%" PRId64 "%s", n, u);
+ } else {
+ // We want to choose a precision that reflects the best choice
+ // for fitting in 5 characters. This can get rather tricky when
+ // we have numbers that are very close to an order of magnitude.
+ // For example, when displaying 10239 (which is really 9.999K),
+ // we want only a single place of precision for 10.0K. We could
+ // develop some complex heuristics for this, but it's much
+ // easier just to try each combination in turn.
+ int i;
+ for (i = 2; i >= 0; i--) {
+ if (snprintf(buffer, sizeof(buffer), "%.*f%s", i,
+ static_cast<double>(v) / mult, u) <= 7)
+ break;
+ }
+ }
+
+ return out << buffer;
+ }
+}
+
+void client_t::dump(ceph::Formatter *f) const {
+ f->dump_int("id", v);
+}
+
+void client_t::generate_test_instances(std::list<client_t*>& ls) {
+ ls.push_back(new client_t);
+ ls.push_back(new client_t(1));
+ ls.push_back(new client_t(123));
+}
+
+std::ostream& operator<<(std::ostream& out, const client_t& c) {
+ return out << c.v;
+}
+
+std::ostream& operator<<(std::ostream& out, const si_u_t& b)
+{
+ uint64_t n = b.v;
+ int index = 0;
+ uint64_t mult = 1;
+ const char* u[] = {"", "k", "M", "G", "T", "P", "E"};
+
+ while (n >= 1000 && index < 7) {
+ n /= 1000;
+ index++;
+ mult *= 1000;
+ }
+
+ return format_u(out, b.v, n, index, mult, u[index]);
+}
+
+std::ostream& operator<<(std::ostream& out, const byte_u_t& b)
+{
+ uint64_t n = b.v;
+ int index = 0;
+ const char* u[] = {" B", " KiB", " MiB", " GiB", " TiB", " PiB", " EiB"};
+
+ while (n >= 1024 && index < 7) {
+ n /= 1024;
+ index++;
+ }
+
+ return format_u(out, b.v, n, index, 1ULL << (10 * index), u[index]);
+}
+
+std::ostream& operator<<(std::ostream& out, const ceph_mon_subscribe_item& i)
+{
+ return out << (long)i.start
+ << ((i.flags & CEPH_SUBSCRIBE_ONETIME) ? "" : "+");
+}
+
+std::ostream& operator<<(std::ostream& out, const weightf_t& w)
+{
+ if (w.v < -0.01F) {
+ return out << "-";
+ } else if (w.v < 0.000001F) {
+ return out << "0";
+ } else {
+ std::streamsize p = out.precision();
+ return out << std::fixed << std::setprecision(5) << w.v << std::setprecision(p);
+ }
+}
+
+void shard_id_t::dump(ceph::Formatter *f) const {
+ f->dump_int("id", id);
+}
+
+void shard_id_t::generate_test_instances(std::list<shard_id_t*>& ls) {
+ ls.push_back(new shard_id_t(1));
+ ls.push_back(new shard_id_t(2));
+}
+
+void errorcode32_t::dump(ceph::Formatter *f) const {
+ f->dump_int("code", code);
+}
+
+void errorcode32_t::generate_test_instances(std::list<errorcode32_t*>& ls) {
+ ls.push_back(new errorcode32_t(1));
+ ls.push_back(new errorcode32_t(2));
+}
using ceph::decode;
decode(v, bl);
}
- void dump(ceph::Formatter *f) const {
- f->dump_int("id", v);
- }
- static void generate_test_instances(std::list<client_t*>& ls) {
- ls.push_back(new client_t);
- ls.push_back(new client_t(1));
- ls.push_back(new client_t(123));
- }
+ void dump(ceph::Formatter *f) const;
+ static void generate_test_instances(std::list<client_t*>& ls);
};
WRITE_CLASS_ENCODER(client_t)
static inline bool operator>=(const client_t& l, int64_t o) { return l.v >= o; }
static inline bool operator<(const client_t& l, int64_t o) { return l.v < o; }
-inline std::ostream& operator<<(std::ostream& out, const client_t& c) {
- return out << c.v;
-}
-
-
+std::ostream& operator<<(std::ostream& out, const client_t& c);
// --
-namespace {
-inline std::ostream& format_u(std::ostream& out, const uint64_t v, const uint64_t n,
- const int index, const uint64_t mult, const char* u)
- {
- char buffer[32];
-
- if (index == 0) {
- (void) snprintf(buffer, sizeof(buffer), "%" PRId64 "%s", n, u);
- } else if ((v % mult) == 0) {
- // If this is an even multiple of the base, always display
- // without any decimal fraction.
- (void) snprintf(buffer, sizeof(buffer), "%" PRId64 "%s", n, u);
- } else {
- // We want to choose a precision that reflects the best choice
- // for fitting in 5 characters. This can get rather tricky when
- // we have numbers that are very close to an order of magnitude.
- // For example, when displaying 10239 (which is really 9.999K),
- // we want only a single place of precision for 10.0K. We could
- // develop some complex heuristics for this, but it's much
- // easier just to try each combination in turn.
- int i;
- for (i = 2; i >= 0; i--) {
- if (snprintf(buffer, sizeof(buffer), "%.*f%s", i,
- static_cast<double>(v) / mult, u) <= 7)
- break;
- }
- }
-
- return out << buffer;
- }
-}
-
/*
* Use this struct to pretty print values that should be formatted with a
* decimal unit prefix (the classic SI units). No actual unit will be added.
explicit si_u_t(uint64_t _v) : v(_v) {};
};
-inline std::ostream& operator<<(std::ostream& out, const si_u_t& b)
-{
- uint64_t n = b.v;
- int index = 0;
- uint64_t mult = 1;
- const char* u[] = {"", "k", "M", "G", "T", "P", "E"};
-
- while (n >= 1000 && index < 7) {
- n /= 1000;
- index++;
- mult *= 1000;
- }
-
- return format_u(out, b.v, n, index, mult, u[index]);
-}
+std::ostream& operator<<(std::ostream& out, const si_u_t& b);
/*
* Use this struct to pretty print values that should be formatted with a
template <> struct fmt::formatter<byte_u_t> : fmt::ostream_formatter {};
#endif
-inline std::ostream& operator<<(std::ostream& out, const byte_u_t& b)
-{
- uint64_t n = b.v;
- int index = 0;
- const char* u[] = {" B", " KiB", " MiB", " GiB", " TiB", " PiB", " EiB"};
-
- while (n >= 1024 && index < 7) {
- n /= 1024;
- index++;
- }
-
- return format_u(out, b.v, n, index, 1ULL << (10 * index), u[index]);
-}
-
-inline std::ostream& operator<<(std::ostream& out, const ceph_mon_subscribe_item& i)
-{
- return out << (long)i.start
- << ((i.flags & CEPH_SUBSCRIBE_ONETIME) ? "" : "+");
-}
+std::ostream& operator<<(std::ostream& out, const byte_u_t& b);
+std::ostream& operator<<(std::ostream& out, const ceph_mon_subscribe_item& i);
struct weightf_t {
float v;
weightf_t(float _v) : v(_v) {}
};
-inline std::ostream& operator<<(std::ostream& out, const weightf_t& w)
-{
- if (w.v < -0.01F) {
- return out << "-";
- } else if (w.v < 0.000001F) {
- return out << "0";
- } else {
- std::streamsize p = out.precision();
- return out << std::fixed << std::setprecision(5) << w.v << std::setprecision(p);
- }
-}
+std::ostream& operator<<(std::ostream& out, const weightf_t& w);
struct shard_id_t {
int8_t id;
using ceph::decode;
decode(id, bl);
}
- void dump(ceph::Formatter *f) const {
- f->dump_int("id", id);
- }
- static void generate_test_instances(std::list<shard_id_t*>& ls) {
- ls.push_back(new shard_id_t(1));
- ls.push_back(new shard_id_t(2));
- }
+ void dump(ceph::Formatter *f) const;
+ static void generate_test_instances(std::list<shard_id_t*>& ls);
shard_id_t& operator++() { ++id; return *this; }
friend constexpr std::strong_ordering operator<=>(const shard_id_t &lhs,
const shard_id_t &rhs) {
decode(newcode, bl);
set_wire_to_host(newcode);
}
- void dump(ceph::Formatter *f) const {
- f->dump_int("code", code);
- }
- static void generate_test_instances(std::list<errorcode32_t*>& ls) {
- ls.push_back(new errorcode32_t(1));
- ls.push_back(new errorcode32_t(2));
- }
+ void dump(ceph::Formatter *f) const;
+ static void generate_test_instances(std::list<errorcode32_t*>& ls);
};
WRITE_CLASS_ENCODER(errorcode32_t)