~evarlast/ubuntu/utopic/mongodb/upstart-workaround-debian-bug-718702

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): James Page, James Page, Robie Basak
  • Date: 2013-05-29 17:44:42 UTC
  • mfrom: (44.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20130529174442-z0a4qmoww4y0t458
Tags: 1:2.4.3-1ubuntu1
[ James Page ]
* Merge from Debian unstable, remaining changes:
  - Enable SSL support:
    + d/control: Add libssl-dev to BD's.
    + d/rules: Enabled --ssl option.
    + d/mongodb.conf: Add example SSL configuration options.
  - d/mongodb-server.mongodb.upstart: Add upstart configuration.
  - d/rules: Don't strip binaries during scons build for Ubuntu.
  - d/control: Add armhf to target archs.
  - d/p/SConscript.client.patch: fixup install of client libraries.
  - d/p/0010-install-libs-to-usr-lib-not-usr-lib64-Closes-588557.patch:
    Install libraries to lib not lib64.
* Dropped changes:
  - d/p/arm-support.patch: Included in Debian.
  - d/p/double-alignment.patch: Included in Debian.
  - d/rules,control: Debian also builds with avaliable system libraries
    now.
* Fix FTBFS due to gcc and boost upgrades in saucy:
  - d/p/0008-ignore-unused-local-typedefs.patch: Add -Wno-unused-typedefs
    to unbreak building with g++-4.8.
  - d/p/0009-boost-1.53.patch: Fixup signed/unsigned casting issue.

[ Robie Basak ]
* d/p/0011-Use-a-signed-char-to-store-BSONType-enumerations.patch: Fixup
  build failure on ARM due to missing signed'ness of char cast.

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/base/disallow_copying.h"
 
22
#include "mongo/base/string_data.h"
 
23
#include "mongo/db/jsobj.h"
 
24
 
 
25
namespace mongo {
 
26
 
 
27
    /**
 
28
     * This class represents the layout and contents of documents contained in the
 
29
     * config.tags collection. All manipulation of documents coming from that
 
30
     * collection should be done with this class.
 
31
     *
 
32
     * Usage Example:
 
33
     *
 
34
     *     // Contact the config. 'conn' has been obtained before.
 
35
     *     DBClientBase* conn;
 
36
     *     BSONObj query = QUERY(TagsType::exampleField("exampleFieldName"));
 
37
     *     exampleDoc = conn->findOne(TagsType::ConfigNS, query);
 
38
     *
 
39
     *     // Process the response.
 
40
     *     TagsType exampleType;
 
41
     *     string errMsg;
 
42
     *     if (!exampleType.parseBSON(exampleDoc, &errMsg) || !exampleType.isValid(&errMsg)) {
 
43
     *         // Can't use 'exampleType'. Take action.
 
44
     *     }
 
45
     *     // use 'exampleType'
 
46
     *
 
47
     */
 
48
    class TagsType {
 
49
        MONGO_DISALLOW_COPYING(TagsType);
 
50
    public:
 
51
 
 
52
        //
 
53
        // schema declarations
 
54
        //
 
55
 
 
56
        // Name of the tags collection in the config server.
 
57
        static const std::string ConfigNS;
 
58
 
 
59
        // Field names and types in the tags collection type.
 
60
        static const BSONField<std::string> ns;
 
61
        static const BSONField<std::string> tag;
 
62
        static const BSONField<BSONObj> min;
 
63
        static const BSONField<BSONObj> max;
 
64
 
 
65
        //
 
66
        // tags type methods
 
67
        //
 
68
 
 
69
        TagsType();
 
70
        ~TagsType();
 
71
 
 
72
        /**
 
73
         * Returns true if all the mandatory fields are present and have valid
 
74
         * representations. Otherwise returns false and fills in the optional 'errMsg' string.
 
75
         */
 
76
        bool isValid(std::string* errMsg) const;
 
77
 
 
78
        /**
 
79
         * Returns the BSON representation of the entry.
 
80
         */
 
81
        BSONObj toBSON() const;
 
82
 
 
83
        /**
 
84
         * Clears and populates the internal state using the 'source' BSON object if the
 
85
         * latter contains valid values. Otherwise sets errMsg and returns false.
 
86
         */
 
87
        bool parseBSON(const BSONObj& source, std::string* errMsg);
 
88
 
 
89
        /**
 
90
         * Clears the internal state.
 
91
         */
 
92
        void clear();
 
93
 
 
94
        /**
 
95
         * Copies all the fields present in 'this' to 'other'.
 
96
         */
 
97
        void cloneTo(TagsType* other) const;
 
98
 
 
99
        /**
 
100
         * Returns a string representation of the current internal state.
 
101
         */
 
102
        std::string toString() const;
 
103
 
 
104
        //
 
105
        // individual field accessors
 
106
        //
 
107
 
 
108
        // Mandatory Fields
 
109
        void setNS(const StringData& ns) {
 
110
            _ns = ns.toString();
 
111
            _isNsSet = true;
 
112
        }
 
113
 
 
114
        void unsetNS() { _isNsSet = false; }
 
115
 
 
116
        bool isNSSet() const { return _isNsSet; }
 
117
 
 
118
        // Calling get*() methods when the member is not set results in undefined behavior
 
119
        const std::string& getNS() const {
 
120
            dassert(_isNsSet);
 
121
            return _ns;
 
122
        }
 
123
 
 
124
        void setTag(const StringData& tag) {
 
125
            _tag = tag.toString();
 
126
            _isTagSet = true;
 
127
        }
 
128
 
 
129
        void unsetTag() { _isTagSet = false; }
 
130
 
 
131
        bool isTagSet() const { return _isTagSet; }
 
132
 
 
133
        // Calling get*() methods when the member is not set results in undefined behavior
 
134
        const std::string& getTag() const {
 
135
            dassert(_isTagSet);
 
136
            return _tag;
 
137
        }
 
138
 
 
139
        void setMin(const BSONObj& min) {
 
140
            _min = min.getOwned();
 
141
            _isMinSet = true;
 
142
        }
 
143
 
 
144
        void unsetMin() { _isMinSet = false; }
 
145
 
 
146
        bool isMinSet() const { return _isMinSet; }
 
147
 
 
148
        // Calling get*() methods when the member is not set results in undefined behavior
 
149
        const BSONObj getMin() const {
 
150
            dassert(_isMinSet);
 
151
            return _min;
 
152
        }
 
153
 
 
154
        void setMax(const BSONObj& max) {
 
155
            _max = max.getOwned();
 
156
            _isMaxSet = true;
 
157
        }
 
158
 
 
159
        void unsetMax() { _isMaxSet = false; }
 
160
 
 
161
        bool isMaxSet() const { return _isMaxSet; }
 
162
 
 
163
        // Calling get*() methods when the member is not set results in undefined behavior
 
164
        const BSONObj getMax() const {
 
165
            dassert(_isMaxSet);
 
166
            return _max;
 
167
        }
 
168
 
 
169
        // Optional Fields
 
170
 
 
171
    private:
 
172
        // Convention: (M)andatory, (O)ptional, (S)pecial rule.
 
173
        std::string _ns;     // (M)  namespace this tag is for
 
174
        bool _isNsSet;
 
175
        std::string _tag;     // (M)  tag name
 
176
        bool _isTagSet;
 
177
        BSONObj _min;     // (M)  first key of the tag, including
 
178
        bool _isMinSet;
 
179
        BSONObj _max;     // (M)  last key of the tag, non-including
 
180
        bool _isMaxSet;
 
181
    };
 
182
 
 
183
} // namespace mongo