ginga 1.0
The Ginga iTV middleware
|
Public Types | |
enum | Error { ERROR_NONE = 0 , ERROR_ELT_UNKNOWN , ERROR_ELT_MISSING_PARENT , ERROR_ELT_BAD_PARENT , ERROR_ELT_UNKNOWN_ATTRIBUTE , ERROR_ELT_MISSING_ATTRIBUTE , ERROR_ELT_BAD_ATTRIBUTE , ERROR_ELT_MUTUALLY_EXCL_ATTRIBUTES , ERROR_ELT_UNKNOWN_CHILD , ERROR_ELT_MISSING_CHILD , ERROR_ELT_BAD_CHILD , ERROR_ELT_IMPORT } |
Parser error codes. More... | |
Public Member Functions | |
ParserState (int, int) | |
Creates a new state. | |
~ParserState () | |
Destroys state. | |
ParserState::Error | getError (string *) |
Gets last parser error. | |
Document * | process (xmlDoc *) |
Processes XML document. | |
Static Public Member Functions | |
static bool | pushNcl (ParserState *, ParserElt *) |
Starts the processing of <ncl> element. | |
static bool | popNcl (ParserState *, ParserElt *) |
Ends the processing of <ncl> element. | |
static bool | pushRegion (ParserState *, ParserElt *) |
Starts the processing of <region> element. | |
static bool | popRegion (ParserState *, ParserElt *) |
Ends the processing of <region> element. | |
static bool | pushDescriptorParam (ParserState *, ParserElt *) |
Starts the processing of <descriptorParam> element. | |
static bool | pushCausalConnector (ParserState *, ParserElt *) |
Starts the processing of <causalConnector> element. | |
static bool | popCausalConnector (ParserState *, ParserElt *) |
Ends the processing of <causalConnector> element. | |
static bool | pushCompoundCondition (ParserState *, ParserElt *) |
Starts the processing of <compoundCondition> element. | |
static bool | pushSimpleCondition (ParserState *, ParserElt *) |
Starts the processing of <simpleCondition> or <simpleAction> element. | |
static bool | pushCompoundStatement (ParserState *, ParserElt *) |
Starts the processing of <compoundStatement> element. | |
static bool | popCompoundStatement (ParserState *, ParserElt *) |
Ends the processing of <compoundStatement> element. | |
static bool | popAssessmentStatement (ParserState *, ParserElt *) |
Ends the processing of <assessmentStatement> element. | |
static bool | pushAttributeAssessment (ParserState *, ParserElt *) |
Starts the processing of <attributeAssessment> or <valueAssessment> element. | |
static bool | pushRule (ParserState *, ParserElt *) |
Starts the processing of <rule> or <compositeRule> element. | |
static bool | pushImportBase (ParserState *, ParserElt *) |
Starts the processing of <importBase> element. | |
static bool | pushContext (ParserState *, ParserElt *) |
Starts the processing of <body> or <context> element. | |
static bool | popContext (ParserState *, ParserElt *) |
Ends the processing of <body> or <context> element. | |
static bool | pushPort (ParserState *, ParserElt *) |
Starts the processing of <port> element. | |
static bool | pushSwitch (ParserState *, ParserElt *) |
Starts the processing of <switch>. | |
static bool | popSwitch (ParserState *, ParserElt *) |
Ends the processing of <switch> element. | |
static bool | pushSwitchPort (ParserState *, ParserElt *) |
Starts the processing of <switchPort>. | |
static bool | pushMapping (ParserState *, ParserElt *) |
static bool | pushBindRule (ParserState *, ParserElt *) |
Starts the processing of <bindRule> or <defaultComponent> element. | |
static bool | pushMedia (ParserState *, ParserElt *) |
Starts the processing of <media> element. | |
static bool | popMedia (ParserState *, ParserElt *) |
Ends the processing of <media> element. | |
static bool | pushArea (ParserState *, ParserElt *) |
Starts the processing of <area> element. | |
static bool | pushProperty (ParserState *, ParserElt *) |
Starts the processing of <property> element. | |
static bool | pushLink (ParserState *, ParserElt *) |
Starts the processing of <link> element. | |
static bool | pushLinkParam (ParserState *, ParserElt *) |
Starts the processing of <linkParam> or <bindParam> element. | |
static bool | pushBind (ParserState *, ParserElt *) |
Starts the processing of <bind> element. | |
static bool | pushFont (ParserState *, ParserElt *) |
Starts the processing of <font> element. | |
Private Member Functions | |
string | genId () |
Generates an unique id. | |
string | getURI () |
Gets the URI of current loaded XML file. | |
bool | isInUniqueSet (const string &) |
Tests whether id is unique (hasn't been seen yet). | |
void | addToUniqueSet (const string &) |
Adds id to the set of known ids. | |
bool | getData (const string &, void **) |
Gets user data attached to parser state. | |
bool | setData (const string &, void *, UserDataCleanFunc fn=nullptr) |
Attaches user data to parser state. | |
bool | errElt (xmlNode *, ParserState::Error, const string &) |
Sets parser error code and error message. | |
bool | errEltUnknown (xmlNode *) |
Sets parser error to "Unknown element". | |
bool | errEltMissingParent (xmlNode *) |
Sets parser error to "Missing parent". | |
bool | errEltBadParent (xmlNode *) |
Sets parser error to "Bad parent". | |
bool | errEltUnknownAttribute (xmlNode *, const string &) |
Sets parser error to "Unknown attribute". | |
bool | errEltMissingAttribute (xmlNode *, const string &) |
Sets parser error to "Missing attribute". | |
bool | errEltBadAttribute (xmlNode *, const string &, const string &, const string &explain="") |
Sets parser error to "Bad value for attribute". | |
bool | errEltMutuallyExclAttributes (xmlNode *, const string &, const string &) |
Sets parser error to "Attributes are mutually exclusive". | |
bool | errEltUnknownChild (xmlNode *, const string &) |
Sets parser error to "Unknown child". | |
bool | errEltMissingChild (xmlNode *, const list< string > &) |
Sets parser error to "Missing child". | |
bool | errEltBadChild (xmlNode *, const string &, const string &explain="") |
Sets parser error to "Bad child". | |
bool | errEltImport (xmlNode *, const string &explain="") |
Sets parser error to "Syntax error in imported document". | |
bool | eltCacheIndex (xmlNode *, ParserElt **) |
Indexes element cache by node. | |
bool | eltCacheIndexParent (xmlNode *, ParserElt **) |
Indexes element cache by node parent. | |
bool | eltCacheIndexById (const string &, ParserElt **, const list< string > &) |
Indexes element cache by id. | |
size_t | eltCacheIndexByTag (const list< string > &, list< ParserElt * > *) |
Indexes element cache by tag. | |
bool | eltCacheAdd (ParserElt *) |
Adds element to cache. | |
string | aliasStackCombine () |
Combines all aliases in alias stack. | |
bool | aliasStackPeek (string *, string *) |
Peeks at alias stack. | |
bool | aliasStackPop (string *, string *) |
Pops alias stack. | |
bool | aliasStackPush (const string &, const string &) |
Pushes alias and path onto alias stack. | |
Object * | objStackPeek () |
Peeks at object stack. | |
Object * | objStackPop () |
Pops object from stack. | |
void | objStackPush (Object *) |
Pushes object onto stack. | |
Rect | rectStackPeek () |
Peeks at rectangle stack. | |
Rect | rectStackPop () |
Pops rectangle from stack. | |
void | rectStackPush (Rect) |
Pushes rectangle onto stack. | |
bool | referMapIndex (const string &, Media **) |
Indexes refer map. | |
bool | referMapAdd (const string &, Media *) |
Adds entry to refer map. | |
bool | resolveComponent (Composition *, ParserElt *, Object **) |
Resolves reference to component within a context. | |
bool | resolveInterface (Composition *, ParserElt *, Event **) |
Resolves reference to an interface within a context. | |
string | resolveParameter (const string &, const map< string, string > *, const map< string, string > *, const map< string, string > *) |
Resolve reference to (bind, link, or ghost) parameter. | |
Predicate * | obtainPredicate (xmlNode *) |
Obtains predicate associated with a <simpleCondition> node. | |
Predicate * | solvePredicate (Predicate *, const map< string, string > *) |
Obtains predicate by solving role references in another predicate. | |
ParserSyntaxElt * | checkNode (xmlNode *, map< string, string > *, list< xmlNode * > *) |
Checks node syntax according to syntax table. | |
bool | processNode (xmlNode *) |
Processes node. | |
Private Attributes | |
Document * | _doc |
The resulting #Document. | |
xmlDoc * | _xml |
The DOM tree being processed. | |
int | _genid |
Last generated id. | |
UserData | _udata |
Attached user data. | |
set< string > | _unique |
Unique attributes seen so far. | |
ParserState::Error | _error |
Last error code. | |
string | _errorMsg |
Last error message. | |
map< xmlNode *, ParserElt * > | _eltCache |
Element cache. | |
map< string, list< ParserElt * > > | _eltCacheByTag |
Element cache by tag. | |
list< pair< string, string > > | _aliasStack |
Alias stack for solving imports. | |
list< Object * > | _objStack |
Rectangle stack for solving region hierarchy. | |
list< Rect > | _rectStack |
Reference map for solving the refer attribute in <media>. | |
map< string, Media * > | _referMap |
Parser error codes.
ginga::ParserState::ParserState | ( | int | width, |
int | height ) |
Creates a new state.
width | Initial screen width (in pixels). |
height | Initial screen height (in pixels). |
|
private |
Adds id to the set of known ids.
id | The id to add. |
|
private |
Combines all aliases in alias stack.
|
private |
Peeks at alias stack.
alias | Variable to store the alias at top of stack. |
path | Variable to store the path at top of stack. |
true
if successful, or false
otherwise (alias stack is empty).
|
private |
Pops alias stack.
alias | Variable to store the popped alias. |
path | Variable to store the popped path. |
true
if successful, or false
otherwise (alias stack is empty).
|
private |
Pushes alias and path onto alias stack.
alias | The alias to push. |
path | The path to push. |
true
if successful, or false
otherwise (path already in stack).
|
private |
Checks node syntax according to syntax table.
node | The node to check. | |
[out] | attrs | Variable to store node's attributes. |
[out] | children | Variable to store node's children. |
nullptr
and sets #Parser error accordingly.
|
private |
Adds element to cache.
elt | The element to add. |
true
if successful, or false
otherwise (already in cache).
|
private |
Indexes element cache by node.
node | The node to be used as key. | |
[out] | elt | Variable to store the element associated with node (if any). |
true
if successful, or false
otherwise.
|
private |
Indexes element cache by id.
id | The id to be used as key. | |
[out] | elt | Variable to store the element associated with id (if any). |
tags | Accepted tags (match only elements with one of these). |
true
if successful, or false
otherwise.
|
private |
Indexes element cache by tag.
tags | The tags to be used as keys. | |
[out] | result | Variable to store the list of matched elements. |
|
private |
Indexes element cache by node parent.
node | The node whose parent will be used as key. | |
[out] | elt | Variable to store the element associated with node (if any). |
true
if successful, or false
otherwise.
|
private |
Sets parser error code and error message.
node | The node that caused the error. |
error | The error code to be set. |
message | The error message to be set. |
false
.
|
private |
Sets parser error to "Bad value for attribute".
node | The node that caused the error. |
name | The name of the attribute that caused the error. |
value | The value of the attribute that caused the error. |
explain | Further explanation. |
false
.
|
private |
Sets parser error to "Bad child".
node | The node that caused the error. |
name | The name of the child that caused the error. |
explain | Further explanation. |
false
.
|
private |
Sets parser error to "Bad parent".
node | The node that caused the error. |
false
.
|
private |
Sets parser error to "Syntax error in imported document".
node | The <importBase> node that caused the error. |
explain | Further explanation. return false |
|
private |
Sets parser error to "Missing attribute".
node | The node that caused the error. |
name | The name of the attribute that caused the error. |
false
.
|
private |
Sets parser error to "Missing child".
node | The node that caused the error. |
children | The list of names of children that caused the error. |
false
.
|
private |
Sets parser error to "Missing parent".
node | The node that caused the error. |
false
.
|
private |
Sets parser error to "Attributes are mutually exclusive".
node | The node that caused the error. |
attr1 | The name of the first attribute. |
attr2 | The name of the second attribute. |
false
.
|
private |
Sets parser error to "Unknown element".
node | The node that caused the error. |
false
.
|
private |
Sets parser error to "Unknown attribute".
node | The node that caused the error. |
name | The name of the attribute that caused the error. |
false
.
|
private |
Sets parser error to "Unknown child".
node | The node that caused the error. |
name | The name of the child element that caused the error. |
false
.
|
private |
Generates an unique id.
|
private |
Gets user data attached to parser state.
key | User data key. | |
[out] | value | Variable to store user data value (if any). |
true
if successful, or false
otherwise. ParserState::Error ginga::ParserState::getError | ( | string * | message | ) |
Gets last parser error.
[out] | message | Variable to store the last error message (if any). |
|
private |
Gets the URI of current loaded XML file.
|
private |
Tests whether id is unique (hasn't been seen yet).
id | The id to test. |
true
if successful, or false
otherwise.
|
private |
Peeks at object stack.
|
private |
Pops object from stack.
|
private |
Pushes object onto stack.
obj | The object to push. |
|
private |
Obtains predicate associated with a <simpleCondition> node.
This function collects all predicates inherited by node
and, if there are such predicates, combines them into a new predicate and returns it.
node | The simple condition node. |
node
, or nullptr
if node
has no associated predicate.
|
static |
Ends the processing of <assessmentStatement> element.
This function creates an associated atomic #Predicate for elt
.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Ends the processing of <causalConnector> element.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Ends the processing of <compoundStatement> element.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Ends the processing of <body> or <context> element.
This function resolves context ports and pops the object stack.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Ends the processing of <media> element.
This function pops the object stack.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Ends the processing of <ncl> element.
This function resolves all non-local references.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Ends the processing of <region> element.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Ends the processing of <switch> element.
This function pops the object stack.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise. Document * ginga::ParserState::process | ( | xmlDoc * | xml | ) |
Processes XML document.
This function is a wrapper over ParserState::processNode(). It calls the later with the root node of the given XML document and, if nothing goes wrong, returns the resulting document.
xml | The XML document to process. |
|
private |
Processes node.
After being called by ParserState::process(), starting from the root node, this function proceeds recursively, processing each node in the input document tree. For each node, it checks its syntax (according to parser_syntax_table), calls the corresponding push function (if any), processes the node's children, and calls the corresponding pop function (if any). At any moment, if something goes wrong the function sets #Parser error and returns false.
node | The node to process. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <area> element.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <attributeAssessment> or <valueAssessment> element.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <bind> element.
This function parsers elt
and stores it as a #ParserLinkBind in the list of binds of the current link.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <bindRule> or <defaultComponent> element.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <causalConnector> element.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <compoundCondition> element.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <compoundStatement> element.
This function creates an associated compound #Predicate for elt
.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <body> or <context> element.
This function parses elt
and pushes it as a #Context onto the object stack.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <descriptorParam> element.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <font> element.
This function parses elt
and loads the font using fontconfig.
st | ParserState |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <importBase> element.
This function uses the ParserState alias stack to collect and process nested imports.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <link> element.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <linkParam> or <bindParam> element.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <media> element.
This function parsers elt
and pushes it as a #Media onto the object stack.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <ncl> element.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <port> element.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <property> element.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <region> element.
This function uses the initial screen dimensions stored in ParserState to convert into absolute values any relative values used in <region> attributes.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <rule> or <compositeRule> element.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <simpleCondition> or <simpleAction> element.
This function parsers elt
and stores it as a #ParserConnRole in the list of rules of the current connector.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <switch>.
This function parsers elt
and pushes it as a #Switch onto the object stack.
st | ParserState. |
elt | Element wrapper. |
true
if successful, or false
otherwise.
|
static |
Starts the processing of <switchPort>.
Starts the processing of <mapping>.
This function parsers elt
and pushes it as a <switchPort> on the object stack.
st | |
elt |
This function parsers elt
and pushes it component/interface attributes in the mappings list cache in the <switchPort>.
st | |
elt |
|
private |
Peeks at rectangle stack.
This function aborts when called with the empty stack.
|
private |
Pops rectangle from stack.
This function aborts when called with the empty stack.
|
private |
Pushes rectangle onto stack.
rect | The rectangle to push. |
|
private |
Adds entry to refer map.
id | The id of the reference. |
media | The referenced media. |
true
if successful, or false
otherwise (already in map).
|
private |
Indexes refer map.
id | The id of the reference. | |
[out] | media | Variable to store referenced media. |
true
if successful, or false
otherwise.
|
private |
Resolves reference to component within a context.
This function assumes that elt
has an attribute "component" which contains the id of the component to be resolved. In case resolution fails, the function sets #Parser error accordingly.
scope | The composition that determines the resolution scope. | |
elt | The element to be resolved. | |
[out] | obj | Variable to store the resulting object (if any). |
true
if successful, or false
otherwise.
|
private |
Resolves reference to an interface within a context.
This function assumes that elt
has attributes "component" and "interface" which identify the interface to be resolved. In case resolution fails, the function sets #Parser error accordingly.
ctx | The contexts that determines the resolution scope. | |
elt | The element to be resolved. | |
[out] | evt | Variable to store the resulting event (if any). |
true
if successful, or false
otherwise.
|
private |
Resolve reference to (bind, link, or ghost) parameter.
The function uses the translation tables in the order they were given, and returns as soon as any of them resolves the reference.
ref | The reference to resolve. |
bindParams | The bind parameter translation table. |
linkParams | The link parameter translation table. |
ghosts | The ghost binds translation table. |
ref
itself if it is not a reference.
|
private |
Attaches user data to parser state.
key | User data key. |
value | User data value. |
fn | Cleanup function (used to destroy data when #ParserElt is destroyed or key is overwritten). |
true
if key was previously unset, or false
otherwise.
|
private |
Obtains predicate by solving role references in another predicate.
This function does not modify predicate pred
.
pred | The predicate to solve. |
tr | The role translation table mapping role references to property references. |
pred
via table tr
.
|
private |
Alias stack for solving imports.
#Object stack for solving object hierarchy.