Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/system/ParamNode.h
/* Copyright (C) 2015 Wildfire Games. | /* Copyright (C) 2017 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 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
* <B/> | * <B/> | ||||
* </Example2> | * </Example2> | ||||
* <Example3> | * <Example3> | ||||
* <C/> | * <C/> | ||||
* </Example3> | * </Example3> | ||||
* <Example4 datatype="tokens"> | * <Example4 datatype="tokens"> | ||||
* one two three | * one two three | ||||
* </Example4> | * </Example4> | ||||
* <Example5> | |||||
* <E/> | |||||
* <F> | |||||
* <I>test</I> | |||||
* </F> | |||||
* <H> | |||||
* <J>example</J> | |||||
* </H> | |||||
* </Example5> | |||||
* </Entity> | * </Entity> | ||||
* @endcode | * @endcode | ||||
* then a second like: | * then a second like: | ||||
* @code | * @code | ||||
* <Entity> | * <Entity> | ||||
* <Example1> | * <Example1> | ||||
* <A>example</A> <!-- replace the content of the old A element --> | * <A>example</A> <!-- replace the content of the old A element --> | ||||
* <D>new</D> <!-- add a new child to the old Example1 element --> | * <D>new</D> <!-- add a new child to the old Example1 element --> | ||||
* </Example1> | * </Example1> | ||||
* <Example2 disable=""/> <!-- delete the old Example2 element --> | * <Example2 disable=""/> <!-- delete the old Example2 element --> | ||||
* <Example3 replace=""> <!-- replace all the old children of the Example3 element --> | * <Example3 replace=""> <!-- replace all the old children of the Example3 element --> | ||||
* <D>new</D> | * <D>new</D> | ||||
* </Example3> | * </Example3> | ||||
* <Example4 datatype="tokens"> <!-- treat as space-separated lists of tokens to merge --> | * <Example4 datatype="tokens"> <!-- treat as space-separated lists of tokens to merge --> | ||||
* four <!-- add a token to the parent's set --> | * four <!-- add a token to the parent's set --> | ||||
* -two <!-- remove a token from the parent's set --> | * -two <!-- remove a token from the parent's set --> | ||||
* </Example4> | * </Example4> | ||||
* <Example5 filtered=""> <!-- drop all children of this node that are not in this file --> | |||||
* <F merge=""> <!-- only add this element if it is also present in the parent --> | |||||
* <K>example</K> <!-- if F is present merge its children normally --> | |||||
* </F> | |||||
* <G merge=""/> <!-- keep the G element of the parent if it exists --> | |||||
* <H> | |||||
* <J>text</J> | |||||
* </H> | |||||
* </Example5> | |||||
* </Entity> | * </Entity> | ||||
* @endcode | * @endcode | ||||
* is equivalent to loading a single file like: | * is equivalent to loading a single file like: | ||||
* @code | * @code | ||||
* <Entity> | * <Entity> | ||||
* <Example1> | * <Example1> | ||||
* <A attr="value">example</A> | * <A attr="value">example</A> | ||||
* <D>new</D> | * <D>new</D> | ||||
* </Example1> | * </Example1> | ||||
* <Example3> | * <Example3> | ||||
* <D>new</D> | * <D>new</D> | ||||
* </Example3> | * </Example3> | ||||
* <Example4> | * <Example4> | ||||
* one three four | * one three four | ||||
* </Example4> | * </Example4> | ||||
* <Example5> | |||||
* <F> | |||||
* <I>test</I> | |||||
* <K>example</K> | |||||
* </F> | |||||
* <H> | |||||
* <J>text</J> | |||||
* </H> | |||||
* </Example5> | |||||
* </Entity> | * </Entity> | ||||
* @endcode | * @endcode | ||||
* | * | ||||
* Parameter nodes can be translated to JavaScript objects. The previous example will become the object: | * Parameter nodes can be translated to JavaScript objects. The previous example will become the object: | ||||
* @code | * @code | ||||
* { "Entity": { | * { "Entity": { | ||||
* "Example1": { | * "Example1": { | ||||
* "A": { "@attr": "value", "_string": "example" }, | * "A": { "@attr": "value", "_string": "example" }, | ||||
* "D": "new" | * "D": "new" | ||||
* }, | * }, | ||||
* "Example3": { | * "Example3": { | ||||
* "D": "new" | * "D": "new" | ||||
* }, | * }, | ||||
* "Example4": { "@datatype": "tokens", "_string": "one three four" } | * "Example4": { "@datatype": "tokens", "_string": "one three four" }, | ||||
* "Example5": { | |||||
* "F": { | |||||
* "I": "test", | |||||
* "K": "example" | |||||
* }, | |||||
* "H": { | |||||
* "J": "text" | |||||
* } | |||||
* } | |||||
* } | * } | ||||
* } | * } | ||||
* @endcode | * @endcode | ||||
* (Note the special @c _string for the hopefully-rare cases where a node contains both child nodes and text.) | * (Note the special @c _string for the hopefully-rare cases where a node contains both child nodes and text.) | ||||
*/ | */ | ||||
class CParamNode | class CParamNode | ||||
{ | { | ||||
public: | public: | ||||
Show All 26 Lines | public: | ||||
* @return error code if parsing failed, else @c PSRETURN_OK | * @return error code if parsing failed, else @c PSRETURN_OK | ||||
* | * | ||||
* @param sourceIdentifier Optional; string you can pass along to indicate the source of | * @param sourceIdentifier Optional; string you can pass along to indicate the source of | ||||
* the data getting loaded. Used for output to log messages if an error occurs. | * the data getting loaded. Used for output to log messages if an error occurs. | ||||
*/ | */ | ||||
static PSRETURN LoadXMLString(CParamNode& ret, const char* xml, const wchar_t* sourceIdentifier = NULL); | static PSRETURN LoadXMLString(CParamNode& ret, const char* xml, const wchar_t* sourceIdentifier = NULL); | ||||
/** | /** | ||||
* Finds the childs named @a name from @a src and from @a this, and copies the source child's children | |||||
* which are in the @a permitted set into this node's child. | |||||
* Intended for use as a filtered clone of XML files. | |||||
* @a this and @a src must have childs named @a name. | |||||
*/ | |||||
void CopyFilteredChildrenOfChild(const CParamNode& src, const char* name, const std::set<std::string>& permitted); | |||||
/** | |||||
* Returns the (unique) child node with the given name, or a node with IsOk() == false if there is none. | * Returns the (unique) child node with the given name, or a node with IsOk() == false if there is none. | ||||
*/ | */ | ||||
const CParamNode& GetChild(const char* name) const; | const CParamNode& GetChild(const char* name) const; | ||||
// (Children are returned as const in order to allow future optimisations, where we assume | // (Children are returned as const in order to allow future optimisations, where we assume | ||||
// a node is always modified explicitly and not indirectly via its children, e.g. to cache jsvals) | // a node is always modified explicitly and not indirectly via its children, e.g. to cache jsvals) | ||||
/** | /** | ||||
* Returns true if this is a valid CParamNode, false if it represents a non-existent node | * Returns true if this is a valid CParamNode, false if it represents a non-existent node | ||||
▲ Show 20 Lines • Show All 98 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator