diff --git a/MongoDB/include/Poco/MongoDB/Document.h b/MongoDB/include/Poco/MongoDB/Document.h index eeb1f233f..de6884553 100644 --- a/MongoDB/include/Poco/MongoDB/Document.h +++ b/MongoDB/include/Poco/MongoDB/Document.h @@ -86,27 +86,36 @@ public: /// Destructor - void addElement(Element::Ptr element); - /// Add an element to the document + Document& addElement(Element::Ptr element); + /// Add an element to the document. + /// The active document is returned to allow chaining of the add methods. template - void add(const std::string& name, T value) - /// Creates an element with the given name and value + Document& add(const std::string& name, T value) + /// Creates an element with the given name and value and // adds it to the document. + /// The active document is returned to allow chaining of the add methods. { - addElement(new ConcreteElement(name, value)); + return addElement(new ConcreteElement(name, value)); } - void add(const std::string& name, const char* value) - /// Creates an element with the given name and value + Document& add(const std::string& name, const char* value) + /// Creates an element with the given name and value and // adds it to the document. + /// The active document is returned to allow chaining of the add methods. { - addElement(new ConcreteElement(name, std::string(value))); + return addElement(new ConcreteElement(name, std::string(value))); } + Document& addNewDocument(const std::string& name); + /// Create a new document and add it to this document. + /// Unlike the other add methods, this method returns + /// a reference to the new document. + + void clear(); /// Removes all elements from the document. @@ -212,6 +221,21 @@ protected: }; +inline Document& Document::addElement(Element::Ptr element) +{ + _elements.insert(element); + return *this; +} + + +inline Document& Document::addNewDocument(const std::string& name) +{ + Document::Ptr newDoc = new Document(); + add(name, newDoc); + return *newDoc; +} + + inline void Document::clear() { _elements.clear(); diff --git a/MongoDB/src/Document.cpp b/MongoDB/src/Document.cpp index c84a77310..90aa18fbf 100644 --- a/MongoDB/src/Document.cpp +++ b/MongoDB/src/Document.cpp @@ -220,9 +220,5 @@ void Document::write(BinaryWriter& writer) writer << '\0'; } -void Document::addElement(Element::Ptr element) -{ - _elements.insert(element); -} }} // Namespace Poco::MongoDB