modlist.cpp

Go to the documentation of this file.
00001 // $Id: modlist.cpp 1464 2006-07-18 12:32:26Z gerry $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 /*
00100 */
00101 
00102 #include "camtypes.h"
00103 
00104 #include "module.h"
00105 #include "modlist.h"
00106 #include "oilmods.h"    // for pOILModule.
00107 
00108 CC_IMPLEMENT_MEMDUMP(ModuleListItem, ListItem)
00109 CC_IMPLEMENT_MEMDUMP(ModuleList, List)
00110 
00111 // Declare smart memory handling in Debug builds
00112 #define new CAM_DEBUG_NEW
00113 
00114 /********************************************************************************************
00115 
00116 >   ModuleListItem(Module *pNewModule, OILModule *pNewOILModule)
00117 
00118     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00119     Created:    30/6/93
00120     Inputs:     NewModule - The module to fill in the list item with.
00121                 pNewOILModule - pointer to the OILModule object to associate with this
00122                 module.
00123     Outputs:    -
00124     Returns:    -
00125     Purpose:    Create a new ModuleListItem with the module pointer and info fields
00126                 filled in.  The info fields are filled in by interrogating the module.
00127     Errors:     -
00128 
00129 ********************************************************************************************/
00130 
00131 ModuleListItem::ModuleListItem(Module *pNewModule, OILModule *pNewOILModule)
00132 {
00133     m_Initialised = FALSE;
00134     pNewModule->Describe( &m_ModInfo );
00135     m_pModule = pNewModule;
00136     m_pOILModule = pNewOILModule;
00137 }
00138 
00139 /********************************************************************************************
00140 
00141 >   ModuleListItem::~ModuleListItem()
00142 
00143     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00144     Created:    7/7/93
00145     Inputs:     -
00146     Outputs:    -
00147     Returns:    -
00148     Purpose:    Destroys a ModuleListItem.  Deletes the module contained within it.
00149     Errors:     -
00150     SeeAlso:    -
00151 
00152 ********************************************************************************************/
00153 
00154 ModuleListItem::~ModuleListItem()
00155 {
00156     delete m_pModule;
00157     m_pModule = NULL;
00158     
00159     if( NULL != m_pOILModule )
00160     {
00161 //      PORTNOTETRACE("other","ModuleListItem::~ModuleListItem - m_pOILModule NOT deleted");
00162 //#ifndef EXCLUDE_FROM_XARALX
00163         delete m_pOILModule;
00164 //#endif
00165         m_pOILModule = NULL;
00166     }
00167 }
00168 
00169 /********************************************************************************************
00170 
00171 >   ModuleList::~ModuleList
00172 
00173     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00174     Created:    7/7/93
00175     Inputs:     -
00176     Outputs:    -
00177     Returns:    -
00178     Purpose:    Destroys a module list, destroying all modules in the list too.
00179     Errors:     -
00180     SeeAlso:    -
00181 
00182 ********************************************************************************************/
00183 
00184 ModuleList::~ModuleList()
00185 {
00186     // Call destructors on all objects in the list
00187     
00188     ModuleListItem *Item = (ModuleListItem *) RemoveHead();
00189     
00190     while (Item != NULL)
00191     {
00192         // Delete the list item
00193         delete Item;
00194         
00195         // Try the next item
00196         Item = (ModuleListItem *) RemoveHead();
00197     }
00198 
00199 }
00200 
00201 /********************************************************************************************
00202 
00203 >   ModuleListItem *ModuleList::Add(Module *pNewModule, OILModule *pNewOILModule)
00204 
00205     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00206     Created:    30/6/93
00207     Inputs:     pNewModule - pointer to the module to add into the list.
00208                 pNewOILModule - pointer to the OILModule object to associate with this
00209                 module.
00210     Outputs:    -
00211     Returns:    Pointer to the new item in the list if the module was successfully added,
00212                 NULL otherwise.
00213     Purpose:    Safe addition of modules to the kernel's list of known modules.  A module
00214                 will only be added if its ID has not already been used.
00215     Errors:     -
00216     SeeAlso:    ModuleListItem
00217 
00218 ********************************************************************************************/
00219 
00220 ModuleListItem *ModuleList::Add(Module *pNewModule, OILModule *pNewOILModule)
00221 {
00222     // Construct a tentative list item.
00223     ModuleListItem *NewItem = new ModuleListItem(pNewModule, pNewOILModule);
00224     if (NewItem == NULL)
00225         return NULL;
00226         
00227     // Fill in the OILModule pointer with the pointer provided by the caller.
00228     NewItem->m_pOILModule = pNewOILModule;
00229     
00230     // Interrogate module about itself.
00231     if( NewItem->m_ModInfo.ID == MODULEID_INVALID )
00232     {
00233         // Invalid ID - discard new list item and abort.
00234         NewItem->m_pModule = NULL;                          // dont delete the module
00235         delete NewItem;
00236         return NULL;
00237     }
00238     
00239     
00240     // Search list to make sure this ID is not already in use.
00241     ModuleListItem *Item = (ModuleListItem *) GetHead();
00242     
00243     while (Item != NULL)
00244     {
00245         if( Item->m_ModInfo.ID == NewItem->m_ModInfo.ID )
00246         {
00247             // Found ID already in use - discard new list item and abort.
00248             NewItem->m_pModule = NULL;                      // dont delete the module
00249             delete NewItem;
00250             return NULL;
00251         }
00252         
00253         // Try the next node in the list.
00254         Item = (ModuleListItem *) GetNext(Item);
00255     }
00256     
00257     // The ID is not already in use so add the module to the list.
00258     AddTail(NewItem);
00259     return NewItem;
00260 }
00261 
00262 

Generated on Sat Nov 10 03:45:43 2007 for Camelot by  doxygen 1.4.4