adding a basic aprser node

This commit is contained in:
Clément Le Bihan
2021-06-17 00:05:36 +02:00
parent 1fe8c0da4d
commit d8cd2875a2
3 changed files with 94 additions and 1 deletions
+1 -1
View File
@@ -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}
+46
View File
@@ -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> Node::getChildNodes(const std::string &childNodeName)
{
std::vector<Node> childs;
for (const auto &child : this->_childNodes) {
if (child.getName() == childNodeName) {
childs.emplace_back(child);
}
}
return childs;
}
}
+47
View File
@@ -0,0 +1,47 @@
//
// Created by cbihan on 16/06/2021.
//
#pragma once
#include <vector>
#include <map>
#include <string>
namespace BBM
{
class Node
{
private:
//! @brief Node name
std::string _name;
//! @brief child nodes
std::vector<Node> _childNodes;
//! @brief node's properties
std::map<std::string, std::string> _properties;
public:
std::string getName() const;
void addChildNode(const Node &childNode);
std::vector<Node> 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;
};
}