Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Protected Attributes | Friends
nsAssignmentSet Class Reference

A collection of value-to-variable assignments that minimizes copying by sharing subsets when possible. More...

#include <nsRuleNetwork.h>

Collaboration diagram for nsAssignmentSet:
Collaboration graph
[legend]

List of all members.

Classes

class  ConstIterator
class  List

Public Member Functions

 nsAssignmentSet ()
 nsAssignmentSet (const nsAssignmentSet &aSet)
nsAssignmentSetoperator= (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

ListmAssignments

Friends

class ConstIterator

Detailed Description

A collection of value-to-variable assignments that minimizes copying by sharing subsets when possible.

Definition at line 411 of file nsRuleNetwork.h.


Constructor & Destructor Documentation

Definition at line 440 of file nsRuleNetwork.h.


Member Function Documentation

Add an assignment to the set.

Parameters:
aElementthe assigment to add
Returns:
NS_OK if all is well, NS_ERROR_OUT_OF_MEMORY if memory could not be allocated for the addition.

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Count the number of assignments in the set.

Returns:
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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 508 of file nsRuleNetwork.h.

Here is the caller graph for this function:

PRBool nsAssignmentSet::GetAssignmentFor ( PRInt32  aVariable,
Value aValue 
) const

Retrieve the assignment for the specified variable.

Parameters:
aVariablethe variable to query
aValuean out parameter that will receive the value assigned to the variable, if any.
Returns:
PR_TRUE if the variable has an assignment, PR_FALSE if there was no assignment for the variable.

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsAssignmentSet::HasAssignment ( PRInt32  aVariable,
const Value aValue 
) const

Determine if the assignment set contains the specified variable to value assignment.

Parameters:
aVariablethe variable for which to lookup the binding
aValuethe value to query
Returns:
PR_TRUE if aVariable is bound to aValue; PR_FALSE otherwise.

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsAssignmentSet::HasAssignment ( const nsAssignment aAssignment) const [inline]

Determine if the assignment set contains the specified assignment.

Parameters:
aAssignmentthe assignment to search for
Returns:
PR_TRUE if the set contains the assignment, PR_FALSE otherwise.

Definition at line 534 of file nsRuleNetwork.h.

                                                                {
        return HasAssignment(aAssignment.mVariable, aAssignment.mValue); }

Here is the call graph for this function:

Determine whether the assignment set has an assignment for the specified variable.

Parameters:
aVariablethe variable to query
Returns:
PR_TRUE if the assignment set has an assignment for the variable, PR_FALSE otherwise.

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsAssignmentSet::IsEmpty ( ) const [inline]

Determine if the set is empty.

Returns:
PR_TRUE if the assignment set is empty, PR_FALSE otherwise.

Definition at line 566 of file nsRuleNetwork.h.

{ return mAssignments == nsnull; }

Definition at line 509 of file nsRuleNetwork.h.

{ return ConstIterator(nsnull); }

Here is the caller graph for this function:

PRBool nsAssignmentSet::operator!= ( const nsAssignmentSet aSet) const [inline]

Definition at line 570 of file nsRuleNetwork.h.

{ return !Equals(aSet); }

Here is the call graph for this function:

nsAssignmentSet& nsAssignmentSet::operator= ( const nsAssignmentSet aSet) [inline]

Definition at line 449 of file nsRuleNetwork.h.

PRBool nsAssignmentSet::operator== ( const nsAssignmentSet aSet) const [inline]

Definition at line 569 of file nsRuleNetwork.h.

{ return Equals(aSet); }

Here is the call graph for this function:


Friends And Related Function Documentation

friend class ConstIterator [friend]

Definition at line 413 of file nsRuleNetwork.h.


Member Data Documentation

Definition at line 437 of file nsRuleNetwork.h.


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