From d8cd2875a252c69277183d26554c5b210f43db8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Thu, 17 Jun 2021 00:05:36 +0200 Subject: [PATCH] adding a basic aprser node --- CMakeLists.txt | 2 +- sources/Parser/Node.cpp | 46 ++++++++++++++++++++++++++++++++++++++++ sources/Parser/Node.hpp | 47 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 sources/Parser/Node.cpp create mode 100644 sources/Parser/Node.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 532cdc7d..5030f6db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,7 +147,7 @@ set(SOURCES sources/Runner/LobbyScene.cpp sources/Runner/ResumeLobbyScene.cpp sources/Runner/ScoreScene.cpp -) + sources/Parser/Node.cpp sources/Parser/Node.hpp) add_executable(bomberman sources/main.cpp ${SOURCES} diff --git a/sources/Parser/Node.cpp b/sources/Parser/Node.cpp new file mode 100644 index 00000000..cbb69025 --- /dev/null +++ b/sources/Parser/Node.cpp @@ -0,0 +1,46 @@ +// +// Created by cbihan on 16/06/2021. +// + +#include "Node.hpp" + +namespace BBM +{ + + Node::Node(std::string name) : + _name(std::move(name)) + { + } + + void Node::setProperty(const std::string &propertyName, const std::string &propertyValue) + { + this->_properties[propertyName] = propertyValue; + } + + std::string Node::getProperty(const std::string &propertyName) const + { + return this->_properties.at(propertyName); + } + + std::string Node::getName() const + { + return this->_name; + } + + void Node::addChildNode(const Node &childNode) + { + this->_childNodes.emplace_back(childNode); + } + + std::vector Node::getChildNodes(const std::string &childNodeName) + { + std::vector childs; + + for (const auto &child : this->_childNodes) { + if (child.getName() == childNodeName) { + childs.emplace_back(child); + } + } + return childs; + } +} \ No newline at end of file diff --git a/sources/Parser/Node.hpp b/sources/Parser/Node.hpp new file mode 100644 index 00000000..2185bdc3 --- /dev/null +++ b/sources/Parser/Node.hpp @@ -0,0 +1,47 @@ +// +// Created by cbihan on 16/06/2021. +// + +#pragma once + +#include +#include +#include + +namespace BBM +{ + class Node + { + private: + //! @brief Node name + std::string _name; + + //! @brief child nodes + std::vector _childNodes; + + //! @brief node's properties + std::map _properties; + + public: + + std::string getName() const; + + void addChildNode(const Node &childNode); + + std::vector getChildNodes(const std::string &childNodeName); + + void setProperty(const std::string &propertyName, const std::string &propertyValue); + + std::string getProperty(const std::string &propertyName) const; + + //! @brief ctor + explicit Node(std::string name); + //! @brief copy ctor + Node(const Node &) = default; + //! @brief dtor + ~Node() = default; + //! @brief assignment operator + Node &operator=(const Node &) = default; + }; +} +