summaryrefslogtreecommitdiff
path: root/src/mongo/bson
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/bson')
-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
5 files changed, 386 insertions, 252 deletions
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"