MongoDB  2.7.0
bson_extract.h
1 /* Copyright 2012 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 #include <string>
19 
20 #include "mongo/base/status.h"
21 #include "mongo/base/string_data.h"
22 #include "mongo/bson/bsontypes.h"
23 
24 namespace mongo {
25 
26  class BSONObj;
27  class BSONElement;
28 
35  Status bsonExtractField(const BSONObj& object,
36  const StringData& fieldName,
37  BSONElement* outElement);
38 
47  Status bsonExtractTypedField(const BSONObj& object,
48  const StringData& fieldName,
49  BSONType type,
50  BSONElement* outElement);
51 
60  Status bsonExtractBooleanField(const BSONObj& object,
61  const StringData& fieldName,
62  bool* out);
63 
74  Status bsonExtractIntegerField(const BSONObj& object,
75  const StringData& fieldName,
76  long long* out);
77 
86  Status bsonExtractStringField(const BSONObj& object,
87  const StringData& fieldName,
88  std::string* out);
89 
100  Status bsonExtractBooleanFieldWithDefault(const BSONObj& object,
101  const StringData& fieldName,
102  bool defaultValue,
103  bool* out);
104 
115  Status bsonExtractIntegerFieldWithDefault(const BSONObj& object,
116  const StringData& fieldName,
117  long long defaultValue,
118  long long* out);
119 
130  Status bsonExtractStringFieldWithDefault(const BSONObj& object,
131  const StringData& fieldName,
132  const StringData& defaultValue,
133  std::string* out);
134 
135 } // namespace mongo
Status bsonExtractIntegerFieldWithDefault(const BSONObj &object, const StringData &fieldName, long long defaultValue, long long *out)
Finds an element named "fieldName" in "object" that represents an integral value. ...
Definition: bson_extract.cpp:134
LogstreamBuilder out()
Synonym for log().
Definition: log.h:79
Status bsonExtractBooleanFieldWithDefault(const BSONObj &object, const StringData &fieldName, bool defaultValue, bool *out)
Finds a bool-like element named "fieldName" in "object".
Definition: bson_extract.cpp:62
Status bsonExtractBooleanField(const BSONObj &object, const StringData &fieldName, bool *out)
Finds a bool-like element named "fieldName" in "object".
Definition: bson_extract.cpp:51
Status bsonExtractTypedField(const BSONObj &object, const StringData &fieldName, BSONType type, BSONElement *outElement)
Finds an element named "fieldName" in "object".
Definition: bson_extract.cpp:35
BSONType
the complete list of valid BSON types see also bsonspec.org
Definition: bsontypes.h:43
Status bsonExtractField(const BSONObj &object, const StringData &fieldName, BSONElement *outElement)
Finds an element named "fieldName" in "object".
Definition: bson_extract.cpp:23
Status bsonExtractStringField(const BSONObj &object, const StringData &fieldName, std::string *out)
Finds a string-typed element named "fieldName" in "object" and stores its value in "out"...
Definition: bson_extract.cpp:86
Status bsonExtractIntegerField(const BSONObj &object, const StringData &fieldName, long long *out)
Finds an element named "fieldName" in "object" that represents an integral value. ...
Definition: bson_extract.cpp:111
Status bsonExtractStringFieldWithDefault(const BSONObj &object, const StringData &fieldName, const StringData &defaultValue, std::string *out)
Finds a string element named "fieldName" in "object".
Definition: bson_extract.cpp:97