diff options
author | Matt Dannenberg <matt.dannenberg@10gen.com> | 2013-05-15 16:25:10 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2013-06-18 12:51:15 -0400 |
commit | c020b94a9e3154cf0b18ea8e504992f2ab3ae885 (patch) | |
tree | 48eebfe68c6d6a3c256b305018874e0d40ceb7b9 /src/mongo/db/pipeline | |
parent | 800da131d4b2877ec924f6a45dadc8574645211c (diff) | |
download | mongo-c020b94a9e3154cf0b18ea8e504992f2ab3ae885.tar.gz |
removes legacy Value "createType" functions
uses constructor instead
Diffstat (limited to 'src/mongo/db/pipeline')
-rw-r--r-- | src/mongo/db/pipeline/accumulator_add_to_set.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/pipeline/accumulator_avg.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/pipeline/accumulator_push.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/pipeline/accumulator_sum.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/pipeline/expression.cpp | 59 | ||||
-rw-r--r-- | src/mongo/db/pipeline/value.cpp | 20 | ||||
-rw-r--r-- | src/mongo/db/pipeline/value.h | 11 |
7 files changed, 44 insertions, 64 deletions
diff --git a/src/mongo/db/pipeline/accumulator_add_to_set.cpp b/src/mongo/db/pipeline/accumulator_add_to_set.cpp index d64faf48b8f..7af52df062b 100644 --- a/src/mongo/db/pipeline/accumulator_add_to_set.cpp +++ b/src/mongo/db/pipeline/accumulator_add_to_set.cpp @@ -51,8 +51,8 @@ namespace mongo { for (itr = set.begin(); itr != set.end(); ++itr) { valVec.push_back(*itr); } - /* there is no issue of scope since createArray copy constructs */ - return Value::createArray(valVec); + + return Value(valVec); } AccumulatorAddToSet::AccumulatorAddToSet( diff --git a/src/mongo/db/pipeline/accumulator_avg.cpp b/src/mongo/db/pipeline/accumulator_avg.cpp index 07787325992..a626ec93e87 100644 --- a/src/mongo/db/pipeline/accumulator_avg.cpp +++ b/src/mongo/db/pipeline/accumulator_avg.cpp @@ -63,14 +63,14 @@ namespace mongo { if (count) avg = doubleTotal / static_cast<double>(count); - return Value::createDouble(avg); + return Value(avg); } MutableDocument out; - out.addField(subTotalName, Value::createDouble(doubleTotal)); - out.addField(countName, Value::createLong(count)); + out.addField(subTotalName, Value(doubleTotal)); + out.addField(countName, Value(count)); - return Value::createDocument(out.freeze()); + return Value(out.freeze()); } AccumulatorAvg::AccumulatorAvg( diff --git a/src/mongo/db/pipeline/accumulator_push.cpp b/src/mongo/db/pipeline/accumulator_push.cpp index f5c76323602..640f627708b 100644 --- a/src/mongo/db/pipeline/accumulator_push.cpp +++ b/src/mongo/db/pipeline/accumulator_push.cpp @@ -47,7 +47,7 @@ namespace mongo { } Value AccumulatorPush::getValue() const { - return Value::createArray(vpValue); + return Value(vpValue); } AccumulatorPush::AccumulatorPush( diff --git a/src/mongo/db/pipeline/accumulator_sum.cpp b/src/mongo/db/pipeline/accumulator_sum.cpp index c737d7ee4a0..bcf8195efd4 100644 --- a/src/mongo/db/pipeline/accumulator_sum.cpp +++ b/src/mongo/db/pipeline/accumulator_sum.cpp @@ -59,10 +59,10 @@ namespace mongo { Value AccumulatorSum::getValue() const { if (totalType == NumberLong) { - return Value::createLong(longTotal); + return Value(longTotal); } else if (totalType == NumberDouble) { - return Value::createDouble(doubleTotal); + return Value(doubleTotal); } else if (totalType == NumberInt) { return Value::createIntOrLong(longTotal); diff --git a/src/mongo/db/pipeline/expression.cpp b/src/mongo/db/pipeline/expression.cpp index d4a26ce78e4..0eae60b57f0 100644 --- a/src/mongo/db/pipeline/expression.cpp +++ b/src/mongo/db/pipeline/expression.cpp @@ -373,13 +373,13 @@ namespace mongo { if (haveDate) { if (totalType == NumberDouble) longTotal = static_cast<long long>(doubleTotal); - return Value::createDate(longTotal); + return Value(Date_t(longTotal)); } else if (totalType == NumberLong) { - return Value::createLong(longTotal); + return Value(longTotal); } else if (totalType == NumberDouble) { - return Value::createDouble(doubleTotal); + return Value(doubleTotal); } else if (totalType == NumberInt) { return Value::createIntOrLong(longTotal); @@ -751,7 +751,7 @@ namespace mongo { result << val.coerceToString(); } - return Value::createString(result.str()); + return Value(result.str()); } const char *ExpressionConcat::getOpName() const { @@ -802,7 +802,7 @@ namespace mongo { } ExpressionConstant::ExpressionConstant(BSONElement *pBsonElement): - pValue(Value::createFromBsonElement(pBsonElement)) { + pValue(Value(*pBsonElement)) { } intrusive_ptr<ExpressionConstant> ExpressionConstant::create(const Value& pValue) { @@ -897,7 +897,7 @@ namespace mongo { checkArgCount(1); Value pDate(vpOperand[0]->evaluate(pDocument)); tm date = pDate.coerceToTm(); - return Value::createInt(date.tm_mday); + return Value(date.tm_mday); } const char *ExpressionDayOfMonth::getOpName() const { @@ -927,7 +927,7 @@ namespace mongo { checkArgCount(1); Value pDate(vpOperand[0]->evaluate(pDocument)); tm date = pDate.coerceToTm(); - return Value::createInt(date.tm_wday+1); // MySQL uses 1-7 tm uses 0-6 + return Value(date.tm_wday+1); // MySQL uses 1-7 tm uses 0-6 } const char *ExpressionDayOfWeek::getOpName() const { @@ -957,7 +957,7 @@ namespace mongo { checkArgCount(1); Value pDate(vpOperand[0]->evaluate(pDocument)); tm date = pDate.coerceToTm(); - return Value::createInt(date.tm_yday+1); // MySQL uses 1-366 tm uses 0-365 + return Value(date.tm_yday+1); // MySQL uses 1-366 tm uses 0-365 } const char *ExpressionDayOfYear::getOpName() const { @@ -995,7 +995,7 @@ namespace mongo { uassert(16608, "can't $divide by zero", denom != 0); - return Value::createDouble(numer / denom); + return Value(numer / denom); } else if (lhs.nullish() || rhs.nullish()) { return Value(BSONNULL); @@ -1227,7 +1227,7 @@ namespace mongo { } Value ExpressionObject::evaluate(const Document& pDocument) const { - return Value::createDocument(evaluateDocument(pDocument)); + return Value(evaluateDocument(pDocument)); } void ExpressionObject::addField(const FieldPath &fieldPath, @@ -1365,7 +1365,7 @@ namespace mongo { result.push_back(nested); } - return Value::createArray(result); + return Value(result); } Value ExpressionFieldPath::evaluatePath(size_t index, const Document& input) const { // Note this function is very hot so it is important that is is well optimized. @@ -1741,7 +1741,8 @@ namespace mongo { checkArgCount(1); Value date(vpOperand[0]->evaluate(document)); const int ms = date.coerceToDate() % 1000LL; - return Value::createInt( ms >= 0 ? ms : 1000 + ms ); + // adding 1000 since dates before 1970 would have negative ms + return Value(ms >= 0 ? ms : 1000 + ms); } const char *ExpressionMillisecond::getOpName() const { @@ -1772,7 +1773,7 @@ namespace mongo { checkArgCount(1); Value pDate(vpOperand[0]->evaluate(pDocument)); tm date = pDate.coerceToTm(); - return Value::createInt(date.tm_min); + return Value(date.tm_min); } const char *ExpressionMinute::getOpName() const { @@ -1821,19 +1822,19 @@ namespace mongo { // Integer-valued double case is handled below double left = lhs.coerceToDouble(); - return Value::createDouble(fmod(left, right)); + return Value(fmod(left, right)); } else if (leftType == NumberLong || rightType == NumberLong) { // if either is long, return long long long left = lhs.coerceToLong(); long long rightLong = rhs.coerceToLong(); - return Value::createLong(left % rightLong); + return Value(left % rightLong); } // lastly they must both be ints, return int int left = lhs.coerceToInt(); int rightInt = rhs.coerceToInt(); - return Value::createInt(left % rightInt); + return Value(left % rightInt); } else if (lhs.nullish() || rhs.nullish()) { return Value(BSONNULL); @@ -1873,7 +1874,7 @@ namespace mongo { checkArgCount(1); Value pDate(vpOperand[0]->evaluate(pDocument)); tm date = pDate.coerceToTm(); - return Value::createInt(date.tm_mon + 1); // MySQL uses 1-12 tm uses 0-11 + return Value(date.tm_mon + 1); // MySQL uses 1-12 tm uses 0-11 } const char *ExpressionMonth::getOpName() const { @@ -1925,9 +1926,9 @@ namespace mongo { } if (productType == NumberDouble) - return Value::createDouble(doubleProduct); + return Value(doubleProduct); else if (productType == NumberLong) - return Value::createLong(longProduct); + return Value(longProduct); else if (productType == NumberInt) return Value::createIntOrLong(longProduct); else @@ -1965,7 +1966,7 @@ namespace mongo { checkArgCount(1); Value pDate(vpOperand[0]->evaluate(pDocument)); tm date = pDate.coerceToTm(); - return Value::createInt(date.tm_hour); + return Value(date.tm_hour); } const char *ExpressionHour::getOpName() const { @@ -2348,7 +2349,7 @@ namespace mongo { checkArgCount(1); Value pDate(vpOperand[0]->evaluate(pDocument)); tm date = pDate.coerceToTm(); - return Value::createInt(date.tm_sec); + return Value(date.tm_sec); } const char *ExpressionSecond::getOpName() const { @@ -2441,9 +2442,9 @@ namespace mongo { if ( lower >= str.length() ) { // If lower > str.length() then string::substr() will throw out_of_range, so return an // empty string if lower is not a valid string index. - return Value::createString( "" ); + return Value(""); } - return Value::createString( str.substr(lower, length) ); + return Value(str.substr(lower, length)); } const char *ExpressionSubstr::getOpName() const { @@ -2480,12 +2481,12 @@ namespace mongo { if (diffType == NumberDouble) { double right = rhs.coerceToDouble(); double left = lhs.coerceToDouble(); - return Value::createDouble(left - right); + return Value(left - right); } else if (diffType == NumberLong) { long long right = rhs.coerceToLong(); long long left = lhs.coerceToLong(); - return Value::createLong(left - right); + return Value(left - right); } else if (diffType == NumberInt) { long long right = rhs.coerceToLong(); @@ -2546,7 +2547,7 @@ namespace mongo { Value pString(vpOperand[0]->evaluate(pDocument)); string str = pString.coerceToString(); boost::to_lower(str); - return Value::createString(str); + return Value(str); } const char *ExpressionToLower::getOpName() const { @@ -2578,7 +2579,7 @@ namespace mongo { Value pString(vpOperand[0]->evaluate(pDocument)); string str(pString.coerceToString()); boost::to_upper(str); - return Value::createString(str); + return Value(str); } const char *ExpressionToUpper::getOpName() const { @@ -2624,7 +2625,7 @@ namespace mongo { verify(int(str::toUnsigned(buf))==nextSundayWeek); } - return Value::createInt(nextSundayWeek); + return Value(nextSundayWeek); } const char *ExpressionWeek::getOpName() const { @@ -2655,7 +2656,7 @@ namespace mongo { checkArgCount(1); Value pDate(vpOperand[0]->evaluate(pDocument)); tm date = pDate.coerceToTm(); - return Value::createInt(date.tm_year + 1900); // tm_year is years since 1900 + return Value(date.tm_year + 1900); // tm_year is years since 1900 } const char *ExpressionYear::getOpName() const { diff --git a/src/mongo/db/pipeline/value.cpp b/src/mongo/db/pipeline/value.cpp index 5561cb41a59..664ffb990dc 100644 --- a/src/mongo/db/pipeline/value.cpp +++ b/src/mongo/db/pipeline/value.cpp @@ -123,10 +123,6 @@ namespace mongo { } - Value Value::createFromBsonElement(const BSONElement* pBsonElement) { - return Value(*pBsonElement); - } - Value::Value(const BSONElement& elem) : _storage(elem.type()) { switch(elem.type()) { // These are all type-only, no data @@ -212,21 +208,15 @@ namespace mongo { } } - Value Value::createIntOrLong(long long value) { - if (value > numeric_limits<int>::max() || value < numeric_limits<int>::min()) { + Value Value::createIntOrLong(long long longValue) { + int intValue = longValue; + if (intValue != longValue) { // it is too large to be an int and should remain a long - return Value(value); + return Value(longValue); } // should be an int since all arguments were int and it fits - return createInt(value); - } - - Value Value::createDate(const long long value) { - // Can't directly construct because constructor would clash with createLong - Value val (Date); - val._storage.dateValue = value; - return val; + return Value(intValue); } double Value::getDouble() const { diff --git a/src/mongo/db/pipeline/value.h b/src/mongo/db/pipeline/value.h index e1772ca8dff..26113876265 100644 --- a/src/mongo/db/pipeline/value.h +++ b/src/mongo/db/pipeline/value.h @@ -224,17 +224,6 @@ namespace mongo { /// Call this after memcpying to update ref counts if needed void memcpyed() const { _storage.memcpyed(); } - // LEGACY creation functions - static Value createFromBsonElement(const BSONElement* pBsonElement); - static Value createInt(int value) { return Value(value); } - static Value createLong(long long value) { return Value(value); } - static Value createDouble(double value) { return Value(value); } - static Value createTimestamp(const OpTime& value) { return Value(value); } - static Value createString(const string& value) { return Value(value); } - static Value createDocument(const Document& doc) { return Value(doc); } - static Value createArray(const vector<Value>& vec) { return Value(vec); } - static Value createDate(const long long value); - private: /** This is a "honeypot" to prevent unexpected implicit conversions to the accepted argument * types. bool is especially bad since without this it will accept any pointer. |