Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Attributes
VariableSet Class Reference

A set of variables. More...

#include <nsRuleNetwork.h>

List of all members.

Public Member Functions

 VariableSet ()
 ~VariableSet ()
nsresult Add (PRInt32 aVariable)
 Add a variable to the set.
nsresult Remove (PRInt32 aVariable)
 Remove a variable from the set.
PRBool Contains (PRInt32 aVariable) const
 Determine if the set contains a variable.
PRInt32 GetCount () const
 Determine the number of variables in the set.
PRInt32 GetVariableAt (PRInt32 aIndex) const
 Get the ith variable in the set.

Protected Attributes

PRInt32mVariables
PRInt32 mCount
PRInt32 mCapacity

Detailed Description

A set of variables.

Definition at line 184 of file nsRuleNetwork.h.


Constructor & Destructor Documentation

Definition at line 440 of file nsRuleNetwork.cpp.

Definition at line 445 of file nsRuleNetwork.cpp.

{
    delete[] mVariables;
}

Member Function Documentation

Add a variable to the set.

Parameters:
aVariablethe variable to add
Returns:
NS_OK, unless something went wrong.

Definition at line 451 of file nsRuleNetwork.cpp.

{
    if (Contains(aVariable))
        return NS_OK;

    if (mCount >= mCapacity) {
        PRInt32 capacity = mCapacity + 4;
        PRInt32* variables = new PRInt32[capacity];
        if (! variables)
            return NS_ERROR_OUT_OF_MEMORY;

        for (PRInt32 i = mCount - 1; i >= 0; --i)
            variables[i] = mVariables[i];

        delete[] mVariables;

        mVariables = variables;
        mCapacity = capacity;
    }

    mVariables[mCount++] = aVariable;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool VariableSet::Contains ( PRInt32  aVariable) const

Determine if the set contains a variable.

Parameters:
aVariablethe variable to test
Returns:
PR_TRUE if the set contains the variable, PR_FALSE otherwise.

Definition at line 500 of file nsRuleNetwork.cpp.

{
    for (PRInt32 i = mCount - 1; i >= 0; --i) {
        if (aVariable == mVariables[i])
            return PR_TRUE;
    }

    return PR_FALSE;
}

Here is the caller graph for this function:

PRInt32 VariableSet::GetCount ( ) const [inline]

Determine the number of variables in the set.

Returns:
the number of variables in the set

Definition at line 215 of file nsRuleNetwork.h.

{ return mCount; }

Here is the caller graph for this function:

PRInt32 VariableSet::GetVariableAt ( PRInt32  aIndex) const [inline]

Get the ith variable in the set.

Parameters:
aIndexthe index to retrieve
Returns:
the ith variable in the set, or -1 if no such variable exists.

Definition at line 223 of file nsRuleNetwork.h.

{ return mVariables[aIndex]; }

Here is the caller graph for this function:

Remove a variable from the set.

Parameters:
aVariablethe variable to remove
Returns:
NS_OK, unless something went wrong.

Definition at line 476 of file nsRuleNetwork.cpp.

{
    PRInt32 i = 0;
    while (i < mCount) {
        if (aVariable == mVariables[i])
            break;

        ++i;
    }

    if (i >= mCount)
        return NS_OK;

    --mCount;

    while (i < mCount) {
        mVariables[i] = mVariables[i + 1];
        ++i;
    }
        
    return NS_OK;
}

Member Data Documentation

Definition at line 228 of file nsRuleNetwork.h.

Definition at line 227 of file nsRuleNetwork.h.

Definition at line 226 of file nsRuleNetwork.h.


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