Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/system/ParamNode.h
Show First 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | |||||
* } | * } | ||||
* } | * } | ||||
* @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: | ||||
typedef std::map<std::string, CParamNode> ChildrenMap; | struct Node | ||||
{ | |||||
Node(const char* s, u16 i = 0) : name(s) | |||||
{ | |||||
attribute = !name.empty() && name[0] == '@'; | |||||
index = i; | |||||
} | |||||
Node(const std::string& s, u16 i = 0) | |||||
{ | |||||
name = s; | |||||
attribute = !name.empty() && name[0] == '@'; | |||||
index = i; | |||||
} | |||||
operator std::string() const | |||||
{ | |||||
if (index == 0) | |||||
return name; | |||||
return name + "_" + std::to_string(index); | |||||
} | |||||
bool operator==(const std::string& o) const { return name == o; } | |||||
bool operator==(const char* o) const { return name.compare(o) == 0; } | |||||
bool operator<(const Node& b) const | |||||
{ | |||||
if (name < b.name) | |||||
return true; | |||||
if (name > b.name) | |||||
return false; | |||||
if (index < b.index) | |||||
return true; | |||||
return false; | |||||
} | |||||
// Name of the node. | |||||
// Starts with '@' if the node is an attribute for backwards compatbility reasons. | |||||
std::string name; | |||||
u16 index = 0; | |||||
bool attribute = false; | |||||
}; | |||||
typedef std::map<Node, CParamNode> ChildrenMap; | |||||
/** | /** | ||||
* Constructs a new, empty node. | * Constructs a new, empty node. | ||||
*/ | */ | ||||
CParamNode(bool isOk = true); | CParamNode(bool isOk = true); | ||||
/** | /** | ||||
* Loads the XML data specified by @a file into the node @a ret. | * Loads the XML data specified by @a file into the node @a ret. | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | public: | ||||
const ChildrenMap& GetChildren() const; | const ChildrenMap& GetChildren() const; | ||||
/** | /** | ||||
* 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); | ||||
void ApplyLayer(const ScriptInterface& scriptInterface, JS::HandleValue value); | |||||
private: | private: | ||||
/** | /** | ||||
* Overlays the specified data onto this node. See class documentation for the concept and examples. | * 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 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 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 | * @param sourceIdentifier Optional; string you can pass along to indicate the source of | ||||
Show All 19 Lines |
Wildfire Games · Phabricator