.. _program_listing_file__tmp_ws_src_fastrtps_include_fastrtps_xmlparser_XMLTree.h: Program Listing for File XMLTree.h ================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/fastrtps/include/fastrtps/xmlparser/XMLTree.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #ifndef _XML_TREE_ #define _XML_TREE_ #include #include #include #include namespace eprosima { namespace fastrtps { namespace xmlparser { enum class NodeType { PROFILES, PARTICIPANT, PUBLISHER, SUBSCRIBER, RTPS, QOS_PROFILE, APPLICATION, TYPE, TOPIC, DATA_WRITER, DATA_READER, ROOT, TYPES, LOG, REQUESTER, REPLIER, LIBRARY_SETTINGS }; class BaseNode { public: BaseNode( NodeType type) : data_type_(type) , parent_(nullptr) { } virtual ~BaseNode() = default; BaseNode( const BaseNode&) = delete; BaseNode& operator =( const BaseNode&) = delete; BaseNode( BaseNode&&) = default; BaseNode& operator =( BaseNode&&) = default; NodeType getType() const { return data_type_; } void addChild( std::unique_ptr child) { child->setParent(this); children.push_back(std::move(child)); } bool removeChild( const size_t& index) { if (children.size() > index) { children.erase(children.begin() + index); return true; } else { return false; } } BaseNode* getChild( const size_t& index) const { if (children.empty()) { return nullptr; } return children[index].get(); } BaseNode* getParent() const { return parent_; } void setParent( BaseNode* parent) { parent_ = parent; } size_t getNumChildren() const { return children.size(); } std::vector>& getChildren() { return children; } private: NodeType data_type_; BaseNode* parent_; std::vector> children; }; template class DataNode : public BaseNode { public: DataNode( NodeType type); DataNode( NodeType type, std::unique_ptr data); virtual ~DataNode(); DataNode( const DataNode&) = delete; DataNode& operator =( const DataNode&) = delete; DataNode( DataNode&&) = default; DataNode& operator =( DataNode&&) = default; T* get() const; std::unique_ptr getData(); void setData( std::unique_ptr data); void addAttribute( const std::string& name, const std::string& value); const std::map& getAttributes(); private: std::map attributes_; std::unique_ptr data_; }; template DataNode::DataNode( NodeType type) : BaseNode(type) , attributes_() , data_(nullptr) { } template DataNode::DataNode( NodeType type, std::unique_ptr data) : BaseNode(type) , attributes_() , data_(std::move(data)) { } template DataNode::~DataNode() { } template T* DataNode::get() const { return data_.get(); } template std::unique_ptr DataNode::getData() { return std::move(data_); } template void DataNode::setData( std::unique_ptr data) { data_ = std::move(data); } template void DataNode::addAttribute( const std::string& name, const std::string& value) { attributes_[name] = value; } template const std::map& DataNode::getAttributes() { return attributes_; } } // namespace xmlparser } // namespace fastrtps } // namespace eprosima #endif // !_XML_TREE_