summaryrefslogtreecommitdiff
path: root/src/mongo/db/field_parser.h
diff options
context:
space:
mode:
authorAlberto Lerner <alerner@10gen.com>2013-09-01 14:43:08 -0400
committerAlberto Lerner <alerner@10gen.com>2013-09-12 10:51:48 -0400
commite82786a9f03cb18e924f72f787e184740576111b (patch)
treecdcc1b7922a994fd681e2cfb234fe645414822f9 /src/mongo/db/field_parser.h
parent98c273d6a9a0aa62182e46ef5c45ed5549d7ce04 (diff)
downloadmongo-e82786a9f03cb18e924f72f787e184740576111b.tar.gz
SERVER-10521 Types for write commands.
Diffstat (limited to 'src/mongo/db/field_parser.h')
-rw-r--r--src/mongo/db/field_parser.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/mongo/db/field_parser.h b/src/mongo/db/field_parser.h
index 498c530a6d7..cbf27544ce8 100644
--- a/src/mongo/db/field_parser.h
+++ b/src/mongo/db/field_parser.h
@@ -32,6 +32,7 @@
#include "mongo/bson/bson_field.h"
#include "mongo/db/jsobj.h"
+#include "mongo/s/bson_serializable.h"
#include "mongo/util/time_support.h"
namespace mongo {
@@ -121,6 +122,68 @@ namespace mongo {
string* errMsg = NULL);
/**
+ * Extracts a mandatory BSONSerializable structure 'field' from the object 'doc'. Write
+ * the extracted contents to '*out' if successful or fills '*errMsg', if exising,
+ * otherwise. This variant relies on T having a parseBSON, which all
+ * BSONSerializable's have.
+ *
+ * TODO: Tighten for BSONSerializable's only
+ */
+ template<typename T>
+ static FieldState extract(BSONObj doc,
+ const BSONField<T>& field,
+ T* out,
+ string* errMsg = NULL);
+
+ /**
+ * Similar to the mandatory 'extract' but on a optional field. '*out' would only be
+ * allocated if the field is present. The ownership of '*out' would be transferred to
+ * the caller, in that case.
+ *
+ * TODO: Tighten for BSONSerializable's only
+ */
+ template<typename T>
+ static FieldState extract(BSONObj doc,
+ const BSONField<T>& field,
+ T** out, // alloc variation
+ string* errMsg = NULL);
+
+ /**
+ * Extracts a mandatory repetition of BSONSerializable structures, 'field', from the
+ * object 'doc'. Write the extracted contents to '*out' if successful or fills
+ * '*errMsg', if exising, otherwise. This variant relies on T having a parseBSON,
+ * which all BSONSerializable's have.
+ *
+ * The vector owns the instances of T.
+ *
+ * TODO: Tighten for BSONSerializable's only
+ */
+ template<typename T>
+ static FieldState extract(BSONObj doc,
+ const BSONField<vector<T*> >& field,
+ vector<T*>* out,
+ string* errMsg = NULL);
+
+ /**
+ * Similar to the mandatory repetition' extract but on an optional field. '*out' would
+ * only be allocated if the field is present. The ownership of '*out' would be
+ * transferred to the caller, in that case.
+ *
+ * The vector owns the instances of T.
+ *
+ * TODO: Tighten for BSONSerializable's only
+ */
+ template<typename T>
+ static FieldState extract(BSONObj doc,
+ const BSONField<vector<T*> >& field,
+ vector<T*>** out,
+ string* errMsg = NULL);
+
+ //
+ // ==================== Below DEPRECATED; use types instead ====================
+ //
+
+ /**
* The following extract methods are templatized to handle extraction of vectors and
* maps of sub-objects. Keys in the map should be StringData compatible.
*
@@ -140,6 +203,10 @@ namespace mongo {
const BSONField<map<K, T> >& field,
map<K, T>* out,
string* errMsg = NULL);
+
+ private:
+ template<typename T>
+ static void clearOwnedVector(vector<T*>* vec);
};
} // namespace mongo