2
* Copyright (C) 2012 10gen Inc.
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.
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.
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/>.
21
#include "mongo/base/disallow_copying.h"
22
#include "mongo/base/string_data.h"
23
#include "mongo/db/jsobj.h"
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.
34
* // Contact the config. 'conn' has been obtained before.
36
* BSONObj query = QUERY(TagsType::exampleField("exampleFieldName"));
37
* exampleDoc = conn->findOne(TagsType::ConfigNS, query);
39
* // Process the response.
40
* TagsType exampleType;
42
* if (!exampleType.parseBSON(exampleDoc, &errMsg) || !exampleType.isValid(&errMsg)) {
43
* // Can't use 'exampleType'. Take action.
45
* // use 'exampleType'
49
MONGO_DISALLOW_COPYING(TagsType);
53
// schema declarations
56
// Name of the tags collection in the config server.
57
static const std::string ConfigNS;
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;
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.
76
bool isValid(std::string* errMsg) const;
79
* Returns the BSON representation of the entry.
81
BSONObj toBSON() const;
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.
87
bool parseBSON(const BSONObj& source, std::string* errMsg);
90
* Clears the internal state.
95
* Copies all the fields present in 'this' to 'other'.
97
void cloneTo(TagsType* other) const;
100
* Returns a string representation of the current internal state.
102
std::string toString() const;
105
// individual field accessors
109
void setNS(const StringData& ns) {
114
void unsetNS() { _isNsSet = false; }
116
bool isNSSet() const { return _isNsSet; }
118
// Calling get*() methods when the member is not set results in undefined behavior
119
const std::string& getNS() const {
124
void setTag(const StringData& tag) {
125
_tag = tag.toString();
129
void unsetTag() { _isTagSet = false; }
131
bool isTagSet() const { return _isTagSet; }
133
// Calling get*() methods when the member is not set results in undefined behavior
134
const std::string& getTag() const {
139
void setMin(const BSONObj& min) {
140
_min = min.getOwned();
144
void unsetMin() { _isMinSet = false; }
146
bool isMinSet() const { return _isMinSet; }
148
// Calling get*() methods when the member is not set results in undefined behavior
149
const BSONObj getMin() const {
154
void setMax(const BSONObj& max) {
155
_max = max.getOwned();
159
void unsetMax() { _isMaxSet = false; }
161
bool isMaxSet() const { return _isMaxSet; }
163
// Calling get*() methods when the member is not set results in undefined behavior
164
const BSONObj getMax() const {
172
// Convention: (M)andatory, (O)ptional, (S)pecial rule.
173
std::string _ns; // (M) namespace this tag is for
175
std::string _tag; // (M) tag name
177
BSONObj _min; // (M) first key of the tag, including
179
BSONObj _max; // (M) last key of the tag, non-including