summaryrefslogtreecommitdiff
path: root/src/mongo/s/mongo_version_range.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s/mongo_version_range.cpp')
-rw-r--r--src/mongo/s/mongo_version_range.cpp208
1 files changed, 98 insertions, 110 deletions
diff --git a/src/mongo/s/mongo_version_range.cpp b/src/mongo/s/mongo_version_range.cpp
index 82870e20418..7ac4b2c4474 100644
--- a/src/mongo/s/mongo_version_range.cpp
+++ b/src/mongo/s/mongo_version_range.cpp
@@ -32,147 +32,135 @@
namespace mongo {
- using std::string;
- using std::vector;
-
- bool MongoVersionRange::parseBSONArray(const BSONArray& arr,
- vector<MongoVersionRange>* excludes,
- std::string* errMsg)
- {
- string dummy;
- if (!errMsg) errMsg = &dummy;
-
- BSONObjIterator it(arr);
-
- while (it.more()) {
- MongoVersionRange range;
- if (!range.parseBSONElement(it.next(), errMsg)) return false;
- excludes->push_back(range);
- }
-
- return true;
- }
-
- BSONArray MongoVersionRange::toBSONArray(const vector<MongoVersionRange>& ranges) {
+using std::string;
+using std::vector;
- BSONArrayBuilder barr;
+bool MongoVersionRange::parseBSONArray(const BSONArray& arr,
+ vector<MongoVersionRange>* excludes,
+ std::string* errMsg) {
+ string dummy;
+ if (!errMsg)
+ errMsg = &dummy;
- for (vector<MongoVersionRange>::const_iterator it = ranges.begin(); it != ranges.end();
- ++it)
- {
- const MongoVersionRange& range = *it;
- range.toBSONElement(&barr);
- }
+ BSONObjIterator it(arr);
- return barr.arr();
+ while (it.more()) {
+ MongoVersionRange range;
+ if (!range.parseBSONElement(it.next(), errMsg))
+ return false;
+ excludes->push_back(range);
}
- bool MongoVersionRange::parseBSONElement(const BSONElement& el, string* errMsg) {
-
- string dummy;
- if (!errMsg) errMsg = &dummy;
+ return true;
+}
- if (el.type() == String) {
- minVersion = el.String();
- if (minVersion == "") {
- *errMsg = (string) "cannot parse single empty mongo version (" + el.toString()
- + ")";
- return false;
- }
- return true;
- }
- else if (el.type() == Array || el.type() == Object) {
+BSONArray MongoVersionRange::toBSONArray(const vector<MongoVersionRange>& ranges) {
+ BSONArrayBuilder barr;
- BSONObj range = el.Obj();
+ for (vector<MongoVersionRange>::const_iterator it = ranges.begin(); it != ranges.end(); ++it) {
+ const MongoVersionRange& range = *it;
+ range.toBSONElement(&barr);
+ }
- if (range.nFields() != 2) {
- *errMsg = (string) "not enough fields in mongo version range (" + el.toString()
- + ")";
- return false;
- }
+ return barr.arr();
+}
- BSONObjIterator it(range);
+bool MongoVersionRange::parseBSONElement(const BSONElement& el, string* errMsg) {
+ string dummy;
+ if (!errMsg)
+ errMsg = &dummy;
- BSONElement subElA = it.next();
- BSONElement subElB = it.next();
+ if (el.type() == String) {
+ minVersion = el.String();
+ if (minVersion == "") {
+ *errMsg = (string) "cannot parse single empty mongo version (" + el.toString() + ")";
+ return false;
+ }
+ return true;
+ } else if (el.type() == Array || el.type() == Object) {
+ BSONObj range = el.Obj();
- if (subElA.type() != String || subElB.type() != String) {
- *errMsg = (string) "wrong field type for mongo version range (" + el.toString()
- + ")";
- return false;
- }
+ if (range.nFields() != 2) {
+ *errMsg = (string) "not enough fields in mongo version range (" + el.toString() + ")";
+ return false;
+ }
- minVersion = subElA.String();
- maxVersion = subElB.String();
+ BSONObjIterator it(range);
- if (minVersion == "") {
- *errMsg = (string) "cannot parse first empty mongo version (" + el.toString() + ")";
- return false;
- }
+ BSONElement subElA = it.next();
+ BSONElement subElB = it.next();
- if (maxVersion == "") {
- *errMsg = (string) "cannot parse second empty mongo version (" + el.toString()
- + ")";
- return false;
- }
+ if (subElA.type() != String || subElB.type() != String) {
+ *errMsg = (string) "wrong field type for mongo version range (" + el.toString() + ")";
+ return false;
+ }
- if (versionCmp(minVersion, maxVersion) > 0) {
- string swap = minVersion;
- minVersion = maxVersion;
- maxVersion = swap;
- }
+ minVersion = subElA.String();
+ maxVersion = subElB.String();
- return true;
- }
- else {
- *errMsg = (string) "wrong type for mongo version range " + el.toString();
+ if (minVersion == "") {
+ *errMsg = (string) "cannot parse first empty mongo version (" + el.toString() + ")";
return false;
}
- }
- void MongoVersionRange::toBSONElement(BSONArrayBuilder* barr) const {
if (maxVersion == "") {
- barr->append(minVersion);
+ *errMsg = (string) "cannot parse second empty mongo version (" + el.toString() + ")";
+ return false;
}
- else {
- BSONArrayBuilder rangeB(barr->subarrayStart());
-
- rangeB.append(minVersion);
- rangeB.append(maxVersion);
- rangeB.done();
+ if (versionCmp(minVersion, maxVersion) > 0) {
+ string swap = minVersion;
+ minVersion = maxVersion;
+ maxVersion = swap;
}
+
+ return true;
+ } else {
+ *errMsg = (string) "wrong type for mongo version range " + el.toString();
+ return false;
}
+}
- bool MongoVersionRange::isInRange(StringData version) const {
+void MongoVersionRange::toBSONElement(BSONArrayBuilder* barr) const {
+ if (maxVersion == "") {
+ barr->append(minVersion);
+ } else {
+ BSONArrayBuilder rangeB(barr->subarrayStart());
- if (maxVersion == "") {
- // If a prefix of the version specified is excluded, the specified version is
- // excluded
- if (version.find(minVersion) == 0) return true;
- }
- else {
- // Range is inclusive, so make sure the end and beginning prefix excludes all
- // prefixed versions as above
- if (version.find(minVersion) == 0) return true;
- if (version.find(maxVersion) == 0) return true;
- if (versionCmp(minVersion, version) <= 0 && versionCmp(maxVersion, version) >= 0) {
- return true;
- }
- }
+ rangeB.append(minVersion);
+ rangeB.append(maxVersion);
- return false;
+ rangeB.done();
}
+}
- bool isInMongoVersionRanges(StringData version, const vector<MongoVersionRange>& ranges)
- {
- for (vector<MongoVersionRange>::const_iterator it = ranges.begin(); it != ranges.end();
- ++it)
- {
- if (it->isInRange(version)) return true;
+bool MongoVersionRange::isInRange(StringData version) const {
+ if (maxVersion == "") {
+ // If a prefix of the version specified is excluded, the specified version is
+ // excluded
+ if (version.find(minVersion) == 0)
+ return true;
+ } else {
+ // Range is inclusive, so make sure the end and beginning prefix excludes all
+ // prefixed versions as above
+ if (version.find(minVersion) == 0)
+ return true;
+ if (version.find(maxVersion) == 0)
+ return true;
+ if (versionCmp(minVersion, version) <= 0 && versionCmp(maxVersion, version) >= 0) {
+ return true;
}
+ }
- return false;
+ return false;
+}
+
+bool isInMongoVersionRanges(StringData version, const vector<MongoVersionRange>& ranges) {
+ for (vector<MongoVersionRange>::const_iterator it = ranges.begin(); it != ranges.end(); ++it) {
+ if (it->isInRange(version))
+ return true;
}
+ return false;
+}
}