summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/base/status_with.h92
-rw-r--r--src/mongo/db/cloner.cpp2
-rw-r--r--src/mongo/db/matcher/expression_parser_leaf_test.cpp2
-rw-r--r--src/mongo/db/matcher/matcher.cpp2
-rw-r--r--src/mongo/db/query/canonical_query_test.cpp2
-rw-r--r--src/mongo/db/query/plan_cache_test.cpp2
-rw-r--r--src/mongo/db/repl/sync.cpp3
-rw-r--r--src/mongo/s/balance.cpp2
-rw-r--r--src/mongo/s/chunk.cpp2
9 files changed, 97 insertions, 12 deletions
diff --git a/src/mongo/base/status_with.h b/src/mongo/base/status_with.h
index 6014e5921d2..59f3618cf6c 100644
--- a/src/mongo/base/status_with.h
+++ b/src/mongo/base/status_with.h
@@ -29,6 +29,10 @@
#pragma once
+#include <boost/static_assert.hpp>
+#include <boost/type_traits/is_same.hpp> // TODO replace with std::is_same in C++11
+#include <iosfwd>
+
#include "mongo/base/status.h"
namespace mongo {
@@ -53,7 +57,9 @@ namespace mongo {
*/
template<typename T>
class StatusWith {
+ BOOST_STATIC_ASSERT(!(boost::is_same<T, Status>::value)); // StatusWith<Status> is banned.
public:
+
/**
* for the error case
*/
@@ -64,7 +70,7 @@ namespace mongo {
/**
* for the error case
*/
- explicit StatusWith( const Status& status )
+ /*implicit*/ StatusWith( const Status& status )
: _status( status ) {
// verify(( !status.isOK() ); // TODO
}
@@ -72,7 +78,7 @@ namespace mongo {
/**
* for the OK case
*/
- explicit StatusWith( const T& t )
+ /*implicit*/ StatusWith( const T& t )
: _status( Status::OK() ), _t( t ) {
}
@@ -81,10 +87,88 @@ namespace mongo {
bool isOK() const { return _status.isOK(); }
- std::string toString() const { return _status.toString(); }
private:
Status _status;
T _t;
};
-}
+ template<typename T>
+ std::ostream& operator<<(std::ostream& stream, const StatusWith<T>& sw) {
+ if (sw.isOK())
+ return stream << sw.getValue();
+ return stream << sw.getStatus();
+ }
+
+ //
+ // EqualityComparable(StatusWith<T>, T). Intentionally not providing an ordering relation.
+ //
+
+ template<typename T>
+ bool operator==(const StatusWith<T>& sw, const T& val) {
+ return sw.isOK() && sw.getValue() == val;
+ }
+
+ template<typename T>
+ bool operator==(const T& val, const StatusWith<T>& sw) {
+ return sw.isOK() && val == sw.getValue();
+ }
+
+ template<typename T>
+ bool operator!=(const StatusWith<T>& sw, const T& val) {
+ return !(sw == val);
+ }
+
+ template<typename T>
+ bool operator!=(const T& val, const StatusWith<T>& sw) {
+ return !(val == sw);
+ }
+
+ //
+ // EqualityComparable(StatusWith<T>, Status)
+ //
+
+ template<typename T>
+ bool operator==(const StatusWith<T>& sw, const Status& status) {
+ return sw.getStatus() == status;
+ }
+
+ template<typename T>
+ bool operator==(const Status& status, const StatusWith<T>& sw) {
+ return status == sw.getStatus();
+ }
+
+ template<typename T>
+ bool operator!=(const StatusWith<T>& sw, const Status& status) {
+ return !(sw == status);
+ }
+
+ template<typename T>
+ bool operator!=(const Status& status, const StatusWith<T>& sw) {
+ return !(status == sw);
+ }
+
+ //
+ // EqualityComparable(StatusWith<T>, ErrorCode)
+ //
+
+ template<typename T>
+ bool operator==(const StatusWith<T>& sw, const ErrorCodes& code) {
+ return sw.getStatus() == code;
+ }
+
+ template<typename T>
+ bool operator==(const ErrorCodes::Error& code, const StatusWith<T>& sw) {
+ return code == sw.getStatus();
+ }
+
+ template<typename T>
+ bool operator!=(const StatusWith<T>& sw, const ErrorCodes::Error& code) {
+ return !(sw == code);
+ }
+
+ template<typename T>
+ bool operator!=(const ErrorCodes::Error& code, const StatusWith<T>& sw) {
+ return !(code == sw);
+ }
+
+} // namespace mongo
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index 5e691f3b4c9..41023abd501 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -228,7 +228,7 @@ namespace mongo {
StatusWith<RecordId> loc = collection->insertDocument( txn, js, true );
if ( !loc.isOK() ) {
error() << "error: exception cloning object in " << from_collection
- << ' ' << loc.toString() << " obj:" << js;
+ << ' ' << loc.getStatus() << " obj:" << js;
}
uassertStatusOK( loc.getStatus() );
if (logForRepl)
diff --git a/src/mongo/db/matcher/expression_parser_leaf_test.cpp b/src/mongo/db/matcher/expression_parser_leaf_test.cpp
index ad28bfd6641..f0ef78ae40c 100644
--- a/src/mongo/db/matcher/expression_parser_leaf_test.cpp
+++ b/src/mongo/db/matcher/expression_parser_leaf_test.cpp
@@ -448,7 +448,7 @@ namespace mongo {
TEST( MatchExpressionParserLeafTest, Regex3 ) {
BSONObj query = BSON( "x" << BSON( "$options" << "i" << "$regex" << "abc" ) );
StatusWithMatchExpression result = MatchExpressionParser::parse( query );
- log() << "result: " << result << endl;
+ log() << "result: " << result.getStatus() << endl;
ASSERT_TRUE( result.isOK() );
boost::scoped_ptr<MatchExpression> destroy(result.getValue());
diff --git a/src/mongo/db/matcher/matcher.cpp b/src/mongo/db/matcher/matcher.cpp
index 7b7f844b822..e57bae6fff7 100644
--- a/src/mongo/db/matcher/matcher.cpp
+++ b/src/mongo/db/matcher/matcher.cpp
@@ -47,7 +47,7 @@ namespace mongo {
StatusWithMatchExpression result = MatchExpressionParser::parse(pattern, whereCallback);
uassert( 16810,
- mongoutils::str::stream() << "bad query: " << result.toString(),
+ mongoutils::str::stream() << "bad query: " << result.getStatus().toString(),
result.isOK() );
_expression.reset( result.getValue() );
diff --git a/src/mongo/db/query/canonical_query_test.cpp b/src/mongo/db/query/canonical_query_test.cpp
index af3f705ca05..4f16dd9d36c 100644
--- a/src/mongo/db/query/canonical_query_test.cpp
+++ b/src/mongo/db/query/canonical_query_test.cpp
@@ -448,7 +448,7 @@ namespace {
if (!status.isOK()) {
mongoutils::str::stream ss;
ss << "failed to parse query: " << obj.toString()
- << ". Reason: " << status.toString();
+ << ". Reason: " << status.getStatus().toString();
FAIL(ss);
}
MatchExpression* expr(status.getValue());
diff --git a/src/mongo/db/query/plan_cache_test.cpp b/src/mongo/db/query/plan_cache_test.cpp
index b21cc891d75..8ebb9221029 100644
--- a/src/mongo/db/query/plan_cache_test.cpp
+++ b/src/mongo/db/query/plan_cache_test.cpp
@@ -145,7 +145,7 @@ namespace {
if (!status.isOK()) {
mongoutils::str::stream ss;
ss << "failed to parse query: " << obj.toString()
- << ". Reason: " << status.toString();
+ << ". Reason: " << status.getStatus().toString();
FAIL(ss);
}
MatchExpression* expr(status.getValue());
diff --git a/src/mongo/db/repl/sync.cpp b/src/mongo/db/repl/sync.cpp
index f5ad8a24471..daa6d305a57 100644
--- a/src/mongo/db/repl/sync.cpp
+++ b/src/mongo/db/repl/sync.cpp
@@ -140,7 +140,8 @@ namespace repl {
StatusWith<RecordId> result = collection->insertDocument(txn, missingObj, true);
uassert(15917,
- str::stream() << "failed to insert missing doc: " << result.toString(),
+ str::stream() << "failed to insert missing doc: "
+ << result.getStatus().toString(),
result.isOK() );
LOG(1) << "inserted missing doc: " << missingObj.toString() << endl;
diff --git a/src/mongo/s/balance.cpp b/src/mongo/s/balance.cpp
index 76e658b8ef6..499adc9c037 100644
--- a/src/mongo/s/balance.cpp
+++ b/src/mongo/s/balance.cpp
@@ -642,7 +642,7 @@ namespace mongo {
writeConcern.reset(extractStatus.getValue());
}
else {
- warning() << extractStatus.toString();
+ warning() << extractStatus.getStatus().toString();
}
}
diff --git a/src/mongo/s/chunk.cpp b/src/mongo/s/chunk.cpp
index 6722ef3ca8a..9814f97f6a3 100644
--- a/src/mongo/s/chunk.cpp
+++ b/src/mongo/s/chunk.cpp
@@ -142,7 +142,7 @@ namespace mongo {
chunk);
if (!tagStatus.isOK()) {
warning() << "Not auto-moving chunk because of an error encountered while "
- << "checking tag for chunk: " << tagStatus.toString() << endl;
+ << "checking tag for chunk: " << tagStatus.getStatus() << endl;
return false;
}