Fixes
This commit is contained in:
10
Src/ConfigParser/CMakeLists.txt
Normal file
10
Src/ConfigParser/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
set(SRC_FILES
|
||||
"imp/cpp/ConfigData.cpp"
|
||||
)
|
||||
|
||||
add_library(ConfigData STATIC ${SRC_FILES})
|
||||
|
||||
target_include_directories(ConfigData PUBLIC inc)
|
||||
target_include_directories(ConfigData PRIVATE imp/hpp)
|
||||
|
||||
target_link_libraries(ConfigData PUBLIC Common)
|
||||
83
Src/ConfigParser/imp/cpp/ConfigData.cpp
Normal file
83
Src/ConfigParser/imp/cpp/ConfigData.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <ConfigData/ConfigData.hpp>
|
||||
|
||||
#include <IACore/File.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
ConfigData::ConfigData(IN pugi::xml_document &&document, IN CONST String &type, IN CONST String &name,
|
||||
IN pugi::xml_node propertiesNode, IN Vector<pugi::xml_node> &&childNodes)
|
||||
: m_document(IA_MOVE(document)), m_type(type), m_name(name), m_propertiesNode(propertiesNode),
|
||||
m_childNodes(IA_MOVE(childNodes))
|
||||
{
|
||||
}
|
||||
|
||||
RefPtr<ConfigData> ConfigData::LoadFromFile(IN CONST String &path)
|
||||
{
|
||||
return LoadFromMemory(File::ReadToString(path));
|
||||
}
|
||||
|
||||
RefPtr<ConfigData> ConfigData::LoadFromMemory(IN CONST String &data)
|
||||
{
|
||||
pugi::xml_document doc;
|
||||
if (!doc.load_string(data.c_str()))
|
||||
return nullptr;
|
||||
|
||||
if (std::distance(doc.children().begin(), doc.children().end()) != 1)
|
||||
return nullptr;
|
||||
const auto rootNode = *doc.children().begin();
|
||||
|
||||
// Verify Engine Version
|
||||
{
|
||||
const auto engineInfoNode = rootNode.child("IAEngine");
|
||||
if (!engineInfoNode)
|
||||
return nullptr;
|
||||
const auto engineVersionNode = engineInfoNode.child("EngineVersion");
|
||||
if (!engineVersionNode)
|
||||
return nullptr;
|
||||
const auto engineVersion = IA_PARSE_VERSION_STRING(engineVersionNode.text().as_string());
|
||||
if (engineVersion > ENGINE_VERSION)
|
||||
{
|
||||
CFG_LOG_WARN("XML data file was created with a newer version of IAEngine, skipping..");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
const auto propertiesNode = rootNode.child("Properties");
|
||||
if (!propertiesNode)
|
||||
return nullptr;
|
||||
|
||||
Vector<pugi::xml_node> childNodes;
|
||||
for (auto &c : rootNode.children())
|
||||
{
|
||||
if ((!strcmp(c.name(), "Properties")) || (!strcmp(c.name(), "IAEngine")))
|
||||
continue;
|
||||
childNodes.pushBack(c);
|
||||
}
|
||||
|
||||
const auto nameAttr = rootNode.attribute("name");
|
||||
|
||||
return MakeRefPtr<ConfigData>(IA_MOVE(doc), rootNode.name(), nameAttr ? nameAttr.as_string() : "",
|
||||
propertiesNode, IA_MOVE(childNodes));
|
||||
}
|
||||
|
||||
pugi::xml_node ConfigData::Property(IN CONST String &name)
|
||||
{
|
||||
return m_propertiesNode.child(name.c_str());
|
||||
}
|
||||
} // namespace ia::iae
|
||||
33
Src/ConfigParser/inc/ConfigData/Base.hpp
Normal file
33
Src/ConfigParser/inc/ConfigData/Base.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Common/Base.hpp>
|
||||
|
||||
#include <pugixml.hpp>
|
||||
|
||||
#define CFG_LOG_TAG "CFG"
|
||||
|
||||
#define CFG_LOG_INFO(...) ia::Logger::Info(CFG_LOG_TAG, __VA_ARGS__)
|
||||
#define CFG_LOG_WARN(...) ia::Logger::Warn(CFG_LOG_TAG, __VA_ARGS__)
|
||||
#define CFG_LOG_ERROR(...) ia::Logger::Error(CFG_LOG_TAG, __VA_ARGS__)
|
||||
#define CFG_LOG_SUCCESS(...) ia::Logger::Success(CFG_LOG_TAG, __VA_ARGS__)
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
|
||||
} // namespace ia::iae
|
||||
59
Src/ConfigParser/inc/ConfigData/ConfigData.hpp
Normal file
59
Src/ConfigParser/inc/ConfigData/ConfigData.hpp
Normal file
@ -0,0 +1,59 @@
|
||||
// IAEngine: 2D Game Engine by IA
|
||||
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ConfigData/Base.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
class ConfigData
|
||||
{
|
||||
public:
|
||||
STATIC RefPtr<ConfigData> LoadFromFile(IN CONST String &path);
|
||||
STATIC RefPtr<ConfigData> LoadFromMemory(IN CONST String &data);
|
||||
|
||||
public:
|
||||
pugi::xml_node Property(IN CONST String &name);
|
||||
|
||||
public:
|
||||
CONST String &Type() CONST
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
CONST String &Name() CONST
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
CONST Vector<pugi::xml_node> &Children() CONST
|
||||
{
|
||||
return m_childNodes;
|
||||
}
|
||||
|
||||
private:
|
||||
CONST String m_type;
|
||||
CONST String m_name;
|
||||
CONST pugi::xml_document m_document;
|
||||
CONST pugi::xml_node m_propertiesNode;
|
||||
CONST Vector<pugi::xml_node> m_childNodes;
|
||||
|
||||
public:
|
||||
ConfigData(IN pugi::xml_document &&document, IN CONST String &type, IN CONST String &name,
|
||||
IN pugi::xml_node propertiesNode, IN Vector<pugi::xml_node> &&childNodes);
|
||||
};
|
||||
} // namespace ia::iae
|
||||
Reference in New Issue
Block a user