home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osr1.exe / src / DrafPriv.cpp < prev    next >
C/C++ Source or Header  |  1997-03-21  |  9KB  |  322 lines

  1. /* @(#)Z 1.12 com/src/bento/DrafPriv.cpp, odstorage, od96os2, odos29712d 97/03/21 17:21:25 (96/10/29 09:12:01) */
  2. //====START_GENERATED_PROLOG======================================
  3. //
  4. //
  5. //   COMPONENT_NAME: odstorage
  6. //
  7. //   CLASSES: none
  8. //
  9. //   ORIGINS: 82,27
  10. //
  11. //
  12. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13. //   All Rights Reserved
  14. //   Licensed Materials - Property of IBM
  15. //   US Government Users Restricted Rights - Use, duplication or
  16. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17. //       
  18. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24. //   OR PERFORMANCE OF THIS SOFTWARE.
  25. //
  26. //====END_GENERATED_PROLOG========================================
  27. //
  28.  
  29. /*
  30.     File:        DrafPriv.cpp
  31.  
  32.     Contains:    Private classes for Draft.
  33.  
  34.     Owned by:    Vincent Lo
  35.  
  36.     Copyright:    ⌐ 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  37.  
  38.     Change History (most recent first):
  39.  
  40.         <18>    10/19/95    EL        1292685: Check for boolean result from hash
  41.                                     manager calls.
  42.         <17>     8/12/95    Té        1276806 Optimization: use kODFalse instead
  43.                                     of kODTrue in comparisons
  44.         <16>     6/16/95    VL        1244940: Removed fEV from PreserveFocus
  45.                                     class.
  46.         <15>     6/13/95    VL        1241352: Moved PreserveFocus from
  47.                                     CMDraft.cpp.
  48.         <14>     5/26/95    VL        1251403: Multithreading naming support.
  49.         <13>     5/25/95    jpa        Fixed usage of ODDebug. [1253321]
  50.         <12>     4/25/95    DM        1172791: Replace AEHashTable with
  51.                                     OpenHashTable
  52.         <11>     4/25/95    VL        1210982: Removed 5$.
  53.         <10>     3/23/95    VL        1230371: Changed ASSERT to WARN in Remove.
  54.          <9>     3/10/95    VL        1227218: Get rid of system heap.
  55.          <8>      2/3/95    VL        1216535: Implemented storage support for
  56.                                     non-persistent frames.
  57.          <7>      9/5/94    VL        1184871: Remove dependency on default heap
  58.                                     by calling ODRecoverHeapID.
  59.          <6>      7/7/94    VL        Commented out use of ODRecoverHeapID.
  60.          <5>     6/28/94    VL        ODRecoverHeap to ODRecoverHeapID.
  61.          <4>     6/20/94    CC        ODMemoryHeap* changed to ODMemoryHeapID.
  62.          <3>     6/15/94    RR        ODHeap -> ODMemoryHeap
  63.          <2>     5/27/94    VL        Changed ODAEHashTable to AEHashTable.
  64.          <1>     5/27/94    VL        first checked in
  65.  
  66.     To Do:
  67.     In Progress:
  68. */
  69.  
  70.  
  71. #ifndef _DRAFPRIV_
  72. #include  "DrafPriv.h"
  73. #endif
  74.  
  75. #ifndef _OPENHASH_
  76. #include "OpenHash.h"
  77. #endif
  78.  
  79. #ifndef _EXCEPT_
  80. #include "Except.h"
  81. #endif
  82.  
  83. #ifndef _ODDebug_
  84. #include "ODDebug.h"
  85. #endif
  86.  
  87. #ifndef _ODMEMORY_
  88. #include "ODMemory.h"
  89. #endif
  90.  
  91. #ifndef _ODNEW_
  92. #include "ODNew.h"
  93. #endif
  94.  
  95. #ifndef SOM_ODStorageUnitCursor_xh
  96. #include <SUCursor.xh>
  97. #endif
  98.  
  99. #if defined(_PLATFORM_WIN32_)||defined(_PLATFORM_OS2_)||defined(_PLATFORM_AIX_)
  100. #ifndef SOM_CMStorageUnit_xh
  101. #include <CMSU.xh>
  102. #endif
  103.  
  104. #ifndef _ODUTILS
  105. #include <ODUtils.h>
  106. #endif
  107. #endif
  108.  
  109. #ifndef _BENTOERR_
  110. #include "BentoErr.h"
  111. #endif
  112.  
  113. #pragma segment DrafPriv
  114.  
  115. //==============================================================================
  116. // Constants
  117. //==============================================================================
  118. const ODULong    kODInitialNumEntries = 8;
  119.  
  120.  
  121. //==============================================================================
  122. // IDList
  123. //==============================================================================
  124.  
  125. //------------------------------------------------------------------------------
  126. // IDList::IDList
  127. //------------------------------------------------------------------------------
  128.  
  129. IDList::IDList()
  130. {
  131.     fIDToObj = kODNULL;
  132.     fObjToID = kODNULL;
  133.     fCurrentID = 0;
  134.     fHeap = kODNULL;
  135. }
  136.  
  137. //------------------------------------------------------------------------------
  138. // IDList::~IDList
  139. //------------------------------------------------------------------------------
  140.  
  141. IDList::~IDList()
  142. {
  143.     delete fIDToObj;
  144.     delete fObjToID;
  145. }
  146.  
  147. //------------------------------------------------------------------------------
  148. // IDList::Initialize
  149. //------------------------------------------------------------------------------
  150.  
  151. void IDList::Initialize()
  152. {
  153.     fHeap = ODRecoverHeapID(this);
  154.  
  155.     ODMemoryHeapID heap = GetHeap();
  156. #ifdef _PLATFORM_MACINTOSH_
  157.     fIDToObj = new(heap) 
  158.         OpenHashTable(OpenHashTable::StdEqual,
  159.                       OpenHashTable::StdHash, heap);
  160. #endif
  161. #if defined(_PLATFORM_WIN32_)||defined(_PLATFORM_OS2_)||defined(_PLATFORM_AIX_)
  162. //    The use of heap is not implemented in Windows platform
  163.     fIDToObj = new OpenHashTable(OpenHashTable::StdEqual,
  164.                       OpenHashTable::StdHash, 0);
  165. #endif
  166.     fIDToObj->Initialize(kODInitialNumEntries,
  167.                          sizeof(ODID),
  168.                          sizeof(void*));
  169.                     
  170. #ifdef _PLATFORM_MACINTOSH_
  171.     fObjToID = new(heap) 
  172.         OpenHashTable(OpenHashTable::StdEqual,
  173.                       OpenHashTable::StdHash, heap);
  174. #endif
  175. #if defined(_PLATFORM_WIN32_)||defined(_PLATFORM_OS2_)||defined(_PLATFORM_AIX_)
  176. //    The use of heap is not implemented in Windows platform
  177.     fObjToID = new OpenHashTable(OpenHashTable::StdEqual,
  178.                       OpenHashTable::StdHash, 0);
  179. #endif
  180.     fObjToID->Initialize(kODInitialNumEntries,
  181.                          sizeof(void*),
  182.                          sizeof(ODID));
  183. }
  184.  
  185. //------------------------------------------------------------------------------
  186. // IDList::Add
  187. //------------------------------------------------------------------------------
  188.  
  189. void IDList::Add(ODID id, void* object)
  190. {
  191.     if (id > fCurrentID)
  192.         fCurrentID = id;
  193.  
  194.     if (fIDToObj->ReplaceEntry(&id, &object) != kODFalse)
  195.         fObjToID->ReplaceEntry(&object, &id);
  196. }
  197.  
  198. //------------------------------------------------------------------------------
  199. // IDList::Add
  200. //------------------------------------------------------------------------------
  201.  
  202. ODID IDList::Add(void* object)
  203. {
  204.     ODID    id = 0;
  205.     
  206.     if ((object != kODNULL) && (this->ObjectExists(object) != kODFalse))
  207.         id = this->GetID(object);
  208.     else {
  209.         fCurrentID++;
  210.         id = fCurrentID;
  211.         if (fIDToObj->ReplaceEntry(&id, &object) != kODFalse)
  212.             fObjToID->ReplaceEntry(&object, &id);
  213.     }
  214.     return id;
  215. }
  216.  
  217. //------------------------------------------------------------------------------
  218. // IDList::Remove
  219. //------------------------------------------------------------------------------
  220.  
  221. void IDList::Remove(ODID id)
  222. {
  223.     void*    object;
  224.     
  225.     if (fIDToObj->GetValue(&id, &object)) {
  226.         fIDToObj->RemoveEntry(&id);
  227.         fObjToID->RemoveEntry(&object);
  228.     }
  229.     else
  230.             WARNMSG_DEBUG(WARN_INDEX(-1),"Object removed already: %d", id);
  231. }
  232.  
  233. //------------------------------------------------------------------------------
  234. // IDList::Get
  235. //------------------------------------------------------------------------------
  236.  
  237. void* IDList::Get(ODID id)
  238. {
  239.     void*    object = kODNULL;
  240.     
  241.     fIDToObj->GetValue(&id, &object);
  242.     return object;
  243. }
  244.  
  245. //------------------------------------------------------------------------------
  246. // IDList::GetID
  247. //------------------------------------------------------------------------------
  248.  
  249. ODID IDList::GetID(void* object)
  250. {
  251.     ODID    id = 0;
  252.  
  253.     fObjToID->GetValue(&object, &id);
  254.     return id;
  255. }
  256.  
  257. //------------------------------------------------------------------------------
  258. // IDList::Exists
  259. //------------------------------------------------------------------------------
  260.  
  261. ODBoolean IDList::Exists(ODID id)
  262. {
  263.         return (fIDToObj->Exists(&id) ? kODTrue : kODFalse);
  264.  
  265. }
  266.  
  267. //------------------------------------------------------------------------------
  268. // IDList::ObjectExists
  269. //------------------------------------------------------------------------------
  270.  
  271. ODBoolean IDList::ObjectExists(void* object)
  272. {
  273.         return (fObjToID->Exists(&object) ? kODTrue : kODFalse);
  274. }
  275.  
  276.  
  277. ODMemoryHeapID IDList::GetHeap()
  278. {
  279.     return fHeap;
  280. }
  281.  
  282. //------------------------------------------------------------------------------
  283. // PreserveFocus::PreserveFocus
  284. //------------------------------------------------------------------------------
  285.  
  286. PreserveFocus::PreserveFocus(Environment* ev, ODStorageUnit* su)
  287. {
  288.     ASSERT(su, kODErrInvalidStorageUnit);
  289.     fSUCursor = kODNULL;
  290.     fSU = kODNULL;
  291.     try
  292.         {
  293.         su->Acquire(ev);
  294.         fSU = su;
  295.         fSUCursor = fSU->CreateCursorWithFocus(ev);
  296.         }
  297.     catch (ODException _exception)
  298.         {
  299.         if (fSU != kODNULL)
  300.         {
  301.                     SaveAndRestoreEv1(fSU);
  302.             fSU = kODNULL;
  303.         }
  304.         throw;
  305.         }
  306. }
  307.  
  308. //------------------------------------------------------------------------------
  309. // PreserveFocus::~PreserveFocus
  310. //------------------------------------------------------------------------------
  311.  
  312. PreserveFocus::~PreserveFocus()
  313. {
  314.         Environment* ev = somGetGlobalEnvironment();
  315.     if (fSUCursor != kODNULL) {
  316.         if (fSU->ExistsWithCursor(ev, fSUCursor))
  317.             fSU->FocusWithCursor(ev, fSUCursor);
  318.         delete fSUCursor;
  319.     }
  320.     ODReleaseObject(ev, fSU);
  321. }
  322.