nsXFormsMDGEngine Class Reference

#include <nsXFormsMDGEngine.h>

Inheritance diagram for nsXFormsMDGEngine:

Inheritance graph
[legend]
Collaboration diagram for nsXFormsMDGEngine:

Collaboration graph
[legend]

List of all members.


Detailed Description

This class handles all the necessary logic to create and maintain the MDG, and update the instance data accordingly.

A bit about the graph: As specified in the spec., one node (nsXFormsMDGNode) is created in the graph for each of the attributes (readonly, calculate, etc.) for a nsIDOMNode. These graph nodes are owned by the mNodeToMDG hash table, which maps from a nsIDOMNode to the first node in a single-linked list (mNext) of nodes for the same nsIDOMNode.

Todo:
Merge SetNodeValue() with nsXFormsUtils::SetNodeValue() (XXX)

Public Member Functions

 nsXFormsMDGEngine ()
 Constructor.
 ~nsXFormsMDGEngine ()
nsresult Init (nsXFormsModelElement *aModel)
 Initializes the internal structures.
nsresult AddMIP (ModelItemPropName aType, nsIDOMNSXPathExpression *aExpression, nsCOMArray< nsIDOMNode > *aDependencies, PRBool aDynFunc, nsIDOMNode *aContextNode, PRInt32 aContextPos, PRInt32 aContextSize)
 Insert new MIP (Model Item Property) into graph.
nsresult Recalculate (nsCOMArray< nsIDOMNode > *aChangedNodes)
 Recalculate the MDG.
nsresult Revalidate (nsCOMArray< nsIDOMNode > *aNodes)
 Revalidate nodes.
nsresult Rebuild ()
 Rebuilds the MDG.
nsresult Clear ()
 Clears all information in the MDG.
nsresult ClearDispatchFlags ()
 Clears all Dispatch flags.
nsresult MarkNodeAsChanged (nsIDOMNode *aContextNode)
 Mark a node as changed.
nsresult SetNodeValue (nsIDOMNode *aContextNode, const nsAString &aNodeValue, PRBool *aNodeChanged=nsnull)
 Set the value of a node -- the public version of SetNodeValueInternal().
nsresult SetNodeContent (nsIDOMNode *aContextNode, nsIDOMNode *aContentEnvelope)
 Set the contents of a node.
const nsXFormsNodeStateGetNodeState (nsIDOMNode *aContextNode)
 External interface of GetNCNodeState(), returns const pointer to the node state.
void PrintDot (const char *aFile=nsnull)
 Write MDG graph to a file in GraphViz dot format.

Protected Member Functions

 nsXFormsMDGEngine (nsXFormsMDGEngine &)
 Hidden copy constructor.
nsXFormsNodeStateGetNCNodeState (nsIDOMNode *aContextNode)
 Get non-const (NC) node state for a node, create a new node state if necessary.
nsresult CreateNewChild (nsIDOMNode *aContextNode, const nsAString &aNodeValue, nsIDOMNode *aBeforeNode=nsnull)
 Inserts a new text child for aContextNode.
nsXFormsMDGNodeGetNode (nsIDOMNode *aDomNode, ModelItemPropName aType, PRBool aCreate=PR_TRUE)
 Retrieve a node from the graph.
PRBool AndFlags (PRUint16 aAndMask)
 Boolean AND _all_ flags with a mask.
nsresult BooleanExpression (nsXFormsMDGNode *aNode, PRBool &aRes)
 Evaluates the expression for the given node and returns the boolean result.
nsresult ComputeMIP (eFlag_t aStateFlag, eFlag_t aDispatchFlag, nsXFormsMDGNode *aNode, PRBool &aDidChange)
 Compute MIP value for node types with boolean result (all except calculate).
nsresult ComputeMIPWithInheritance (eFlag_t aStateFlag, eFlag_t aDispatchFlag, eFlag_t aInheritanceFlag, nsXFormsMDGNode *aNode, nsCOMArray< nsIDOMNode > *aSet)
 Same as ComputeMIP(), but also handles any inheritance of attributes.
nsresult AttachInheritance (nsCOMArray< nsIDOMNode > *aSet, nsIDOMNode *aSrc, PRBool aState, eFlag_t aStateFlag)
 Attaches inheritance to all children of a given node.
nsresult Invalidate ()
 Invalidate the information, ie.
nsresult SetNodeValueInternal (nsIDOMNode *aContextNode, const nsAString &aNodeValue, PRBool aMarkNode=PR_TRUE, PRBool aIsCalculate=PR_FALSE, PRBool *aNodeChanged=nsnull)
 Set the value of a node.
nsresult HandleMarkedNodes (nsCOMArray< nsIDOMNode > *aArray)
 Handle nodes nodes marked as dirty, and insert into "changed nodes array".

Static Protected Member Functions

static PLDHashOperator PR_CALLBACK DeleteLinkedNodes (nsISupports *aKey, nsAutoPtr< nsXFormsMDGNode > &aNode, void *aArg)
 Used by Clear() and ~ to delete the linked nodes in mNodeToMDG, the hash table itself handles the main nodes.
static PLDHashOperator PR_CALLBACK AddStartNodes (nsISupports *aKey, nsXFormsMDGNode *aNode, void *aDeque)
 Used by Rebuild() to find the start nodes for mGraph, that is nodes where mCount == 0.
static PLDHashOperator PR_CALLBACK AndFlag (nsISupports *aKey, nsAutoPtr< nsXFormsNodeState > &aState, void *aMask)
 Used by AndFlags() to boolean AND _all_ flags with aMask.

Protected Attributes

nsClassHashtable
< nsISupportsHashKey,
nsXFormsMDGNode
mNodeToMDG
 Maps from nsIDOMNode to nsXFormsMDGNode.
nsClassHashtable
< nsISupportsHashKey,
nsXFormsNodeState
mNodeStates
 Maps from nsIDOMNode to nsXFormsNodeState.
nsXFormsNodeState mDefaultState
 Default node state.
PRBool mJustRebuilt
 True when Rebuild() has been run, but not ClearDispatchFlags().
PRBool mFirstCalculate
 True when last Calculate() was run when mJustRebuilt was true.
nsVoidArray mGraph
 The actual MDG.
nsXFormsModelElementmModel
 The model that created the MDG.
nsCOMArray< nsIDOMNodemMarkedNodes
 Nodes that are marked as changed, and should be included in recalculation.
PRInt32 mNodesInGraph
 Number of nodes in the graph.

Constructor & Destructor Documentation

nsXFormsMDGEngine::nsXFormsMDGEngine ( nsXFormsMDGEngine  )  [inline, protected]

nsXFormsMDGEngine::nsXFormsMDGEngine (  ) 

nsXFormsMDGEngine::~nsXFormsMDGEngine (  ) 


Member Function Documentation

PLDHashOperator nsXFormsMDGEngine::DeleteLinkedNodes ( nsISupports aKey,
nsAutoPtr< nsXFormsMDGNode > &  aNode,
void *  aArg 
) [static, protected]

PLDHashOperator nsXFormsMDGEngine::AddStartNodes ( nsISupports aKey,
nsXFormsMDGNode aNode,
void *  aDeque 
) [static, protected]

Todo:
Is it not possible to check error condition? (XXX)

PLDHashOperator nsXFormsMDGEngine::AndFlag ( nsISupports aKey,
nsAutoPtr< nsXFormsNodeState > &  aState,
void *  aMask 
) [static, protected]

nsXFormsNodeState * nsXFormsMDGEngine::GetNCNodeState ( nsIDOMNode aContextNode  )  [protected]

Parameters:
aContextNode The node to get the state for
Returns:
The state (owned by nsXFormsMDGEngine)

nsresult nsXFormsMDGEngine::CreateNewChild ( nsIDOMNode aContextNode,
const nsAString aNodeValue,
nsIDOMNode aBeforeNode = nsnull 
) [protected]

Parameters:
aContextNode The node to create a child for
aNodeValue The value of the new node
aBeforeNode If non-null, insert new node before this node

nsXFormsMDGNode * nsXFormsMDGEngine::GetNode ( nsIDOMNode aDomNode,
ModelItemPropName  aType,
PRBool  aCreate = PR_TRUE 
) [protected]

Parameters:
aDomNode The DOM node to retrieve
aType The type to retrieve (readonly, calculate, etc)
aCreate Create the node and insert it into the graph if it does not exist?
Returns:
The node, nsnull if not found and aCreate != PR_TRUE
Note:
aType == eModel_type means "any type", as we do not store type information in the MDG.

PRBool nsXFormsMDGEngine::AndFlags ( PRUint16  aAndMask  )  [protected]

Parameters:
aAndMask The mask
Returns:
Did operation succeed?

nsresult nsXFormsMDGEngine::BooleanExpression ( nsXFormsMDGNode aNode,
PRBool aRes 
) [protected]

Parameters:
aNode The node to evaluate
aRes The result of the evaluation

nsresult nsXFormsMDGEngine::ComputeMIP ( eFlag_t  aStateFlag,
eFlag_t  aDispatchFlag,
nsXFormsMDGNode aNode,
PRBool aDidChange 
) [protected]

Parameters:
aStateFlag The flag for the type of MIP
aDispatchFlag The dispatch flag
aNode The context node
aDidChange Was the node changed?

nsresult nsXFormsMDGEngine::ComputeMIPWithInheritance ( eFlag_t  aStateFlag,
eFlag_t  aDispatchFlag,
eFlag_t  aInheritanceFlag,
nsXFormsMDGNode aNode,
nsCOMArray< nsIDOMNode > *  aSet 
) [protected]

Parameters:
aStateFlag The flag for the type of MIP
aDispatchFlag The dispatch flag
aInheritanceFlag The inheritance flag for the type of MIP
aNode The context node
aSet Set of the nodes influenced by operation

nsresult nsXFormsMDGEngine::AttachInheritance ( nsCOMArray< nsIDOMNode > *  aSet,
nsIDOMNode aSrc,
PRBool  aState,
eFlag_t  aStateFlag 
) [protected]

Parameters:
aSet Set of the nodes influenced by operation
aSrc The node
aState The state of the flag
aStateFlag The flag

nsresult nsXFormsMDGEngine::Invalidate (  )  [protected]

mark all nodes as dirty.

nsresult nsXFormsMDGEngine::SetNodeValueInternal ( nsIDOMNode aContextNode,
const nsAString aNodeValue,
PRBool  aMarkNode = PR_TRUE,
PRBool  aIsCalculate = PR_FALSE,
PRBool aNodeChanged = nsnull 
) [protected]

Parameters:
aContextNode The node to set the value for
aNodeValue The value
aMarkNode Whether to mark node as changed
aNodeChanged Was node changed?
aIsCalculate Is it a setting the value?

Todo:
Better feedback for readonly nodes? (XXX)

Unsupported nodeType

Todo:
Should return more specific error? (XXX)

nsresult nsXFormsMDGEngine::HandleMarkedNodes ( nsCOMArray< nsIDOMNode > *  aArray  )  [protected]

Parameters:
aArray The "changed nodes array" to insert into

nsresult nsXFormsMDGEngine::Init ( nsXFormsModelElement aModel  ) 

Needs to be called before class is used!

Parameters:
aModel The model that created this MDGEngine instance.

nsresult nsXFormsMDGEngine::AddMIP ( ModelItemPropName  aType,
nsIDOMNSXPathExpression aExpression,
nsCOMArray< nsIDOMNode > *  aDependencies,
PRBool  aDynFunc,
nsIDOMNode aContextNode,
PRInt32  aContextPos,
PRInt32  aContextSize 
)

Parameters:
aType The type of MIP
aExpression The XPath expression
aDependencies Set of nodes expression depends on
aDynFunc True if expression uses dynamic functions
aContextNode The context node for aExpression
aContextPos The context positions of aExpression
aContextSize The context size for aExpression

nsresult nsXFormsMDGEngine::Recalculate ( nsCOMArray< nsIDOMNode > *  aChangedNodes  ) 

Parameters:
aChangedNodes Returns the nodes that was changed during recalculation.

nsresult nsXFormsMDGEngine::Revalidate ( nsCOMArray< nsIDOMNode > *  aNodes  ) 

Parameters:
aNodes The nodes to revalidate

nsresult nsXFormsMDGEngine::Rebuild (  ) 

nsresult nsXFormsMDGEngine::Clear ( void   ) 

nsresult nsXFormsMDGEngine::ClearDispatchFlags (  ) 

nsresult nsXFormsMDGEngine::MarkNodeAsChanged ( nsIDOMNode aContextNode  ) 

Parameters:
aContextNode The node to be marked.

nsresult nsXFormsMDGEngine::SetNodeValue ( nsIDOMNode aContextNode,
const nsAString aNodeValue,
PRBool aNodeChanged = nsnull 
)

Parameters:
aContextNode The node to set the value for
aNodeValue The value
aNodeChanged Was node changed?

nsresult nsXFormsMDGEngine::SetNodeContent ( nsIDOMNode aContextNode,
nsIDOMNode aContentEnvelope 
)

Parameters:
aContextNode The node to set the contents of
aContentEnvelope The container of the contents that need to be moved under aContextNode

Todo:
Better feedback for readonly nodes? (XXX)

const nsXFormsNodeState * nsXFormsMDGEngine::GetNodeState ( nsIDOMNode aContextNode  ) 

Parameters:
aContextNode The node to get the state for
Returns:
The state (owned by nsXFormsMDGEngine)

void nsXFormsMDGEngine::PrintDot ( const char aFile = nsnull  ) 

Parameters:
aFile Filename to write to (nsnull = stdout)


Member Data Documentation


The documentation for this class was generated from the following files:

Generated Mozilla by doxygen 1.5.6