Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
nsRuleNetwork Class Reference

#include <nsRuleNetwork.h>

Collaboration diagram for nsRuleNetwork:
Collaboration graph
[legend]

List of all members.

Classes

struct  SymtabEntry

Public Member Functions

 nsRuleNetwork ()
 ~nsRuleNetwork ()
void Clear ()
 Remove all the nodes from the network.
nsresult AddNode (ReteNode *aNode)
 Add a node to the network.
RootNodeGetRoot ()
 Retrieve the root node in the rule network.
PRInt32 CreateAnonymousVariable ()
 Create an unnamed variable.
void PutSymbol (const PRUnichar *aSymbol, PRInt32 aVariable)
 Assign a symbol to a variable.
PRInt32 LookupSymbol (const PRUnichar *aSymbol, PRBool aCreate=PR_FALSE)
 Lookup the variable associated with the symbol.

Protected Member Functions

void Init ()
void Finish ()

Protected Attributes

RootNode mRoot
 The root node in the network.
ReteNodeSet mNodes
 Other nodes in the network.
PLDHashTable mSymtab
 Symbol table, mapping symbolic names to variable identifiers.
PRInt32 mNextVariable
 The next available variable identifier.

Static Protected Attributes

static PLDHashTableOps gOps

Detailed Description

Definition at line 1105 of file nsRuleNetwork.h.


Class Documentation

struct nsRuleNetwork::SymtabEntry

Definition at line 1108 of file nsRuleNetwork.h.

Class Members
PLDHashEntryHdr mHdr
PRUnichar * mSymbol
PRInt32 mVariable

Constructor & Destructor Documentation

Definition at line 1114 of file nsRuleNetwork.h.

{ Init(); }

Here is the call graph for this function:

Definition at line 1115 of file nsRuleNetwork.h.

{ Finish(); }

Here is the call graph for this function:


Member Function Documentation

nsresult nsRuleNetwork::AddNode ( ReteNode aNode) [inline]

Add a node to the network.

The network assumes ownership of the node; it will be destroyed when the network is destroyed, or if Clear() is called.

Parameters:
aNodethe node to add to the network
Returns:
NS_OK if no errors occur

Definition at line 1132 of file nsRuleNetwork.h.

{ return mNodes.Add(aNode); }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsRuleNetwork::Clear ( ) [inline]

Remove all the nodes from the network.

The nodes will be destroyed

Returns:
NS_OK if no errors occur

Definition at line 1122 of file nsRuleNetwork.h.

{ Finish(); Init(); }

Here is the call graph for this function:

Here is the caller graph for this function:

Create an unnamed variable.

Definition at line 1143 of file nsRuleNetwork.h.

{ return ++mNextVariable; }

Here is the caller graph for this function:

void nsRuleNetwork::Finish ( ) [protected]

Definition at line 117 of file nsRuleNetwork.cpp.

{
    if (mSymtab.ops)
        PL_DHashTableFinish(&mSymtab);

    // We "own" the nodes. So it's up to us to delete 'em
    for (ReteNodeSet::Iterator node = mNodes.First(); node != mNodes.Last(); ++node)
        delete *node;

    mNodes.Clear();
    mRoot.RemoveAllChildren();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Retrieve the root node in the rule network.

Returns:
the root node in the rule network

Definition at line 1138 of file nsRuleNetwork.h.

{ return &mRoot; };

Here is the caller graph for this function:

void nsRuleNetwork::Init ( void  ) [protected]

Definition at line 108 of file nsRuleNetwork.cpp.

{
    mNextVariable = 0;
    if (!PL_DHashTableInit(&mSymtab, &gOps, nsnull,
                           sizeof(SymtabEntry), PL_DHASH_MIN_SIZE))
        mSymtab.ops = nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsRuleNetwork::LookupSymbol ( const PRUnichar aSymbol,
PRBool  aCreate = PR_FALSE 
) [inline]

Lookup the variable associated with the symbol.

Definition at line 1166 of file nsRuleNetwork.h.

                                                                              {
        if (!mSymtab.ops) return 0;
        SymtabEntry* entry =
            NS_REINTERPRET_CAST(SymtabEntry*,
                                PL_DHashTableOperate(&mSymtab,
                                                     aSymbol,
                                                     PL_DHASH_LOOKUP));

        if (PL_DHASH_ENTRY_IS_BUSY(&entry->mHdr))
            return entry->mVariable;

        PRInt32 result = 0;
        if (aCreate) {
            result = CreateAnonymousVariable();
            PutSymbol(aSymbol, result);
        }

        return result; }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsRuleNetwork::PutSymbol ( const PRUnichar aSymbol,
PRInt32  aVariable 
) [inline]

Assign a symbol to a variable.

Definition at line 1148 of file nsRuleNetwork.h.

                                                                {
        if (!mSymtab.ops) return;
        NS_PRECONDITION(LookupSymbol(aSymbol) == 0, "symbol already defined");

        SymtabEntry* entry =
            NS_REINTERPRET_CAST(SymtabEntry*,
                                PL_DHashTableOperate(&mSymtab,
                                                     aSymbol,
                                                     PL_DHASH_ADD));

        if (entry) {
            entry->mSymbol   = nsCRT::strdup(aSymbol);
            entry->mVariable = aVariable;
        } };

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

PLDHashTableOps nsRuleNetwork::gOps [static, protected]

The next available variable identifier.

Definition at line 1207 of file nsRuleNetwork.h.

Other nodes in the network.

Definition at line 1194 of file nsRuleNetwork.h.

The root node in the network.

Definition at line 1189 of file nsRuleNetwork.h.

Symbol table, mapping symbolic names to variable identifiers.

Definition at line 1202 of file nsRuleNetwork.h.


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