home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / freedraft.tar.gz / freedraft.tar / FREEdraft-050298 / DATAENGINE / handle.cpp < prev    next >
C/C++ Source or Header  |  1998-03-07  |  3KB  |  118 lines

  1. // handle.cpp
  2.  
  3. // Copyright (C) 1997  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 <handle.h>        //THIS
  20.  
  21. unsigned int Handle::nextHandle=1;
  22.  
  23. //***************************************************************
  24.  
  25. Handle::Handle() // default constructor
  26. {
  27.     geometry = NULL;
  28.     handle = 0;
  29.     locale = UNUSED;
  30. }
  31.  
  32. //***************************************************************
  33.  
  34. Handle::Handle(const Geom* ptr,Locale l) : locale(l)
  35. {
  36.     // a new geometry ...
  37.     if(ptr){
  38.         handle = nextHandle;
  39.         nextHandle++;
  40.         geometry = ptr;
  41.     }
  42. }
  43.  
  44. //***************************************************************
  45.  
  46. Handle::Handle(const Handle& h)
  47. {
  48.     geometry = h.geometry;
  49.     handle = h.handle;
  50.     locale = h.locale;
  51. }
  52.  
  53. //***************************************************************
  54.  
  55. Handle& Handle::operator=(const Handle& h)
  56. {
  57.     geometry = h.geometry;
  58.     handle = h.handle;
  59.     locale = h.locale;
  60.  
  61.     return *this;
  62. }
  63.  
  64. //***************************************************************
  65.  
  66. // typical friend functions
  67. ostream& operator<<(ostream& os, const Handle& h)
  68. {
  69.     os << "Handle : " << h.handle << " Addr: " << h.geometry << " locale = " << (int) h.locale;
  70.     return os;
  71. }
  72.  
  73. //***************************************************************
  74.  
  75. bool operator==(const Handle& h1, const Handle& h2) 
  76.     return h1.handle == h2.handle; 
  77. }
  78.  
  79. //***************************************************************
  80.  
  81. bool operator==(unsigned int i, const Handle& h) 
  82.     return i == h.handle; 
  83. }
  84.  
  85. //***************************************************************
  86.  
  87. bool operator==(const Geom* ptr, const Handle& h) 
  88.     return ptr == h.geometry; 
  89. }
  90.  
  91. //***************************************************************
  92.  
  93. bool Handle::CleanUp()     // clean up for local use. 
  94. {
  95.     if(locale == LOCAL){
  96.         delete geometry;
  97.         locale = DELETED;
  98.         return true;
  99.     }
  100.     return false; // no de-allocation
  101. }
  102.  
  103. //***************************************************************
  104.  
  105. bool Handle::Destroy()    // clean up for global use.
  106. {
  107.     if(handle && locale == PERSISTENT ){
  108.         delete geometry;
  109.         handle = 0;        // set handle to 0  so it won't be destroyed twice.
  110.         locale = DELETED;
  111.         return true;
  112.     }
  113.     return false; // no  de-allocation 
  114. }
  115.