26 _builders.push_back(std::make_pair(
"", b));
30 void prepareContext(std::string& name) {
31 int i = 1, n = _builders.size();
33 i < n && name.substr(0, _builders[i].first.length()) == _builders[i].first &&
34 (name[_builders[i].first.length()] ==
'.' || name[_builders[i].first.length()] == 0)) {
35 name = name.substr(_builders[i].first.length() + 1);
38 for (
int j = n - 1; j >= i; --j) {
41 for (std::string next = splitDot(name); !next.empty(); next = splitDot(name)) {
45 void appendAs(
const BSONElement& e, std::string name) {
48 std::string dummyName = name +
".foo";
49 prepareContext(dummyName);
55 BufBuilder& subarrayStartAs(std::string name) {
60 while (!_builderStorage.empty())
64 static std::string splitDot(std::string& str) {
65 size_t pos = str.find(
'.');
66 if (pos == std::string::npos)
68 std::string ret = str.substr(0, pos);
69 str = str.substr(pos + 1);
74 void addBuilder(
const std::string& name) {
75 boost::shared_ptr<BSONObjBuilder> newBuilder(
new BSONObjBuilder(back()->subobjStart(name)));
76 _builders.push_back(std::make_pair(name, newBuilder.get()));
77 _builderStorage.push_back(newBuilder);
82 _builderStorage.pop_back();
86 return _builders.back().second;
89 std::vector<std::pair<std::string, BSONObjBuilder*> > _builders;
90 std::vector<boost::shared_ptr<BSONObjBuilder> > _builderStorage;
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
BufBuilder & subarrayStart(const StringData &fieldName)
add header for a new subarray and return bufbuilder for writing to the subarray's body ...
Definition: bsonobjbuilder.h:200
Utility for creating a BSONObj.
Definition: bsonobjbuilder.h:53
BSONObj done()
Fetch the object we have built.
Definition: bsonobjbuilder.h:631
BSONType type() const
Returns the type of the element.
Definition: bsonelement.h:154
an embedded object
Definition: bsontypes.h:48
int valuesize() const
size in bytes of the element's value (when applicable).
Definition: bsonelement.h:216
BSONObjBuilder & appendAs(const BSONElement &e, const StringData &fieldName)
append an element but with a new name
Definition: bsonobjbuilder.h:132
BSONElement represents an "element" in a BSONObj.
Definition: bsonelement.h:55
Definition: embedded_builder.h:23