MongoDB  2.7.0
document-inl.h
1 /* Copyright 2013 10gen Inc.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 namespace mongo {
19 namespace mutablebson {
20 
21  inline int Document::compareWith(const Document& other, bool considerFieldName) const {
22  // We cheat and use Element::compareWithElement since we know that 'other' is a
23  // Document and has a 'hidden' fieldname that is always indentical across all Document
24  // instances.
25  return root().compareWithElement(other.root(), considerFieldName);
26  }
27 
28  inline int Document::compareWithBSONObj(const BSONObj& other, bool considerFieldName) const {
29  return root().compareWithBSONObj(other, considerFieldName);
30  }
31 
32  inline void Document::writeTo(BSONObjBuilder* builder) const {
33  return root().writeTo(builder);
34  }
35 
36  inline BSONObj Document::getObject() const {
37  BSONObjBuilder builder;
38  writeTo(&builder);
39  return builder.obj();
40  }
41 
43  return _root;
44  }
45 
46  inline ConstElement Document::root() const {
47  return _root;
48  }
49 
51  return Element(this, Element::kInvalidRepIdx);
52  }
53 
54  inline ConstElement Document::end() const {
55  return const_cast<Document*>(this)->end();
56  }
57 
58  inline std::string Document::toString() const {
59  return getObject().toString();
60  }
61 
62  inline bool Document::isInPlaceModeEnabled() const {
63  return getCurrentInPlaceMode() == kInPlaceEnabled;
64  }
65 
66 } // namespace mutablebson
67 } // namespace mongo
Utility for creating a BSONObj.
Definition: bsonobjbuilder.h:52
void writeTo(BSONObjBuilder *builder) const
Serialize the Elements reachable from the root Element of this Document to the provided builder...
Definition: document-inl.h:32
BSONObj obj()
destructive The returned BSONObj will free the buffer when it is finished.
Definition: bsonobjbuilder.h:573
Element root()
Returns the root element for this document.
Definition: document-inl.h:42
int compareWithBSONObj(const BSONObj &other, bool considerFieldName=true) const
Compare this Document to 'other' with the semantics of BSONObj::woCompare.
Definition: document-inl.h:28
Element end()
Returns an element that will compare equal to a non-ok element.
Definition: document-inl.h:50
bool isInPlaceModeEnabled() const
A convenience routine, this returns true if the current in-place mode is kInPlaceEnabled, and false otherwise.
Definition: document-inl.h:62
void writeTo(BSONObjBuilder *builder) const
Write this Element to the provided object builder.
Definition: document.cpp:1655
InPlaceMode getCurrentInPlaceMode() const
Returns the current in-place mode for the document.
Definition: document.cpp:2240
Element represents a BSON value or object in a mutable BSON Document.
Definition: element.h:99
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary representa...
Definition: bsonobj.h:77
For an overview of mutable BSON, please see the file document.h in this directory.
Definition: const_element.h:36
int compareWith(const Document &other, bool considerFieldName=true) const
Compare this Document to 'other' with the semantics of BSONObj::woCompare.
Definition: document-inl.h:21
int compareWithBSONObj(const BSONObj &other, bool considerFieldName=true) const
Compare this Element, which must be an Object or an Array, with 'other'.
Definition: document.cpp:1625
Mutable BSON Overview.
Definition: document.h:221
int compareWithElement(const ConstElement &other, bool considerFieldName=true) const
Compare this Element with Element 'other'.
Definition: document.cpp:1504
BSONObj getObject() const
Serialize the Elements reachable from the root Element of this Document and return the result as a BS...
Definition: document-inl.h:36