mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-25 10:09:36 +02:00
Add method addNewDocument and return a reference of the active document in the add methods to allow chaining these methods ...
This commit is contained in:
@@ -86,27 +86,36 @@ public:
|
|||||||
/// Destructor
|
/// Destructor
|
||||||
|
|
||||||
|
|
||||||
void addElement(Element::Ptr element);
|
Document& addElement(Element::Ptr element);
|
||||||
/// Add an element to the document
|
/// Add an element to the document.
|
||||||
|
/// The active document is returned to allow chaining of the add methods.
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void add(const std::string& name, T value)
|
Document& add(const std::string& name, T value)
|
||||||
/// Creates an element with the given name and value
|
/// Creates an element with the given name and value and
|
||||||
// adds it to the document.
|
// adds it to the document.
|
||||||
|
/// The active document is returned to allow chaining of the add methods.
|
||||||
{
|
{
|
||||||
addElement(new ConcreteElement<T>(name, value));
|
return addElement(new ConcreteElement<T>(name, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void add(const std::string& name, const char* value)
|
Document& add(const std::string& name, const char* value)
|
||||||
/// Creates an element with the given name and value
|
/// Creates an element with the given name and value and
|
||||||
// adds it to the document.
|
// adds it to the document.
|
||||||
|
/// The active document is returned to allow chaining of the add methods.
|
||||||
{
|
{
|
||||||
addElement(new ConcreteElement<std::string>(name, std::string(value)));
|
return addElement(new ConcreteElement<std::string>(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();
|
void clear();
|
||||||
/// Removes all elements from the document.
|
/// 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()
|
inline void Document::clear()
|
||||||
{
|
{
|
||||||
_elements.clear();
|
_elements.clear();
|
||||||
|
|||||||
@@ -220,9 +220,5 @@ void Document::write(BinaryWriter& writer)
|
|||||||
writer << '\0';
|
writer << '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
void Document::addElement(Element::Ptr element)
|
|
||||||
{
|
|
||||||
_elements.insert(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
}} // Namespace Poco::MongoDB
|
}} // Namespace Poco::MongoDB
|
||||||
|
|||||||
Reference in New Issue
Block a user