Back to index

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

A type-safe value that can be bound to a variable in the rule network. More...

#include <nsRuleNetwork.h>

Collaboration diagram for Value:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Type { eUndefined, eISupports, eString, eInteger }

Public Member Functions

 Value ()
 Value (const Value &aValue)
 Value (nsISupports *aISupports)
 Value (const PRUnichar *aString)
 Value (PRInt32 aInteger)
Valueoperator= (const Value &aValue)
Valueoperator= (nsISupports *aISupports)
Valueoperator= (const PRUnichar *aString)
Valueoperator= (PRInt32 aInteger)
 ~Value ()
PRBool operator== (const Value &aValue) const
PRBool operator== (nsISupports *aISupports) const
PRBool operator== (const PRUnichar *aString) const
PRBool operator== (PRInt32 aInteger) const
PRBool operator!= (const Value &aValue) const
PRBool operator!= (nsISupports *aISupports) const
PRBool operator!= (const PRUnichar *aString) const
PRBool operator!= (PRInt32 aInteger) const
Type GetType () const
 Get the value's type.
 operator nsISupports * () const
 Treat the Value as an nsISupports.
 operator const PRUnichar * () const
 Treat the value as a Unicode string.
 operator PRInt32 () const
 Treat the value as an integer.
PLHashNumber Hash () const

Protected Member Functions

PRBool Equals (const Value &aValue) const
PRBool Equals (nsISupports *aISupports) const
PRBool Equals (const PRUnichar *aString) const
PRBool Equals (PRInt32 aInteger) const
void Clear ()

Protected Attributes

Type mType
union {
nsISupports * mISupports
PRUnicharmString
PRInt32 mInteger
}; 

Detailed Description

A type-safe value that can be bound to a variable in the rule network.

Definition at line 79 of file nsRuleNetwork.h.


Member Enumeration Documentation

Enumerator:
eUndefined 
eISupports 
eString 
eInteger 

Definition at line 81 of file nsRuleNetwork.h.


Constructor & Destructor Documentation

Value::Value ( ) [inline]

Definition at line 100 of file nsRuleNetwork.h.

Value::Value ( const Value aValue)

Definition at line 160 of file nsRuleNetwork.cpp.

    : mType(aValue.mType)
{
    MOZ_COUNT_CTOR(Value);

    switch (mType) {
    case eUndefined:
        break;

    case eISupports:
        mISupports = aValue.mISupports;
        NS_IF_ADDREF(mISupports);
        break;

    case eString:
        mString = nsCRT::strdup(aValue.mString);
        break;

    case eInteger:
        mInteger = aValue.mInteger;
        break;
    }
}
Value::Value ( nsISupports *  aISupports)

Definition at line 184 of file nsRuleNetwork.cpp.

    : mType(eISupports)
{
    MOZ_COUNT_CTOR(Value);
    mISupports = aISupports;
    NS_IF_ADDREF(mISupports);
}
Value::Value ( const PRUnichar aString)

Definition at line 192 of file nsRuleNetwork.cpp.

    : mType(eString)
{
    MOZ_COUNT_CTOR(Value);
    mString = nsCRT::strdup(aString);
}
Value::Value ( PRInt32  aInteger)

Definition at line 199 of file nsRuleNetwork.cpp.

    : mType(eInteger)
{
    MOZ_COUNT_CTOR(Value);
    mInteger = aInteger;
}

Definition at line 258 of file nsRuleNetwork.cpp.

Here is the call graph for this function:


Member Function Documentation

void Value::Clear ( ) [protected]

Definition at line 266 of file nsRuleNetwork.cpp.

{
    switch (mType) {
    case eInteger:
    case eUndefined:
        break;

    case eISupports:
        NS_IF_RELEASE(mISupports);
        break;

    case eString:
        nsCRT::free(mString);
        break;

    }
}

Here is the caller graph for this function:

PRBool Value::Equals ( const Value aValue) const [protected]

Definition at line 286 of file nsRuleNetwork.cpp.

{
    if (mType == aValue.mType) {
        switch (mType) {
        case eUndefined:
            return PR_FALSE;

        case eISupports:
            return mISupports == aValue.mISupports;

        case eString:
            return nsCRT::strcmp(mString, aValue.mString) == 0;

        case eInteger:
            return mInteger == aValue.mInteger;
        }
    }
    return PR_FALSE;
}

Here is the caller graph for this function:

PRBool Value::Equals ( nsISupports *  aISupports) const [protected]

Definition at line 307 of file nsRuleNetwork.cpp.

{
    return (mType == eISupports) && (mISupports == aISupports);
}
PRBool Value::Equals ( const PRUnichar aString) const [protected]

Definition at line 313 of file nsRuleNetwork.cpp.

{
    return (mType == eString) && (nsCRT::strcmp(aString, mString) == 0);
}
PRBool Value::Equals ( PRInt32  aInteger) const [protected]

Definition at line 319 of file nsRuleNetwork.cpp.

{
    return (mType == eInteger) && (mInteger == aInteger);
}
Type Value::GetType ( ) const [inline]

Get the value's type.

Returns:
the value's type

Definition at line 129 of file nsRuleNetwork.h.

{ return mType; }

Here is the caller graph for this function:

Definition at line 326 of file nsRuleNetwork.cpp.

{
    PLHashNumber temp = 0;

    switch (mType) {
    case eUndefined:
        break;

    case eISupports:
        temp = PLHashNumber(NS_PTR_TO_INT32(mISupports)) >> 2; // strip alignment bits
        break;

    case eString:
        {
            PRUnichar* p = mString;
            PRUnichar c;
            while ((c = *p) != 0) {
                temp = (temp >> 28) ^ (temp << 4) ^ c;
                ++p;
            }
        }
        break;

    case eInteger:
        temp = mInteger;
        break;
    }

    return temp;
}

Here is the caller graph for this function:

Value::operator const PRUnichar * ( ) const

Treat the value as a Unicode string.

Returns:
the value as a Unicode string, or null if the value is not a Unicode string.

Definition at line 364 of file nsRuleNetwork.cpp.

{
    NS_ASSERTION(mType == eString, "not a string");
    return (mType == eString) ? mString : 0;
}
Value::operator nsISupports * ( ) const

Treat the Value as an nsISupports.

(Note that the result is not addref'd.)

Returns:
the value as an nsISupports, or null if the value is not an nsISupports.

Definition at line 358 of file nsRuleNetwork.cpp.

{
    NS_ASSERTION(mType == eISupports, "not an nsISupports");
    return (mType == eISupports) ? mISupports : 0;
}
Value::operator PRInt32 ( ) const

Treat the value as an integer.

Returns:
the value as an integer, or zero if the value is not an integer

Definition at line 370 of file nsRuleNetwork.cpp.

{
    NS_ASSERTION(mType == eInteger, "not an integer");
    return (mType == eInteger) ? mInteger : 0;
}
PRBool Value::operator!= ( const Value aValue) const [inline]

Definition at line 120 of file nsRuleNetwork.h.

{ return !Equals(aValue); }

Here is the call graph for this function:

PRBool Value::operator!= ( nsISupports *  aISupports) const [inline]

Definition at line 121 of file nsRuleNetwork.h.

{ return !Equals(aISupports); }

Here is the call graph for this function:

PRBool Value::operator!= ( const PRUnichar aString) const [inline]

Definition at line 122 of file nsRuleNetwork.h.

{ return !Equals(aString); }

Here is the call graph for this function:

PRBool Value::operator!= ( PRInt32  aInteger) const [inline]

Definition at line 123 of file nsRuleNetwork.h.

{ return !Equals(aInteger); }

Here is the call graph for this function:

Value & Value::operator= ( const Value aValue)

Definition at line 207 of file nsRuleNetwork.cpp.

{
    Clear();

    mType = aValue.mType;

    switch (mType) {
    case eUndefined:
        break;

    case eISupports:
        mISupports = aValue.mISupports;
        NS_IF_ADDREF(mISupports);
        break;

    case eString:
        mString = nsCRT::strdup(aValue.mString);
        break;

    case eInteger:
        mInteger = aValue.mInteger;
        break;
    }

    return *this;
}

Here is the call graph for this function:

Value & Value::operator= ( nsISupports *  aISupports)

Definition at line 235 of file nsRuleNetwork.cpp.

{
    Clear();

    mType = eISupports;
    mISupports = aISupports;
    NS_IF_ADDREF(mISupports);

    return *this;
}

Here is the call graph for this function:

Value & Value::operator= ( const PRUnichar aString)

Definition at line 247 of file nsRuleNetwork.cpp.

{
    Clear();

    mType = eString;
    mString = nsCRT::strdup(aString);

    return *this;
}

Here is the call graph for this function:

Value& Value::operator= ( PRInt32  aInteger)
PRBool Value::operator== ( const Value aValue) const [inline]

Definition at line 115 of file nsRuleNetwork.h.

{ return Equals(aValue); }

Here is the call graph for this function:

PRBool Value::operator== ( nsISupports *  aISupports) const [inline]

Definition at line 116 of file nsRuleNetwork.h.

{ return Equals(aISupports); }

Here is the call graph for this function:

PRBool Value::operator== ( const PRUnichar aString) const [inline]

Definition at line 117 of file nsRuleNetwork.h.

{ return Equals(aString); }

Here is the call graph for this function:

PRBool Value::operator== ( PRInt32  aInteger) const [inline]

Definition at line 118 of file nsRuleNetwork.h.

{ return Equals(aInteger); }

Here is the call graph for this function:


Member Data Documentation

union { ... } [protected]
Type Value::mType [protected]

Definition at line 84 of file nsRuleNetwork.h.


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