home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / freedraft.tar.gz / freedraft.tar / FREEdraft-050298 / DATAENGINE / geombank.cpp < prev    next >
C/C++ Source or Header  |  1998-04-19  |  2KB  |  84 lines

  1. // geombank.cpp
  2.  
  3. // Copyright (C) 1997, 1998 Cliff Johnson                                  //
  4. //                                                                         //
  5. // This program is free software; you can redistribute it and/or           //
  6. // modify it under the terms of the GNU  General Public                    //
  7. // License as published by the Free Software Foundation; either            //
  8. // version 2 of the License, or (at your option) any later version.        //
  9. //                                                                         //
  10. // This software is distributed in the hope that it will be useful,        //
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of          //
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       //
  13. // General Public License for more details.                                //
  14. //                                                                         //
  15. // You should have received a copy of the GNU General Public License       //
  16. // along with this software (see COPYING.LIB); if not, write to the        //
  17. // Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //
  18.  
  19. #include <geombank.h>        //THIS
  20.  
  21. #include <locale_enum.h>
  22.  
  23. #include <algo.h>        //ITO
  24.  
  25. #include <bankexception.h>
  26.  
  27. Handle GeomBank::Create(Geom* gx)
  28. {
  29.     Handle hx(gx,PERSISTENT);
  30.     handleArray.push_back(hx);
  31.     return hx;
  32. }
  33.  
  34. bool GeomBank::Destroy(const Handle& h)
  35. {
  36.     Handle tmp;
  37.  
  38.     list<Handle>::iterator i;
  39.  
  40.     i = find(handleArray.begin(),handleArray.end(),h);
  41.  
  42.     if ( i != handleArray.end() ){
  43.  
  44.     // delete the memory allocated by the handle 
  45.  
  46.         tmp = Handle(*i);
  47.  
  48.     // remove the handle from the list
  49.         handleArray.erase(i++);
  50.  
  51.     // toast it
  52.         return tmp.Destroy();
  53.     }
  54.     else return false;
  55. }
  56.  
  57.  
  58. void GeomBank::Print(ostream& os)
  59. {
  60.     list<Handle>::iterator i;
  61.  
  62.     for(i=handleArray.begin(); i!=handleArray.end(); i++)
  63.         os << Handle(*i) << '\n';
  64. }
  65.  
  66. Handle GeomBank::GetHandleFromPointer(const Geom* ptr) const throw (BankException)
  67. {
  68. // find the handle with the input address or throw an exception
  69. // by brute force of course! Actually I'm having trouble figgering
  70. // out the proper operators to add to the handle class to make if work
  71. // with find... So brute force it will be. 
  72.  
  73.     Handle tmp;
  74.  
  75.     list<Handle>::const_iterator i;
  76.  
  77.     for(i=handleArray.begin(); i!=handleArray.end(); i++)
  78.     {
  79.         tmp = Handle(*i);
  80.         if(tmp == ptr)return tmp;
  81.     }
  82.     throw BankException("GeomBank::GetHandleFromPointer() : geometry handle not found");
  83. }
  84.