summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/base/status-inl.h100
-rw-r--r--src/mongo/base/status.h68
-rw-r--r--src/mongo/bson/mutable/const_element.h214
-rw-r--r--src/mongo/bson/mutable/document-inl.h85
-rw-r--r--src/mongo/bson/mutable/document.h51
-rw-r--r--src/mongo/bson/mutable/element-inl.h161
-rw-r--r--src/mongo/bson/mutable/element.h127
-rw-r--r--src/mongo/db/exec/and_common.h (renamed from src/mongo/db/exec/and_common-inl.h)2
-rw-r--r--src/mongo/db/exec/and_hash.cpp2
-rw-r--r--src/mongo/db/exec/and_sorted.cpp2
-rw-r--r--src/mongo/db/field_parser-inl.h364
-rw-r--r--src/mongo/db/field_parser.h312
-rw-r--r--src/mongo/logger/log_severity-inl.h90
-rw-r--r--src/mongo/logger/log_severity.h56
-rw-r--r--src/mongo/util/descriptive_stats-inl.h199
-rw-r--r--src/mongo/util/safe_num-inl.h130
-rw-r--r--src/mongo/util/safe_num.h98
17 files changed, 915 insertions, 1146 deletions
diff --git a/src/mongo/base/status-inl.h b/src/mongo/base/status-inl.h
deleted file mode 100644
index 742cc4714b5..00000000000
--- a/src/mongo/base/status-inl.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-namespace mongo {
-
-inline Status Status::OK() {
- return Status();
-}
-
-inline Status::Status(const Status& other) : _error(other._error) {
- ref(_error);
-}
-
-inline Status& Status::operator=(const Status& other) {
- ref(other._error);
- unref(_error);
- _error = other._error;
- return *this;
-}
-
-inline Status::Status(Status&& other) noexcept : _error(other._error) {
- other._error = nullptr;
-}
-
-inline Status& Status::operator=(Status&& other) noexcept {
- unref(_error);
- _error = other._error;
- other._error = nullptr;
- return *this;
-}
-
-inline Status::~Status() {
- unref(_error);
-}
-
-inline bool Status::isOK() const {
- return !_error;
-}
-
-inline ErrorCodes::Error Status::code() const {
- return _error ? _error->code : ErrorCodes::OK;
-}
-
-inline std::string Status::codeString() const {
- return ErrorCodes::errorString(code());
-}
-
-inline unsigned Status::refCount() const {
- return _error ? _error->refs.load() : 0;
-}
-
-inline Status::Status() : _error(NULL) {}
-
-inline void Status::ref(ErrorInfo* error) {
- if (error)
- error->refs.fetchAndAdd(1);
-}
-
-inline void Status::unref(ErrorInfo* error) {
- if (error && (error->refs.subtractAndFetch(1) == 0))
- delete error;
-}
-
-inline bool operator==(const ErrorCodes::Error lhs, const Status& rhs) {
- return rhs == lhs;
-}
-
-inline bool operator!=(const ErrorCodes::Error lhs, const Status& rhs) {
- return rhs != lhs;
-}
-
-} // namespace mongo
diff --git a/src/mongo/base/status.h b/src/mongo/base/status.h
index 61a155e98cf..52a46d0adb0 100644
--- a/src/mongo/base/status.h
+++ b/src/mongo/base/status.h
@@ -266,6 +266,70 @@ std::ostream& operator<<(std::ostream& os, const Status& status);
template <typename Allocator>
StringBuilderImpl<Allocator>& operator<<(StringBuilderImpl<Allocator>& os, const Status& status);
-} // namespace mongo
+inline Status Status::OK() {
+ return Status();
+}
+
+inline Status::Status(const Status& other) : _error(other._error) {
+ ref(_error);
+}
+
+inline Status& Status::operator=(const Status& other) {
+ ref(other._error);
+ unref(_error);
+ _error = other._error;
+ return *this;
+}
+
+inline Status::Status(Status&& other) noexcept : _error(other._error) {
+ other._error = nullptr;
+}
+
+inline Status& Status::operator=(Status&& other) noexcept {
+ unref(_error);
+ _error = other._error;
+ other._error = nullptr;
+ return *this;
+}
+
+inline Status::~Status() {
+ unref(_error);
+}
+
+inline bool Status::isOK() const {
+ return !_error;
+}
+
+inline ErrorCodes::Error Status::code() const {
+ return _error ? _error->code : ErrorCodes::OK;
+}
+
+inline std::string Status::codeString() const {
+ return ErrorCodes::errorString(code());
+}
+
+inline unsigned Status::refCount() const {
+ return _error ? _error->refs.load() : 0;
+}
+
+inline Status::Status() : _error(NULL) {}
+
+inline void Status::ref(ErrorInfo* error) {
+ if (error)
+ error->refs.fetchAndAdd(1);
+}
+
+inline void Status::unref(ErrorInfo* error) {
+ if (error && (error->refs.subtractAndFetch(1) == 0))
+ delete error;
+}
+
+inline bool operator==(const ErrorCodes::Error lhs, const Status& rhs) {
+ return rhs == lhs;
+}
+
+inline bool operator!=(const ErrorCodes::Error lhs, const Status& rhs) {
+ return rhs != lhs;
+}
-#include "mongo/base/status-inl.h"
+} // namespace mongo
diff --git a/src/mongo/bson/mutable/const_element.h b/src/mongo/bson/mutable/const_element.h
index 2035113866b..4b8d483095e 100644
--- a/src/mongo/bson/mutable/const_element.h
+++ b/src/mongo/bson/mutable/const_element.h
@@ -135,7 +135,217 @@ inline bool operator!=(const Element& l, const ConstElement& r);
inline bool operator==(const ConstElement& l, const Element& r);
inline bool operator!=(const ConstElement& l, const Element& r);
+inline ConstElement::ConstElement(const Element& basis) : _basis(basis) {}
+
+inline ConstElement ConstElement::leftChild() const {
+ return _basis.leftChild();
+}
+
+inline ConstElement ConstElement::rightChild() const {
+ return _basis.rightChild();
+}
+
+inline bool ConstElement::hasChildren() const {
+ return _basis.hasChildren();
+}
+
+inline ConstElement ConstElement::leftSibling(size_t distance) const {
+ return _basis.leftSibling(distance);
+}
+
+inline ConstElement ConstElement::rightSibling(size_t distance) const {
+ return _basis.rightSibling(distance);
+}
+
+inline ConstElement ConstElement::parent() const {
+ return _basis.parent();
+}
+
+inline ConstElement ConstElement::findNthChild(size_t n) const {
+ return _basis.findNthChild(n);
+}
+
+inline ConstElement ConstElement::operator[](size_t n) const {
+ return _basis[n];
+}
+
+inline ConstElement ConstElement::findFirstChildNamed(StringData name) const {
+ return _basis.findFirstChildNamed(name);
+}
+
+inline ConstElement ConstElement::operator[](StringData name) const {
+ return _basis[name];
+}
+
+inline ConstElement ConstElement::findElementNamed(StringData name) const {
+ return _basis.findElementNamed(name);
+}
+
+inline size_t ConstElement::countSiblingsLeft() const {
+ return _basis.countSiblingsLeft();
+}
+
+inline size_t ConstElement::countSiblingsRight() const {
+ return _basis.countSiblingsRight();
+}
+
+inline size_t ConstElement::countChildren() const {
+ return _basis.countChildren();
+}
+
+inline bool ConstElement::hasValue() const {
+ return _basis.hasValue();
+}
+
+inline const BSONElement ConstElement::getValue() const {
+ return _basis.getValue();
+}
+
+inline double ConstElement::getValueDouble() const {
+ return _basis.getValueDouble();
+}
+
+inline StringData ConstElement::getValueString() const {
+ return _basis.getValueString();
+}
+
+inline BSONObj ConstElement::getValueObject() const {
+ return _basis.getValueObject();
+}
+
+inline BSONArray ConstElement::getValueArray() const {
+ return _basis.getValueArray();
+}
+
+inline bool ConstElement::isValueUndefined() const {
+ return _basis.isValueUndefined();
+}
+
+inline OID ConstElement::getValueOID() const {
+ return _basis.getValueOID();
+}
+
+inline bool ConstElement::getValueBool() const {
+ return _basis.getValueBool();
+}
+
+inline Date_t ConstElement::getValueDate() const {
+ return _basis.getValueDate();
+}
+
+inline bool ConstElement::isValueNull() const {
+ return _basis.isValueNull();
+}
+
+inline StringData ConstElement::getValueSymbol() const {
+ return _basis.getValueSymbol();
+}
+
+inline int32_t ConstElement::getValueInt() const {
+ return _basis.getValueInt();
+}
+
+inline Timestamp ConstElement::getValueTimestamp() const {
+ return _basis.getValueTimestamp();
+}
+
+inline int64_t ConstElement::getValueLong() const {
+ return _basis.getValueLong();
+}
+
+inline Decimal128 ConstElement::getValueDecimal() const {
+ return _basis.getValueDecimal();
+}
+
+inline bool ConstElement::isValueMinKey() const {
+ return _basis.isValueMinKey();
+}
+
+inline bool ConstElement::isValueMaxKey() const {
+ return _basis.isValueMaxKey();
+}
+
+inline SafeNum ConstElement::getValueSafeNum() const {
+ return _basis.getValueSafeNum();
+}
+
+inline int ConstElement::compareWithElement(const ConstElement& other,
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName) const {
+ return _basis.compareWithElement(other, comparator, considerFieldName);
+}
+
+inline int ConstElement::compareWithBSONElement(const BSONElement& other,
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName) const {
+ return _basis.compareWithBSONElement(other, comparator, considerFieldName);
+}
+
+inline int ConstElement::compareWithBSONObj(const BSONObj& other,
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName) const {
+ return _basis.compareWithBSONObj(other, comparator, considerFieldName);
+}
+
+inline void ConstElement::writeTo(BSONObjBuilder* builder) const {
+ return _basis.writeTo(builder);
+}
+
+inline void ConstElement::writeArrayTo(BSONArrayBuilder* builder) const {
+ return _basis.writeArrayTo(builder);
+}
+
+inline bool ConstElement::ok() const {
+ return _basis.ok();
+}
+
+inline const Document& ConstElement::getDocument() const {
+ return _basis.getDocument();
+}
+
+inline BSONType ConstElement::getType() const {
+ return _basis.getType();
+}
+
+inline bool ConstElement::isType(BSONType type) const {
+ return _basis.isType(type);
+}
+
+inline StringData ConstElement::getFieldName() const {
+ return _basis.getFieldName();
+}
+
+inline Element::RepIdx ConstElement::getIdx() const {
+ return _basis.getIdx();
+}
+
+inline std::string ConstElement::toString() const {
+ return _basis.toString();
+}
+
+inline bool operator==(const ConstElement& l, const ConstElement& r) {
+ return l._basis == r._basis;
+}
+
+inline bool operator!=(const ConstElement& l, const ConstElement& r) {
+ return !(l == r);
+}
+
+inline bool operator==(const Element& l, const ConstElement& r) {
+ return ConstElement(l) == r;
+}
+
+inline bool operator!=(const Element& l, const ConstElement& r) {
+ return !(l == r);
+}
+
+inline bool operator==(const ConstElement& l, const Element& r) {
+ return l == ConstElement(r);
+}
+
+inline bool operator!=(const ConstElement& l, const Element& r) {
+ return !(l == r);
+}
+
} // namespace mutablebson
} // namespace mongo
-
-#include "mongo/bson/mutable/const_element-inl.h"
diff --git a/src/mongo/bson/mutable/document-inl.h b/src/mongo/bson/mutable/document-inl.h
deleted file mode 100644
index 1ab491b5362..00000000000
--- a/src/mongo/bson/mutable/document-inl.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-namespace mongo {
-namespace mutablebson {
-
-inline int Document::compareWith(const Document& other,
- const StringData::ComparatorInterface* comparator,
- bool considerFieldName) const {
- // We cheat and use Element::compareWithElement since we know that 'other' is a
- // Document and has a 'hidden' fieldname that is always indentical across all Document
- // instances.
- return root().compareWithElement(other.root(), comparator, considerFieldName);
-}
-
-inline int Document::compareWithBSONObj(const BSONObj& other,
- const StringData::ComparatorInterface* comparator,
- bool considerFieldName) const {
- return root().compareWithBSONObj(other, comparator, considerFieldName);
-}
-
-inline void Document::writeTo(BSONObjBuilder* builder) const {
- return root().writeTo(builder);
-}
-
-inline BSONObj Document::getObject() const {
- BSONObjBuilder builder;
- writeTo(&builder);
- return builder.obj();
-}
-
-inline Element Document::root() {
- return _root;
-}
-
-inline ConstElement Document::root() const {
- return _root;
-}
-
-inline Element Document::end() {
- return Element(this, Element::kInvalidRepIdx);
-}
-
-inline ConstElement Document::end() const {
- return const_cast<Document*>(this)->end();
-}
-
-inline std::string Document::toString() const {
- return getObject().toString();
-}
-
-inline bool Document::isInPlaceModeEnabled() const {
- return getCurrentInPlaceMode() == kInPlaceEnabled;
-}
-
-} // namespace mutablebson
-} // namespace mongo
diff --git a/src/mongo/bson/mutable/document.h b/src/mongo/bson/mutable/document.h
index 0098a6f06d9..0feb056cc35 100644
--- a/src/mongo/bson/mutable/document.h
+++ b/src/mongo/bson/mutable/document.h
@@ -518,7 +518,54 @@ private:
const Element _root;
};
+inline int Document::compareWith(const Document& other,
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName) const {
+ // We cheat and use Element::compareWithElement since we know that 'other' is a
+ // Document and has a 'hidden' fieldname that is always indentical across all Document
+ // instances.
+ return root().compareWithElement(other.root(), comparator, considerFieldName);
+}
+
+inline int Document::compareWithBSONObj(const BSONObj& other,
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName) const {
+ return root().compareWithBSONObj(other, comparator, considerFieldName);
+}
+
+inline void Document::writeTo(BSONObjBuilder* builder) const {
+ return root().writeTo(builder);
+}
+
+inline BSONObj Document::getObject() const {
+ BSONObjBuilder builder;
+ writeTo(&builder);
+ return builder.obj();
+}
+
+inline Element Document::root() {
+ return _root;
+}
+
+inline ConstElement Document::root() const {
+ return _root;
+}
+
+inline Element Document::end() {
+ return Element(this, Element::kInvalidRepIdx);
+}
+
+inline ConstElement Document::end() const {
+ return const_cast<Document*>(this)->end();
+}
+
+inline std::string Document::toString() const {
+ return getObject().toString();
+}
+
+inline bool Document::isInPlaceModeEnabled() const {
+ return getCurrentInPlaceMode() == kInPlaceEnabled;
+}
+
} // namespace mutablebson
} // namespace mongo
-
-#include "mongo/bson/mutable/document-inl.h"
diff --git a/src/mongo/bson/mutable/element-inl.h b/src/mongo/bson/mutable/element-inl.h
deleted file mode 100644
index 6f413399dd7..00000000000
--- a/src/mongo/bson/mutable/element-inl.h
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-namespace mongo {
-namespace mutablebson {
-
-inline Element Element::operator[](size_t n) const {
- return findNthChild(n);
-}
-
-inline Element Element::operator[](StringData name) const {
- return findFirstChildNamed(name);
-}
-
-inline double Element::getValueDouble() const {
- dassert(hasValue() && isType(mongo::NumberDouble));
- return getValue()._numberDouble();
-}
-
-inline StringData Element::getValueString() const {
- dassert(hasValue() && isType(mongo::String));
- return getValueStringOrSymbol();
-}
-
-inline BSONObj Element::getValueObject() const {
- dassert(hasValue() && isType(mongo::Object));
- return getValue().Obj();
-}
-
-inline BSONArray Element::getValueArray() const {
- dassert(hasValue() && isType(mongo::Array));
- return BSONArray(getValue().Obj());
-}
-
-inline bool Element::isValueUndefined() const {
- return isType(mongo::Undefined);
-}
-
-inline OID Element::getValueOID() const {
- dassert(hasValue() && isType(mongo::jstOID));
- return getValue().__oid();
-}
-
-inline bool Element::getValueBool() const {
- dassert(hasValue() && isType(mongo::Bool));
- return getValue().boolean();
-}
-
-inline Date_t Element::getValueDate() const {
- dassert(hasValue() && isType(mongo::Date));
- return getValue().date();
-}
-
-inline bool Element::isValueNull() const {
- return isType(mongo::jstNULL);
-}
-
-inline StringData Element::getValueSymbol() const {
- dassert(hasValue() && isType(mongo::Symbol));
- return getValueStringOrSymbol();
-}
-
-inline int32_t Element::getValueInt() const {
- dassert(hasValue() && isType(mongo::NumberInt));
- return getValue()._numberInt();
-}
-
-inline Timestamp Element::getValueTimestamp() const {
- dassert(hasValue() && isType(mongo::bsonTimestamp));
- return getValue().timestamp();
-}
-
-inline int64_t Element::getValueLong() const {
- dassert(hasValue() && isType(mongo::NumberLong));
- return getValue()._numberLong();
-}
-
-inline Decimal128 Element::getValueDecimal() const {
- dassert(hasValue() && isType(mongo::NumberDecimal));
- return getValue()._numberDecimal();
-}
-
-inline bool Element::isValueMinKey() const {
- return isType(mongo::MinKey);
-}
-
-inline bool Element::isValueMaxKey() const {
- return isType(mongo::MaxKey);
-}
-
-inline bool Element::ok() const {
- dassert(_doc != NULL);
- return _repIdx <= kMaxRepIdx;
-}
-
-inline Document& Element::getDocument() {
- return *_doc;
-}
-
-inline const Document& Element::getDocument() const {
- return *_doc;
-}
-
-inline bool Element::isType(BSONType type) const {
- return (getType() == type);
-}
-
-inline Element::RepIdx Element::getIdx() const {
- return _repIdx;
-}
-
-inline Element::Element(Document* doc, RepIdx repIdx) : _doc(doc), _repIdx(repIdx) {
- dassert(_doc != NULL);
-}
-
-inline StringData Element::getValueStringOrSymbol() const {
- const BSONElement value = getValue();
- const char* str = value.valuestr();
- const size_t size = value.valuestrsize() - 1;
- return StringData(str, size);
-}
-
-inline bool operator==(const Element& l, const Element& r) {
- return (l._doc == r._doc) && (l._repIdx == r._repIdx);
-}
-
-inline bool operator!=(const Element& l, const Element& r) {
- return !(l == r);
-}
-
-
-} // namespace mutablebson
-} // namespace mongo
diff --git a/src/mongo/bson/mutable/element.h b/src/mongo/bson/mutable/element.h
index 207dd1ae111..85756d1fea9 100644
--- a/src/mongo/bson/mutable/element.h
+++ b/src/mongo/bson/mutable/element.h
@@ -639,7 +639,130 @@ inline bool operator==(const Element& l, const Element& r);
/** Returns false if l and r refer to the same data, true otherwise. */
inline bool operator!=(const Element& l, const Element& r);
+inline Element Element::operator[](size_t n) const {
+ return findNthChild(n);
+}
+
+inline Element Element::operator[](StringData name) const {
+ return findFirstChildNamed(name);
+}
+
+inline double Element::getValueDouble() const {
+ dassert(hasValue() && isType(mongo::NumberDouble));
+ return getValue()._numberDouble();
+}
+
+inline StringData Element::getValueString() const {
+ dassert(hasValue() && isType(mongo::String));
+ return getValueStringOrSymbol();
+}
+
+inline BSONObj Element::getValueObject() const {
+ dassert(hasValue() && isType(mongo::Object));
+ return getValue().Obj();
+}
+
+inline BSONArray Element::getValueArray() const {
+ dassert(hasValue() && isType(mongo::Array));
+ return BSONArray(getValue().Obj());
+}
+
+inline bool Element::isValueUndefined() const {
+ return isType(mongo::Undefined);
+}
+
+inline OID Element::getValueOID() const {
+ dassert(hasValue() && isType(mongo::jstOID));
+ return getValue().__oid();
+}
+
+inline bool Element::getValueBool() const {
+ dassert(hasValue() && isType(mongo::Bool));
+ return getValue().boolean();
+}
+
+inline Date_t Element::getValueDate() const {
+ dassert(hasValue() && isType(mongo::Date));
+ return getValue().date();
+}
+
+inline bool Element::isValueNull() const {
+ return isType(mongo::jstNULL);
+}
+
+inline StringData Element::getValueSymbol() const {
+ dassert(hasValue() && isType(mongo::Symbol));
+ return getValueStringOrSymbol();
+}
+
+inline int32_t Element::getValueInt() const {
+ dassert(hasValue() && isType(mongo::NumberInt));
+ return getValue()._numberInt();
+}
+
+inline Timestamp Element::getValueTimestamp() const {
+ dassert(hasValue() && isType(mongo::bsonTimestamp));
+ return getValue().timestamp();
+}
+
+inline int64_t Element::getValueLong() const {
+ dassert(hasValue() && isType(mongo::NumberLong));
+ return getValue()._numberLong();
+}
+
+inline Decimal128 Element::getValueDecimal() const {
+ dassert(hasValue() && isType(mongo::NumberDecimal));
+ return getValue()._numberDecimal();
+}
+
+inline bool Element::isValueMinKey() const {
+ return isType(mongo::MinKey);
+}
+
+inline bool Element::isValueMaxKey() const {
+ return isType(mongo::MaxKey);
+}
+
+inline bool Element::ok() const {
+ dassert(_doc != NULL);
+ return _repIdx <= kMaxRepIdx;
+}
+
+inline Document& Element::getDocument() {
+ return *_doc;
+}
+
+inline const Document& Element::getDocument() const {
+ return *_doc;
+}
+
+inline bool Element::isType(BSONType type) const {
+ return (getType() == type);
+}
+
+inline Element::RepIdx Element::getIdx() const {
+ return _repIdx;
+}
+
+inline Element::Element(Document* doc, RepIdx repIdx) : _doc(doc), _repIdx(repIdx) {
+ dassert(_doc != NULL);
+}
+
+inline StringData Element::getValueStringOrSymbol() const {
+ const BSONElement value = getValue();
+ const char* str = value.valuestr();
+ const size_t size = value.valuestrsize() - 1;
+ return StringData(str, size);
+}
+
+inline bool operator==(const Element& l, const Element& r) {
+ return (l._doc == r._doc) && (l._repIdx == r._repIdx);
+}
+
+inline bool operator!=(const Element& l, const Element& r) {
+ return !(l == r);
+}
+
+
} // namespace mutablebson
} // namespace mongo
-
-#include "mongo/bson/mutable/element-inl.h"
diff --git a/src/mongo/db/exec/and_common-inl.h b/src/mongo/db/exec/and_common.h
index e44918f480b..beb84e5751f 100644
--- a/src/mongo/db/exec/and_common-inl.h
+++ b/src/mongo/db/exec/and_common.h
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#pragma once
+
#include "mongo/bson/simple_bsonobj_comparator.h"
#include "mongo/db/exec/working_set.h"
diff --git a/src/mongo/db/exec/and_hash.cpp b/src/mongo/db/exec/and_hash.cpp
index 76427fe126f..dc8197afc8e 100644
--- a/src/mongo/db/exec/and_hash.cpp
+++ b/src/mongo/db/exec/and_hash.cpp
@@ -29,7 +29,7 @@
#include "mongo/db/exec/and_hash.h"
-#include "mongo/db/exec/and_common-inl.h"
+#include "mongo/db/exec/and_common.h"
#include "mongo/db/exec/scoped_timer.h"
#include "mongo/db/exec/working_set.h"
#include "mongo/db/exec/working_set_common.h"
diff --git a/src/mongo/db/exec/and_sorted.cpp b/src/mongo/db/exec/and_sorted.cpp
index 31c7426f8d9..cdb095ba08d 100644
--- a/src/mongo/db/exec/and_sorted.cpp
+++ b/src/mongo/db/exec/and_sorted.cpp
@@ -29,7 +29,7 @@
#include "mongo/db/exec/and_sorted.h"
-#include "mongo/db/exec/and_common-inl.h"
+#include "mongo/db/exec/and_common.h"
#include "mongo/db/exec/scoped_timer.h"
#include "mongo/db/exec/working_set_common.h"
#include "mongo/stdx/memory.h"
diff --git a/src/mongo/db/field_parser-inl.h b/src/mongo/db/field_parser-inl.h
deleted file mode 100644
index 3ad18fad184..00000000000
--- a/src/mongo/db/field_parser-inl.h
+++ /dev/null
@@ -1,364 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#include "mongo/db/field_parser.h"
-#include "mongo/util/str.h"
-
-namespace mongo {
-namespace {
-
-template <class T>
-void _genFieldErrMsg(const BSONElement& elem,
- const BSONField<T>& field,
- const std::string expected,
- std::string* errMsg) {
- if (!errMsg)
- return;
- *errMsg = str::stream() << "wrong type for '" << field() << "' field, expected " << expected
- << ", found " << elem.toString();
-}
-
-template <typename T>
-void _clearOwnedVector(std::vector<T*>* vec) {
- for (typename std::vector<T*>::iterator it = vec->begin(); it != vec->end(); ++it) {
- delete (*it);
- }
-}
-
-} // namespace
-
-template <typename T>
-FieldParser::FieldState FieldParser::extract(BSONObj doc,
- const BSONField<T>& field,
- T* out,
- std::string* errMsg) {
- BSONElement elem = doc[field.name()];
- if (elem.eoo()) {
- if (field.hasDefault()) {
- field.getDefault().cloneTo(out);
- return FIELD_DEFAULT;
- } else {
- return FIELD_NONE;
- }
- }
-
- if (elem.type() != Object && elem.type() != Array) {
- _genFieldErrMsg(elem, field, "Object/Array", errMsg);
- return FIELD_INVALID;
- }
-
- if (!out->parseBSON(elem.embeddedObject(), errMsg)) {
- return FIELD_INVALID;
- }
-
- return FIELD_SET;
-}
-
-template <typename T>
-FieldParser::FieldState FieldParser::extract(BSONObj doc,
- const BSONField<T*>& field,
- T** out,
- std::string* errMsg) {
- BSONElement elem = doc[field.name()];
- if (elem.eoo()) {
- if (field.hasDefault()) {
- std::unique_ptr<T> temp(new T);
- field.getDefault()->cloneTo(temp.get());
-
- *out = temp.release();
- return FIELD_DEFAULT;
- } else {
- return FIELD_NONE;
- }
- }
-
- if (elem.type() != Object && elem.type() != Array) {
- _genFieldErrMsg(elem, field, "Object/Array", errMsg);
- return FIELD_INVALID;
- }
-
- std::unique_ptr<T> temp(new T);
- if (!temp->parseBSON(elem.embeddedObject(), errMsg)) {
- return FIELD_INVALID;
- }
-
- *out = temp.release();
- return FIELD_SET;
-}
-
-template <typename T>
-FieldParser::FieldState FieldParser::extract(BSONObj doc,
- const BSONField<T>& field,
- T** out,
- std::string* errMsg) {
- BSONElement elem = doc[field.name()];
- if (elem.eoo()) {
- if (field.hasDefault()) {
- *out = new T;
- field.getDefault().cloneTo(*out);
- return FIELD_DEFAULT;
- } else {
- return FIELD_NONE;
- }
- }
-
- if (elem.type() != Object && elem.type() != Array) {
- if (errMsg) {
- *errMsg = str::stream() << "wrong type for '" << field() << "' field, expected "
- << "vector or array"
- << ", found " << doc[field.name()].toString();
- }
- return FIELD_INVALID;
- }
-
- std::unique_ptr<T> temp(new T);
- if (!temp->parseBSON(elem.embeddedObject(), errMsg)) {
- return FIELD_INVALID;
- }
-
- *out = temp.release();
- return FIELD_SET;
-}
-
-// Extracts an array into a vector
-template <typename T>
-FieldParser::FieldState FieldParser::extract(BSONObj doc,
- const BSONField<std::vector<T>>& field,
- std::vector<T>* out,
- std::string* errMsg) {
- return extract(doc[field.name()], field, out, errMsg);
-}
-
-template <typename T>
-FieldParser::FieldState FieldParser::extract(BSONElement elem,
- const BSONField<std::vector<T>>& field,
- std::vector<T>* out,
- std::string* errMsg) {
- if (elem.eoo()) {
- if (field.hasDefault()) {
- *out = field.getDefault();
- return FIELD_DEFAULT;
- } else {
- return FIELD_NONE;
- }
- }
-
- if (elem.type() == Array) {
- BSONArray arr = BSONArray(elem.embeddedObject());
- std::string elErrMsg;
-
- // Append all the new elements to the end of the vector
- size_t initialSize = out->size();
- out->resize(initialSize + arr.nFields());
-
- int i = 0;
- BSONObjIterator objIt(arr);
- while (objIt.more()) {
- BSONElement next = objIt.next();
- BSONField<T> fieldFor(next.fieldName(), out->at(initialSize + i));
-
- if (!FieldParser::extract(next, fieldFor, &out->at(initialSize + i), &elErrMsg)) {
- if (errMsg) {
- *errMsg = str::stream() << "error parsing element " << i << " of field "
- << field() << causedBy(elErrMsg);
- }
- return FIELD_INVALID;
- }
- i++;
- }
-
- return FIELD_SET;
- }
-
- if (errMsg) {
- *errMsg = str::stream() << "wrong type for '" << field() << "' field, expected "
- << "vector array"
- << ", found " << elem.toString();
- }
- return FIELD_INVALID;
-}
-
-template <typename T>
-FieldParser::FieldState FieldParser::extract(BSONObj doc,
- const BSONField<std::vector<T*>>& field,
- std::vector<T*>* out,
- std::string* errMsg) {
- dassert(!field.hasDefault());
-
- BSONElement elem = doc[field.name()];
- if (elem.eoo()) {
- return FIELD_NONE;
- }
-
- return extract(elem, field, out, errMsg);
-}
-
-template <typename T>
-FieldParser::FieldState FieldParser::extract(BSONElement elem,
- const BSONField<std::vector<T*>>& field,
- std::vector<T*>* out,
- std::string* errMsg) {
- if (elem.type() != Array) {
- if (errMsg) {
- *errMsg = str::stream() << "wrong type for '" << field() << "' field, expected "
- << "vector array"
- << ", found " << elem.toString();
- }
- return FIELD_INVALID;
- }
-
- BSONArray arr = BSONArray(elem.embeddedObject());
- BSONObjIterator objIt(arr);
- while (objIt.more()) {
- BSONElement next = objIt.next();
-
- if (next.type() != Object) {
- if (errMsg) {
- *errMsg = str::stream() << "wrong type for '" << field() << "' field contents, "
- << "expected object, found " << elem.type();
- }
- return FIELD_INVALID;
- }
-
- std::unique_ptr<T> toInsert(new T);
-
- if (!toInsert->parseBSON(next.embeddedObject(), errMsg)) {
- return FIELD_INVALID;
- }
-
- out->push_back(toInsert.release());
- }
-
- return FIELD_SET;
-}
-
-template <typename T>
-FieldParser::FieldState FieldParser::extract(BSONObj doc,
- const BSONField<std::vector<T*>>& field,
- std::vector<T*>** out,
- std::string* errMsg) {
- dassert(!field.hasDefault());
-
- BSONElement elem = doc[field.name()];
- if (elem.eoo()) {
- return FIELD_NONE;
- }
-
- if (elem.type() != Array) {
- if (errMsg) {
- *errMsg = str::stream() << "wrong type for '" << field() << "' field, expected "
- << "vector array"
- << ", found " << doc[field.name()].toString();
- }
- return FIELD_INVALID;
- }
-
- std::unique_ptr<std::vector<T*>> tempVector(new std::vector<T*>);
-
- BSONArray arr = BSONArray(elem.embeddedObject());
- BSONObjIterator objIt(arr);
- while (objIt.more()) {
- BSONElement next = objIt.next();
-
- if (next.type() != Object) {
- if (errMsg) {
- *errMsg = str::stream() << "wrong type for '" << field() << "' field contents, "
- << "expected object, found " << elem.type();
- }
- _clearOwnedVector(tempVector.get());
- return FIELD_INVALID;
- }
-
- std::unique_ptr<T> toInsert(new T);
- if (!toInsert->parseBSON(next.embeddedObject(), errMsg)) {
- _clearOwnedVector(tempVector.get());
- return FIELD_INVALID;
- }
-
- tempVector->push_back(toInsert.release());
- }
-
- *out = tempVector.release();
- return FIELD_SET;
-}
-
-// Extracts an object into a map
-template <typename K, typename T>
-FieldParser::FieldState FieldParser::extract(BSONObj doc,
- const BSONField<std::map<K, T>>& field,
- std::map<K, T>* out,
- std::string* errMsg) {
- return extract(doc[field.name()], field, out, errMsg);
-}
-
-template <typename K, typename T>
-FieldParser::FieldState FieldParser::extract(BSONElement elem,
- const BSONField<std::map<K, T>>& field,
- std::map<K, T>* out,
- std::string* errMsg) {
- if (elem.eoo()) {
- if (field.hasDefault()) {
- *out = field.getDefault();
- return FIELD_DEFAULT;
- } else {
- return FIELD_NONE;
- }
- }
-
- if (elem.type() == Object) {
- BSONObj obj = elem.embeddedObject();
- std::string elErrMsg;
-
- BSONObjIterator objIt(obj);
- while (objIt.more()) {
- BSONElement next = objIt.next();
- T& value = (*out)[next.fieldName()];
-
- BSONField<T> fieldFor(next.fieldName(), value);
- if (!FieldParser::extract(next, fieldFor, &value, &elErrMsg)) {
- if (errMsg) {
- *errMsg = str::stream() << "error parsing map element " << next.fieldName()
- << " of field " << field() << causedBy(elErrMsg);
- }
- return FIELD_INVALID;
- }
- }
-
- return FIELD_SET;
- }
-
- if (errMsg) {
- *errMsg = str::stream() << "wrong type for '" << field() << "' field, expected "
- << "vector array"
- << ", found " << elem.toString();
- }
- return FIELD_INVALID;
-}
-
-} // namespace mongo
diff --git a/src/mongo/db/field_parser.h b/src/mongo/db/field_parser.h
index 7ad0315efd3..748787affe9 100644
--- a/src/mongo/db/field_parser.h
+++ b/src/mongo/db/field_parser.h
@@ -29,14 +29,31 @@
#pragma once
+#include <fmt/format.h>
+#include <fmt/ostream.h>
#include <string>
+#include "mongo/base/string_data.h"
#include "mongo/db/jsobj.h"
+#include "mongo/util/scopeguard.h"
#include "mongo/util/time_support.h"
namespace mongo {
class FieldParser {
+private:
+ template <typename T>
+ static void _genFieldErrMsg(const BSONElement& elem,
+ const BSONField<T>& field,
+ StringData expected,
+ std::string* errMsg) {
+ using namespace fmt::literals;
+ if (!errMsg)
+ return;
+ *errMsg = "wrong type for '{}' field, expected {}, found {}"_format(
+ field(), expected, elem.toString());
+ }
+
public:
/**
* Returns true and fills in 'out' with the contents of the field described by 'field'
@@ -321,7 +338,296 @@ public:
std::string* errMsg = NULL);
};
-} // namespace mongo
+template <typename T>
+FieldParser::FieldState FieldParser::extract(BSONObj doc,
+ const BSONField<T>& field,
+ T* out,
+ std::string* errMsg) {
+ BSONElement elem = doc[field.name()];
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ field.getDefault().cloneTo(out);
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
+ }
+ }
+
+ if (elem.type() != Object && elem.type() != Array) {
+ _genFieldErrMsg(elem, field, "Object/Array", errMsg);
+ return FIELD_INVALID;
+ }
+
+ if (!out->parseBSON(elem.embeddedObject(), errMsg)) {
+ return FIELD_INVALID;
+ }
+
+ return FIELD_SET;
+}
+
+template <typename T>
+FieldParser::FieldState FieldParser::extract(BSONObj doc,
+ const BSONField<T*>& field,
+ T** out,
+ std::string* errMsg) {
+ BSONElement elem = doc[field.name()];
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ std::unique_ptr<T> temp(new T);
+ field.getDefault()->cloneTo(temp.get());
+
+ *out = temp.release();
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
+ }
+ }
+
+ if (elem.type() != Object && elem.type() != Array) {
+ _genFieldErrMsg(elem, field, "Object/Array", errMsg);
+ return FIELD_INVALID;
+ }
+
+ std::unique_ptr<T> temp(new T);
+ if (!temp->parseBSON(elem.embeddedObject(), errMsg)) {
+ return FIELD_INVALID;
+ }
+
+ *out = temp.release();
+ return FIELD_SET;
+}
+
+template <typename T>
+FieldParser::FieldState FieldParser::extract(BSONObj doc,
+ const BSONField<T>& field,
+ T** out,
+ std::string* errMsg) {
+ BSONElement elem = doc[field.name()];
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ *out = new T;
+ field.getDefault().cloneTo(*out);
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
+ }
+ }
+
+ if (elem.type() != Object && elem.type() != Array) {
+ _genFieldErrMsg(elem, field(), "vector or array", errMsg);
+ return FIELD_INVALID;
+ }
+
+ std::unique_ptr<T> temp(new T);
+ if (!temp->parseBSON(elem.embeddedObject(), errMsg)) {
+ return FIELD_INVALID;
+ }
+
+ *out = temp.release();
+ return FIELD_SET;
+}
+
+// Extracts an array into a vector
+template <typename T>
+FieldParser::FieldState FieldParser::extract(BSONObj doc,
+ const BSONField<std::vector<T>>& field,
+ std::vector<T>* out,
+ std::string* errMsg) {
+ return extract(doc[field.name()], field, out, errMsg);
+}
+
+template <typename T>
+FieldParser::FieldState FieldParser::extract(BSONElement elem,
+ const BSONField<std::vector<T>>& field,
+ std::vector<T>* out,
+ std::string* errMsg) {
+ using namespace fmt::literals;
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ *out = field.getDefault();
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
+ }
+ }
+
+ if (elem.type() == Array) {
+ BSONArray arr = BSONArray(elem.embeddedObject());
+ std::string elErrMsg;
+
+ // Append all the new elements to the end of the vector
+ size_t initialSize = out->size();
+ out->resize(initialSize + arr.nFields());
+
+ int i = 0;
+ BSONObjIterator objIt(arr);
+ while (objIt.more()) {
+ BSONElement next = objIt.next();
+ BSONField<T> fieldFor(next.fieldName(), out->at(initialSize + i));
+
+ if (!FieldParser::extract(next, fieldFor, &out->at(initialSize + i), &elErrMsg)) {
+ if (errMsg) {
+ *errMsg = "error parsing element {} of field {}{}"_format(
+ i, field(), causedBy(elErrMsg));
+ }
+ return FIELD_INVALID;
+ }
+ i++;
+ }
+
+ return FIELD_SET;
+ }
+
+ _genFieldErrMsg(elem, field, "vector array", errMsg);
+ return FIELD_INVALID;
+}
+
+template <typename T>
+FieldParser::FieldState FieldParser::extract(BSONObj doc,
+ const BSONField<std::vector<T*>>& field,
+ std::vector<T*>* out,
+ std::string* errMsg) {
+ dassert(!field.hasDefault());
+
+ BSONElement elem = doc[field.name()];
+ if (elem.eoo()) {
+ return FIELD_NONE;
+ }
+
+ return extract(elem, field, out, errMsg);
+}
+
+template <typename T>
+FieldParser::FieldState FieldParser::extract(BSONElement elem,
+ const BSONField<std::vector<T*>>& field,
+ std::vector<T*>* out,
+ std::string* errMsg) {
+ if (elem.type() != Array) {
+ _genFieldErrMsg(elem, field, "vector array", errMsg);
+ return FIELD_INVALID;
+ }
+
+ BSONArray arr = BSONArray(elem.embeddedObject());
+ BSONObjIterator objIt(arr);
+ while (objIt.more()) {
+ BSONElement next = objIt.next();
+
+ if (next.type() != Object) {
+ _genFieldErrMsg(elem, field, "object", errMsg);
+ return FIELD_INVALID;
+ }
+
+ std::unique_ptr<T> toInsert(new T);
+
+ if (!toInsert->parseBSON(next.embeddedObject(), errMsg)) {
+ return FIELD_INVALID;
+ }
+
+ out->push_back(toInsert.release());
+ }
+
+ return FIELD_SET;
+}
+
+template <typename T>
+FieldParser::FieldState FieldParser::extract(BSONObj doc,
+ const BSONField<std::vector<T*>>& field,
+ std::vector<T*>** out,
+ std::string* errMsg) {
+ using namespace fmt::literals;
+ dassert(!field.hasDefault());
+
+ BSONElement elem = doc[field.name()];
+ if (elem.eoo()) {
+ return FIELD_NONE;
+ }
+
+ if (elem.type() != Array) {
+ _genFieldErrMsg(elem, field, "vector array", errMsg);
+ return FIELD_INVALID;
+ }
+
+ auto tempVector = std::make_unique<std::vector<T*>>();
+ auto guard = makeGuard([&tempVector] {
+ if (tempVector) {
+ for (T*& raw : *tempVector) {
+ delete raw;
+ }
+ }
+ });
+
+ BSONArray arr = BSONArray(elem.embeddedObject());
+ BSONObjIterator objIt(arr);
+ while (objIt.more()) {
+ BSONElement next = objIt.next();
+
+ if (next.type() != Object) {
+ if (errMsg) {
+ *errMsg = "wrong type for '{}' field contents, expected object, found {}"_format(
+ field(), elem.type());
+ }
+ return FIELD_INVALID;
+ }
+
+ std::unique_ptr<T> toInsert(new T);
+ if (!toInsert->parseBSON(next.embeddedObject(), errMsg)) {
+ return FIELD_INVALID;
+ }
+
+ tempVector->push_back(toInsert.release());
+ }
+ *out = tempVector.release();
+ return FIELD_SET;
+}
+
+// Extracts an object into a map
+template <typename K, typename T>
+FieldParser::FieldState FieldParser::extract(BSONObj doc,
+ const BSONField<std::map<K, T>>& field,
+ std::map<K, T>* out,
+ std::string* errMsg) {
+ return extract(doc[field.name()], field, out, errMsg);
+}
+
+template <typename K, typename T>
+FieldParser::FieldState FieldParser::extract(BSONElement elem,
+ const BSONField<std::map<K, T>>& field,
+ std::map<K, T>* out,
+ std::string* errMsg) {
+ using namespace fmt::literals;
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ *out = field.getDefault();
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
+ }
+ }
+
+ if (elem.type() == Object) {
+ BSONObj obj = elem.embeddedObject();
+ std::string elErrMsg;
+
+ BSONObjIterator objIt(obj);
+ while (objIt.more()) {
+ BSONElement next = objIt.next();
+ T& value = (*out)[next.fieldName()];
+
+ BSONField<T> fieldFor(next.fieldName(), value);
+ if (!FieldParser::extract(next, fieldFor, &value, &elErrMsg)) {
+ if (errMsg) {
+ *errMsg = "error parsing map element {} of field {}{}"_format(
+ next.fieldName(), field(), causedBy(elErrMsg));
+ }
+ return FIELD_INVALID;
+ }
+ }
+
+ return FIELD_SET;
+ }
+
+ _genFieldErrMsg(elem, field, "vector array", errMsg);
+ return FIELD_INVALID;
+}
-// Inline functions for templating
-#include "field_parser-inl.h"
+} // namespace mongo
diff --git a/src/mongo/logger/log_severity-inl.h b/src/mongo/logger/log_severity-inl.h
deleted file mode 100644
index e76e10b91f5..00000000000
--- a/src/mongo/logger/log_severity-inl.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-namespace mongo {
-namespace logger {
-
-LogSeverity LogSeverity::Severe() {
- return LogSeverity(-4);
-}
-LogSeverity LogSeverity::Error() {
- return LogSeverity(-3);
-}
-LogSeverity LogSeverity::Warning() {
- return LogSeverity(-2);
-}
-LogSeverity LogSeverity::Info() {
- return LogSeverity(-1);
-}
-LogSeverity LogSeverity::Log() {
- return LogSeverity(0);
-}
-LogSeverity LogSeverity::Debug(int debugLevel) {
- // It would be appropriate to use std::max or std::clamp instead,
- // but it seems better not to drag in all of <algorithm> here.
- return LogSeverity(debugLevel > kMaxDebugLevel ? kMaxDebugLevel : debugLevel);
-}
-
-LogSeverity LogSeverity::cast(int ll) {
- return LogSeverity(ll);
-}
-
-int LogSeverity::toInt() const {
- return _severity;
-}
-LogSeverity LogSeverity::moreSevere() const {
- return LogSeverity(_severity - 1);
-}
-LogSeverity LogSeverity::lessSevere() const {
- return LogSeverity(_severity + 1);
-}
-
-bool LogSeverity::operator==(LogSeverity other) const {
- return _severity == other._severity;
-}
-bool LogSeverity::operator!=(LogSeverity other) const {
- return _severity != other._severity;
-}
-bool LogSeverity::operator<(LogSeverity other) const {
- return _severity > other._severity;
-}
-bool LogSeverity::operator<=(LogSeverity other) const {
- return _severity >= other._severity;
-}
-bool LogSeverity::operator>(LogSeverity other) const {
- return _severity < other._severity;
-}
-bool LogSeverity::operator>=(LogSeverity other) const {
- return _severity <= other._severity;
-}
-
-} // namespace logger
-} // namespace mongo
diff --git a/src/mongo/logger/log_severity.h b/src/mongo/logger/log_severity.h
index b0eeccbd859..c96b53cfe67 100644
--- a/src/mongo/logger/log_severity.h
+++ b/src/mongo/logger/log_severity.h
@@ -145,7 +145,59 @@ private:
std::ostream& operator<<(std::ostream& os, LogSeverity severity);
+LogSeverity LogSeverity::Severe() {
+ return LogSeverity(-4);
+}
+LogSeverity LogSeverity::Error() {
+ return LogSeverity(-3);
+}
+LogSeverity LogSeverity::Warning() {
+ return LogSeverity(-2);
+}
+LogSeverity LogSeverity::Info() {
+ return LogSeverity(-1);
+}
+LogSeverity LogSeverity::Log() {
+ return LogSeverity(0);
+}
+LogSeverity LogSeverity::Debug(int debugLevel) {
+ // It would be appropriate to use std::max or std::clamp instead,
+ // but it seems better not to drag in all of <algorithm> here.
+ return LogSeverity(debugLevel > kMaxDebugLevel ? kMaxDebugLevel : debugLevel);
+}
+
+LogSeverity LogSeverity::cast(int ll) {
+ return LogSeverity(ll);
+}
+
+int LogSeverity::toInt() const {
+ return _severity;
+}
+LogSeverity LogSeverity::moreSevere() const {
+ return LogSeverity(_severity - 1);
+}
+LogSeverity LogSeverity::lessSevere() const {
+ return LogSeverity(_severity + 1);
+}
+
+bool LogSeverity::operator==(LogSeverity other) const {
+ return _severity == other._severity;
+}
+bool LogSeverity::operator!=(LogSeverity other) const {
+ return _severity != other._severity;
+}
+bool LogSeverity::operator<(LogSeverity other) const {
+ return _severity > other._severity;
+}
+bool LogSeverity::operator<=(LogSeverity other) const {
+ return _severity >= other._severity;
+}
+bool LogSeverity::operator>(LogSeverity other) const {
+ return _severity < other._severity;
+}
+bool LogSeverity::operator>=(LogSeverity other) const {
+ return _severity <= other._severity;
+}
+
} // namespace logger
} // namespace mongo
-
-#include "mongo/logger/log_severity-inl.h"
diff --git a/src/mongo/util/descriptive_stats-inl.h b/src/mongo/util/descriptive_stats-inl.h
deleted file mode 100644
index 1b7239a3cbf..00000000000
--- a/src/mongo/util/descriptive_stats-inl.h
+++ /dev/null
@@ -1,199 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-#include <algorithm>
-#include <limits>
-
-#include "mongo/util/str.h"
-
-namespace mongo {
-
-template <class Sample>
-BasicEstimators<Sample>::BasicEstimators()
- : _count(0),
- _sum(0),
- _diff(0),
- _min(std::numeric_limits<Sample>::max()),
- _max(std::numeric_limits<Sample>::min()) {}
-
-template <class Sample>
-BasicEstimators<Sample>& BasicEstimators<Sample>::operator<<(const Sample sample) {
- const double oldMean = (_count > 0) ? _sum / _count : 0;
- const double delta = oldMean - static_cast<double>(sample);
- const double weight = static_cast<double>(_count) / (_count + 1);
- _diff += delta * delta * weight;
- _sum += static_cast<double>(sample);
- _count++;
- _min = std::min(sample, _min);
- _max = std::max(sample, _max);
- return *this;
-}
-
-template <class Sample>
-void BasicEstimators<Sample>::appendBasicToBSONObjBuilder(BSONObjBuilder& b) const {
- b << "count" << static_cast<long long>(count()) << "mean" << mean() << "stddev" << stddev()
- << "min" << min() << "max" << max();
-}
-
-template <std::size_t NumQuantiles>
-DistributionEstimators<NumQuantiles>::DistributionEstimators() : _count(0) {
- for (std::size_t i = 0; i < NumMarkers; i++) {
- _actual_positions[i] = i + 1;
- }
-
- for (std::size_t i = 0; i < NumMarkers; i++) {
- _desired_positions[i] = 1.0 + (2.0 * (NumQuantiles + 1.0) * _positions_increments(i));
- }
-}
-
-/*
- * The quantile estimation follows the extended_p_square implementation in boost.accumulators.
- * It differs by removing the ability to request arbitrary quantiles and computing exactly
- * 'NumQuantiles' equidistant quantiles (plus minimum and maximum) instead.
- * See http://www.boost.org/doc/libs/1_51_0/doc/html/boost/accumulators/impl/
- * extended_p_square_impl.html ,
- * R. Jain and I. Chlamtac, The P^2 algorithmus for dynamic calculation of quantiles and histograms
- * without storing observations, Communications of the ACM, Volume 28
- * (October), Number 10, 1985, p. 1076-1085. and
- * K. E. E. Raatikainen, Simultaneous estimation of several quantiles, Simulation,
- * Volume 49, Number 4 (October), 1986, p. 159-164.
- */
-template <std::size_t NumQuantiles>
-DistributionEstimators<NumQuantiles>& DistributionEstimators<NumQuantiles>::operator<<(
- const double sample) {
- // first accumulate num_markers samples
- if (_count++ < NumMarkers) {
- _heights[_count - 1] = sample;
-
- if (_count == NumMarkers) {
- std::sort(_heights, _heights + NumMarkers);
- }
- } else {
- std::size_t sample_cell = 1;
-
- // find cell k = sample_cell such that heights[k-1] <= sample < heights[k]
- if (sample < _heights[0]) {
- _heights[0] = sample;
- sample_cell = 1;
- } else if (sample >= _heights[NumMarkers - 1]) {
- _heights[NumMarkers - 1] = sample;
- sample_cell = NumMarkers - 1;
- } else {
- double* it = std::upper_bound(_heights, _heights + NumMarkers, sample);
-
- sample_cell = std::distance(_heights, it);
- }
-
- // update actual positions of all markers above sample_cell index
- for (std::size_t i = sample_cell; i < NumMarkers; i++) {
- _actual_positions[i]++;
- }
-
- // update desired positions of all markers
- for (std::size_t i = 0; i < NumMarkers; i++) {
- _desired_positions[i] += _positions_increments(i);
- }
-
- // adjust heights and actual positions of markers 1 to num_markers-2 if necessary
- for (std::size_t i = 1; i <= NumMarkers - 2; i++) {
- // offset to desired position
- double d = _desired_positions[i] - _actual_positions[i];
-
- // offset to next position
- double dp = _actual_positions[i + 1] - _actual_positions[i];
-
- // offset to previous position
- double dm = _actual_positions[i - 1] - _actual_positions[i];
-
- // height ds
- double hp = (_heights[i + 1] - _heights[i]) / dp;
- double hm = (_heights[i - 1] - _heights[i]) / dm;
-
- if ((d >= 1 && dp > 1) || (d <= -1 && dm < -1)) {
- short sign_d = static_cast<short>(d / std::abs(d));
-
- double h =
- _heights[i] + sign_d / (dp - dm) * ((sign_d - dm) * hp + (dp - sign_d) * hm);
-
- // try adjusting heights[i] using p-squared formula
- if (_heights[i - 1] < h && h < _heights[i + 1]) {
- _heights[i] = h;
- } else {
- // use linear formula
- if (d > 0) {
- _heights[i] += hp;
- }
- if (d < 0) {
- _heights[i] -= hm;
- }
- }
- _actual_positions[i] += sign_d;
- }
- }
- }
-
- return *this;
-}
-
-template <std::size_t NumQuantiles>
-void DistributionEstimators<NumQuantiles>::appendQuantilesToBSONArrayBuilder(
- BSONArrayBuilder& arr) const {
- verify(quantilesReady());
- for (std::size_t i = 0; i <= NumQuantiles + 1; i++) {
- arr << quantile(i);
- }
-}
-
-template <std::size_t NumQuantiles>
-inline double DistributionEstimators<NumQuantiles>::_positions_increments(std::size_t i) const {
- return static_cast<double>(i) / (2 * (NumQuantiles + 1));
-}
-
-template <class Sample, std::size_t NumQuantiles>
-BSONObj SummaryEstimators<Sample, NumQuantiles>::statisticSummaryToBSONObj() const {
- BSONObjBuilder b;
- this->BasicEstimators<Sample>::appendBasicToBSONObjBuilder(b);
- if (this->DistributionEstimators<NumQuantiles>::quantilesReady()) {
- // Not using appendQuantiles to be explicit about which probability each quantile
- // refers to. This way the user does not need to count the quantiles or know in
- // advance how many quantiles were computed to figure out their meaning.
- BSONObjBuilder quantilesBuilder(b.subobjStart("quantiles"));
- for (size_t i = 1; i <= NumQuantiles; i++) {
- const double probability = this->DistributionEstimators<NumQuantiles>::probability(i);
- const double quantile = this->DistributionEstimators<NumQuantiles>::quantile(i);
- quantilesBuilder.append(std::string(str::stream() << probability), quantile);
- }
- quantilesBuilder.doneFast();
- }
- return b.obj();
-}
-
-} // namespace mongo
diff --git a/src/mongo/util/safe_num-inl.h b/src/mongo/util/safe_num-inl.h
deleted file mode 100644
index 8cd925aff72..00000000000
--- a/src/mongo/util/safe_num-inl.h
+++ /dev/null
@@ -1,130 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-namespace mongo {
-
-inline SafeNum::SafeNum() : _type(EOO) {}
-
-inline SafeNum::~SafeNum() {}
-
-inline SafeNum::SafeNum(const SafeNum& rhs) : _type(rhs._type), _value(rhs._value) {}
-
-inline SafeNum& SafeNum::operator=(const SafeNum& rhs) {
- _type = rhs._type;
- _value = rhs._value;
- return *this;
-}
-
-inline SafeNum::SafeNum(int32_t num) : _type(NumberInt) {
- _value.int32Val = num;
-}
-
-inline SafeNum::SafeNum(int64_t num) : _type(NumberLong) {
- _value.int64Val = num;
-}
-
-inline SafeNum::SafeNum(double num) : _type(NumberDouble) {
- _value.doubleVal = num;
-}
-
-inline SafeNum::SafeNum(Decimal128 num) : _type(NumberDecimal) {
- _value.decimalVal = num.getValue();
-}
-
-inline bool SafeNum::operator==(const SafeNum& rhs) const {
- return isEquivalent(rhs);
-}
-
-inline bool SafeNum::operator!=(const SafeNum& rhs) const {
- return !isEquivalent(rhs);
-}
-
-inline SafeNum SafeNum::operator+(const SafeNum& rhs) const {
- return addInternal(*this, rhs);
-}
-
-inline SafeNum& SafeNum::operator+=(const SafeNum& rhs) {
- return *this = addInternal(*this, rhs);
-}
-
-inline SafeNum SafeNum::operator*(const SafeNum& rhs) const {
- return mulInternal(*this, rhs);
-}
-
-inline SafeNum& SafeNum::operator*=(const SafeNum& rhs) {
- return *this = mulInternal(*this, rhs);
-}
-
-inline SafeNum SafeNum::bitAnd(const SafeNum& rhs) const {
- return andInternal(*this, rhs);
-}
-
-inline SafeNum SafeNum::operator&(const SafeNum& rhs) const {
- return bitAnd(rhs);
-}
-
-inline SafeNum& SafeNum::operator&=(const SafeNum& rhs) {
- return *this = bitAnd(rhs);
-}
-
-inline SafeNum SafeNum::bitOr(const SafeNum& rhs) const {
- return orInternal(*this, rhs);
-}
-
-inline SafeNum SafeNum::operator|(const SafeNum& rhs) const {
- return bitOr(rhs);
-}
-
-inline SafeNum& SafeNum::operator|=(const SafeNum& rhs) {
- return *this = bitOr(rhs);
-}
-
-inline SafeNum SafeNum::bitXor(const SafeNum& rhs) const {
- return xorInternal(*this, rhs);
-}
-
-inline SafeNum SafeNum::operator^(const SafeNum& rhs) const {
- return bitXor(rhs);
-}
-
-inline SafeNum& SafeNum::operator^=(const SafeNum& rhs) {
- return *this = bitXor(rhs);
-}
-
-inline bool SafeNum::isValid() const {
- return _type != EOO;
-}
-
-inline BSONType SafeNum::type() const {
- return _type;
-}
-
-} // namespace mongo
diff --git a/src/mongo/util/safe_num.h b/src/mongo/util/safe_num.h
index f6ef4042533..529adec4878 100644
--- a/src/mongo/util/safe_num.h
+++ b/src/mongo/util/safe_num.h
@@ -242,6 +242,100 @@ private:
// Convenience method for unittest code. Please use accessors otherwise.
std::ostream& operator<<(std::ostream& os, const SafeNum& snum);
-} // namespace mongo
+inline SafeNum::SafeNum() : _type(EOO) {}
+
+inline SafeNum::~SafeNum() {}
+
+inline SafeNum::SafeNum(const SafeNum& rhs) : _type(rhs._type), _value(rhs._value) {}
+
+inline SafeNum& SafeNum::operator=(const SafeNum& rhs) {
+ _type = rhs._type;
+ _value = rhs._value;
+ return *this;
+}
+
+inline SafeNum::SafeNum(int32_t num) : _type(NumberInt) {
+ _value.int32Val = num;
+}
+
+inline SafeNum::SafeNum(int64_t num) : _type(NumberLong) {
+ _value.int64Val = num;
+}
+
+inline SafeNum::SafeNum(double num) : _type(NumberDouble) {
+ _value.doubleVal = num;
+}
+
+inline SafeNum::SafeNum(Decimal128 num) : _type(NumberDecimal) {
+ _value.decimalVal = num.getValue();
+}
+
+inline bool SafeNum::operator==(const SafeNum& rhs) const {
+ return isEquivalent(rhs);
+}
+
+inline bool SafeNum::operator!=(const SafeNum& rhs) const {
+ return !isEquivalent(rhs);
+}
+
+inline SafeNum SafeNum::operator+(const SafeNum& rhs) const {
+ return addInternal(*this, rhs);
+}
+
+inline SafeNum& SafeNum::operator+=(const SafeNum& rhs) {
+ return *this = addInternal(*this, rhs);
+}
+
+inline SafeNum SafeNum::operator*(const SafeNum& rhs) const {
+ return mulInternal(*this, rhs);
+}
+
+inline SafeNum& SafeNum::operator*=(const SafeNum& rhs) {
+ return *this = mulInternal(*this, rhs);
+}
+
+inline SafeNum SafeNum::bitAnd(const SafeNum& rhs) const {
+ return andInternal(*this, rhs);
+}
+
+inline SafeNum SafeNum::operator&(const SafeNum& rhs) const {
+ return bitAnd(rhs);
+}
+
+inline SafeNum& SafeNum::operator&=(const SafeNum& rhs) {
+ return *this = bitAnd(rhs);
+}
+
+inline SafeNum SafeNum::bitOr(const SafeNum& rhs) const {
+ return orInternal(*this, rhs);
+}
+
+inline SafeNum SafeNum::operator|(const SafeNum& rhs) const {
+ return bitOr(rhs);
+}
+
+inline SafeNum& SafeNum::operator|=(const SafeNum& rhs) {
+ return *this = bitOr(rhs);
+}
+
+inline SafeNum SafeNum::bitXor(const SafeNum& rhs) const {
+ return xorInternal(*this, rhs);
+}
+
+inline SafeNum SafeNum::operator^(const SafeNum& rhs) const {
+ return bitXor(rhs);
+}
+
+inline SafeNum& SafeNum::operator^=(const SafeNum& rhs) {
+ return *this = bitXor(rhs);
+}
+
+inline bool SafeNum::isValid() const {
+ return _type != EOO;
+}
-#include "mongo/util/safe_num-inl.h"
+inline BSONType SafeNum::type() const {
+ return _type;
+}
+
+} // namespace mongo