summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/field_path.h
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2012-07-26 00:04:46 -0700
committerAaron <aaron@10gen.com>2012-07-26 13:57:44 -0700
commit6580d32cc4d0792034e470e851a09ade5fd252a9 (patch)
treee5f605fa7aa57fffd02b80a5d670d615408d9d86 /src/mongo/db/pipeline/field_path.h
parent8e6189095eaa2fd517481f3b1c7b757b8dcbe0ad (diff)
downloadmongo-6580d32cc4d0792034e470e851a09ade5fd252a9.tar.gz
SERVER-6592 Improve FieldPath's validation and simplify its invariants.
Diffstat (limited to 'src/mongo/db/pipeline/field_path.h')
-rwxr-xr-xsrc/mongo/db/pipeline/field_path.h38
1 files changed, 20 insertions, 18 deletions
diff --git a/src/mongo/db/pipeline/field_path.h b/src/mongo/db/pipeline/field_path.h
index 5a7c19161a0..767a106ee59 100755
--- a/src/mongo/db/pipeline/field_path.h
+++ b/src/mongo/db/pipeline/field_path.h
@@ -22,22 +22,18 @@ namespace mongo {
class FieldPath {
public:
- virtual ~FieldPath();
/**
- Constructor.
-
- @param fieldPath the dotted field path string or pre-split vector
+ * Constructor.
+ *
+ * @param fieldPath the dotted field path string or non empty pre-split vector.
+ * The constructed object will have getPathLength() > 0.
+ * Uassert if any component field names do not pass validation.
*/
FieldPath(const string& fieldPath);
FieldPath(const vector<string>& fieldPath);
/**
- Constructor.
- */
- FieldPath();
-
- /**
Get the number of path elements in the field path.
@returns the number of path elements
@@ -47,7 +43,7 @@ namespace mongo {
/**
Get a particular path element from the path.
- @param i the index of the path element
+ @param i the zero based index of the path element.
@returns the path element
*/
string getFieldName(size_t i) const;
@@ -69,13 +65,6 @@ namespace mongo {
void writePath(ostream &outStream, bool fieldPrefix) const;
/**
- Assignment operator.
-
- @param rRHS right hand side of the assignment
- */
- FieldPath &operator=(const FieldPath &rRHS);
-
- /**
Get the prefix string.
@returns the prefix string
@@ -84,10 +73,22 @@ namespace mongo {
static const char prefix[];
- /** a FieldPath like this but missing the first element (useful for recursion) */
+ /**
+ * A FieldPath like this but missing the first element (useful for recursion).
+ * Precondition getPathLength() > 1.
+ */
FieldPath tail() const;
private:
+ /** Uassert if a field name does not pass validation. */
+ static void uassertValidFieldName(const string& fieldName);
+
+ /**
+ * Push a new field name to the back of the vector of names comprising the field path.
+ * Uassert if 'fieldName' does not pass validation.
+ */
+ void pushFieldName(const string& fieldName);
+
vector<string> vFieldName;
};
}
@@ -102,6 +103,7 @@ namespace mongo {
}
inline string FieldPath::getFieldName(size_t i) const {
+ verify(i < getPathLength());
return vFieldName[i];
}