Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/system/ParamNode.h
Show First 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | |||||
* "J": "text" | * "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 ParamNodeLayer; | |||||
class CParamNode | class CParamNode | ||||
{ | { | ||||
friend class ParamNodeLayer; | |||||
public: | public: | ||||
typedef std::map<std::string, CParamNode> ChildrenMap; | typedef std::map<std::string, CParamNode> ChildrenMap; | ||||
/** | /** | ||||
* Constructs a new, empty node. | * Apply a ParamNodeLayer from XML data specified by @a path into node @ret. | ||||
*/ | |||||
CParamNode(bool isOk = true); | |||||
/** | |||||
* Loads the XML data specified by @a file into the node @a ret. | |||||
* Any existing data in @a ret will be overwritten or else kept, so this | * Any existing data in @a ret will be overwritten or else kept, so this | ||||
* can be called multiple times to build up a node from multiple inputs. | * can be called multiple times to build up a node from multiple inputs. | ||||
* | |||||
* @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. | |||||
*/ | */ | ||||
static void LoadXML(CParamNode& ret, const XMBFile& file, const wchar_t* sourceIdentifier = NULL); | static bool ApplyXML(CParamNode& ret, const VfsPath& path, const std::string& validatorName); | ||||
/** | /** | ||||
* Loads the XML data specified by @a path into the node @a ret. | * Constructs a new, empty node. | ||||
* Any existing data in @a ret will be overwritten or else kept, so this | |||||
* can be called multiple times to build up a node from multiple inputs. | |||||
*/ | |||||
static void LoadXML(CParamNode& ret, const VfsPath& path, const std::string& validatorName); | |||||
/** | |||||
* See LoadXML, but parses the XML string @a xml. | |||||
* @return error code if parsing failed, else @c PSRETURN_OK | |||||
* | |||||
* @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. | |||||
*/ | */ | ||||
static PSRETURN LoadXMLString(CParamNode& ret, const char* xml, const wchar_t* sourceIdentifier = NULL); | CParamNode(bool isOk = true); | ||||
/** | /** | ||||
* 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 JS::Values) | // a node is always modified explicitly and not indirectly via its children, e.g. to cache JS::Values) | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | public: | ||||
/** | /** | ||||
* Escapes a string so that it is well-formed XML content/attribute text. | * Escapes a string so that it is well-formed XML content/attribute text. | ||||
* (Replaces "&" with "&" etc, and replaces invalid characters with U+FFFD.) | * (Replaces "&" with "&" etc, and replaces invalid characters with U+FFFD.) | ||||
*/ | */ | ||||
static std::wstring EscapeXMLString(const std::wstring& str); | static std::wstring EscapeXMLString(const std::wstring& str); | ||||
private: | private: | ||||
/** | |||||
* Overlays the specified data onto this node. See class documentation for the concept and examples. | |||||
* | |||||
* @param xmb Representation of the XMB file containing an element with the data to apply. | |||||
* @param element Element inside the specified @p xmb file containing the data to apply. | |||||
* @param sourceIdentifier Optional; string you can pass along to indicate the source of | |||||
* the data getting applied. Used for output to log messages if an error occurs. | |||||
*/ | |||||
void ApplyLayer(const XMBFile& xmb, const XMBElement& element, const wchar_t* sourceIdentifier = NULL); | |||||
void ResetScriptVal(); | void ResetScriptVal(); | ||||
void ConstructJSVal(const ScriptRequest& rq, JS::MutableHandleValue ret) const; | void ConstructJSVal(const ScriptRequest& rq, JS::MutableHandleValue ret) const; | ||||
std::wstring m_Value; | std::wstring m_Value; | ||||
ChildrenMap m_Childs; | ChildrenMap m_Childs; | ||||
bool m_IsOk; | bool m_IsOk; | ||||
/** | /** | ||||
* Caches the ToJSVal script representation of this node. | * Caches the ToJSVal script representation of this node. | ||||
*/ | */ | ||||
mutable std::shared_ptr<JS::PersistentRootedValue> m_ScriptVal; | mutable std::shared_ptr<JS::PersistentRootedValue> m_ScriptVal; | ||||
}; | }; | ||||
#endif // INCLUDED_PARAMNODE | #endif // INCLUDED_PARAMNODE |
Wildfire Games · Phabricator