Unigine::Xml Class
Header: | #include <UnigineXml.h> |
As Unigine extensively uses XML for storing different types of data, it also provides functionality for parsing and saving files of this type.
Xml Class
Members
static XmlPtr create()
Default constructor that creates an empty instance.static XmlPtr create(const char * name, const char * args = 0)
Creates an XML tree with a given node as a root.Arguments
- const char * name - Name of the node that will be a root.
- const char * args - Optional arguments to the root node. If provided, they should be in this form:
arg1=\"value1\" arg2=\"value2\" …
If values do not contain spaces, escaped quotes can be omitted.
static XmlPtr create(const Ptr<Xml> & xml)
Constructor. Creates a path out of the specified XML file.Arguments
- const Ptr<Xml> & xml - Pointer to the XML file.
int setArg(const char * name, const char * value)
Sets a literal value of a given argument.Arguments
- const char * name - The XML argument name.
- const char * value - The XML argument value.
Return value
Returns 1 if the argument is set successfully; otherwise, 0.const char * getArg(const char * name)
Gets an XML argument.Arguments
- const char * name - The XML argument name.
Return value
Value of the argument, if it is found; otherwise, 0.int isArg(const char * name)
Checks whether an argument with a given name exists.Arguments
- const char * name - Name of XML argument.
Return value
1 if the argument exists; otherwise, 0.void setArgName(int num, const char * name)
Sets the XML argument name.Arguments
- int num - The argument number.
- const char * name - The argument name.
const char * getArgName(int num)
Returns argument name by its number.Arguments
- int num - Argument number.
Return value
Argument name.void setArgValue(int num, const char * value)
Sets the XML argument value.Arguments
- int num - The argument number.
- const char * value - The argument value.
const char * getArgValue(int num)
Returns the XML argument value.Arguments
- int num - The argument number.
Return value
Argument value.int setBoolArg(const char * name, int value)
Sets a value of a given boolean argument.Arguments
- const char * name - Name of an argument.
- int value - Value of the argument. Any non-zero value means true, the zero value means false.
Return value
Returns 1 if the operation was successful; otherwise, 0.int getBoolArg(const char * name, int value)
Returns a value of a given boolean argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
- int value - Default value of the argument.
Return value
1 if the argument has a value 1, true or TRUE; 0, if the argument has a value 0, false or FALSE; otherwise, 0.int getBoolArg(const char * name)
Returns a value of a given boolean argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
Return value
1 if the argument has a value 1, true or TRUE; 0, if the argument has a value 0, false or FALSE; otherwise, 0.void setBoolData(int data)
Sets a boolean content for the node. This can be done only for nodes with no children.Arguments
- int data - Content to set. Any non-zero value means true, the zero value means false.
int getBoolData()
Returns a boolean interpretation of data stored in the node.Return value
1 if a value equals to 1, true or TRUE; 0, if the value equals to 0, false or FALSE; otherwise, 0.Ptr<Xml> getChild(const char * name)
Returns the child of the XML tree.Arguments
- const char * name - The child number.
Return value
Pointer to XML.Ptr<Xml> getChild(int num)
Returns a child node by its name or index number in the child list.Notice
To check, if a child with a given name exists, use the isChild() method.
Arguments
- int num - The child number.
Return value
Target child node, if it is found; otherwise, 0.int isChild(const char * name)
Checks if a child element with a given name exists.Arguments
- const char * name - Element name to check.
Return value
const char * getChildData(const char * name)
Gets the data from the XML child node.Arguments
- const char * name - Name of the child node.
Return value
The value of the child node.void setData(const char * data)
Sets an XML data.Arguments
- const char * data - The XML data.
const char * getData()
Gets a data from the XML file.Return value
Data.int setDMat4Arg(const char * name, const Math::dmat4 & value)
Sets a value of a given dmat4 argument.Arguments
- const char * name - Name of an argument.
- const Math::dmat4 & value - Value of an argument.
Return value
Always 1.Math::dmat4 getDMat4Arg(const char * name)
Returns a value of a given dmat4 argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
Return value
Argument value.void setDMat4Data(const Math::dmat4 & data)
Sets a dmat4 matrix content for the node. This can be done only for nodes with no children.Arguments
- const Math::dmat4 & data - Content to set.
Math::dmat4 getDMat4Data()
Returns a dmat4 matrix interpretation of data stored in the node.Return value
Data stored in the node.int setDoubleArg(const char * name, double value)
Sets a value of a given double argument.Arguments
- const char * name - Name of an argument.
- double value - Value of an argument.
Return value
Always 1.double getDoubleArg(const char * name, double value)
Returns a value of a given double argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
- double value - Default value of the argument.
Return value
Argument value.double getDoubleArg(const char * name)
Returns a value of a given double argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
Return value
Argument value.int setDoubleArrayArg(const char * name, double[] src)
Sets a vector of double as a value of a given argument.Arguments
- const char * name - Name of an argument.
- double[] src - Reference to a vector with double components.
Return value
Always 1.int getDoubleArrayArg(out double[] name)
Returns a set of double values stored in an argument and puts them in a vector.Arguments
- out double[] name
Return value
1 if dest contains anything; otherwise, 0.int setDoubleArrayData(double[] src)
Sets a vector of double components as a content for the node. This can be done only for nodes with no children.Arguments
- double[] src - Reference to a vector with double components.
Return value
1 if the content is set successfully; otherwise, 0.int getDoubleArrayData(out double[] dest)
Returns an interpretation of data stored in the node as a vector of double components.Arguments
- out double[] dest - Reference to a vector with double components.
Return value
1 if dest contains anything; otherwise, 0.void setDoubleData(double data)
Sets a double content for the node. This can be done only for nodes with no children.Arguments
- double data - Content to set.
double getDoubleData()
Returns a double interpretation of data stored in the node.Return value
Data stored in the node.int setDVec2Arg(const char * name, const Math::dvec2 & value)
Sets a value of a given dvec2 argument.Arguments
- const char * name - Name of an argument.
- const Math::dvec2 & value - Value of an argument.
Return value
Always 1.Math::dvec2 getDVec2Arg(const char * name)
Returns a value of a given dvec2 argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
Return value
Argument value.void setDVec2Data(const Math::dvec2 & data)
Sets a dvec2 content for the node. This can be done only for nodes with no children.Arguments
- const Math::dvec2 & data - Content to set.
Math::dvec2 getDVec2Data()
Returns a dvec2 interpretation of data stored in the node.Return value
Data stored in the node.int setDVec3Arg(const char * name, const Math::dvec3 & value)
Sets a value of a given dvec3 argument.Arguments
- const char * name - Name of an argument.
- const Math::dvec3 & value - Value of an argument.
Return value
Always 1.Math::dvec3 getDVec3Arg(const char * name)
Returns a value of a given dvec3 argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
Return value
Argument value.void setDVec3Data(const Math::dvec3 & data)
Sets a dvec3 content for the node. This can be done only for nodes with no children.Arguments
- const Math::dvec3 & data - Content to set.
Math::dvec3 getDVec3Data()
Returns a dvec3 interpretation of data stored in the node.Return value
Data stored in the node.int setDVec4Arg(const char * name, const Math::dvec4 & value)
Sets a value of a given dvec4 argument.Arguments
- const char * name - Name of an argument.
- const Math::dvec4 & value - Value of an argument.
Return value
Always 1.Math::dvec4 getDVec4Arg(const char * name)
Returns a value of a given dvec4 argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
Return value
Argument value.void setDVec4Data(const Math::dvec4 & data)
Sets a dvec4 content for the node. This can be done only for nodes with no children.Arguments
- const Math::dvec4 & data - Content to set.
Math::dvec4 getDVec4Data()
Returns a dvec4 interpretation of data stored in the node.Return value
Data stored in the node.int setFloatArg(const char * name, float value)
Sets a value of a given float argument.Arguments
- const char * name - Name of an argument.
- float value - Value of an argument.
Return value
Always 1.float getFloatArg(const char * name, float value)
Returns a value of a given float argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
- float value - Default value of the argument.
Return value
Argument value.float getFloatArg(const char * name)
Returns a value of a given float argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
Return value
Argument value.int setFloatArrayArg(const char * name, float[] src)
Sets a vector of floats as a value of a given argument.Arguments
- const char * name - Name of an argument.
- float[] src
Return value
Always 1.int getFloatArrayArg(const char * name, out float[] dest)
Returns a set of float values stored in an argument and puts them in a vector.Arguments
- const char * name - Name of a target argument.
- out float[] dest - Target vector.
Return value
1 if dest contains anything; otherwise, 0.int setFloatArrayData(float[] src)
Sets a vector of floats as a content for the node. This can be done only for nodes with no children.Arguments
- float[] src - A float array data.
Return value
1 if the content is set successfully; otherwise, 0.int getFloatArrayData(out float[] dest)
Returns an interpretation of data stored in the node as a vector of floats.Arguments
- out float[] dest - Reference to a vector.
Return value
1 if dest contains anything; otherwise, 0.void setFloatData(float data)
Sets a float content for the node. This can be done only for nodes with no children.Arguments
- float data - Content to set.
float getFloatData()
Returns a float interpretation of data stored in the node.Return value
Data stored in the node.String getFormattedSubTree(const char * path = 0)
Converts an XML tree into the formatted string.Arguments
- const char * path - Path to XML sub-tree.
Return value
The result.int setIntArg(const char * name, int value, int radix = 10)
Sets a value for a given int argument in a given number notation. By default, the decimal number notation is used.Arguments
- const char * name - Name of an argument.
- int value - Value of an argument.
- int radix - Radix to use when setting a value.
Return value
1 if the value is set successfully; otherwise, 0.int getIntArg(const char * name)
Returns a value of a given int argument.Notice
To check whether the argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
Return value
Argument value.int getIntArg(const char * name, int value)
Returns a value of a given int argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
- int value - Default value of the argument.
Return value
Argument value.int setIntArrayArg(const char * name, const Vector< String > & src, int radix = 10)
Sets an array of integers as xml argument in a given number notation. By default, the decimal number notation is used.Arguments
- const char * name - Name of an argument.
- const Vector< String > & src - An array of integers.
- int radix - Radix to use when setting a value.
Return value
1 if the array is set successfully; otherwise, 0.int getIntArrayArg(const char * name)
Returns a set of int values stored in an argument and puts them in a vector.Arguments
- const char * name - Name of a target argument.
Return value
1 if values are read successfully; otherwise, 0.int setIntArrayData(int[] src, int radix)
Sets a vector of integers as a content for the XML node in a given number notation. By default, the decimal number notation is used. This can be done only for XML nodes with no children.Arguments
- int[] src - Reference to a vector.
- int radix - Radix to use when setting a value.
Return value
1 if the content is set successfully; otherwise, 0.int getIntArrayData(out int[] dest)
Returns an interpretation of data stored in the node as a vector of integers.Arguments
- out int[] dest - Reference to a vector.
Return value
1 if values are read successfully; otherwise, 0.int setIntData(int value, int radix = 10)
Sets an integer as a content for the XML node in a given number notation. By default, the decimal number notation is used. This can be done only for XML nodes with no children.Arguments
- int value - Content to set.
- int radix - Radix to use when setting a value.
Return value
1 if the content is set successfully; otherwise, 0.int getIntData()
Returns an integer interpretation of data stored in the node.Return value
Data stored in the node.int setIVec2Arg(const char * name, const Math::ivec2 & value)
Sets a value of a given ivec2 argument.Arguments
- const char * name - Name of an argument.
- const Math::ivec2 & value - Value of an argument.
Return value
Always 1.Math::ivec2 getIVec2Arg(const char * name)
Returns a value of a given ivec2 argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
Return value
Argument value.void setIVec2Data(const Math::ivec2 & data)
Sets a ivec2 content for the node. This can be done only for nodes with no children.Arguments
- const Math::ivec2 & data - Content to set.
Math::ivec2 getIVec2Data()
Returns a ivec2 interpretation of data stored in the node.Return value
Data stored in the node.int setIVec3Arg(const char * name, const Math::ivec3 & value)
Sets a value of a given ivec3 argument.Arguments
- const char * name - Name of an argument.
- const Math::ivec3 & value - Value of an argument.
Return value
Always 1.Math::ivec3 getIVec3Arg(const char * name)
Returns a value of a given ivec3 argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
Return value
Argument value.void setIVec3Data(const Math::ivec3 & data)
Sets a ivec3 content for the node. This can be done only for nodes with no children.Arguments
- const Math::ivec3 & data - Content to set.
Math::ivec3 getIVec3Data()
Returns a ivec3 interpretation of data stored in the node.Return value
Data stored in the node.int setIVec4Arg(const char * name, const Math::ivec4 & value)
Sets a value of a given ivec4 argument.Arguments
- const char * name - Name of an argument.
- const Math::ivec4 & value - Value of an argument.
Return value
Always 1.Math::ivec4 getIVec4Arg(const char * name)
Returns a value of a given ivec4 argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
Return value
Argument value.void setIVec4Data(const Math::ivec4 & data)
Sets a ivec4 content for the node. This can be done only for nodes with no children.Arguments
- const Math::ivec4 & data - Content to set.
Math::ivec4 getIVec4Data()
Returns a ivec4 interpretation of data stored in the node.Return value
Data stored in the node.void setLongData(long long data)
Sets a long content for the node. This can be done only for nodes with no children.Arguments
- long long data - Content to be set.
long long getLongData()
Returns a long interpretation of data stored in the node.Return value
Data stored in the node.int setMat4Arg(const char * name, const Math::mat4 & value)
Sets a value of a given mat4 argument.Arguments
- const char * name - Name of an argument.
- const Math::mat4 & value - Value of an argument.
Return value
Always 1.Math::mat4 getMat4Arg(const char * name)
Returns a value of a given mat4 argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
Return value
Argument value.void setMat4Data(const Math::mat4 & data)
Sets a mat4 matrix content for the node. This can be done only for nodes with no children.Arguments
- const Math::mat4 & data - Content to set.
Math::mat4 getMat4Data()
Returns a mat4 matrix interpretation of data stored in the node.Return value
Data stored in the node.void setName(const char * name)
Sets a name of the node.Arguments
- const char * name - Node name.
const char * getName()
Returns a name of the node.Return value
Node name.int getNumArgs()
Returns a number of arguments.Return value
Number of arguments.int getNumChildren()
Returns the number of the node children.Return value
The result.int isOwner()
Returns the owner flag. If the pointer is the owner, on its deletion the image also will be deleted. Use grab() and release() functions to change ownership.Return value
Owner flag.Ptr<Xml> getParent()
Returns the parent of the current XML node.Return value
XML node.int setQuatArg(const char * name, const Math::quat & value)
Sets a value of a given quat argument.Arguments
- const char * name - Name of an argument.
- const Math::quat & value - Value of an argument.
Return value
Always 1.Math::quat getQuatArg(const char * name)
Returns a value of a given quat argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
Return value
Argument value.void setQuatData(const Math::quat & data)
Sets a quaternion content for the node. This can be done only for nodes with no children.Arguments
- const Math::quat & data - Content to set.
Math::quat getQuatData()
Returns a quaternion interpretation of data stored in the node.Return value
Data stored in the node.int setRawData(const char * data)
Sets a raw content for the node. Raw data will be automatically formatted as a CDATA section. This can be done only for nodes with no children.Arguments
- const char * data - Content to set.
Return value
1 if the content is set successfully; otherwise, 0.int setStringArrayArg(const char * name, const Vector< String > & src)
Sets a vector of strings as a value of a given argument in a given number notation. By default, the decimal number notation is used.Arguments
- const char * name - Name of an argument.
- const Vector< String > & src - An array of strings.
Return value
Always 1.int getStringArrayArg(const char * name, Vector< String > & dest)
Returns a set of string values stored in an argument and puts them in a vector.Arguments
- const char * name - Name of the string.
- Vector< String > & dest - Reference to a vector.
Return value
1 if dest contains anything; otherwise, 0.int setStringArrayData(const Vector< String > & src, const char * delimiter = ",")
Sets a vector of strings as a content for the node. This can be done only for nodes with no children.Arguments
- const Vector< String > & src - Reference to a vector of strings.
- const char * delimiter - Character(s) to be used as a delimiter to split tokens.
Return value
1 if the content is set successfully; otherwise, 0.int getStringArrayData(Vector< String > & dest, const char * delimiter = ",")
Returns an interpretation of data stored in the node as a vector of strings.Arguments
- Vector< String > & dest - Reference to a vector of strings.
- const char * delimiter - Character(s) to be used as a delimiter to split tokens.
Return value
1 if dest contains anything; otherwise, 0.String getSubTree(const char * path = 0)
Dumps the node tree.Arguments
- const char * path - Path to XML sub-tree.
Return value
Single-line non-indented output of the node tree. If no arguments are passed, the entire XML tree would be output.int setVec2Arg(const char * name, const Math::vec2 & value)
Sets a value of a given vec2 argument.Arguments
- const char * name - Name of an argument.
- const Math::vec2 & value - Value of an argument.
Return value
Always 1.Math::vec2 getVec2Arg(const char * name)
Returns a value of a given vec2 argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
Return value
Argument value.void setVec2Data(const Math::vec2 & data)
Sets a vec2 content for the node. This can be done only for nodes with no children.Arguments
- const Math::vec2 & data - Content to set.
Math::vec2 getVec2Data()
Returns a vec2 interpretation of data stored in the node.Return value
Data stored in the node.int setVec3Arg(const char * name, const Math::vec3 & value)
Sets a value of a given vec3 argument.Arguments
- const char * name - Name of an argument.
- const Math::vec3 & value - Value of an argument.
Return value
Always 1.Math::vec3 getVec3Arg(const char * name)
Returns a value of a given vec3 argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
Return value
Argument value.void setVec3Data(const Math::vec3 & data)
Sets a vec3 content for the node. This can be done only for nodes with no children.Arguments
- const Math::vec3 & data - Content to set.
Math::vec3 getVec3Data()
Returns a vec3 interpretation of data stored in the node.Return value
Data stored in the node.int setVec4Arg(const char * name, const Math::vec4 & value)
Sets a value of a given vec4 argument.Arguments
- const char * name - Name of an argument.
- const Math::vec4 & value - Value of an argument.
Return value
Always 1.Math::vec4 getVec4Arg(const char * name)
Returns a value of a given vec4 argument.Notice
To check, if an argument exists, use the isArg() method.
Arguments
- const char * name - Name of a target argument.
Return value
Argument value.void setVec4Data(const Math::vec4 & data)
Sets a vec4 content for the node. This can be done only for nodes with no children.Arguments
- const Math::vec4 & data - Content to set.
Math::vec4 getVec4Data()
Returns a vec4 interpretation of data stored in the node.Return value
Data stored in the node.int setXmlData(const char * data)
Sets an unquoted string to data stored in the node. This string can also contain XML sub-tree with rich text formating.Arguments
- const char * data - Unquoted string to set.
Return value
1 if the string is set successfully; otherwise, 0.Ptr<Xml> addChild(const char * name, const char * args = 0)
Appends a new XML node to the current XML node as a child.Arguments
- const char * name - Name of the XML node.
- const char * args - Arguments of the XML node. The default value is 0.
NoticeThis value should be passed if the first argument is a string
Return value
Created XML node.Ptr<Xml> addChild(const Ptr<Xml> & xml)
Appends a new XML node to the current XML node as a child.Arguments
- const Ptr<Xml> & xml - XML sub-tree smart pointer.
Return value
Created XML node.void clear()
Clears all data associated with the node.void clearChildren()
Clears all children of the current XML node.void clearUnusedData()
Clears the unused nodes and arguments.void copy(const Ptr<Xml> & source)
Copies all data (name, arguments, data, flags and a child hierarchy) from the source XML node to the current one.Arguments
- const Ptr<Xml> & source - Source XML node.
String decode(const char * arg1)
Decodes special XML characters (less-than, greater-than, ampersand, double-quote and apostrophe) and numeric character references.Arguments
- const char * arg1 - Data to decode.
Return value
Decoded string.String encode(const char * arg1)
Encodes special XML characters (less-than, greater-than, ampersand, double-quote and apostrophe) to their character entity reference.Arguments
- const char * arg1 - Data to encode.
Return value
Encoded string.Ptr<Xml> find(const char * path)
Searches for an XML sub-tree.Arguments
- const char * path - Path to the XML sub-tree.
Return value
Pointer to the XML node.int findArg(const char * name)
Searches for a XML argument by its name.Arguments
- const char * name - XML argument name.
Return value
XML argument number.int findChild(const char * name)
Searches for the number of the XML node child by name.Arguments
- const char * name - Name of the XML node child.
Return value
The number of the XML node child if it is exists; otherwise, -1.void grab()
Grabs the image (sets the owner flag to 1). The image should not be handled by the engine after this function is called.int load(const char * name)
Loads an XML document and sets the current node to be the root of the parsed tree.Arguments
- const char * name - File name.
Return value
1 if the file is read and parsed successfully; otherwise, 0.int parse(const char * src)
Parses a string with XML mark-up and sets the current node to be the root of the parsed tree.Arguments
- const char * src - String pointer.
Return value
1 if a string is successfully parsed; otherwise 0.void printUnusedData(const char * name)
Logs warnings of unused data for debugging.Arguments
- const char * name
void release()
Sets the owner flag to 0 for the world pointer. The world should be handled by the class after this function is called.int removeArg(const char * name)
Removes the argument with the given name from the list of the current XML node arguments.Arguments
- const char * name - Name of the target argument.
Return value
1 if the argument is deleted successfully; otherwise, 0.Ptr<Xml> removeChild(const Ptr<Xml> & xml)
Removes a child node and its descendants from the current XML node.Arguments
- const Ptr<Xml> & xml - XML sub-tree smart pointer.
Return value
Removed child node and its descendants, if they are found; otherwise, 0.int save(const char * name, int binary = 0)
Formats the tree of the current node and writes is to a file.Arguments
- const char * name - File name.
- int binary - Binary format flag.
Return value
String symbols(const char * arg1)
Replaces ampersand characters with character entity references.Arguments
- const char * arg1 - String to encode.
Return value
String which contains replaced ampersand characters with character entity references.Last update: 04.06.2018
Помогите сделать статью лучше
Была ли эта статья полезной?
(или выберите слово/фразу и нажмите Ctrl+Enter