lightningsunbird
0.9+nobinonly

A collection of valuetovariable assignments that minimizes copying by sharing subsets when possible. More...
#include <nsRuleNetwork.h>
Classes  
class  ConstIterator 
class  List 
Public Member Functions  
nsAssignmentSet ()  
nsAssignmentSet (const nsAssignmentSet &aSet)  
nsAssignmentSet &  operator= (const nsAssignmentSet &aSet) 
~nsAssignmentSet ()  
ConstIterator  First () const 
ConstIterator  Last () const 
nsresult  Add (const nsAssignment &aElement) 
Add an assignment to the set.  
PRBool  HasAssignment (PRInt32 aVariable, const Value &aValue) const 
Determine if the assignment set contains the specified variable to value assignment.  
PRBool  HasAssignment (const nsAssignment &aAssignment) const 
Determine if the assignment set contains the specified assignment.  
PRBool  HasAssignmentFor (PRInt32 aVariable) const 
Determine whether the assignment set has an assignment for the specified variable.  
PRBool  GetAssignmentFor (PRInt32 aVariable, Value *aValue) const 
Retrieve the assignment for the specified variable.  
PRInt32  Count () const 
Count the number of assignments in the set.  
PRBool  IsEmpty () const 
Determine if the set is empty.  
PRBool  Equals (const nsAssignmentSet &aSet) const 
PRBool  operator== (const nsAssignmentSet &aSet) const 
PRBool  operator!= (const nsAssignmentSet &aSet) const 
Protected Attributes  
List *  mAssignments 
Friends  
class  ConstIterator 
A collection of valuetovariable assignments that minimizes copying by sharing subsets when possible.
Definition at line 411 of file nsRuleNetwork.h.
nsAssignmentSet::nsAssignmentSet  (  )  [inline] 
Definition at line 440 of file nsRuleNetwork.h.
: mAssignments(nsnull) { MOZ_COUNT_CTOR(nsAssignmentSet); }
nsAssignmentSet::nsAssignmentSet  (  const nsAssignmentSet &  aSet  )  [inline] 
Definition at line 444 of file nsRuleNetwork.h.
: mAssignments(aSet.mAssignments) { MOZ_COUNT_CTOR(nsAssignmentSet); NS_IF_ADDREF(mAssignments); }
nsAssignmentSet::~nsAssignmentSet  (  )  [inline] 
Definition at line 455 of file nsRuleNetwork.h.
nsresult nsAssignmentSet::Add  (  const nsAssignment &  aElement  ) 
Add an assignment to the set.
aElement  the assigment to add 
Definition at line 542 of file nsRuleNetwork.cpp.
{ NS_PRECONDITION(! HasAssignmentFor(aAssignment.mVariable), "variable already bound"); if (HasAssignmentFor(aAssignment.mVariable)) return NS_ERROR_UNEXPECTED; List* list = new List; if (! list) return NS_ERROR_OUT_OF_MEMORY; list>mAssignment = aAssignment; list>mRefCnt = 1; list>mNext = mAssignments; mAssignments = list; return NS_OK; }
PRInt32 nsAssignmentSet::Count  (  )  const 
Count the number of assignments in the set.
Definition at line 562 of file nsRuleNetwork.cpp.
{ PRInt32 count = 0; for (ConstIterator assignment = First(); assignment != Last(); ++assignment) ++count; return count; }
PRBool nsAssignmentSet::Equals  (  const nsAssignmentSet &  aSet  )  const 
Definition at line 607 of file nsRuleNetwork.cpp.
{ if (aSet.mAssignments == mAssignments) return PR_TRUE; // If they have a different number of assignments, then they're different. if (Count() != aSet.Count()) return PR_FALSE; // XXX O(n^2)! Ugh! for (ConstIterator assignment = First(); assignment != Last(); ++assignment) { Value value; if (! aSet.GetAssignmentFor(assignment>mVariable, &value)) return PR_FALSE; if (assignment>mValue != value) return PR_FALSE; } return PR_TRUE; }
ConstIterator nsAssignmentSet::First  (  )  const [inline] 
Definition at line 508 of file nsRuleNetwork.h.
{ return ConstIterator(mAssignments); }
PRBool nsAssignmentSet::GetAssignmentFor  (  PRInt32  aVariable, 
Value *  aValue  
)  const 
Retrieve the assignment for the specified variable.
aVariable  the variable to query 
aValue  an out parameter that will receive the value assigned to the variable, if any. 
Definition at line 594 of file nsRuleNetwork.cpp.
{ for (ConstIterator assignment = First(); assignment != Last(); ++assignment) { if (assignment>mVariable == aVariable) { *aValue = assignment>mValue; return PR_TRUE; } } return PR_FALSE; }
PRBool nsAssignmentSet::HasAssignment  (  PRInt32  aVariable, 
const Value &  aValue  
)  const 
Determine if the assignment set contains the specified variable to value assignment.
aVariable  the variable for which to lookup the binding 
aValue  the value to query 
Definition at line 572 of file nsRuleNetwork.cpp.
{ for (ConstIterator assignment = First(); assignment != Last(); ++assignment) { if (assignment>mVariable == aVariable && assignment>mValue == aValue) return PR_TRUE; } return PR_FALSE; }
PRBool nsAssignmentSet::HasAssignment  (  const nsAssignment &  aAssignment  )  const [inline] 
Determine if the assignment set contains the specified assignment.
aAssignment  the assignment to search for 
Definition at line 534 of file nsRuleNetwork.h.
{ return HasAssignment(aAssignment.mVariable, aAssignment.mValue); }
PRBool nsAssignmentSet::HasAssignmentFor  (  PRInt32  aVariable  )  const 
Determine whether the assignment set has an assignment for the specified variable.
aVariable  the variable to query 
Definition at line 583 of file nsRuleNetwork.cpp.
{ for (ConstIterator assignment = First(); assignment != Last(); ++assignment) { if (assignment>mVariable == aVariable) return PR_TRUE; } return PR_FALSE; }
PRBool nsAssignmentSet::IsEmpty  (  )  const [inline] 
Determine if the set is empty.
Definition at line 566 of file nsRuleNetwork.h.
{ return mAssignments == nsnull; }
ConstIterator nsAssignmentSet::Last  (  )  const [inline] 
Definition at line 509 of file nsRuleNetwork.h.
{ return ConstIterator(nsnull); }
PRBool nsAssignmentSet::operator!=  (  const nsAssignmentSet &  aSet  )  const [inline] 
Definition at line 570 of file nsRuleNetwork.h.
{ return !Equals(aSet); }
nsAssignmentSet& nsAssignmentSet::operator=  (  const nsAssignmentSet &  aSet  )  [inline] 
Definition at line 449 of file nsRuleNetwork.h.
{ NS_IF_RELEASE(mAssignments); mAssignments = aSet.mAssignments; NS_IF_ADDREF(mAssignments); return *this; }
PRBool nsAssignmentSet::operator==  (  const nsAssignmentSet &  aSet  )  const [inline] 
Definition at line 569 of file nsRuleNetwork.h.
{ return Equals(aSet); }
friend class ConstIterator [friend] 
Definition at line 413 of file nsRuleNetwork.h.
List* nsAssignmentSet::mAssignments [protected] 
Definition at line 437 of file nsRuleNetwork.h.