mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-30 09:08:35 +00:00
adding a basic aprser node
This commit is contained in:
+1
-1
@@ -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}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user