Back to index

lightning-sunbird  0.9+nobinonly
nsAEClassIterator.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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  *   Simon Fraser <sfraser@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 
00040 #ifndef __AECLASSITERATOR__
00041 #define __AECLASSITERATOR__
00042 
00043 
00044 #include "nsAETokens.h"
00045 
00046 class AEClassIterator
00047 {
00048 
00049 protected:
00050 
00051        enum
00052        {
00053               eFormAbsolutePositionBit           = 0,
00054               eFormRelativePositionBit,
00055               eFormTestBit,
00056               eFormRangeBit,
00057               eFormPropertyIDBit,
00058               eFormNameBit
00059        };
00060        
00061        
00062 public:
00063 
00064        enum
00065        {
00066               eHasFormAbsolutePosition           = (1 << eFormAbsolutePositionBit),
00067               eHasFormRelativePosition           = (1 << eFormRelativePositionBit),
00068               eHasFormTest                       = (1 << eFormTestBit),
00069               eHasFormRange                      = (1 << eFormPropertyIDBit),
00070               eHasFormPropertyID                 = (1 << eFormRangeBit),
00071               eHasFormName                       = (1 << eFormNameBit),
00072               
00073               eStandardKeyFormSupport = (eHasFormAbsolutePosition | eHasFormRelativePosition | eHasFormRange | eHasFormName)
00074        };
00075        
00076        
00077                                           AEClassIterator(DescType classType, UInt16 keyFormSupport = eStandardKeyFormSupport)
00078                                           :      mClass(classType)
00079                                           ,      mKeyFormSupport(keyFormSupport)
00080                                           {}
00081                                           
00082        virtual                            ~AEClassIterator() {}
00083        
00084        virtual void                GetItemFromContainer(              DescType                    desiredClass,
00085                                                                                     const AEDesc*        containerToken,
00086                                                                                     DescType                    containerClass, 
00087                                                                                     DescType                    keyForm,
00088                                                                                     const AEDesc*        keyData,
00089                                                                                     AEDesc*                     resultToken);
00090 
00091        virtual UInt32                     GetNumItems(const AEDesc* containerToken) = 0;                 // get the number of items
00092 
00093        typedef UInt32                     ItemRef;                           // runtime, optimized reference to an object
00094        typedef UInt32                     ItemID;                            // persistent reference, used for storage
00095 
00096 protected:
00097        
00098        static const ItemRef        kNoItemRef;                 // value for a nonexistent item reference (usu. -1)
00099        static const ItemID         kNoItemID;                  // value for a nonexistent item ID (usu -1)
00100 
00101 
00102        virtual ItemRef                    GetNamedItemReference(const AEDesc* containerToken, const char *itemName) = 0;
00103        virtual ItemRef                    GetIndexedItemReference(const AEDesc* containerToken, TAEListIndex itemIndex) = 0;
00104        
00105        virtual TAEListIndex        GetIndexFromItemID(const AEDesc* containerToken, ItemID itemID) = 0;
00106        
00107        virtual ItemID                     GetNamedItemID(const AEDesc* containerToken, const char *itemName) = 0;
00108        virtual ItemID                     GetIndexedItemID(const AEDesc* containerToken, TAEListIndex itemIndex) = 0;
00109 
00110        // index to name
00111        virtual void                GetIndexedItemName(const AEDesc* containerToken, TAEListIndex itemIndex, char *outName, long maxLen) = 0;
00112 
00113        // conversion routines.
00114        virtual ItemID                     GetIDFromReference(const AEDesc* containerToken, ItemRef itemRef) = 0;
00115        virtual ItemRef                    GetReferenceFromID(const AEDesc* containerToken, ItemID itemID) = 0;
00116 
00117        virtual ItemID                     GetItemIDFromToken(const AEDesc* token) = 0;
00118        virtual void                SetItemIDInCoreToken(const AEDesc* containerToken, CoreTokenRecord* tokenRecord, ItemID itemID) = 0;
00119        
00120        // Range and index processing routines.
00121        virtual ItemRef                    ProcessFormRelativePostition(const AEDesc* anchorToken, const AEDesc *keyData);
00122        TAEListIndex                NormalizeAbsoluteIndex(const AEDesc *keyData, TAEListIndex maxIndex, Boolean *isAllItems);
00123        void                               ProcessFormRange(AEDesc *keyData, AEDesc *start, AEDesc *stop);
00124 
00125        void                               CheckKeyFormSupport(DescType keyForm);           // throws if unsupported key form
00126        
00127        DescType                           GetClass() { return mClass; }
00128        
00129 
00130        DescType                           mClass;
00131        UInt16                      mKeyFormSupport;
00132 };
00133 
00134 
00135 class AENamedClassIterator : public AEClassIterator
00136 {
00137 public:
00138                                           AENamedClassIterator(DescType classType)
00139                                           : AEClassIterator(classType, eHasFormName)
00140                                           {}
00141                                           
00142                                           ~AENamedClassIterator() {}
00143 
00144        virtual void                GetItemFromContainer(              DescType                    desiredClass,
00145                                                                                     const AEDesc*        containerToken,
00146                                                                                     DescType                    containerClass, 
00147                                                                                     DescType                    keyForm,
00148                                                                                     const AEDesc*        keyData,
00149                                                                                     AEDesc*                     resultToken);
00150 
00151 protected:
00152 
00153        
00154        // stubs for those pure virtual functions that we can't use with named items
00155        virtual UInt32                     GetNumItems(const AEDesc* containerToken) { return 0; }
00156 
00157        virtual ItemRef                    GetNamedItemReference(const AEDesc* containerToken, const char *itemName) { return kNoItemRef; }
00158        virtual ItemRef                    GetIndexedItemReference(const AEDesc* containerToken, TAEListIndex itemIndex) { return kNoItemRef; }
00159        
00160        virtual TAEListIndex        GetIndexFromItemID(const AEDesc* containerToken, ItemID itemID) { return 0; }
00161        
00162        virtual Boolean                    NamedItemExists(const AEDesc* containerToken, const char *itemName) = 0;
00163 
00164        virtual ItemID                     GetNamedItemID(const AEDesc* containerToken, const char *itemName) { return kNoItemID; }
00165        virtual ItemID                     GetIndexedItemID(const AEDesc* containerToken, TAEListIndex itemIndex) { return kNoItemID; }
00166 
00167        // index to name
00168        virtual void                GetIndexedItemName(const AEDesc* containerToken, TAEListIndex itemIndex, char *outName, long maxLen) {}
00169 
00170        // conversion routines.
00171        virtual ItemID                     GetIDFromReference(const AEDesc* containerToken, ItemRef itemRef) { return kNoItemID; }
00172        virtual ItemRef                    GetReferenceFromID(const AEDesc* containerToken, ItemID itemID) { return kNoItemRef; }
00173 
00174        virtual ItemID                     GetItemIDFromToken(const AEDesc* token) { return kNoItemID; }
00175        virtual void                SetItemIDInCoreToken(const AEDesc* containerToken, CoreTokenRecord* tokenRecord, ItemID itemID) {}
00176        virtual void                SetNamedItemIDInCoreToken(const AEDesc* containerToken, CoreTokenRecord* token, const char *itemName) = 0;
00177 
00178 };
00179 
00180 
00181 // base class for items that cannot be referred to by name
00182 class AEUnnamedClassIterator : public AEClassIterator
00183 {
00184 public:
00185 
00186        enum
00187        {
00188               eNoNameKeyFormSupport = (eHasFormAbsolutePosition | eHasFormRelativePosition | eHasFormRange)
00189        };
00190        
00191 
00192                                           AEUnnamedClassIterator(DescType classType)
00193                                           : AEClassIterator(classType, eNoNameKeyFormSupport)
00194                                           {}
00195                                           
00196                                           ~AEUnnamedClassIterator() {}
00197 
00198 protected:
00199 
00200        virtual ItemRef                    GetNamedItemReference(const AEDesc* containerToken, const char *itemName) { ThrowOSErr(errAEEventNotHandled); return 0; }
00201        virtual ItemID                     GetNamedItemID(const AEDesc* containerToken, const char *itemName) { ThrowOSErr(errAEEventNotHandled); return 0; }
00202        virtual void                GetIndexedItemName(const AEDesc* containerToken, TAEListIndex itemIndex, char *outName, long maxLen) { ThrowOSErr(errAEEventNotHandled); }
00203 
00204 };
00205 
00206 
00207 #endif /* __AECLASSITERATOR__ */