Changeset View
Changeset View
Standalone View
Standalone View
source/ps/TemplateLoader.h
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 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 | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 28 Lines | |||||
* efficiency (we have a lot of strings so this is significant); | * efficiency (we have a lot of strings so this is significant); | ||||
* they correspond to filenames so they shouldn't contain non-ASCII anyway. | * they correspond to filenames so they shouldn't contain non-ASCII anyway. | ||||
* | * | ||||
* | * | ||||
* TODO: Find a way to validate templates outside of the simulation. | * TODO: Find a way to validate templates outside of the simulation. | ||||
*/ | */ | ||||
class CTemplateLoader | class CTemplateLoader | ||||
{ | { | ||||
friend class CParamNode; | |||||
public: | public: | ||||
CTemplateLoader() | CTemplateLoader() | ||||
{ | { | ||||
} | } | ||||
/** | /** | ||||
* Provides the file data for requested template. | * Provides the file data for requested template. | ||||
*/ | */ | ||||
const CParamNode& GetTemplateFileData(const std::string& templateName); | const CParamNode& GetTemplateFileData(const std::string& templateName); | ||||
/** | /** | ||||
* Check if the template XML file exits, without trying to load it. | * Check if the template XML file exits, without trying to load it. | ||||
*/ | */ | ||||
bool TemplateExists(const std::string& templateName) const; | bool TemplateExists(const std::string& templateName) const; | ||||
/** | /** | ||||
* Returns a list of strings that could be validly passed as @c templateName to LoadTemplateFile. | * Returns a list of strings that could be validly passed as @c templateName to LoadTemplateFile. | ||||
* (This includes "actor|foo" etc names). | * (This includes "actor|foo" etc names). | ||||
*/ | */ | ||||
std::vector<std::string> FindTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType) const; | std::vector<std::string> FindTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType) const; | ||||
private: | private: | ||||
CParamNode& GetData(const std::string& templateName); | |||||
/** | /** | ||||
* (Re)loads the given template, regardless of whether it exists already, | * (Re)loads the given template, regardless of whether it exists already, | ||||
* and saves into m_TemplateFileData. Also loads any parents that are not yet | * and saves into m_TemplateFileData. Also loads any parents that are not yet | ||||
* loaded. Returns false on error. | * loaded. Returns false on error. | ||||
* @param templateName XML filename to load (not a |-separated string) | * @param templateName XML filename to load (not a |-separated string) | ||||
*/ | */ | ||||
bool LoadTemplateFile(const std::string& templateName, int depth); | bool LoadTemplateFile(const std::string& templateName, int depth); | ||||
Show All 15 Lines |
Wildfire Games · Phabricator