mirror of
https://gitee.com/zyjblog/oatpp.git
synced 2024-12-21 16:15:13 +08:00
add Tree object-wrapper
This commit is contained in:
parent
5460bd404d
commit
0ee2e3325d
@ -23,6 +23,7 @@
|
||||
***************************************************************************/
|
||||
|
||||
#include "./Tree.hpp"
|
||||
#include "oatpp/data/mapping/Tree.hpp"
|
||||
|
||||
namespace oatpp { namespace data { namespace type {
|
||||
|
||||
@ -37,5 +38,99 @@ Type* Tree::getType() {
|
||||
|
||||
}
|
||||
|
||||
Tree::Tree()
|
||||
: ObjectWrapper<mapping::Tree, __class::Tree>()
|
||||
{}
|
||||
|
||||
Tree::Tree(std::nullptr_t)
|
||||
: ObjectWrapper<mapping::Tree, __class::Tree>()
|
||||
{}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @param other - other Any.
|
||||
*/
|
||||
Tree::Tree(const Tree& other)
|
||||
: ObjectWrapper<mapping::Tree, __class::Tree>(other)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Move constructor.
|
||||
* @param other
|
||||
*/
|
||||
Tree::Tree(Tree&& other)
|
||||
: ObjectWrapper<mapping::Tree, __class::Tree>(std::forward<ObjectWrapper<mapping::Tree, __class::Tree>>(other))
|
||||
{}
|
||||
|
||||
Tree::Tree(const mapping::Tree& other)
|
||||
: ObjectWrapper<mapping::Tree, __class::Tree>(std::make_shared<mapping::Tree>(other))
|
||||
{}
|
||||
|
||||
Tree::Tree(mapping::Tree&& other)
|
||||
: ObjectWrapper<mapping::Tree, __class::Tree>(std::make_shared<mapping::Tree>(std::forward<mapping::Tree>(other)))
|
||||
{}
|
||||
|
||||
Tree::Tree(const std::shared_ptr<mapping::Tree>& node, const Type* const type)
|
||||
: ObjectWrapper<mapping::Tree, __class::Tree>(node, type)
|
||||
{}
|
||||
|
||||
Tree& Tree::operator = (std::nullptr_t) {
|
||||
m_ptr.reset();
|
||||
}
|
||||
|
||||
Tree& Tree::operator = (const Tree& other) {
|
||||
m_ptr = other.m_ptr;
|
||||
}
|
||||
|
||||
Tree& Tree::operator = (Tree&& other) {
|
||||
m_ptr = std::move(other.m_ptr);
|
||||
}
|
||||
|
||||
Tree& Tree::operator = (const mapping::Tree& other) {
|
||||
if(m_ptr) {
|
||||
*m_ptr = other;
|
||||
} else {
|
||||
m_ptr = std::make_shared<mapping::Tree>(other);
|
||||
}
|
||||
}
|
||||
|
||||
Tree& Tree::operator = (mapping::Tree&& other) {
|
||||
if(m_ptr) {
|
||||
*m_ptr = std::forward<mapping::Tree>(std::forward<mapping::Tree>(other));
|
||||
} else {
|
||||
m_ptr = std::make_shared<mapping::Tree>(std::forward<mapping::Tree>(other));
|
||||
}
|
||||
}
|
||||
|
||||
bool Tree::operator == (std::nullptr_t) const {
|
||||
return m_ptr.get() == nullptr;
|
||||
}
|
||||
|
||||
bool Tree::operator != (std::nullptr_t) const {
|
||||
return m_ptr.get() != nullptr;
|
||||
}
|
||||
|
||||
bool Tree::operator == (const Tree& other) const {
|
||||
return m_ptr.get() == other.m_ptr.get();
|
||||
}
|
||||
|
||||
bool Tree::operator != (const Tree& other) const {
|
||||
return !operator == (other);
|
||||
}
|
||||
|
||||
const mapping::Tree& Tree::operator*() const {
|
||||
if(!m_ptr) {
|
||||
throw std::runtime_error("[oatpp::data::type::Tree::operator *()]: null-pointer exception");
|
||||
}
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
mapping::Tree& Tree::operator*() {
|
||||
if(!m_ptr) {
|
||||
throw std::runtime_error("[oatpp::data::type::Tree::operator *()]: null-pointer exception");
|
||||
}
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
|
||||
}}}
|
||||
|
@ -54,7 +54,64 @@ public:
|
||||
|
||||
}
|
||||
|
||||
typedef ObjectWrapper<mapping::Tree, __class::Tree> Tree;
|
||||
class Tree : public ObjectWrapper<mapping::Tree, __class::Tree> {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
Tree();
|
||||
|
||||
/**
|
||||
* Nullptr constructor.
|
||||
*/
|
||||
Tree(std::nullptr_t);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @param other - other Any.
|
||||
*/
|
||||
Tree(const Tree& other);
|
||||
|
||||
/**
|
||||
* Move constructor.
|
||||
* @param other
|
||||
*/
|
||||
Tree(Tree&& other);
|
||||
|
||||
/**
|
||||
* Constructor from `mapping::Tree`.
|
||||
* @param other
|
||||
*/
|
||||
Tree(const mapping::Tree& other);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Construct from `mapping::Tree`
|
||||
* @param other
|
||||
*/
|
||||
Tree(mapping::Tree&& other);
|
||||
|
||||
Tree(const std::shared_ptr<mapping::Tree>& node, const Type* const type);
|
||||
|
||||
Tree& operator = (std::nullptr_t);
|
||||
|
||||
Tree& operator = (const Tree& other);
|
||||
Tree& operator = (Tree&& other);
|
||||
|
||||
Tree& operator = (const mapping::Tree& other);
|
||||
Tree& operator = (mapping::Tree&& other);
|
||||
|
||||
bool operator == (std::nullptr_t) const;
|
||||
bool operator != (std::nullptr_t) const;
|
||||
|
||||
bool operator == (const Tree& other) const;
|
||||
bool operator != (const Tree& other) const;
|
||||
|
||||
const mapping::Tree& operator*() const;
|
||||
mapping::Tree& operator*();
|
||||
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
|
@ -86,7 +86,7 @@ oatpp::Void ObjectMapper::read(utils::parser::Caret& caret, const data::type::Ty
|
||||
|
||||
/* if expected type is Tree (root element is Tree) - then we can just move deserialized tree */
|
||||
if(type == data::type::Tree::Class::getType()) {
|
||||
return oatpp::Tree(std::make_shared<data::mapping::Tree>(std::move(tree)));
|
||||
return oatpp::Tree(tree);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -157,6 +157,8 @@ void TreeTest::onRun() {
|
||||
|
||||
{
|
||||
Tree article;
|
||||
oatpp::Tree ot;
|
||||
|
||||
|
||||
article["name"] = "Hello World!";
|
||||
article["pages"] = 96;
|
||||
|
Loading…
Reference in New Issue
Block a user