home *** CD-ROM | disk | FTP | other *** search
/ Quark 3 / Quark3.iso / KATALOG / ARCHIV / TOOL / T001.ZIP / SOURCE.ZIP / nodedictionary.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-27  |  3.1 KB  |  98 lines

  1. /*
  2. Copyright (C) Matthew 'pagan' Baranowski & Sander 'FireStorm' van Rossen
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17. */
  18.  
  19. #include "ndictionary.h"
  20. #include <iostream.h>
  21.  
  22. void NodeDictionaryInfo::insert( Object element, Object key )
  23. {
  24.         NodeLocator nL = new NodeLocatorInfo( this, element, key );
  25.         insertLast( nL );
  26. };
  27.  
  28.  
  29. Object NodeDictionaryInfo::insertReplace( Object element, Object key )
  30. {
  31.     Object toReturn;
  32.         for (NodeLocator nL = (NodeLocator)first(); nL != NULL; nL = (NodeLocator)after(nL))
  33.         {
  34.                 if (m_keyComp->equal( nL->key(), key )) {
  35.           toReturn = nL->element();
  36.           nL->setElement( element );
  37.                   return toReturn;
  38.                 }
  39.         }
  40.  
  41.     // found nothing so append
  42.     nL = new NodeLocatorInfo( this, element, key );
  43.         insertLast( nL );
  44.         return NULL;
  45. };
  46.  
  47.  
  48. Object NodeDictionaryInfo::find(Object key)
  49. {
  50.         for (NodeLocator nL = (NodeLocator)first(); nL != NULL; nL = (NodeLocator)after(nL))
  51.         {       
  52.                 if (m_keyComp->equal( nL->key(), key )) {
  53.                         return nL->element();
  54.                 }
  55.         }       
  56.         return NULL; // found nothing   
  57. }
  58.  
  59. Object NodeDictionaryInfo::remove( Object key )
  60. {
  61.         for (NodeLocator nL = (NodeLocator)first(); nL != NULL; nL = (NodeLocator)after(nL))
  62.         {
  63.                 if (m_keyComp->equal( nL->key(), key )) {
  64.                         return remove( nL );                                            
  65.                 }
  66.         }       
  67.         return NULL; // found nothing   
  68. }
  69.  
  70.  
  71. Object NodeDictionaryInfo::replace( Object element, Object key )
  72. {
  73.   Object toReturn;
  74.         for (NodeLocator nL = (NodeLocator)first(); nL != NULL; nL = (NodeLocator)after(nL))
  75.         {
  76.                 if (m_keyComp->equal( nL->key(), key )) {
  77.           toReturn = nL->element();
  78.           nL->setElement( element );
  79.                   return toReturn;                                         
  80.                 }
  81.         }       
  82.         return NULL; // found nothing   
  83. }
  84.  
  85.  
  86. void NodeDictionaryInfo::dumpDictionary()
  87. {      
  88.   cout << "Dictionary Dump, size " <<  size() << endl; 
  89.   for (NodeLocator nL = (NodeLocator)first(); nL != NULL; nL = (NodeLocator)after(nL))
  90.   {
  91.     cout << "           Position " << nL; 
  92.     cout << " next " << nL->getNextNode();
  93.     cout << " prev " << nL->getPrevNode();
  94.     cout << " element " << nL->element();
  95.     cout << " key " << (char *)nL->key() << endl;
  96.   }   
  97. }
  98.