summaryrefslogtreecommitdiff
path: root/src/mongo/db/field_parser.cpp
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2015-06-20 00:22:50 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2015-06-20 10:56:02 -0400
commit9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch)
tree3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/db/field_parser.cpp
parent01965cf52bce6976637ecb8f4a622aeb05ab256a (diff)
downloadmongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/field_parser.cpp')
-rw-r--r--src/mongo/db/field_parser.cpp716
1 files changed, 346 insertions, 370 deletions
diff --git a/src/mongo/db/field_parser.cpp b/src/mongo/db/field_parser.cpp
index 6437c35febf..e06806b6ea8 100644
--- a/src/mongo/db/field_parser.cpp
+++ b/src/mongo/db/field_parser.cpp
@@ -32,442 +32,418 @@
namespace mongo {
- using std::string;
-
- FieldParser::FieldState FieldParser::extract( BSONObj doc,
- const BSONField<bool>& field,
- bool* out,
- string* errMsg ) {
- return extract( doc[field.name()], field, out, errMsg );
- }
-
- FieldParser::FieldState FieldParser::extract( BSONElement elem,
- const BSONField<bool>& field,
- bool* out,
- string* errMsg )
- {
- if (elem.eoo()) {
- if (field.hasDefault()) {
- *out = field.getDefault();
- return FIELD_DEFAULT;
- }
- else {
- return FIELD_NONE;
- }
+using std::string;
+
+FieldParser::FieldState FieldParser::extract(BSONObj doc,
+ const BSONField<bool>& field,
+ bool* out,
+ string* errMsg) {
+ return extract(doc[field.name()], field, out, errMsg);
+}
+
+FieldParser::FieldState FieldParser::extract(BSONElement elem,
+ const BSONField<bool>& field,
+ bool* out,
+ string* errMsg) {
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ *out = field.getDefault();
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
}
-
- if (elem.type() == Bool) {
- *out = elem.boolean();
- return FIELD_SET;
- }
-
- _genFieldErrMsg(elem, field, "boolean", errMsg);
- return FIELD_INVALID;
}
- FieldParser::FieldState FieldParser::extract( BSONObj doc,
- const BSONField<BSONArray>& field,
- BSONArray* out,
- string* errMsg ) {
- return extract( doc[field.name()], field, out, errMsg );
+ if (elem.type() == Bool) {
+ *out = elem.boolean();
+ return FIELD_SET;
}
-
- FieldParser::FieldState FieldParser::extract( BSONElement elem,
- const BSONField<BSONArray>& field,
- BSONArray* out,
- string* errMsg )
- {
- if (elem.eoo()) {
- if (field.hasDefault()) {
- *out = field.getDefault();
- return FIELD_DEFAULT;
- }
- else {
- return FIELD_NONE;
- }
+ _genFieldErrMsg(elem, field, "boolean", errMsg);
+ return FIELD_INVALID;
+}
+
+FieldParser::FieldState FieldParser::extract(BSONObj doc,
+ const BSONField<BSONArray>& field,
+ BSONArray* out,
+ string* errMsg) {
+ return extract(doc[field.name()], field, out, errMsg);
+}
+
+
+FieldParser::FieldState FieldParser::extract(BSONElement elem,
+ const BSONField<BSONArray>& field,
+ BSONArray* out,
+ string* errMsg) {
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ *out = field.getDefault();
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
}
-
- if (elem.type() == Array) {
- *out = BSONArray(elem.embeddedObject().getOwned());
- return FIELD_SET;
- }
-
- _genFieldErrMsg(elem, field, "array", errMsg);
- return FIELD_INVALID;
}
- FieldParser::FieldState FieldParser::extract( BSONObj doc,
- const BSONField<BSONObj>& field,
- BSONObj* out,
- string* errMsg ) {
- return extract( doc[field.name()], field, out, errMsg );
+ if (elem.type() == Array) {
+ *out = BSONArray(elem.embeddedObject().getOwned());
+ return FIELD_SET;
}
-
- FieldParser::FieldState FieldParser::extract( BSONElement elem,
- const BSONField<BSONObj>& field,
- BSONObj* out,
- string* errMsg )
- {
- if (elem.eoo()) {
- if (field.hasDefault()) {
- *out = field.getDefault().getOwned();
- return FIELD_DEFAULT;
- }
- else {
- return FIELD_NONE;
- }
- }
-
- if (elem.type() == Object) {
- *out = elem.embeddedObject().getOwned();
- return FIELD_SET;
+ _genFieldErrMsg(elem, field, "array", errMsg);
+ return FIELD_INVALID;
+}
+
+FieldParser::FieldState FieldParser::extract(BSONObj doc,
+ const BSONField<BSONObj>& field,
+ BSONObj* out,
+ string* errMsg) {
+ return extract(doc[field.name()], field, out, errMsg);
+}
+
+
+FieldParser::FieldState FieldParser::extract(BSONElement elem,
+ const BSONField<BSONObj>& field,
+ BSONObj* out,
+ string* errMsg) {
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ *out = field.getDefault().getOwned();
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
}
-
- _genFieldErrMsg(elem, field, "object", errMsg);
- return FIELD_INVALID;
}
- FieldParser::FieldState FieldParser::extract( BSONObj doc,
- const BSONField<Date_t>& field,
- Date_t* out,
- string* errMsg ) {
- return extract( doc[field.name()], field, out, errMsg );
+ if (elem.type() == Object) {
+ *out = elem.embeddedObject().getOwned();
+ return FIELD_SET;
}
-
- FieldParser::FieldState FieldParser::extract( BSONElement elem,
- const BSONField<Date_t>& field,
- Date_t* out,
- string* errMsg )
- {
- if (elem.eoo()) {
- if (field.hasDefault()) {
- *out = field.getDefault();
- return FIELD_DEFAULT;
- }
- else {
- return FIELD_NONE;
- }
- }
-
- if (elem.type() == Date) {
- *out = elem.date();
- return FIELD_SET;
+ _genFieldErrMsg(elem, field, "object", errMsg);
+ return FIELD_INVALID;
+}
+
+FieldParser::FieldState FieldParser::extract(BSONObj doc,
+ const BSONField<Date_t>& field,
+ Date_t* out,
+ string* errMsg) {
+ return extract(doc[field.name()], field, out, errMsg);
+}
+
+
+FieldParser::FieldState FieldParser::extract(BSONElement elem,
+ const BSONField<Date_t>& field,
+ Date_t* out,
+ string* errMsg) {
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ *out = field.getDefault();
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
}
-
- _genFieldErrMsg(elem, field, "date", errMsg);
- return FIELD_INVALID;
}
- FieldParser::FieldState FieldParser::extract( BSONObj doc,
- const BSONField<Timestamp>& field,
- Timestamp* out,
- string* errMsg ) {
- return extract( doc[field.name()], field, out, errMsg );
+ if (elem.type() == Date) {
+ *out = elem.date();
+ return FIELD_SET;
}
-
- FieldParser::FieldState FieldParser::extract( BSONElement elem,
- const BSONField<Timestamp>& field,
- Timestamp* out,
- string* errMsg )
- {
- if (elem.eoo()) {
- if (field.hasDefault()) {
- *out = field.getDefault();
- return FIELD_DEFAULT;
- }
- else {
- return FIELD_NONE;
- }
+ _genFieldErrMsg(elem, field, "date", errMsg);
+ return FIELD_INVALID;
+}
+
+FieldParser::FieldState FieldParser::extract(BSONObj doc,
+ const BSONField<Timestamp>& field,
+ Timestamp* out,
+ string* errMsg) {
+ return extract(doc[field.name()], field, out, errMsg);
+}
+
+
+FieldParser::FieldState FieldParser::extract(BSONElement elem,
+ const BSONField<Timestamp>& field,
+ Timestamp* out,
+ string* errMsg) {
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ *out = field.getDefault();
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
}
-
- if (elem.type() == bsonTimestamp) {
- *out = elem.timestamp();
- return FIELD_SET;
- }
-
- _genFieldErrMsg(elem, field, "timestamp", errMsg);
- return FIELD_INVALID;
}
- FieldParser::FieldState FieldParser::extract( BSONObj doc,
- const BSONField<string>& field,
- string* out,
- string* errMsg ) {
- return extract( doc[field.name()], field, out, errMsg );
+ if (elem.type() == bsonTimestamp) {
+ *out = elem.timestamp();
+ return FIELD_SET;
}
- FieldParser::FieldState FieldParser::extract( BSONElement elem,
- const BSONField<string>& field,
- string* out,
- string* errMsg )
- {
- if (elem.eoo()) {
- if (field.hasDefault()) {
- *out = field.getDefault();
- return FIELD_DEFAULT;
- }
- else {
- return FIELD_NONE;
- }
- }
-
- if (elem.type() == String) {
- // Extract everything, including embedded null characters.
- *out = string(elem.valuestr(), elem.valuestrsize() - 1);
- return FIELD_SET;
+ _genFieldErrMsg(elem, field, "timestamp", errMsg);
+ return FIELD_INVALID;
+}
+
+FieldParser::FieldState FieldParser::extract(BSONObj doc,
+ const BSONField<string>& field,
+ string* out,
+ string* errMsg) {
+ return extract(doc[field.name()], field, out, errMsg);
+}
+
+FieldParser::FieldState FieldParser::extract(BSONElement elem,
+ const BSONField<string>& field,
+ string* out,
+ string* errMsg) {
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ *out = field.getDefault();
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
}
-
- _genFieldErrMsg(elem, field, "string", errMsg);
- return FIELD_INVALID;
}
- FieldParser::FieldState FieldParser::extract( BSONObj doc,
- const BSONField<OID>& field,
- OID* out,
- string* errMsg ) {
- return extract( doc[field.name()], field, out, errMsg );
+ if (elem.type() == String) {
+ // Extract everything, including embedded null characters.
+ *out = string(elem.valuestr(), elem.valuestrsize() - 1);
+ return FIELD_SET;
}
-
- FieldParser::FieldState FieldParser::extract( BSONElement elem,
- const BSONField<OID>& field,
- OID* out,
- string* errMsg )
- {
- if (elem.eoo()) {
- if (field.hasDefault()) {
- *out = field.getDefault();
- return FIELD_DEFAULT;
- }
- else {
- return FIELD_NONE;
- }
+ _genFieldErrMsg(elem, field, "string", errMsg);
+ return FIELD_INVALID;
+}
+
+FieldParser::FieldState FieldParser::extract(BSONObj doc,
+ const BSONField<OID>& field,
+ OID* out,
+ string* errMsg) {
+ return extract(doc[field.name()], field, out, errMsg);
+}
+
+
+FieldParser::FieldState FieldParser::extract(BSONElement elem,
+ const BSONField<OID>& field,
+ OID* out,
+ string* errMsg) {
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ *out = field.getDefault();
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
}
-
- if (elem.type() == jstOID) {
- *out = elem.__oid();
- return FIELD_SET;
- }
-
- _genFieldErrMsg(elem, field, "OID", errMsg);
- return FIELD_INVALID;
}
- FieldParser::FieldState FieldParser::extract( BSONObj doc,
- const BSONField<int>& field,
- int* out,
- string* errMsg ) {
- return extract( doc[field.name()], field, out, errMsg );
+ if (elem.type() == jstOID) {
+ *out = elem.__oid();
+ return FIELD_SET;
}
- FieldParser::FieldState FieldParser::extract( BSONElement elem,
- const BSONField<int>& field,
- int* out,
- string* errMsg )
- {
- if (elem.eoo()) {
- if (field.hasDefault()) {
- *out = field.getDefault();
- return FIELD_DEFAULT;
- }
- else {
- return FIELD_NONE;
- }
+ _genFieldErrMsg(elem, field, "OID", errMsg);
+ return FIELD_INVALID;
+}
+
+FieldParser::FieldState FieldParser::extract(BSONObj doc,
+ const BSONField<int>& field,
+ int* out,
+ string* errMsg) {
+ return extract(doc[field.name()], field, out, errMsg);
+}
+
+FieldParser::FieldState FieldParser::extract(BSONElement elem,
+ const BSONField<int>& field,
+ int* out,
+ string* errMsg) {
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ *out = field.getDefault();
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
}
-
- if (elem.type() == NumberInt) {
- *out = elem.numberInt();
- return FIELD_SET;
- }
-
- _genFieldErrMsg(elem, field, "integer", errMsg);
- return FIELD_INVALID;
}
- FieldParser::FieldState FieldParser::extractNumber( BSONObj doc,
- const BSONField<int>& field,
- int* out,
- string* errMsg ) {
- return extractNumber( doc[field.name()], field, out, errMsg );
+ if (elem.type() == NumberInt) {
+ *out = elem.numberInt();
+ return FIELD_SET;
}
- FieldParser::FieldState FieldParser::extractNumber( BSONElement elem,
- const BSONField<int>& field,
- int* out,
- string* errMsg ) {
- if (elem.eoo()) {
- if (field.hasDefault()) {
- *out = field.getDefault();
- return FIELD_DEFAULT;
- }
- else {
- return FIELD_NONE;
- }
+ _genFieldErrMsg(elem, field, "integer", errMsg);
+ return FIELD_INVALID;
+}
+
+FieldParser::FieldState FieldParser::extractNumber(BSONObj doc,
+ const BSONField<int>& field,
+ int* out,
+ string* errMsg) {
+ return extractNumber(doc[field.name()], field, out, errMsg);
+}
+
+FieldParser::FieldState FieldParser::extractNumber(BSONElement elem,
+ const BSONField<int>& field,
+ int* out,
+ string* errMsg) {
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ *out = field.getDefault();
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
}
-
- if (elem.isNumber()) {
- *out = elem.numberInt();
- return FIELD_SET;
- }
-
- _genFieldErrMsg(elem, field, "number", errMsg);
- return FIELD_INVALID;
}
- FieldParser::FieldState FieldParser::extract( BSONObj doc,
- const BSONField<long long>& field,
- long long* out,
- string* errMsg ) {
- return extract( doc[field.name()], field, out, errMsg );
+ if (elem.isNumber()) {
+ *out = elem.numberInt();
+ return FIELD_SET;
}
- FieldParser::FieldState FieldParser::extract( BSONElement elem,
- const BSONField<long long>& field,
- long long* out,
- string* errMsg )
- {
- if (elem.eoo()) {
- if (field.hasDefault()) {
- *out = field.getDefault();
- return FIELD_DEFAULT;
- }
- else {
- return FIELD_NONE;
- }
- }
-
- if (elem.type() == NumberLong) {
- *out = elem.numberLong();
- return FIELD_SET;
+ _genFieldErrMsg(elem, field, "number", errMsg);
+ return FIELD_INVALID;
+}
+
+FieldParser::FieldState FieldParser::extract(BSONObj doc,
+ const BSONField<long long>& field,
+ long long* out,
+ string* errMsg) {
+ return extract(doc[field.name()], field, out, errMsg);
+}
+
+FieldParser::FieldState FieldParser::extract(BSONElement elem,
+ const BSONField<long long>& field,
+ long long* out,
+ string* errMsg) {
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ *out = field.getDefault();
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
}
-
- _genFieldErrMsg(elem, field, "long", errMsg);
- return FIELD_INVALID;
}
- FieldParser::FieldState FieldParser::extractNumber( BSONObj doc,
- const BSONField<long long>& field,
- long long* out,
- string* errMsg ) {
- return extractNumber( doc[field.name()], field, out, errMsg );
+ if (elem.type() == NumberLong) {
+ *out = elem.numberLong();
+ return FIELD_SET;
}
- FieldParser::FieldState FieldParser::extractNumber( BSONElement elem,
- const BSONField<long long>& field,
- long long* out,
- string* errMsg ) {
- if (elem.eoo()) {
- if (field.hasDefault()) {
- *out = field.getDefault();
- return FIELD_DEFAULT;
- }
- else {
- return FIELD_NONE;
- }
+ _genFieldErrMsg(elem, field, "long", errMsg);
+ return FIELD_INVALID;
+}
+
+FieldParser::FieldState FieldParser::extractNumber(BSONObj doc,
+ const BSONField<long long>& field,
+ long long* out,
+ string* errMsg) {
+ return extractNumber(doc[field.name()], field, out, errMsg);
+}
+
+FieldParser::FieldState FieldParser::extractNumber(BSONElement elem,
+ const BSONField<long long>& field,
+ long long* out,
+ string* errMsg) {
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ *out = field.getDefault();
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
}
-
- if (elem.isNumber()) {
- *out = elem.numberLong();
- return FIELD_SET;
- }
-
- _genFieldErrMsg(elem, field, "number", errMsg);
- return FIELD_INVALID;
}
- FieldParser::FieldState FieldParser::extract( BSONObj doc,
- const BSONField<double>& field,
- double* out,
- string* errMsg ) {
- return extract( doc[field.name()], field, out, errMsg );
+ if (elem.isNumber()) {
+ *out = elem.numberLong();
+ return FIELD_SET;
}
- FieldParser::FieldState FieldParser::extract( BSONElement elem,
- const BSONField<double>& field,
- double* out,
- string* errMsg )
- {
- if (elem.eoo()) {
- if (field.hasDefault()) {
- *out = field.getDefault();
- return FIELD_DEFAULT;
- }
- else {
- return FIELD_NONE;
- }
- }
-
- if (elem.type() == NumberDouble) {
- *out = elem.numberDouble();
- return FIELD_SET;
+ _genFieldErrMsg(elem, field, "number", errMsg);
+ return FIELD_INVALID;
+}
+
+FieldParser::FieldState FieldParser::extract(BSONObj doc,
+ const BSONField<double>& field,
+ double* out,
+ string* errMsg) {
+ return extract(doc[field.name()], field, out, errMsg);
+}
+
+FieldParser::FieldState FieldParser::extract(BSONElement elem,
+ const BSONField<double>& field,
+ double* out,
+ string* errMsg) {
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ *out = field.getDefault();
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
}
-
- _genFieldErrMsg(elem, field, "double", errMsg);
- return FIELD_INVALID;
}
- FieldParser::FieldState FieldParser::extractNumber( BSONObj doc,
- const BSONField<double>& field,
- double* out,
- string* errMsg ) {
- return extractNumber( doc[field.name()], field, out, errMsg );
+ if (elem.type() == NumberDouble) {
+ *out = elem.numberDouble();
+ return FIELD_SET;
}
- FieldParser::FieldState FieldParser::extractNumber( BSONElement elem,
- const BSONField<double>& field,
- double* out,
- string* errMsg ) {
- if (elem.eoo()) {
- if (field.hasDefault()) {
- *out = field.getDefault();
- return FIELD_DEFAULT;
- }
- else {
- return FIELD_NONE;
- }
- }
-
- if (elem.isNumber()) {
- *out = elem.numberDouble();
- return FIELD_SET;
+ _genFieldErrMsg(elem, field, "double", errMsg);
+ return FIELD_INVALID;
+}
+
+FieldParser::FieldState FieldParser::extractNumber(BSONObj doc,
+ const BSONField<double>& field,
+ double* out,
+ string* errMsg) {
+ return extractNumber(doc[field.name()], field, out, errMsg);
+}
+
+FieldParser::FieldState FieldParser::extractNumber(BSONElement elem,
+ const BSONField<double>& field,
+ double* out,
+ string* errMsg) {
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ *out = field.getDefault();
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
}
-
- _genFieldErrMsg(elem, field, "number", errMsg);
- return FIELD_INVALID;
}
- FieldParser::FieldState FieldParser::extractID( BSONObj doc,
- const BSONField<BSONObj>& field,
- BSONObj* out,
- string* errMsg ) {
- return extractID( doc[field.name()], field, out, errMsg );
+ if (elem.isNumber()) {
+ *out = elem.numberDouble();
+ return FIELD_SET;
}
- FieldParser::FieldState FieldParser::extractID( BSONElement elem,
- const BSONField<BSONObj>& field,
- BSONObj* out,
- string* errMsg ) {
- if (elem.eoo()) {
- if (field.hasDefault()) {
- *out = field.getDefault().firstElement().wrap( "" );
- return FIELD_DEFAULT;
- }
- else {
- return FIELD_NONE;
- }
- }
-
- if ( elem.type() != Array ) {
- *out = elem.wrap( "" ).getOwned();
- return FIELD_SET;
+ _genFieldErrMsg(elem, field, "number", errMsg);
+ return FIELD_INVALID;
+}
+
+FieldParser::FieldState FieldParser::extractID(BSONObj doc,
+ const BSONField<BSONObj>& field,
+ BSONObj* out,
+ string* errMsg) {
+ return extractID(doc[field.name()], field, out, errMsg);
+}
+
+FieldParser::FieldState FieldParser::extractID(BSONElement elem,
+ const BSONField<BSONObj>& field,
+ BSONObj* out,
+ string* errMsg) {
+ if (elem.eoo()) {
+ if (field.hasDefault()) {
+ *out = field.getDefault().firstElement().wrap("");
+ return FIELD_DEFAULT;
+ } else {
+ return FIELD_NONE;
}
+ }
- _genFieldErrMsg(elem, field, "id", errMsg);
- return FIELD_INVALID;
+ if (elem.type() != Array) {
+ *out = elem.wrap("").getOwned();
+ return FIELD_SET;
}
-} // namespace mongo
+ _genFieldErrMsg(elem, field, "id", errMsg);
+ return FIELD_INVALID;
+}
+
+} // namespace mongo