summaryrefslogtreecommitdiff
path: root/src/mongo/s/shard_id.h
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2018-07-29 22:57:56 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2018-08-01 12:00:24 -0400
commit24e411d5cd7f64c5b4da25a351529cd1873284b8 (patch)
tree060674e8824d23401972831e1d13e5d909ca9f30 /src/mongo/s/shard_id.h
parentce94b03f8c141dc0a34ff8682866795458684e45 (diff)
downloadmongo-24e411d5cd7f64c5b4da25a351529cd1873284b8.tar.gz
SERVER-29908 Remove ShardingState::appendInfo
Expose the ShardingState properties and move the appendInfo logic to be entirely inside the 'getShardingState' function, which is its only consumer.
Diffstat (limited to 'src/mongo/s/shard_id.h')
-rw-r--r--src/mongo/s/shard_id.h50
1 files changed, 27 insertions, 23 deletions
diff --git a/src/mongo/s/shard_id.h b/src/mongo/s/shard_id.h
index cbb15032cca..d4aed48a972 100644
--- a/src/mongo/s/shard_id.h
+++ b/src/mongo/s/shard_id.h
@@ -28,36 +28,25 @@
#pragma once
-#include <iostream>
+#include <ostream>
#include <string>
#include "mongo/base/string_data.h"
#include "mongo/bson/util/builder.h"
-
namespace mongo {
-class NamespaceString;
-
/**
* Representation of a shard identifier.
*/
class ShardId {
public:
- friend std::ostream& operator<<(std::ostream&, const ShardId&);
-
ShardId() = default;
-
- // Note that this c-tor allows the implicit conversion from std::string
ShardId(std::string shardId) : _shardId(std::move(shardId)) {}
- // Implicit StringData conversion
- operator StringData();
-
- bool operator==(const ShardId&) const;
- bool operator!=(const ShardId&) const;
- bool operator==(const std::string&) const;
- bool operator!=(const std::string&) const;
+ operator StringData() const {
+ return StringData(_shardId);
+ }
template <size_t N>
bool operator==(const char (&val)[N]) const {
@@ -69,10 +58,14 @@ public:
return (strncmp(val, _shardId.data(), N) != 0);
}
- // The operator< is needed to do proper comparison in a std::map
- bool operator<(const ShardId&) const;
+ const std::string& toString() const {
+ return _shardId;
+ }
- const std::string& toString() const;
+ /**
+ * Returns true if _shardId is not empty. Subject to include more validations in the future.
+ */
+ bool isValid() const;
/**
* Returns -1, 0, or 1 if 'this' is less, equal, or greater than 'other' in
@@ -81,11 +74,6 @@ public:
int compare(const ShardId& other) const;
/**
- * Returns true if _shardId is not empty. Subject to include more validations in the future.
- */
- bool isValid() const;
-
- /**
* Functor compatible with std::hash for std::unordered_{map,set}
*/
struct Hasher {
@@ -96,6 +84,22 @@ private:
std::string _shardId;
};
+inline bool operator==(const ShardId& lhs, const ShardId& rhs) {
+ return lhs.compare(rhs) == 0;
+}
+
+inline bool operator!=(const ShardId& lhs, const ShardId& rhs) {
+ return !(lhs == rhs);
+}
+
+inline bool operator<(const ShardId& lhs, const ShardId& rhs) {
+ return lhs.compare(rhs) < 0;
+}
+
+inline std::ostream& operator<<(std::ostream& os, const ShardId& shardId) {
+ return os << shardId.toString();
+}
+
template <typename Allocator>
StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& stream,
const ShardId& shardId) {