An entity initialisation parameter node. More...
#include <ParamNode.h>
Public Types | |
| typedef std::map< std::string, CParamNode > | ChildrenMap |
Public Member Functions | |
| CParamNode (bool isOk=true) | |
| Constructs a new, empty node. | |
| void | CopyFilteredChildrenOfChild (const CParamNode &src, const char *name, const std::set< std::string > &permitted) |
| Finds the childs named name from src and from this, and copies the source child's children which are in the permitted set into this node's child. | |
| const CParamNode & | GetChild (const char *name) const |
| Returns the (unique) child node with the given name, or a node with IsOk() == false if there is none. | |
| bool | IsOk () const |
| Returns true if this is a valid CParamNode, false if it represents a non-existent node. | |
| const std::wstring & | ToString () const |
| Returns the content of this node as a string. | |
| const std::string | ToUTF8 () const |
| Returns the content of this node as an 8-bit string. | |
| const CStrIntern | ToUTF8Intern () const |
| Returns the content of this node as an internalized 8-bit string. | |
| int | ToInt () const |
| Parses the content of this node as an integer. | |
| fixed | ToFixed () const |
| Parses the content of this node as a fixed-point number. | |
| float | ToFloat () const |
| Parses the content of this node as a floating-point number. | |
| bool | ToBool () const |
| Parses the content of this node as a boolean ("true" == true, anything else == false). | |
| std::wstring | ToXML () const |
| Returns the content of this node and its children as an XML string. | |
| void | ToXML (std::wostream &strm) const |
| Write the content of this node and its children as an XML string, to the stream. | |
| jsval | ToJSVal (JSContext *cx, bool cacheValue) const |
| Returns a jsval representation of this node and its children. | |
| const ChildrenMap & | GetChildren () const |
| Returns the names/nodes of the children of this node, ordered by name. | |
Static Public Member Functions | |
| static void | LoadXML (CParamNode &ret, const XMBFile &file, const wchar_t *sourceIdentifier=NULL) |
| Loads the XML data specified by file into the node ret. | |
| static void | LoadXML (CParamNode &ret, const VfsPath &path) |
| Loads the XML data specified by path into the node ret. | |
| static PSRETURN | LoadXMLString (CParamNode &ret, const char *xml, const wchar_t *sourceIdentifier=NULL) |
| See LoadXML, but parses the XML string xml. | |
| static std::wstring | EscapeXMLString (const std::wstring &str) |
| Escapes a string so that it is well-formed XML content/attribute text. | |
Private Member Functions | |
| void | ApplyLayer (const XMBFile &xmb, const XMBElement &element, const wchar_t *sourceIdentifier=NULL) |
| Overlays the specified data onto this node. | |
| void | ResetScriptVal () |
| jsval | ConstructJSVal (JSContext *cx) const |
Private Attributes | |
| std::wstring | m_Value |
| ChildrenMap | m_Childs |
| bool | m_IsOk |
| CScriptValRooted | m_ScriptVal |
| Caches the ToJSVal script representation of this node. | |
An entity initialisation parameter node.
Each node has a text value, plus a number of named child nodes (in a tree structure). Child nodes are unordered, and there cannot be more than one with the same name. Nodes are immutable.
Nodes can be initialised from XML files. Child elements are mapped onto child nodes. Attributes are mapped onto child nodes with names prefixed by "@" (e.g. the XML <a b="c"><d/></a> is loaded as a node with two child nodes, one called "@b" and one called "d").
They can also be initialised from multiple XML files, which is used by ICmpTemplateManager for entity template inheritance. Loading one XML file like:
<Entity> <Example1> <A attr="value">text</A> </Example1> <Example2> <B/> </Example2> <Example3> <C/> </Example3> <Example4 datatype="tokens"> one two three </Example4> </Entity>
then a second like:
<Entity> <Example1> <A>example</A> <!-- replace the content of the old A element --> <D>new</D> <!-- add a new child to the old Example1 element --> </Example1> <Example2 disable=""/> <!-- delete the old Example2 element --> <Example3 replace=""> <!-- replace all the old children of the Example3 element --> <D>new</D> </Example3> <Example4 datatype="tokens"> <!-- treat as space-separated lists of tokens to merge --> four <!-- add a token to the parent's set --> -two <!-- remove a token from the parent's set --> </Example4> </Entity>
is equivalent to loading a single file like:
<Entity> <Example1> <A attr="value">example</A> <D>new</D> </Example1> <Example3> <D>new</D> </Example3> <Example4> one three four </Example4> </Entity>
Parameter nodes can be translated to JavaScript objects. The previous example will become the object:
{ "Entity": {
"Example1": {
"A": { "@attr": "value", "_string": "example" },
"D": "new"
},
"Example3": {
"D": "new"
},
"Example4": { "@datatype": "tokens", "_string": "one three four" }
}
}
(Note the special _string for the hopefully-rare cases where a node contains both child nodes and text.)
| typedef std::map<std::string, CParamNode> CParamNode::ChildrenMap |
| CParamNode::CParamNode | ( | bool | isOk = true |
) |
Constructs a new, empty node.
| void CParamNode::ApplyLayer | ( | const XMBFile & | xmb, | |
| const XMBElement & | element, | |||
| const wchar_t * | sourceIdentifier = NULL | |||
| ) | [private] |
Overlays the specified data onto this node.
See class documentation for the concept and examples.
| xmb | Representation of the XMB file containing an element with the data to apply. | |
| element | Element inside the specified xmb file containing the data to apply. | |
| 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. |
| jsval CParamNode::ConstructJSVal | ( | JSContext * | cx | ) | const [private] |
| void CParamNode::CopyFilteredChildrenOfChild | ( | const CParamNode & | src, | |
| const char * | name, | |||
| const std::set< std::string > & | permitted | |||
| ) |
Finds the childs named name from src and from this, and copies the source child's children which are in the permitted set into this node's child.
Intended for use as a filtered clone of XML files. this and src must have childs named name.
| std::wstring CParamNode::EscapeXMLString | ( | const std::wstring & | str | ) | [static] |
Escapes a string so that it is well-formed XML content/attribute text.
(Replaces "&" with "&" etc, and replaces invalid characters with U+FFFD.)
| const CParamNode & CParamNode::GetChild | ( | const char * | name | ) | const |
Returns the (unique) child node with the given name, or a node with IsOk() == false if there is none.
| const CParamNode::ChildrenMap & CParamNode::GetChildren | ( | ) | const |
Returns the names/nodes of the children of this node, ordered by name.
| bool CParamNode::IsOk | ( | ) | const |
Returns true if this is a valid CParamNode, false if it represents a non-existent node.
| void CParamNode::LoadXML | ( | CParamNode & | ret, | |
| const VfsPath & | path | |||
| ) | [static] |
Loads the XML data specified by path into the node ret.
Any existing data in ret will be overwritten or else kept, so this can be called multiple times to build up a node from multiple inputs.
| void CParamNode::LoadXML | ( | CParamNode & | ret, | |
| const XMBFile & | file, | |||
| const wchar_t * | sourceIdentifier = NULL | |||
| ) | [static] |
Loads the XML data specified by file into the node ret.
Any existing data in ret will be overwritten or else kept, so this can be called multiple times to build up a node from multiple inputs.
| 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. |
| PSRETURN CParamNode::LoadXMLString | ( | CParamNode & | ret, | |
| const char * | xml, | |||
| const wchar_t * | sourceIdentifier = NULL | |||
| ) | [static] |
See LoadXML, but parses the XML string xml.
PSRETURN_OK | 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. |
| void CParamNode::ResetScriptVal | ( | ) | [private] |
| bool CParamNode::ToBool | ( | ) | const |
Parses the content of this node as a boolean ("true" == true, anything else == false).
| fixed CParamNode::ToFixed | ( | ) | const |
Parses the content of this node as a fixed-point number.
| float CParamNode::ToFloat | ( | ) | const |
Parses the content of this node as a floating-point number.
| int CParamNode::ToInt | ( | ) | const |
Parses the content of this node as an integer.
| jsval CParamNode::ToJSVal | ( | JSContext * | cx, | |
| bool | cacheValue | |||
| ) | const |
Returns a jsval representation of this node and its children.
If cacheValue is true, then the same jsval will be returned each time this is called (regardless of whether you passed the same cx - be careful to only use the cache in one context). When caching, the lifetime of cx must be longer than the lifetime of this node. The cache will be reset if *this* node is modified (e.g. by LoadXML), but *not* if any child nodes are modified (so don't do that).
| const std::wstring & CParamNode::ToString | ( | ) | const |
Returns the content of this node as a string.
| const std::string CParamNode::ToUTF8 | ( | ) | const |
Returns the content of this node as an 8-bit string.
| const CStrIntern CParamNode::ToUTF8Intern | ( | ) | const |
Returns the content of this node as an internalized 8-bit string.
Should only be used for predictably small and frequently-used strings.
| void CParamNode::ToXML | ( | std::wostream & | strm | ) | const |
Write the content of this node and its children as an XML string, to the stream.
| std::wstring CParamNode::ToXML | ( | ) | const |
Returns the content of this node and its children as an XML string.
ChildrenMap CParamNode::m_Childs [private] |
bool CParamNode::m_IsOk [private] |
CScriptValRooted CParamNode::m_ScriptVal [mutable, private] |
Caches the ToJSVal script representation of this node.
std::wstring CParamNode::m_Value [private] |
1.6.3