common/ceph_argparse.cc \
common/ceph_context.cc \
common/buffer.cc \
+ common/types.cc \
common/code_environment.cc \
common/dout.cc \
common/histogram.cc \
snap)
typedef version_t gen_t;
-typedef uint8_t shard_t;
-#ifndef UINT8_MAX
-#define UINT8_MAX (255)
-#endif
#ifndef UINT64_MAX
#define UINT64_MAX (18446744073709551615ULL)
#endif
struct ghobject_t {
hobject_t hobj;
gen_t generation;
- shard_t shard_id;
+ shard_id_t shard_id;
public:
- static const shard_t NO_SHARD = UINT8_MAX;
- static shard_t no_shard() { return NO_SHARD; }
static const gen_t NO_GEN = UINT64_MAX;
- ghobject_t() : generation(NO_GEN), shard_id(NO_SHARD) {}
+ ghobject_t() : generation(NO_GEN), shard_id(shard_id_t::NO_SHARD) {}
- ghobject_t(const hobject_t &obj) : hobj(obj), generation(NO_GEN), shard_id(NO_SHARD) {}
+ ghobject_t(const hobject_t &obj) : hobj(obj), generation(NO_GEN), shard_id(shard_id_t::NO_SHARD) {}
- ghobject_t(const hobject_t &obj, gen_t gen, shard_t shard) : hobj(obj), generation(gen), shard_id(shard) {}
+ ghobject_t(const hobject_t &obj, gen_t gen, shard_id_t shard) : hobj(obj), generation(gen), shard_id(shard) {}
bool match(uint32_t bits, uint32_t match) const {
return hobj.match_hash(hobj.hash, bits, match);
--- /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) 2014 Cloudwatt <libre.licensing@cloudwatt.com>
+ *
+ * Author: Loic Dachary <loic@dachary.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ */
+#ifndef __CEPH_TYPES_H
+#define __CEPH_TYPES_H
+
+#include <include/types.h>
+
+#ifndef UINT8_MAX
+#define UINT8_MAX (255)
+#endif
+
+const shard_id_t shard_id_t::NO_SHARD(UINT8_MAX);
+
+ostream &operator<<(ostream &lhs, const shard_id_t &rhs)
+{
+ return lhs << (unsigned)rhs.id;
+}
+
+#endif
}
#endif
+struct shard_id_t {
+ uint8_t id;
+
+ shard_id_t() : id(0) {}
+ explicit shard_id_t(uint8_t _id) : id(_id) {}
+
+ operator uint8_t() const { return id; }
+
+ const static shard_id_t NO_SHARD;
+
+ void encode(bufferlist &bl) const {
+ ::encode(id, bl);
+ }
+ void decode(bufferlist::iterator &bl) {
+ ::decode(id, bl);
+ }
+};
+WRITE_CLASS_ENCODER(shard_id_t)
+WRITE_EQ_OPERATORS_1(shard_id_t, id)
+WRITE_CMP_OPERATORS_1(shard_id_t, id)
+ostream &operator<<(ostream &lhs, const shard_id_t &rhs);
+
#endif
typedef hobject_t collection_list_handle_t;
-typedef uint8_t shard_id_t;
-
/// convert a single CPEH_OSD_FLAG_* to a string
const char *ceph_osd_flag_name(unsigned flag);
}
}
+TEST(shard_id_t, iostream) {
+ set<shard_id_t> shards;
+ shards.insert(shard_id_t(0));
+ shards.insert(shard_id_t(1));
+ shards.insert(shard_id_t(2));
+ ostringstream out;
+ out << shards;
+ ASSERT_EQ(out.str(), "0,1,2");
+}
+
/*
* Local Variables:
- * compile-command: "cd .. ;
+ * compile-command: "cd ../.. ;
* make unittest_osd_types ;
* ./unittest_osd_types # --gtest_filter=pg_missing_t.constructor
* "