summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/exec/projection_exec.cpp4
-rw-r--r--src/mongo/db/exec/projection_exec_test.cpp14
-rw-r--r--src/mongo/db/exec/sort_test.cpp6
-rw-r--r--src/mongo/db/exec/stagedebug_cmd.cpp2
-rw-r--r--src/mongo/db/query/canonical_query.cpp30
-rw-r--r--src/mongo/db/query/canonical_query_test.cpp12
-rw-r--r--src/mongo/db/query/index_bounds.cpp10
-rw-r--r--src/mongo/db/query/index_bounds_builder.cpp12
-rw-r--r--src/mongo/db/query/index_entry.h5
-rw-r--r--src/mongo/db/query/interval.h5
-rw-r--r--src/mongo/db/query/lite_parsed_query_test.cpp10
-rw-r--r--src/mongo/db/query/parsed_projection.cpp8
-rw-r--r--src/mongo/db/query/plan_cache.cpp25
-rw-r--r--src/mongo/db/query/plan_cache_test.cpp38
-rw-r--r--src/mongo/db/query/plan_enumerator.cpp20
-rw-r--r--src/mongo/db/query/planner_ixselect_test.cpp26
-rw-r--r--src/mongo/db/query/query_planner.cpp16
-rw-r--r--src/mongo/db/query/query_planner_test.cpp27
-rw-r--r--src/mongo/db/query/query_planner_test_lib.cpp1
-rw-r--r--src/mongo/db/query/query_planner_test_lib.h1
-rw-r--r--src/mongo/db/query/query_solution.cpp112
-rw-r--r--src/mongo/db/query/query_solution.h42
-rw-r--r--src/mongo/db/query/stage_builder.cpp5
23 files changed, 205 insertions, 226 deletions
diff --git a/src/mongo/db/exec/projection_exec.cpp b/src/mongo/db/exec/projection_exec.cpp
index d78c2d59a7f..e080d774926 100644
--- a/src/mongo/db/exec/projection_exec.cpp
+++ b/src/mongo/db/exec/projection_exec.cpp
@@ -510,11 +510,11 @@ namespace mongo {
if (details && arrayOpType == ARRAY_OP_POSITIONAL) {
// $ positional operator specified
if (!details->hasElemMatchKey()) {
- stringstream error;
+ mongoutils::str::stream error;
error << "positional operator (" << elt.fieldName()
<< ".$) requires corresponding field"
<< " in query specifier";
- return Status(ErrorCodes::BadValue, error.str());
+ return Status(ErrorCodes::BadValue, error);
}
if (elt.embeddedObject()[details->elemMatchKey()].eoo()) {
diff --git a/src/mongo/db/exec/projection_exec_test.cpp b/src/mongo/db/exec/projection_exec_test.cpp
index c4f0717d582..6267f32fabe 100644
--- a/src/mongo/db/exec/projection_exec_test.cpp
+++ b/src/mongo/db/exec/projection_exec_test.cpp
@@ -32,7 +32,6 @@
#include "mongo/db/exec/projection_exec.h"
-#include <sstream>
#include <memory>
#include "mongo/db/json.h"
#include "mongo/db/matcher/expression_parser.h"
@@ -43,7 +42,6 @@ using namespace mongo;
namespace {
using std::auto_ptr;
- using std::stringstream;
/**
* Utility function to create MatchExpression
@@ -90,12 +88,12 @@ namespace {
// There are fewer checks to perform if we are expected a failed status.
if (!expectedStatusOK) {
if (status.isOK()) {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "expected transform() to fail but got success instead."
<< "\nprojection spec: " << specStr
<< "\nquery: " << queryStr
<< "\nobject before projection: " << objStr;
- FAIL(ss.str());
+ FAIL(ss);
}
return;
}
@@ -103,27 +101,27 @@ namespace {
// If we are expecting a successful transformation but got a failed status instead,
// print out status message in assertion message.
if (!status.isOK()) {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "transform() test failed: unexpected failed status: " << status.toString()
<< "\nprojection spec: " << specStr
<< "\nquery: " << queryStr
<< "\nobject before projection: " << objStr
<< "\nexpected object after projection: " << expectedObjStr;
- FAIL(ss.str());
+ FAIL(ss);
}
// Finally, we compare the projected object.
const BSONObj& obj = wsm.obj;
BSONObj expectedObj = fromjson(expectedObjStr);
if (obj != expectedObj) {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "transform() test failed: unexpected projected object."
<< "\nprojection spec: " << specStr
<< "\nquery: " << queryStr
<< "\nobject before projection: " << objStr
<< "\nexpected object after projection: " << expectedObjStr
<< "\nactual object after projection: " << obj.toString();
- FAIL(ss.str());
+ FAIL(ss);
}
}
diff --git a/src/mongo/db/exec/sort_test.cpp b/src/mongo/db/exec/sort_test.cpp
index 8d0731ec75b..225e2732b09 100644
--- a/src/mongo/db/exec/sort_test.cpp
+++ b/src/mongo/db/exec/sort_test.cpp
@@ -32,7 +32,6 @@
#include "mongo/db/exec/sort.h"
-#include <sstream>
#include "mongo/db/json.h"
#include "mongo/db/exec/mock_stage.h"
#include "mongo/unittest/unittest.h"
@@ -41,7 +40,6 @@ using namespace mongo;
namespace {
- using std::stringstream;
TEST(SortStageTest, SortEmptyWorkingSet) {
WorkingSet ws;
@@ -145,14 +143,14 @@ namespace {
// Finally, we get to compare the sorted results against what we expect.
BSONObj expectedObj = fromjson(expectedStr);
if (outputObj != expectedObj) {
- stringstream ss;
+ mongoutils::str::stream ss;
// Even though we have the original string representation of the expected output,
// we invoke BSONObj::toString() to get a format consistent with outputObj.
ss << "Unexpected sort result with query=" << queryStr << "; pattern=" << patternStr
<< "; limit=" << limit << ":\n"
<< "Expected: " << expectedObj.toString() << "\n"
<< "Actual: " << outputObj.toString() << "\n";
- FAIL(ss.str());
+ FAIL(ss);
}
}
diff --git a/src/mongo/db/exec/stagedebug_cmd.cpp b/src/mongo/db/exec/stagedebug_cmd.cpp
index c7bc293950e..ecc0c15caeb 100644
--- a/src/mongo/db/exec/stagedebug_cmd.cpp
+++ b/src/mongo/db/exec/stagedebug_cmd.cpp
@@ -93,7 +93,7 @@ namespace mongo {
virtual LockType locktype() const { return READ; }
bool slaveOk() const { return true; }
bool slaveOverrideOk() const { return true; }
- void help(stringstream& h) const { }
+ void help(std::stringstream& h) const { }
virtual void addRequiredPrivileges(const std::string& dbname,
const BSONObj& cmdObj,
diff --git a/src/mongo/db/query/canonical_query.cpp b/src/mongo/db/query/canonical_query.cpp
index 46d358bccce..4e3f7233503 100644
--- a/src/mongo/db/query/canonical_query.cpp
+++ b/src/mongo/db/query/canonical_query.cpp
@@ -35,12 +35,10 @@
namespace {
using std::auto_ptr;
- using std::ostream;
using std::string;
- using std::stringstream;
using namespace mongo;
- void encodePlanCacheKeyTree(const MatchExpression* tree, ostream* os);
+ void encodePlanCacheKeyTree(const MatchExpression* tree, mongoutils::str::stream* os);
/**
* Comparator for MatchExpression nodes. nodes by:
@@ -73,10 +71,12 @@ namespace {
return lhsPath < rhsPath;
}
// Third, cache key.
- stringstream ssLeft, ssRight;
+ mongoutils::str::stream ssLeft, ssRight;
encodePlanCacheKeyTree(lhs, &ssLeft);
encodePlanCacheKeyTree(rhs, &ssRight);
- return ssLeft.str() < ssRight.str();
+ string strLeft(ssLeft);
+ string strRight(ssRight);
+ return strLeft < strRight;
}
/**
@@ -121,7 +121,7 @@ namespace {
* Appends an encoding of each node's match type and path name
* to the output stream.
*/
- void encodePlanCacheKeyTree(const MatchExpression* tree, ostream* os) {
+ void encodePlanCacheKeyTree(const MatchExpression* tree, mongoutils::str::stream* os) {
// Encode match type and path.
*os << encodeMatchType(tree->matchType()) << tree->path();
// Traverse child nodes.
@@ -135,7 +135,7 @@ namespace {
* Sort order is normalized because it provided by
* LiteParsedQuery.
*/
- void encodePlanCacheKeySort(const BSONObj& sortObj, ostream* os) {
+ void encodePlanCacheKeySort(const BSONObj& sortObj, mongoutils::str::stream* os) {
BSONObjIterator it(sortObj);
while (it.more()) {
BSONElement elt = it.next();
@@ -161,7 +161,7 @@ namespace {
* in the BSON object.
* This handles all the special projection types ($meta, $elemMatch, etc.)
*/
- void encodePlanCacheKeyProj(const BSONObj& projObj, ostream* os) {
+ void encodePlanCacheKeyProj(const BSONObj& projObj, mongoutils::str::stream* os) {
if (projObj.isEmpty()) {
return;
}
@@ -266,11 +266,11 @@ namespace mongo {
}
void CanonicalQuery::generateCacheKey(void) {
- stringstream ss;
+ mongoutils::str::stream ss;
encodePlanCacheKeyTree(_root.get(), &ss);
encodePlanCacheKeySort(_pq->getSort(), &ss);
encodePlanCacheKeyProj(_pq->getProj(), &ss);
- _cacheKey = ss.str();
+ _cacheKey = ss;
}
// static
@@ -445,14 +445,14 @@ namespace mongo {
}
string CanonicalQuery::toString() const {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "ns=" << _pq->ns() << " limit=" << _pq->getNumToReturn()
- << " skip=" << _pq->getSkip() << endl;
+ << " skip=" << _pq->getSkip() << '\n';
// The expression tree puts an endl on for us.
ss << "Tree: " << _root->toString();
- ss << "Sort: " << _pq->getSort().toString() << endl;
- ss << "Proj: " << _pq->getProj().toString() << endl;
- return ss.str();
+ ss << "Sort: " << _pq->getSort().toString() << '\n';
+ ss << "Proj: " << _pq->getProj().toString() << '\n';
+ return ss;
}
} // namespace mongo
diff --git a/src/mongo/db/query/canonical_query_test.cpp b/src/mongo/db/query/canonical_query_test.cpp
index fdc5f9280c5..359a46ff35a 100644
--- a/src/mongo/db/query/canonical_query_test.cpp
+++ b/src/mongo/db/query/canonical_query_test.cpp
@@ -270,10 +270,10 @@ namespace {
MatchExpression* parseMatchExpression(const BSONObj& obj) {
StatusWithMatchExpression status = MatchExpressionParser::parse(obj);
if (!status.isOK()) {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "failed to parse query: " << obj.toString()
<< ". Reason: " << status.toString();
- FAIL(ss.str());
+ FAIL(ss);
}
MatchExpression* expr(status.getValue());
return expr;
@@ -285,12 +285,12 @@ namespace {
if (actual->equivalent(expected)) {
return;
}
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "Match expressions are not equivalent."
<< "\nOriginal query: " << queryStr
<< "\nExpected: " << expected->toString()
<< "\nActual: " << actual->toString();
- FAIL(ss.str());
+ FAIL(ss);
}
/**
@@ -342,10 +342,10 @@ namespace {
if (key == expectedKey) {
return;
}
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "Unexpected plan cache key. Expected: " << expectedKey << ". Actual: " << key
<< ". Query: " << cq->toString();
- FAIL(ss.str());
+ FAIL(ss);
}
TEST(PlanCacheTest, GetPlanCacheKey) {
diff --git a/src/mongo/db/query/index_bounds.cpp b/src/mongo/db/query/index_bounds.cpp
index 38aa103ad03..e024cf09f33 100644
--- a/src/mongo/db/query/index_bounds.cpp
+++ b/src/mongo/db/query/index_bounds.cpp
@@ -64,7 +64,7 @@ namespace mongo {
}
string OrderedIntervalList::toString() const {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "['" << name << "']: ";
for (size_t j = 0; j < intervals.size(); ++j) {
ss << intervals[j].toString();
@@ -72,11 +72,11 @@ namespace mongo {
ss << ", ";
}
}
- return ss.str();
+ return ss;
}
string IndexBounds::toString() const {
- stringstream ss;
+ mongoutils::str::stream ss;
if (isSimpleRange) {
ss << "[" << startKey.toString() << ", ";
if (endKey.isEmpty()) {
@@ -91,7 +91,7 @@ namespace mongo {
ss << ")";
}
}
- return ss.str();
+ return ss;
}
for (size_t i = 0; i < fields.size(); ++i) {
if (i > 0) {
@@ -100,7 +100,7 @@ namespace mongo {
ss << "field #" << i << fields[i].toString();
}
- return ss.str();
+ return ss;
}
BSONObj IndexBounds::toBSON() const {
diff --git a/src/mongo/db/query/index_bounds_builder.cpp b/src/mongo/db/query/index_bounds_builder.cpp
index 44cd185b9fe..ac9bcaabcc4 100644
--- a/src/mongo/db/query/index_bounds_builder.cpp
+++ b/src/mongo/db/query/index_bounds_builder.cpp
@@ -76,13 +76,13 @@ namespace mongo {
}
}
- stringstream ss;
+ mongoutils::str::stream ss;
while(*regex) {
char c = *(regex++);
if ( c == '*' || c == '?' ) {
// These are the only two symbols that make the last char optional
- r = ss.str();
+ r = ss;
r = r.substr( 0 , r.size() - 1 );
return r; //breaking here fails with /^a?/
}
@@ -110,7 +110,7 @@ namespace mongo {
(c >= '0' && c <= '0') ||
(c == '\0')) {
// don't know what to do with these
- r = ss.str();
+ r = ss;
break;
}
else {
@@ -120,12 +120,12 @@ namespace mongo {
}
else if (strchr("^$.[()+{", c)) {
// list of "metacharacters" from man pcrepattern
- r = ss.str();
+ r = ss;
break;
}
else if (extended && c == '#') {
// comment
- r = ss.str();
+ r = ss;
break;
}
else if (extended && isspace(c)) {
@@ -138,7 +138,7 @@ namespace mongo {
}
if ( r.empty() && *regex == 0 ) {
- r = ss.str();
+ r = ss;
*tightnessOut = r.empty() ? IndexBoundsBuilder::INEXACT_COVERED : IndexBoundsBuilder::EXACT;
}
diff --git a/src/mongo/db/query/index_entry.h b/src/mongo/db/query/index_entry.h
index 0b772438347..04e60e9d999 100644
--- a/src/mongo/db/query/index_entry.h
+++ b/src/mongo/db/query/index_entry.h
@@ -28,7 +28,6 @@
#pragma once
-#include <sstream>
#include <string>
#include "mongo/db/jsobj.h"
@@ -62,7 +61,7 @@ namespace mongo {
BSONObj infoObj;
std::string toString() const {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "kp: " << keyPattern.toString();
if (multikey) {
@@ -77,7 +76,7 @@ namespace mongo {
ss << " io: " << infoObj.toString();
}
- return ss.str();
+ return ss;
}
};
diff --git a/src/mongo/db/query/interval.h b/src/mongo/db/query/interval.h
index 70b07e67f08..e74cabcee35 100644
--- a/src/mongo/db/query/interval.h
+++ b/src/mongo/db/query/interval.h
@@ -29,6 +29,7 @@
#pragma once
#include "mongo/db/jsobj.h"
+#include "mongo/util/mongoutils/str.h"
namespace mongo {
@@ -52,7 +53,7 @@ namespace mongo {
Interval();
string toString() const {
- stringstream ss;
+ mongoutils::str::stream ss;
if (startInclusive) {
ss << "[";
}
@@ -69,7 +70,7 @@ namespace mongo {
else {
ss << ")";
}
- return ss.str();
+ return ss;
}
/**
diff --git a/src/mongo/db/query/lite_parsed_query_test.cpp b/src/mongo/db/query/lite_parsed_query_test.cpp
index 066c2c32950..ba5c05ca108 100644
--- a/src/mongo/db/query/lite_parsed_query_test.cpp
+++ b/src/mongo/db/query/lite_parsed_query_test.cpp
@@ -32,11 +32,9 @@
#include "mongo/db/query/lite_parsed_query.h"
-#include <sstream>
#include "mongo/db/json.h"
#include "mongo/unittest/unittest.h"
-using std::stringstream;
using namespace mongo;
namespace {
@@ -143,16 +141,16 @@ namespace {
BSONObj sortOrder = fromjson(sortStr);
bool valid = LiteParsedQuery::isValidSortOrder(sortOrder);
if (expectedValid != valid) {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << sortStr << ": unexpected validation result. Expected: " << expectedValid;
- FAIL(ss.str());
+ FAIL(ss);
}
BSONObj normalizedSortOrder = LiteParsedQuery::normalizeSortOrder(sortOrder);
if (fromjson(expectedStr) != normalizedSortOrder) {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << sortStr << ": unexpected normalization result. Expected: " << expectedStr
<< ". Actual: " << normalizedSortOrder.toString();
- FAIL(ss.str());
+ FAIL(ss);
}
}
diff --git a/src/mongo/db/query/parsed_projection.cpp b/src/mongo/db/query/parsed_projection.cpp
index a3f0c8c4e81..b10f65ceebb 100644
--- a/src/mongo/db/query/parsed_projection.cpp
+++ b/src/mongo/db/query/parsed_projection.cpp
@@ -212,18 +212,18 @@ namespace mongo {
std::string after = mongoutils::str::after(e.fieldName(), ".$");
if (mongoutils::str::contains(after, ".$")) {
- std::stringstream ss;
+ mongoutils::str::stream ss;
ss << "Positional projection '" << e.fieldName() << "' contains "
<< "the positional operator more than once.";
- return Status(ErrorCodes::BadValue, ss.str());
+ return Status(ErrorCodes::BadValue, ss);
}
std::string matchfield = mongoutils::str::before(e.fieldName(), '.');
if (!_hasPositionalOperatorMatch(query, matchfield)) {
- std::stringstream ss;
+ mongoutils::str::stream ss;
ss << "Positional projection '" << e.fieldName() << "' does not "
<< "match the query document.";
- return Status(ErrorCodes::BadValue, ss.str());
+ return Status(ErrorCodes::BadValue, ss);
}
arrayOpType = ARRAY_OP_POSITIONAL;
diff --git a/src/mongo/db/query/plan_cache.cpp b/src/mongo/db/query/plan_cache.cpp
index 51ccd37fef0..f66c69274e7 100644
--- a/src/mongo/db/query/plan_cache.cpp
+++ b/src/mongo/db/query/plan_cache.cpp
@@ -30,7 +30,6 @@
#include <algorithm>
#include <memory>
-#include <sstream>
#include "boost/thread/locks.hpp"
#include "mongo/db/query/plan_ranker.h"
#include "mongo/db/query/query_solution.h"
@@ -132,19 +131,19 @@ namespace mongo {
}
string PlanCacheEntry::toString() const {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "(query: " << query.toString()
<< ";sort: " << sort.toString()
<< ";projection: " << projection.toString()
<< ";solutions: " << plannerData.size()
<< ")";
- return ss.str();
+ return ss;
}
string CachedSolution::toString() const {
- stringstream ss;
- ss << "key: " << key << endl;
- return ss.str();
+ mongoutils::str::stream ss;
+ ss << "key: " << key << '\n';
+ return ss;
}
//
@@ -171,24 +170,24 @@ namespace mongo {
}
std::string PlanCacheIndexTree::toString(int indents) const {
- std::stringstream ss;
+ mongoutils::str::stream ss;
if (!children.empty()) {
- ss << string(3 * indents, '-') << "Node" << std::endl;
+ ss << string(3 * indents, '-') << "Node\n";
int newIndent = indents + 1;
for (vector<PlanCacheIndexTree*>::const_iterator it = children.begin();
it != children.end(); ++it) {
ss << (*it)->toString(newIndent);
}
- return ss.str();
+ return ss;
}
else {
ss << string(3 * indents, '-') << "Leaf ";
if (NULL != entry.get()) {
ss << entry->keyPattern.toString() << ", pos: " << index_pos;
}
- ss << std::endl;
+ ss << '\n';
}
- return ss.str();
+ return ss;
}
//
@@ -208,7 +207,7 @@ namespace mongo {
}
std::string SolutionCacheData::toString() const {
- stringstream ss;
+ mongoutils::str::stream ss;
switch (this->solnType) {
case WHOLE_IXSCAN_SOLN:
verify(this->tree.get());
@@ -226,7 +225,7 @@ namespace mongo {
<< "tree=" << this->tree->toString()
<< ")";
}
- return ss.str();
+ return ss;
}
//
diff --git a/src/mongo/db/query/plan_cache_test.cpp b/src/mongo/db/query/plan_cache_test.cpp
index e6d88e2316c..ac6d6774534 100644
--- a/src/mongo/db/query/plan_cache_test.cpp
+++ b/src/mongo/db/query/plan_cache_test.cpp
@@ -34,7 +34,6 @@
#include <algorithm>
#include <ostream>
-#include <sstream>
#include <memory>
#include "mongo/db/jsobj.h"
#include "mongo/db/json.h"
@@ -51,7 +50,6 @@ using namespace mongo;
namespace {
using std::auto_ptr;
- using std::stringstream;
static const char* ns = "somebogusns";
@@ -107,10 +105,10 @@ namespace {
MatchExpression* parseMatchExpression(const BSONObj& obj) {
StatusWithMatchExpression status = MatchExpressionParser::parse(obj);
if (!status.isOK()) {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "failed to parse query: " << obj.toString()
<< ". Reason: " << status.toString();
- FAIL(ss.str());
+ FAIL(ss);
}
MatchExpression* expr(status.getValue());
return expr;
@@ -120,12 +118,12 @@ namespace {
if (actual->equivalent(expected)) {
return;
}
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "Match expressions are not equivalent."
<< "\nOriginal query: " << queryStr
<< "\nExpected: " << expected->toString()
<< "\nActual: " << actual->toString();
- FAIL(ss.str());
+ FAIL(ss);
}
//
@@ -167,18 +165,18 @@ namespace {
if (PlanCache::shouldCacheQuery(query)) {
return;
}
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "Canonical query should be cacheable: " << query.toString();
- FAIL(ss.str());
+ FAIL(ss);
}
void assertShouldNotCacheQuery(const CanonicalQuery& query) {
if (!PlanCache::shouldCacheQuery(query)) {
return;
}
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "Canonical query should not be cacheable: " << query.toString();
- FAIL(ss.str());
+ FAIL(ss);
}
void assertShouldNotCacheQuery(const char* queryStr) {
@@ -425,18 +423,14 @@ namespace {
// Solution introspection.
//
- void dumpSolutions(ostream& ost) const {
+ void dumpSolutions(mongoutils::str::stream& ost) const {
for (vector<QuerySolution*>::const_iterator it = solns.begin();
it != solns.end();
++it) {
- ost << (*it)->toString() << endl;
+ ost << (*it)->toString() << '\n';
}
}
- void dumpSolutions() const {
- dumpSolutions(std::cout);
- }
-
/**
* Plan 'query' from the cache. A mock cache entry is created using
* the cacheData stored inside the QuerySolution 'soln'.
@@ -498,11 +492,11 @@ namespace {
}
}
- std::stringstream ss;
+ mongoutils::str::stream ss;
ss << "Could not find a match for solution " << solnJson
- << " All solutions generated: " << std::endl;
+ << " All solutions generated: " << '\n';
dumpSolutions(ss);
- FAIL(ss.str());
+ FAIL(ss);
return NULL;
}
@@ -516,10 +510,10 @@ namespace {
void assertSolutionMatches(QuerySolution* trueSoln, const string& solnJson) const {
BSONObj testSoln = fromjson(solnJson);
if (!QueryPlannerTestLib::solutionMatches(testSoln, trueSoln->root.get())) {
- std::stringstream ss;
+ mongoutils::str::stream ss;
ss << "Expected solution " << solnJson << " did not match true solution: "
- << trueSoln->toString() << std::endl;
- FAIL(ss.str());
+ << trueSoln->toString() << '\n';
+ FAIL(ss);
}
}
diff --git a/src/mongo/db/query/plan_enumerator.cpp b/src/mongo/db/query/plan_enumerator.cpp
index 92dd62bb4a6..8e72be4901f 100644
--- a/src/mongo/db/query/plan_enumerator.cpp
+++ b/src/mongo/db/query/plan_enumerator.cpp
@@ -68,7 +68,7 @@ namespace mongo {
string PlanEnumerator::NodeAssignment::toString() const {
if (NULL != pred) {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "predicate, first indices: [";
for (size_t i = 0; i < pred->first.size(); ++i) {
ss << pred->first[i];
@@ -77,10 +77,10 @@ namespace mongo {
}
ss << "], pred: " << pred->expr->toString();
ss << " indexToAssign: " << pred->indexToAssign;
- return ss.str();
+ return ss;
}
else if (NULL != andAssignment) {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "AND enumstate counter " << andAssignment->counter;
for (size_t i = 0; i < andAssignment->choices.size(); ++i) {
ss << "\nchoice " << i << ":\n";
@@ -89,37 +89,37 @@ namespace mongo {
for (size_t j = 0; j < state.subnodesToIndex.size(); ++j) {
ss << state.subnodesToIndex[j] << " ";
}
- ss << endl;
+ ss << '\n';
for (size_t j = 0; j < state.assignments.size(); ++j) {
const OneIndexAssignment& oie = state.assignments[j];
ss << "\tidx[" << oie.index << "]\n";
for (size_t k = 0; k < oie.preds.size(); ++k) {
ss << "\t\tpos " << oie.positions[k]
- << " pred " << oie.preds[k]->toString() << endl;
+ << " pred " << oie.preds[k]->toString() << '\n';
}
}
}
- return ss.str();
+ return ss;
}
else if (NULL != arrayAssignment) {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "ARRAY SUBNODES enumstate " << arrayAssignment->counter << "/ ONE OF: [";
for (size_t i = 0; i < arrayAssignment->subnodes.size(); ++i) {
ss << " " << arrayAssignment->subnodes[i];
}
ss << "]";
- return ss.str();
+ return ss;
}
else {
verify(NULL != orAssignment);
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "ALL OF: [";
for (size_t i = 0; i < orAssignment->subnodes.size(); ++i) {
ss << " " << orAssignment->subnodes[i];
}
ss << "]";
- return ss.str();
+ return ss;
}
}
diff --git a/src/mongo/db/query/planner_ixselect_test.cpp b/src/mongo/db/query/planner_ixselect_test.cpp
index e4441a273d7..1ee2183e3da 100644
--- a/src/mongo/db/query/planner_ixselect_test.cpp
+++ b/src/mongo/db/query/planner_ixselect_test.cpp
@@ -33,7 +33,6 @@
#include "mongo/db/query/planner_ixselect.h"
#include <memory>
-#include <sstream>
#include "mongo/db/json.h"
#include "mongo/db/matcher/expression_parser.h"
#include "mongo/db/query/index_tag.h"
@@ -45,7 +44,6 @@ using namespace mongo;
namespace {
using std::auto_ptr;
- using std::stringstream;
using std::string;
using std::vector;
@@ -63,7 +61,7 @@ namespace {
* Utility function to join elements in iterator range with comma
*/
template <typename Iter> string toString(Iter begin, Iter end) {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "[";
for (Iter i = begin; i != end; i++) {
if (i != begin) {
@@ -72,7 +70,7 @@ namespace {
ss << *i;
}
ss << "]";
- return ss.str();
+ return ss;
}
/**
@@ -93,21 +91,21 @@ namespace {
for (vector<string>::const_iterator i = expectedFields.begin(); i != expectedFields.end();
i++) {
if (fields.find(*i) == fields.end()) {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "getFields(query=" << query << ", prefix=" << prefix << "): unable to find "
<< *i << " in result: " << toString(fields.begin(), fields.end());
- FAIL(ss.str());
+ FAIL(ss);
}
}
// Next, confirm that results do not contain any unexpected fields.
if (fields.size() != expectedFields.size()) {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "getFields(query=" << query << ", prefix=" << prefix
<< "): unexpected fields in result. expected: "
<< toString(expectedFields.begin(), expectedFields.end())
<< ". actual: " << toString(fields.begin(), fields.end());
- FAIL(ss.str());
+ FAIL(ss);
}
}
@@ -163,10 +161,10 @@ namespace {
tag->debugString(&buf);
RelevantTag* r = dynamic_cast<RelevantTag*>(tag);
if (!r) {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "tag is not instance of RelevantTag. tree: " << root->toString()
<< "; tag: " << buf.str();
- FAIL(ss.str());
+ FAIL(ss);
}
paths->push_back(r->path);
}
@@ -205,12 +203,12 @@ namespace {
// First verify number of paths retrieved.
vector<string> expectedPaths = StringSplitter::split(expectedPathsStr, ",");
if (paths.size() != expectedPaths.size()) {
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "rateIndices(query=" << query << ", prefix=" << prefix
<< "): unexpected number of tagged nodes found. expected: "
<< toString(expectedPaths.begin(), expectedPaths.end()) << ". actual: "
<< toString(paths.begin(), paths.end());
- FAIL(ss.str());
+ FAIL(ss);
}
// Next, check that value and order of each element match between the two lists.
@@ -219,12 +217,12 @@ namespace {
if (*i == *j) {
continue;
}
- stringstream ss;
+ mongoutils::str::stream ss;
ss << "rateIndices(query=" << query << ", prefix=" << prefix
<< "): unexpected path found. expected: " << *j << " "
<< toString(expectedPaths.begin(), expectedPaths.end()) << ". actual: "
<< *i << " " << toString(paths.begin(), paths.end());
- FAIL(ss.str());
+ FAIL(ss);
}
}
diff --git a/src/mongo/db/query/query_planner.cpp b/src/mongo/db/query/query_planner.cpp
index 10d333c11a6..bd8956cbf26 100644
--- a/src/mongo/db/query/query_planner.cpp
+++ b/src/mongo/db/query/query_planner.cpp
@@ -70,7 +70,7 @@ namespace mongo {
}
string optionString(size_t options) {
- stringstream ss;
+ mongoutils::str::stream ss;
// These options are all currently mutually exclusive.
if (QueryPlannerParams::DEFAULT == options) {
@@ -88,7 +88,7 @@ namespace mongo {
if (options & QueryPlannerParams::NO_BLOCKING_SORT) {
ss << "NO_BLOCKING_SORT";
}
- return ss.str();
+ return ss;
}
static BSONObj getKeyFromQuery(const BSONObj& keyPattern, const BSONObj& query) {
@@ -176,11 +176,11 @@ namespace mongo {
if (NULL != taggedTree->getTag()) {
IndexTag* itag = static_cast<IndexTag*>(taggedTree->getTag());
if (itag->index >= relevantIndices.size()) {
- std::stringstream ss;
+ mongoutils::str::stream ss;
ss << "Index number is " << itag->index
<< " but there are only " << relevantIndices.size()
<< " relevant indices.";
- return Status(ErrorCodes::BadValue, ss.str());
+ return Status(ErrorCodes::BadValue, ss);
}
// Make sure not to cache solutions which use '2d' indices.
@@ -228,11 +228,11 @@ namespace mongo {
verify(NULL == filter->getTag());
if (filter->numChildren() != indexTree->children.size()) {
- std::stringstream ss;
+ mongoutils::str::stream ss;
ss << "Cache topology and query did not match: "
<< "query has " << filter->numChildren() << " children "
<< "and cache has " << indexTree->children.size() << " children.";
- return Status(ErrorCodes::BadValue, ss.str());
+ return Status(ErrorCodes::BadValue, ss);
}
// Continue the depth-first tree traversal.
@@ -246,9 +246,9 @@ namespace mongo {
if (NULL != indexTree->entry.get()) {
map<BSONObj, size_t>::const_iterator got = indexMap.find(indexTree->entry->keyPattern);
if (got == indexMap.end()) {
- std::stringstream ss;
+ mongoutils::str::stream ss;
ss << "Did not find index with keyPattern: " << indexTree->entry->keyPattern.toString();
- return Status(ErrorCodes::BadValue, ss.str());
+ return Status(ErrorCodes::BadValue, ss);
}
filter->setTag(new IndexTag(got->second, indexTree->index_pos));
}
diff --git a/src/mongo/db/query/query_planner_test.cpp b/src/mongo/db/query/query_planner_test.cpp
index 7b9642011e5..32084f95db5 100644
--- a/src/mongo/db/query/query_planner_test.cpp
+++ b/src/mongo/db/query/query_planner_test.cpp
@@ -33,7 +33,6 @@
#include "mongo/db/query/query_planner_test_lib.h"
#include <ostream>
-#include <sstream>
#include "mongo/db/jsobj.h"
#include "mongo/db/json.h"
#include "mongo/db/matcher/expression_parser.h"
@@ -203,18 +202,14 @@ namespace {
return solns.size();
}
- void dumpSolutions(ostream& ost) const {
+ void dumpSolutions(mongoutils::str::stream& ost) const {
for (vector<QuerySolution*>::const_iterator it = solns.begin();
it != solns.end();
++it) {
- ost << (*it)->toString() << endl;
+ ost << (*it)->toString() << '\n';
}
}
- void dumpSolutions() const {
- dumpSolutions(std::cout);
- }
-
/**
* Checks number solutions. Generates assertion message
* containing solution dump if applicable.
@@ -223,11 +218,11 @@ namespace {
if (getNumSolutions() == expectSolutions) {
return;
}
- std::stringstream ss;
+ mongoutils::str::stream ss;
ss << "expected " << expectSolutions << " solutions but got " << getNumSolutions()
- << " instead. solutions generated: " << std::endl;
+ << " instead. solutions generated: " << '\n';
dumpSolutions(ss);
- FAIL(ss.str());
+ FAIL(ss);
}
size_t numSolutionMatches(const string& solnJson) const {
@@ -256,12 +251,12 @@ namespace {
if (numMatches == matches) {
return;
}
- std::stringstream ss;
+ mongoutils::str::stream ss;
ss << "expected " << numMatches << " matches for solution " << solnJson
<< " but got " << matches
- << " instead. all solutions generated: " << std::endl;
+ << " instead. all solutions generated: " << '\n';
dumpSolutions(ss);
- FAIL(ss.str());
+ FAIL(ss);
}
/**
@@ -280,12 +275,12 @@ namespace {
if (1U == matches) {
return;
}
- std::stringstream ss;
+ mongoutils::str::stream ss;
ss << "assertHasOneSolutionOf expected one matching solution"
<< " but got " << matches
- << " instead. all solutions generated: " << std::endl;
+ << " instead. all solutions generated: " << '\n';
dumpSolutions(ss);
- FAIL(ss.str());
+ FAIL(ss);
}
BSONObj queryObj;
diff --git a/src/mongo/db/query/query_planner_test_lib.cpp b/src/mongo/db/query/query_planner_test_lib.cpp
index 6a04677e8df..c653a458c1a 100644
--- a/src/mongo/db/query/query_planner_test_lib.cpp
+++ b/src/mongo/db/query/query_planner_test_lib.cpp
@@ -33,7 +33,6 @@
#include "mongo/db/query/query_planner_test_lib.h"
#include <ostream>
-#include <sstream>
#include "mongo/db/jsobj.h"
#include "mongo/db/json.h"
#include "mongo/db/matcher/expression_parser.h"
diff --git a/src/mongo/db/query/query_planner_test_lib.h b/src/mongo/db/query/query_planner_test_lib.h
index 014c897bd11..1a8b6372d57 100644
--- a/src/mongo/db/query/query_planner_test_lib.h
+++ b/src/mongo/db/query/query_planner_test_lib.h
@@ -31,7 +31,6 @@
*/
#include <ostream>
-#include <sstream>
#include "mongo/db/jsobj.h"
#include "mongo/db/json.h"
#include "mongo/db/matcher/expression_parser.h"
diff --git a/src/mongo/db/query/query_solution.cpp b/src/mongo/db/query/query_solution.cpp
index d118f4deade..4cb0b0c0630 100644
--- a/src/mongo/db/query/query_solution.cpp
+++ b/src/mongo/db/query/query_solution.cpp
@@ -32,44 +32,44 @@
namespace mongo {
string QuerySolutionNode::toString() const {
- stringstream ss;
+ mongoutils::str::stream ss;
appendToString(&ss, 0);
- return ss.str();
+ return ss;
}
// static
- void QuerySolutionNode::addIndent(stringstream* ss, int level) {
+ void QuerySolutionNode::addIndent(mongoutils::str::stream* ss, int level) {
for (int i = 0; i < level; ++i) {
*ss << "---";
}
}
- void QuerySolutionNode::addCommon(stringstream* ss, int indent) const {
+ void QuerySolutionNode::addCommon(mongoutils::str::stream* ss, int indent) const {
addIndent(ss, indent + 1);
- *ss << "fetched = " << fetched() << endl;
+ *ss << "fetched = " << fetched() << '\n';
addIndent(ss, indent + 1);
- *ss << "sortedByDiskLoc = " << sortedByDiskLoc() << endl;
+ *ss << "sortedByDiskLoc = " << sortedByDiskLoc() << '\n';
addIndent(ss, indent + 1);
*ss << "getSort = [";
for (BSONObjSet::const_iterator it = getSort().begin(); it != getSort().end(); it++) {
*ss << it->toString() << ", ";
}
- *ss << "]" << endl;
+ *ss << "]" << '\n';
}
//
// TextNode
//
- void TextNode::appendToString(stringstream* ss, int indent) const {
+ void TextNode::appendToString(mongoutils::str::stream* ss, int indent) const {
addIndent(ss, indent);
*ss << "TEXT\n";
addIndent(ss, indent + 1);
- *ss << "keyPattern = " << _indexKeyPattern.toString() << endl;
+ *ss << "keyPattern = " << _indexKeyPattern.toString() << '\n';
addIndent(ss, indent + 1);
- *ss << "query = " << _query << endl;
+ *ss << "query = " << _query << '\n';
addIndent(ss, indent + 1);
- *ss << "language = " << _language << endl;
+ *ss << "language = " << _language << '\n';
addCommon(ss, indent);
}
@@ -79,11 +79,11 @@ namespace mongo {
CollectionScanNode::CollectionScanNode() : tailable(false), direction(1), maxScan(0) { }
- void CollectionScanNode::appendToString(stringstream* ss, int indent) const {
+ void CollectionScanNode::appendToString(mongoutils::str::stream* ss, int indent) const {
addIndent(ss, indent);
*ss << "COLLSCAN\n";
addIndent(ss, indent + 1);
- *ss << "ns = " << name << endl;
+ *ss << "ns = " << name << '\n';
if (NULL != filter) {
addIndent(ss, indent + 1);
*ss << " filter = " << filter->toString();
@@ -99,12 +99,12 @@ namespace mongo {
AndHashNode::~AndHashNode() { }
- void AndHashNode::appendToString(stringstream* ss, int indent) const {
+ void AndHashNode::appendToString(mongoutils::str::stream* ss, int indent) const {
addIndent(ss, indent);
*ss << "AND_HASH\n";
if (NULL != filter) {
addIndent(ss, indent + 1);
- *ss << " filter = " << filter->toString() << endl;
+ *ss << " filter = " << filter->toString() << '\n';
}
addCommon(ss, indent);
for (size_t i = 0; i < children.size(); ++i) {
@@ -144,12 +144,12 @@ namespace mongo {
AndSortedNode::~AndSortedNode() { }
- void AndSortedNode::appendToString(stringstream* ss, int indent) const {
+ void AndSortedNode::appendToString(mongoutils::str::stream* ss, int indent) const {
addIndent(ss, indent);
*ss << "AND_SORTED\n";
if (NULL != filter) {
addIndent(ss, indent + 1);
- *ss << " filter = " << filter->toString() << endl;
+ *ss << " filter = " << filter->toString() << '\n';
}
addCommon(ss, indent);
for (size_t i = 0; i < children.size(); ++i) {
@@ -189,19 +189,19 @@ namespace mongo {
OrNode::~OrNode() { }
- void OrNode::appendToString(stringstream* ss, int indent) const {
+ void OrNode::appendToString(mongoutils::str::stream* ss, int indent) const {
addIndent(ss, indent);
*ss << "OR\n";
if (NULL != filter) {
addIndent(ss, indent + 1);
- *ss << " filter = " << filter->toString() << endl;
+ *ss << " filter = " << filter->toString() << '\n';
}
addCommon(ss, indent);
for (size_t i = 0; i < children.size(); ++i) {
addIndent(ss, indent + 1);
*ss << "Child " << i << ":\n";
children[i]->appendToString(ss, indent + 2);
- *ss << endl;
+ *ss << '\n';
}
}
@@ -239,19 +239,19 @@ namespace mongo {
MergeSortNode::~MergeSortNode() { }
- void MergeSortNode::appendToString(stringstream* ss, int indent) const {
+ void MergeSortNode::appendToString(mongoutils::str::stream* ss, int indent) const {
addIndent(ss, indent);
*ss << "MERGE_SORT\n";
if (NULL != filter) {
addIndent(ss, indent + 1);
- *ss << " filter = " << filter->toString() << endl;
+ *ss << " filter = " << filter->toString() << '\n';
}
addCommon(ss, indent);
for (size_t i = 0; i < children.size(); ++i) {
addIndent(ss, indent + 1);
*ss << "Child " << i << ":\n";
children[i]->appendToString(ss, indent + 2);
- *ss << endl;
+ *ss << '\n';
}
}
@@ -287,7 +287,7 @@ namespace mongo {
FetchNode::FetchNode() { }
- void FetchNode::appendToString(stringstream* ss, int indent) const {
+ void FetchNode::appendToString(mongoutils::str::stream* ss, int indent) const {
addIndent(ss, indent);
*ss << "FETCH\n";
if (NULL != filter) {
@@ -299,7 +299,7 @@ namespace mongo {
}
addCommon(ss, indent);
addIndent(ss, indent + 1);
- *ss << "Child:" << endl;
+ *ss << "Child:" << '\n';
children[0]->appendToString(ss, indent + 2);
}
@@ -310,21 +310,21 @@ namespace mongo {
IndexScanNode::IndexScanNode()
: indexIsMultiKey(false), limit(0), direction(1), maxScan(0), addKeyMetadata(false) { }
- void IndexScanNode::appendToString(stringstream* ss, int indent) const {
+ void IndexScanNode::appendToString(mongoutils::str::stream* ss, int indent) const {
addIndent(ss, indent);
*ss << "IXSCAN\n";
addIndent(ss, indent + 1);
- *ss << "keyPattern = " << indexKeyPattern << endl;
+ *ss << "keyPattern = " << indexKeyPattern << '\n';
if (NULL != filter) {
addIndent(ss, indent + 1);
- *ss << " filter= " << filter->toString() << endl;
+ *ss << " filter= " << filter->toString() << '\n';
}
addIndent(ss, indent + 1);
- *ss << "direction = " << direction << endl;
+ *ss << "direction = " << direction << '\n';
addIndent(ss, indent + 1);
- *ss << "bounds = " << bounds.toString() << endl;
+ *ss << "bounds = " << bounds.toString() << '\n';
addIndent(ss, indent + 1);
- *ss << "fetched = " << fetched() << endl;
+ *ss << "fetched = " << fetched() << '\n';
addCommon(ss, indent);
}
@@ -463,13 +463,13 @@ namespace mongo {
// ProjectionNode
//
- void ProjectionNode::appendToString(stringstream* ss, int indent) const {
+ void ProjectionNode::appendToString(mongoutils::str::stream* ss, int indent) const {
addIndent(ss, indent);
*ss << "PROJ\n";
addIndent(ss, indent + 1);
- *ss << "proj = " << projection.toString() << endl;
+ *ss << "proj = " << projection.toString() << '\n';
addCommon(ss, indent);
- *ss << "Child:" << endl;
+ *ss << "Child:" << '\n';
children[0]->appendToString(ss, indent + 2);
}
@@ -477,17 +477,17 @@ namespace mongo {
// SortNode
//
- void SortNode::appendToString(stringstream* ss, int indent) const {
+ void SortNode::appendToString(mongoutils::str::stream* ss, int indent) const {
addIndent(ss, indent);
*ss << "SORT\n";
addIndent(ss, indent + 1);
- *ss << "pattern = " << pattern.toString() << endl;
+ *ss << "pattern = " << pattern.toString() << '\n';
addIndent(ss, indent + 1);
- *ss << "query for bounds = " << query.toString() << endl;
+ *ss << "query for bounds = " << query.toString() << '\n';
addIndent(ss, indent + 1);
- *ss << "limit = " << limit << endl;
+ *ss << "limit = " << limit << '\n';
addCommon(ss, indent);
- *ss << "Child:" << endl;
+ *ss << "Child:" << '\n';
children[0]->appendToString(ss, indent + 2);
}
@@ -496,14 +496,14 @@ namespace mongo {
//
- void LimitNode::appendToString(stringstream* ss, int indent) const {
+ void LimitNode::appendToString(mongoutils::str::stream* ss, int indent) const {
addIndent(ss, indent);
*ss << "LIMIT\n";
addIndent(ss, indent + 1);
- *ss << "limit = " << limit << endl;
+ *ss << "limit = " << limit << '\n';
addIndent(ss, indent + 1);
addCommon(ss, indent);
- *ss << "Child:" << endl;
+ *ss << "Child:" << '\n';
children[0]->appendToString(ss, indent + 2);
}
@@ -511,13 +511,13 @@ namespace mongo {
// SkipNode
//
- void SkipNode::appendToString(stringstream* ss, int indent) const {
+ void SkipNode::appendToString(mongoutils::str::stream* ss, int indent) const {
addIndent(ss, indent);
*ss << "SKIP\n";
addIndent(ss, indent + 1);
- *ss << "skip= " << skip << endl;
+ *ss << "skip= " << skip << '\n';
addCommon(ss, indent);
- *ss << "Child:" << endl;
+ *ss << "Child:" << '\n';
children[0]->appendToString(ss, indent + 2);
}
@@ -525,13 +525,13 @@ namespace mongo {
// GeoNear2DNode
//
- void GeoNear2DNode::appendToString(stringstream* ss, int indent) const {
+ void GeoNear2DNode::appendToString(mongoutils::str::stream* ss, int indent) const {
addIndent(ss, indent);
*ss << "GEO_NEAR_2D\n";
addIndent(ss, indent + 1);
- *ss << "keyPattern = " << indexKeyPattern.toString() << endl;
+ *ss << "keyPattern = " << indexKeyPattern.toString() << '\n';
addCommon(ss, indent);
- *ss << "nearQuery = " << nq.toString() << endl;
+ *ss << "nearQuery = " << nq.toString() << '\n';
if (NULL != filter) {
addIndent(ss, indent + 1);
*ss << " filter = " << filter->toString();
@@ -542,15 +542,15 @@ namespace mongo {
// GeoNear2DSphereNode
//
- void GeoNear2DSphereNode::appendToString(stringstream* ss, int indent) const {
+ void GeoNear2DSphereNode::appendToString(mongoutils::str::stream* ss, int indent) const {
addIndent(ss, indent);
*ss << "GEO_NEAR_2DSPHERE\n";
addIndent(ss, indent + 1);
- *ss << "keyPattern = " << indexKeyPattern.toString() << endl;
+ *ss << "keyPattern = " << indexKeyPattern.toString() << '\n';
addCommon(ss, indent);
- *ss << "baseBounds = " << baseBounds.toString() << endl;
+ *ss << "baseBounds = " << baseBounds.toString() << '\n';
addIndent(ss, indent + 1);
- *ss << "nearQuery = " << nq.toString() << endl;
+ *ss << "nearQuery = " << nq.toString() << '\n';
if (NULL != filter) {
addIndent(ss, indent + 1);
*ss << " filter = " << filter->toString();
@@ -561,11 +561,11 @@ namespace mongo {
// Geo2DNode
//
- void Geo2DNode::appendToString(stringstream* ss, int indent) const {
+ void Geo2DNode::appendToString(mongoutils::str::stream* ss, int indent) const {
addIndent(ss, indent);
*ss << "GEO_2D\n";
addIndent(ss, indent + 1);
- *ss << "keyPattern = " << indexKeyPattern.toString() << endl;
+ *ss << "keyPattern = " << indexKeyPattern.toString() << '\n';
addCommon(ss, indent);
}
@@ -583,7 +583,7 @@ namespace mongo {
// ShardingFilterNode
//
- void ShardingFilterNode::appendToString(stringstream* ss, int indent) const {
+ void ShardingFilterNode::appendToString(mongoutils::str::stream* ss, int indent) const {
addIndent(ss, indent);
*ss << "SHARDING_FILTER\n";
if (NULL != filter) {
@@ -595,7 +595,7 @@ namespace mongo {
}
addCommon(ss, indent);
addIndent(ss, indent + 1);
- *ss << "Child:" << endl;
+ *ss << "Child:" << '\n';
children[0]->appendToString(ss, indent + 2);
}
diff --git a/src/mongo/db/query/query_solution.h b/src/mongo/db/query/query_solution.h
index 846b5d8e990..2f66dd706c1 100644
--- a/src/mongo/db/query/query_solution.h
+++ b/src/mongo/db/query/query_solution.h
@@ -67,7 +67,7 @@ namespace mongo {
*
* TODO: Consider outputting into a BSONObj or builder thereof.
*/
- virtual void appendToString(stringstream* ss, int indent) const = 0;
+ virtual void appendToString(mongoutils::str::stream* ss, int indent) const = 0;
//
// Computed properties
@@ -136,13 +136,13 @@ namespace mongo {
/**
* Formatting helper used by toString().
*/
- static void addIndent(stringstream* ss, int level);
+ static void addIndent(mongoutils::str::stream* ss, int level);
/**
* Every solution node has properties and this adds the debug info for the
* properties.
*/
- void addCommon(stringstream* ss, int indent) const;
+ void addCommon(mongoutils::str::stream* ss, int indent) const;
private:
MONGO_DISALLOW_COPYING(QuerySolutionNode);
@@ -180,9 +180,9 @@ namespace mongo {
return "empty query solution";
}
- stringstream ss;
+ mongoutils::str::stream ss;
root->appendToString(&ss, 0);
- return ss.str();
+ return ss;
}
private:
MONGO_DISALLOW_COPYING(QuerySolution);
@@ -194,7 +194,7 @@ namespace mongo {
virtual StageType getType() const { return STAGE_TEXT; }
- virtual void appendToString(stringstream* ss, int indent) const;
+ virtual void appendToString(mongoutils::str::stream* ss, int indent) const;
// text's return is LOC_AND_UNOWNED_OBJ so it's fetched and has all fields.
bool fetched() const { return true; }
@@ -215,7 +215,7 @@ namespace mongo {
virtual StageType getType() const { return STAGE_COLLSCAN; }
- virtual void appendToString(stringstream* ss, int indent) const;
+ virtual void appendToString(mongoutils::str::stream* ss, int indent) const;
bool fetched() const { return true; }
bool hasField(const string& field) const { return true; }
@@ -242,7 +242,7 @@ namespace mongo {
virtual StageType getType() const { return STAGE_AND_HASH; }
- virtual void appendToString(stringstream* ss, int indent) const;
+ virtual void appendToString(mongoutils::str::stream* ss, int indent) const;
bool fetched() const;
bool hasField(const string& field) const;
@@ -258,7 +258,7 @@ namespace mongo {
virtual StageType getType() const { return STAGE_AND_SORTED; }
- virtual void appendToString(stringstream* ss, int indent) const;
+ virtual void appendToString(mongoutils::str::stream* ss, int indent) const;
bool fetched() const;
bool hasField(const string& field) const;
@@ -274,7 +274,7 @@ namespace mongo {
virtual StageType getType() const { return STAGE_OR; }
- virtual void appendToString(stringstream* ss, int indent) const;
+ virtual void appendToString(mongoutils::str::stream* ss, int indent) const;
bool fetched() const;
bool hasField(const string& field) const;
@@ -296,7 +296,7 @@ namespace mongo {
virtual StageType getType() const { return STAGE_SORT_MERGE; }
- virtual void appendToString(stringstream* ss, int indent) const;
+ virtual void appendToString(mongoutils::str::stream* ss, int indent) const;
bool fetched() const;
bool hasField(const string& field) const;
@@ -324,7 +324,7 @@ namespace mongo {
virtual StageType getType() const { return STAGE_FETCH; }
- virtual void appendToString(stringstream* ss, int indent) const;
+ virtual void appendToString(mongoutils::str::stream* ss, int indent) const;
bool fetched() const { return true; }
bool hasField(const string& field) const { return true; }
@@ -342,7 +342,7 @@ namespace mongo {
virtual StageType getType() const { return STAGE_IXSCAN; }
- virtual void appendToString(stringstream* ss, int indent) const;
+ virtual void appendToString(mongoutils::str::stream* ss, int indent) const;
bool fetched() const { return false; }
bool hasField(const string& field) const;
@@ -378,7 +378,7 @@ namespace mongo {
virtual StageType getType() const { return STAGE_PROJECTION; }
- virtual void appendToString(stringstream* ss, int indent) const;
+ virtual void appendToString(mongoutils::str::stream* ss, int indent) const;
/**
* This node changes the type to OWNED_OBJ. There's no fetching possible after this.
@@ -423,7 +423,7 @@ namespace mongo {
virtual StageType getType() const { return STAGE_SORT; }
- virtual void appendToString(stringstream* ss, int indent) const;
+ virtual void appendToString(mongoutils::str::stream* ss, int indent) const;
bool fetched() const { return children[0]->fetched(); }
bool hasField(const string& field) const { return children[0]->hasField(field); }
@@ -455,7 +455,7 @@ namespace mongo {
virtual StageType getType() const { return STAGE_LIMIT; }
- virtual void appendToString(stringstream* ss, int indent) const;
+ virtual void appendToString(mongoutils::str::stream* ss, int indent) const;
bool fetched() const { return children[0]->fetched(); }
bool hasField(const string& field) const { return children[0]->hasField(field); }
@@ -470,7 +470,7 @@ namespace mongo {
virtual ~SkipNode() { }
virtual StageType getType() const { return STAGE_SKIP; }
- virtual void appendToString(stringstream* ss, int indent) const;
+ virtual void appendToString(mongoutils::str::stream* ss, int indent) const;
bool fetched() const { return children[0]->fetched(); }
bool hasField(const string& field) const { return children[0]->hasField(field); }
@@ -491,7 +491,7 @@ namespace mongo {
virtual ~Geo2DNode() { }
virtual StageType getType() const { return STAGE_GEO_2D; }
- virtual void appendToString(stringstream* ss, int indent) const;
+ virtual void appendToString(mongoutils::str::stream* ss, int indent) const;
bool fetched() const { return false; }
bool hasField(const string& field) const;
@@ -509,7 +509,7 @@ namespace mongo {
virtual ~GeoNear2DNode() { }
virtual StageType getType() const { return STAGE_GEO_NEAR_2D; }
- virtual void appendToString(stringstream* ss, int indent) const;
+ virtual void appendToString(mongoutils::str::stream* ss, int indent) const;
bool fetched() const { return true; }
bool hasField(const string& field) const { return true; }
@@ -530,7 +530,7 @@ namespace mongo {
virtual ~GeoNear2DSphereNode() { }
virtual StageType getType() const { return STAGE_GEO_NEAR_2DSPHERE; }
- virtual void appendToString(stringstream* ss, int indent) const;
+ virtual void appendToString(mongoutils::str::stream* ss, int indent) const;
bool fetched() const { return true; }
bool hasField(const string& field) const { return true; }
@@ -562,7 +562,7 @@ namespace mongo {
virtual ~ShardingFilterNode() { }
virtual StageType getType() const { return STAGE_SHARDING_FILTER; }
- virtual void appendToString(stringstream* ss, int indent) const;
+ virtual void appendToString(mongoutils::str::stream* ss, int indent) const;
bool fetched() const { return children[0]->fetched(); }
bool hasField(const string& field) const { return children[0]->hasField(field); }
diff --git a/src/mongo/db/query/stage_builder.cpp b/src/mongo/db/query/stage_builder.cpp
index 11cf7f76174..9c65cb76a48 100644
--- a/src/mongo/db/query/stage_builder.cpp
+++ b/src/mongo/db/query/stage_builder.cpp
@@ -254,9 +254,10 @@ namespace mongo {
return new ShardFilterStage(shardingState.getCollectionMetadata(qsol.ns), ws, childStage);
}
else {
- stringstream ss;
+ mongoutils::str::stream ss;
root->appendToString(&ss, 0);
- warning() << "Could not build exec tree for node " << ss.str() << endl;
+ string nodeStr(ss);
+ warning() << "Could not build exec tree for node " << nodeStr << endl;
return NULL;
}
}