diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2018-07-29 22:57:56 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2018-08-01 12:00:24 -0400 |
commit | 24e411d5cd7f64c5b4da25a351529cd1873284b8 (patch) | |
tree | 060674e8824d23401972831e1d13e5d909ca9f30 /src/mongo/s | |
parent | ce94b03f8c141dc0a34ff8682866795458684e45 (diff) | |
download | mongo-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')
-rw-r--r-- | src/mongo/s/shard_id.cpp | 43 | ||||
-rw-r--r-- | src/mongo/s/shard_id.h | 50 |
2 files changed, 30 insertions, 63 deletions
diff --git a/src/mongo/s/shard_id.cpp b/src/mongo/s/shard_id.cpp index 961c8711e17..098fcedde1f 100644 --- a/src/mongo/s/shard_id.cpp +++ b/src/mongo/s/shard_id.cpp @@ -30,54 +30,16 @@ #include "mongo/platform/basic.h" -#include <functional> -#include <string.h> - -#include "mongo/base/status_with.h" #include "mongo/s/shard_id.h" -namespace mongo { - -using std::string; -using std::ostream; - -bool ShardId::operator==(const ShardId& other) const { - return (this->_shardId == other._shardId); -} - -bool ShardId::operator!=(const ShardId& other) const { - return !(*this == other); -} - -bool ShardId::operator==(const string& other) const { - return (this->_shardId == other); -} - -bool ShardId::operator!=(const string& other) const { - return !(*this == other); -} - -ShardId::operator StringData() { - return StringData(_shardId.data(), _shardId.size()); -} +#include <functional> -const string& ShardId::toString() const { - return _shardId; -} +namespace mongo { bool ShardId::isValid() const { return !_shardId.empty(); } -ostream& operator<<(ostream& os, const ShardId& shardId) { - os << shardId._shardId; - return os; -} - -bool ShardId::operator<(const ShardId& other) const { - return _shardId < other._shardId; -} - int ShardId::compare(const ShardId& other) const { return _shardId.compare(other._shardId); } @@ -85,4 +47,5 @@ int ShardId::compare(const ShardId& other) const { std::size_t ShardId::Hasher::operator()(const ShardId& shardId) const { return std::hash<std::string>()(shardId._shardId); } + } // namespace mongo 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) { |