Back to index

lightning-sunbird  0.9+nobinonly
nsClusterKey.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Chris Waterson <waterson@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef nsClusterKey_h__
00040 #define nsClusterKey_h__
00041 
00042 #include "prtypes.h"
00043 #include "nsISupports.h"
00044 #include "nsRuleNetwork.h"
00045 class nsTemplateRule;
00046 
00062 class nsClusterKey {
00063 public:
00064     nsClusterKey() { MOZ_COUNT_CTOR(nsClusterKey); }
00065 
00075     nsClusterKey(const Instantiation& aInstantiation, const nsTemplateRule* aRule);
00076 
00077     nsClusterKey(PRInt32 aContainerVariable,
00078                const Value& aContainerValue,
00079                PRInt32 aMemberVariable,
00080                const Value& aMemberValue)
00081         : mContainerVariable(aContainerVariable),
00082           mContainerValue(aContainerValue),
00083           mMemberVariable(aMemberVariable),
00084           mMemberValue(aMemberValue) {
00085         MOZ_COUNT_CTOR(nsClusterKey); }
00086 
00087     nsClusterKey(const nsClusterKey& aKey)
00088         : mContainerVariable(aKey.mContainerVariable),
00089           mContainerValue(aKey.mContainerValue),
00090           mMemberVariable(aKey.mMemberVariable),
00091           mMemberValue(aKey.mMemberValue) {
00092         MOZ_COUNT_CTOR(nsClusterKey); }
00093 
00094     ~nsClusterKey() { MOZ_COUNT_DTOR(nsClusterKey); }
00095 
00096     nsClusterKey& operator=(const nsClusterKey& aKey) {
00097         mContainerVariable = aKey.mContainerVariable;
00098         mContainerValue    = aKey.mContainerValue;
00099         mMemberVariable    = aKey.mMemberVariable;
00100         mMemberValue       = aKey.mMemberValue;
00101         return *this; }
00102 
00103     PRBool operator==(const nsClusterKey& aKey) const {
00104         return Equals(aKey); }
00105 
00106     PRBool operator!=(const nsClusterKey& aKey) const {
00107         return !Equals(aKey); }
00108 
00109     PRInt32     mContainerVariable;
00110     Value       mContainerValue;
00111     PRInt32     mMemberVariable;
00112     Value       mMemberValue;
00113 
00114     PLHashNumber Hash() const {
00115         PLHashNumber temp1;
00116         temp1 = mContainerValue.Hash();
00117         temp1 &= 0xffff;
00118         temp1 |= PLHashNumber(mContainerVariable) << 16;
00119         PLHashNumber temp2;
00120         temp2 = mMemberValue.Hash();
00121         temp2 &= 0xffff;
00122         temp2 |= PLHashNumber(mMemberVariable) << 16;
00123         return temp1 ^ temp2; }
00124 
00125     static PLHashNumber PR_CALLBACK HashClusterKey(const void* aKey);
00126     static PRIntn PR_CALLBACK CompareClusterKeys(const void* aLeft, const void* aRight);
00127 
00128 protected:
00129     PRBool Equals(const nsClusterKey& aKey) const {
00130         return mContainerVariable == aKey.mContainerVariable &&
00131             mContainerValue == aKey.mContainerValue &&
00132             mMemberVariable == aKey.mMemberVariable &&
00133             mMemberValue == aKey.mMemberValue; }
00134 };
00135 
00136 #endif // nsClusterKey_h__