#include <Twig.hpp>
Public Member Functions | |
| Twig () | |
| Creates a new Twig. | |
| Twig (std::string twig_str, bool has_ele_name=false) | |
| Creates a new Twig from an old one. | |
| bool | fromString (std::string trig_str, bool has_ele_name=false) |
| Parses a string and converts it into a Twig. | |
| std::string | toString () |
| Translates from a Twig to the equivalent string. | |
| std::string | toNodeString (bool include_target_attrib=false) |
| Translates the node part of a Twig to the equivalent string. | |
| UAPNode * | getLocalSubNode (UAPNode *root, bool create=false) |
| Finds a subnode that matches a Twig. | |
| UAPNode * | getSubNode (UAPNode *root) |
| Finds a subnode that matches a Twig. | |
| NodeVec | getSubNodes (UAPNode *root) |
| Finds all subnodes that matches a Twig. | |
| bool | matchNameAndPrefix (UAPNode *named_node) |
| Match name and prefix from a Twig to the name and prefix attributes in a UAPNode. | |
| bool | operator== (Twig t) |
| Test to see if two Twigs are identical. | |
Static Public Member Functions | |
| static UAPNode * | getLocalSubNode (UAPNode *root, std::string twig_str, bool create=false) |
| Finds a subnode that matches a Twig. | |
| static NodeVec | getSubNodes (UAPNode *root, std::string twig_str) |
| Finds all subnodes that matches a Twig. | |
Example: A string (in what is called "bracket" notation): "p1.p2.q[quadrupole:k(a=1,b)@err]" When translated into a Twig the string looks like: .target_attribute = "err" .name = "q" .prefix[0] = "p1" .prefix[1] = "p2" .has_brackets = true .node_vec[0] .name = "quadrupole" .node_vec[1] .name = "k" .attrib[0] .name = "a" .value = "1" .attrib[1] .name = "b" .value = "" And, for example, this Twig will match to the following portion of a UAPNode tree: <xxx name="q"> |- <quadrupole ttt="yyy"> |- <k a="1" b="zzz">
In this example the <k> node is called the "base" node of the twig, and the <xxx> node is called the "head" node.
The above string is equivalent to the string (in "bracketless" notation): "*(name = q,prefix = p1.p2):quadrupole:k(a=1,b)%err" When translated into a Twig this string looks like .target_attribute = "err" .has_brackets = false .node_vec[0] .name = "*" .attrib[0] .name = "name" .value = "q" .attrib[1] .name = "prefix" .value = "p1.p2" .node_vec[1] .name = "quadrupole" .node_vec[2] .name = "k" .attrib[0] .name = "a" .value = "1" .attrib[1] .name = "b" .value = ""
Some examples:
Input Prefix name node_vec ---------- --------------- ---- --------- "A...B.Z[]" ["A", ".", "B"] "Z" None "A...Z[]" ["A", "."] "Z" None ".Z[]" [""] "Z" None "Z[]" [] "Z" None "X:Y:Z" [] "" ["X", "Y", "Z"]
Note that something in "bracket" notation can always be converted into "bracketless" but the reverse is not always possible.
Note: The difference between Twig("a[]", true) and Twig("a", true) is that the first Twig has .has_brackets = true and the second has .has_brackets = false.
Note: When a component is potentially confusing (has internal ".", ":", etc.), quotation Marks can be used. Example: q[quadrupole:(k(a="1.3")] beam:'{http://cern.ch/madx}madx':energy
Definition at line 184 of file Twig.hpp.
| Twig::Twig | ( | std::string | twig_str, | |
| bool | has_ele_name = false | |||
| ) |
| bool Twig::fromString | ( | std::string | trig_str, | |
| bool | has_ele_name = false | |||
| ) |
Parses a string and converts it into a Twig.
The parsing will handle strings that are or are not in bracket notation. For example: twig_str = "q1[quadrupole:k(n=1)@err]" If the string does not have brackets "[...]", or ":", etc. like: twig_str = "q" Then it is ambiguous whether "q" is an element name or an attribute name.
| twig_str | Input string. | |
| has_ele_name | If True then an ambiguous name is interpreted as an element name. |
| UAPNode * Twig::getLocalSubNode | ( | UAPNode * | root, | |
| std::string | twig_str, | |||
| bool | create = false | |||
| ) | [static] |
Finds a subnode that matches a Twig.
The root node is assumed to match .name and the root's children are searched for a match to .node_vec[0]. When a match to .node_vec[0] is found, the children of the matching node are searched for a match to .node_vec[1], etc.
| root | Root node for searching. | |
| twig_str | String equivalent of a string. | |
| create | If true then create subnode if not found. |
Finds a subnode that matches a Twig.
The root node is assumed to match .name and the root's children are searched for a match to .node_vec[0]. When a match to .node_vec[0] is found, the children of the matching node are searched for a match to .node_vec[1], etc. This method assumes that there are no multiple matches to .node_vec[i].
| root | root node for searching. | |
| create | If true then create subnode if not found. |
| NodeVec Twig::getSubNodes | ( | UAPNode * | root | ) |
| NodeVec Twig::getSubNodes | ( | UAPNode * | root, | |
| std::string | twig_str | |||
| ) | [static] |
| bool Twig::matchNameAndPrefix | ( | UAPNode * | named_node | ) |
Match name and prefix from a Twig to the name and prefix attributes in a UAPNode.
That is, the node is of the form: <xxx name="..." prefix="...">. Note: The twig name and prefix may contain "*" and "%" wild card characters.
| named_node | Node with a name attribute and possibly a prefix attribute. |
| bool Twig::operator== | ( | Twig | t | ) |
| string Twig::toNodeString | ( | bool | include_target_attrib = false |
) |
| string Twig::toString | ( | ) |
1.5.7