Changeset View
Changeset View
Standalone View
Standalone View
source/ps/ParamNodeLayer.h
- This file was added.
/* Copyright (C) 2021 Wildfire Games. | |||||
* This file is part of 0 A.D. | |||||
* | |||||
* 0 A.D. 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 2 of the License, or | |||||
* (at your option) any later version. | |||||
* | |||||
* 0 A.D. 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 0 A.D. If not, see <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef INCLUDED_PARAMNODELAYER | |||||
#define INCLUDED_PARAMNODELAYER | |||||
#include <memory> | |||||
class CParamNode; | |||||
/** | |||||
* A layer to apply on a ParamNode. | |||||
* A ParamNode is made by applying several layers to the same node. | |||||
* This class is intended as a file-format agnostic wrapper: | |||||
* you pass a VfsPath and it does its thing and can be applied on a CParamNode. | |||||
*/ | |||||
class ParamNodeLayer | |||||
{ | |||||
public: | |||||
ParamNodeLayer(); | |||||
~ParamNodeLayer(); | |||||
bool ApplyOnNode(CParamNode& node); | |||||
// Generic layer loader - automatically determines the correct format. | |||||
bool Load(const VfsPath& path); | |||||
// Specific loaders below for optimisation. | |||||
// XML loaders support validating individual layers (on top of the ParamNode validation). | |||||
bool LoadXML(const VfsPath& path, const std::string& validator = ""); | |||||
bool LoadXML(const std::string& xml, const std::string& validator = ""); | |||||
std::string GetParent() const; | |||||
void SetParent(const std::string& parent); | |||||
private: | |||||
// The whole point of this class is to modify CParamNode, | |||||
// and as such it is a friend of CParamNode to make things convenient. | |||||
// However, friendship is neither transitive nor inherited, so the 'apply' | |||||
// function cannot be virtual and/or in the implementation classes. | |||||
// The workaround is to define them here, but that leaks implementation details in the header. | |||||
// To avoid that, we'll just specialize this template function: it's a friend, | |||||
// and it can be defined entirely in the .cpp file. | |||||
template<typename ...T> | |||||
bool ApplyOnNode(CParamNode& node, T&&... args); | |||||
std::string m_Parent; | |||||
// PImpled data, to hide implementation details & make it easier to implement different file types. | |||||
// (shared pointer to make copying cheaper - it seems fair to assume the raw data won't be changed). | |||||
class Impl; | |||||
std::shared_ptr<Impl> m_Data; | |||||
}; | |||||
#endif // INCLUDED_PARAMLAYERNODE |
Wildfire Games · Phabricator