~ubuntu-branches/ubuntu/utopic/mongodb/utopic

« back to all changes in this revision

Viewing changes to src/mongo/s/field_parser.h

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-07-03 09:23:46 UTC
  • mfrom: (1.3.10) (44.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20140703092346-c5bvt46wnzougyly
Tags: 1:2.6.3-0ubuntu1
* New upstream stable release:
  - Dropped patches, included upstream:
    + 0003-All-platforms-but-Windows-find-hash-in-std-tr1.patch
    + 0008-Use-system-libstemmer.patch
    + 0011-Use-a-signed-char-to-store-BSONType-enumerations.patch
    + 0001-SERVER-12064-Atomic-operations-for-gcc-non-Intel-arc.patch
    + 0002-SERVER-12065-Support-ARM-and-AArch64-builds.patch
  - d/p/*: Refreshed/rebased remaining patches.
  - Use system provided libyaml-cpp:
    + d/control: Add libyaml-cpp-dev to BD's.
    + d/rules: Enable --with-system-yaml option.
    + d/p/fix-yaml-detection.patch: Fix detection of libyaml-cpp library.
  - d/mongodb-server.mongodb.upstart: Sync changes from upstream.
  - d/control,mongodb-dev.*: Drop mongodb-dev package; it has no reverse
    dependencies and upstream no longer install header files.
  - d/NEWS: Point users to upstream upgrade documentation for upgrades
    from 2.4 to 2.6.
* Merge from Debian unstable.
* d/control: BD on libv8-3.14-dev to ensure that transitioning to new v8
  versions is a explicit action due to changes in behaviour in >= 3.25
  (LP: #1295723).
* d/mongodb-server.prerm: Dropped debug echo call from maintainer script
  (LP: #1294455).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 *    Copyright (C) 2012 10gen Inc.
3
 
 *
4
 
 *    This program is free software: you can redistribute it and/or  modify
5
 
 *    it under the terms of the GNU Affero General Public License, version 3,
6
 
 *    as published by the Free Software Foundation.
7
 
 *
8
 
 *    This program is distributed in the hope that it will be useful,
9
 
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 *    GNU Affero General Public License for more details.
12
 
 *
13
 
 *    You should have received a copy of the GNU Affero General Public License
14
 
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 */
16
 
 
17
 
#pragma once
18
 
 
19
 
#include <string>
20
 
 
21
 
#include "mongo/bson/bson_field.h"
22
 
#include "mongo/bson/util/misc.h" // for Date_t
23
 
#include "mongo/db/jsobj.h"
24
 
 
25
 
namespace mongo {
26
 
 
27
 
    class FieldParser {
28
 
    public:
29
 
        /**
30
 
         * Returns true and fills in 'out' with the contents of the field described by 'field'
31
 
         * or with the value in 'def', depending on whether the field is present and has the
32
 
         * correct type in 'doc' or not, respectively. Otherwise, if the field exists but has
33
 
         * the wrong type, returns false.
34
 
         *
35
 
         * NOTE ON BSON OWNERSHIP:
36
 
         *
37
 
         *   The caller must assume that this class will point to data inside 'doc' without
38
 
         *   copying it. In practice this means that 'doc' MUST EXIST for as long as 'out'
39
 
         *   stays in scope.
40
 
         */
41
 
 
42
 
        enum FieldState {
43
 
            // The field is present but has the wrong type
44
 
            FIELD_INVALID = 0,
45
 
 
46
 
            // The field is present and has the correct type
47
 
            FIELD_SET,
48
 
 
49
 
            // The field is absent in the BSON object but set from default
50
 
            FIELD_DEFAULT,
51
 
 
52
 
            // The field is absent and no default was specified
53
 
            FIELD_NONE
54
 
        };
55
 
 
56
 
        static FieldState extract(BSONObj doc,
57
 
                            const BSONField<bool>& field,
58
 
                            bool* out,
59
 
                            string* errMsg = NULL);
60
 
 
61
 
        static FieldState extract(BSONObj doc,
62
 
                            const BSONField<BSONArray>& field,
63
 
                            BSONArray* out,
64
 
                            string* errMsg = NULL);
65
 
 
66
 
        static FieldState extract(BSONObj doc,
67
 
                            const BSONField<BSONObj>& field,
68
 
                            BSONObj* out,
69
 
                            string* errMsg = NULL);
70
 
 
71
 
        static FieldState extract(BSONObj doc,
72
 
                            const BSONField<Date_t>& field,
73
 
                            Date_t* out,
74
 
                            string* errMsg = NULL);
75
 
 
76
 
        static FieldState extract(BSONObj doc,
77
 
                            const BSONField<string>& field,
78
 
                            string* out,
79
 
                            string* errMsg = NULL);
80
 
 
81
 
        static FieldState extract(BSONObj doc,
82
 
                            const BSONField<OID>& field,
83
 
                            OID* out,
84
 
                            string* errMsg = NULL);
85
 
 
86
 
        static FieldState extract(BSONObj doc,
87
 
                            const BSONField<int>& field,
88
 
                            int* out,
89
 
                            string* errMsg = NULL);
90
 
 
91
 
        static FieldState extract(BSONObj doc,
92
 
                            const BSONField<long long>& field,
93
 
                            long long* out,
94
 
                            string* errMsg = NULL);
95
 
 
96
 
        /**
97
 
         * The following extractNumber methods do implicit conversion between any numeric type and
98
 
         * the BSONField type.  This can be useful when an exact numeric type is not needed, for
99
 
         * example if the field is sometimes modified from the shell which can change the type.
100
 
         */
101
 
        static FieldState extractNumber(BSONObj doc,
102
 
                                  const BSONField<int>& field,
103
 
                                  int* out,
104
 
                                  string* errMsg = NULL);
105
 
 
106
 
        static FieldState extractNumber(BSONObj doc,
107
 
                                  const BSONField<long long>& field,
108
 
                                  long long* out,
109
 
                                  string* errMsg = NULL);
110
 
 
111
 
        /**
112
 
         * The following extract methods are templatized to handle extraction of vectors and
113
 
         * maps of sub-objects.  Keys in the map should be StringData compatible.
114
 
         *
115
 
         * It's possible to nest extraction of vectors and maps to any depth, i.e:
116
 
         *
117
 
         * vector<map<string,vector<string> > > val;
118
 
         * FieldParser::extract(doc, field, val, &val);
119
 
         */
120
 
        template<typename T>
121
 
        static FieldState extract(BSONObj doc,
122
 
                            const BSONField<vector<T> >& field,
123
 
                            vector<T>* out,
124
 
                            string* errMsg = NULL);
125
 
 
126
 
        template<typename K, typename T>
127
 
        static FieldState extract(BSONObj doc,
128
 
                            const BSONField<map<K, T> >& field,
129
 
                            map<K, T>* out,
130
 
                            string* errMsg = NULL);
131
 
    };
132
 
 
133
 
} // namespace mongo
134
 
 
135
 
// Inline functions for templating
136
 
#include "field_parser-inl.h"
137