home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Applications / Nuntius 1.2 / src / Nuntius / UProgressCache.cp < prev    next >
Encoding:
Text File  |  1994-02-20  |  2.2 KB  |  108 lines  |  [TEXT/MPS ]

  1. // Copyright © 1992 Peter Speck, speck@dat.ruc.dk. All rights reserved.
  2. // UProgress.cp
  3.  
  4. #include "UProgressCache.h"
  5. #include "UProgress.h"
  6.  
  7. #pragma segment MyThread
  8.  
  9. #define qDebugProgressCache qDebug & 0
  10.  
  11. TProgressCache *gProgressCache = nil;
  12.  
  13. //-----------------------------------------------------------------
  14. TProgressCache::TProgressCache()
  15. {
  16. }
  17.  
  18. pascal void TProgressCache::Initialize()
  19. {
  20.     inherited::Initialize();
  21. }
  22.  
  23. void TProgressCache::IProgressCache()
  24. {
  25.     inherited::IObjectCache();
  26.     fObjectsInUseList->SetEltType("TProgress");
  27.     fFreeObjectsList->SetEltType("TProgress");
  28.     SetObjectCacheParams(5, kMaxIdleTime);
  29. }
  30.  
  31. pascal void TProgressCache::Free()
  32. {
  33.     inherited::Free();
  34. }
  35.  
  36. TProgress *TProgressCache::GetProgress()
  37. {
  38.     TProgress *pgrs = (TProgress*) inherited::GetObject();
  39. #if qDebugProgressCache
  40.     fprintf(stderr, "GetProgress: at $%lx\n", pgrs);
  41. #endif
  42.     return pgrs;
  43. }
  44.  
  45. void TProgressCache::ReturnProgress(TProgress *progress)
  46. {
  47. #if qDebugProgressCache
  48.     fprintf(stderr, "ReturnProgress: at $%lx\n", progress);
  49. #endif
  50.     if (progress)
  51.         progress->SetThread(nil);
  52.     inherited::ReturnObject(progress);
  53. }
  54.  
  55. void TProgressCache::DiscardProgress(TProgress *progress)
  56. {
  57. #if qDebugProgressCache
  58.     fprintf(stderr, "DiscardProgress: at $%lx\n", progress);
  59. #endif
  60.     if (progress)
  61.         progress->SetThread(nil);
  62.     inherited::DiscardObject(progress);
  63. }
  64.  
  65. TObject *TProgressCache::CreateNewObject()
  66. {
  67.     TProgress *progress = new TProgress();
  68.     progress->IProgress();
  69. #if qDebugProgressCache
  70.     fprintf(stderr, "TProgressCache::CreateNewObject: at $%lx\n", progress);
  71. #endif
  72.     return progress;
  73. }
  74.  
  75. const char *TProgressCache::GetObjectName()
  76. {
  77.     return "TProgress";
  78. }
  79.  
  80. //.................................................................
  81.  
  82. void InitUProgressCache()
  83. {
  84. #if qDebug
  85.     if (gProgressCache)
  86.         ProgramBreak("InitUProgress is called twice");
  87. #endif
  88.     TProgressCache *pc = new TProgressCache();
  89.     pc->IProgressCache();
  90.     gProgressCache = pc;
  91. }
  92.  
  93. void CloseDownUProgressCache()
  94. {
  95.     if (!gProgressCache)
  96.     {
  97. #if qDebug
  98.         fprintf(stderr, "gProgressCache is nil in CloseDownUProgress\n");
  99. #endif
  100.         return;
  101.     }
  102. #if qDebug
  103.     //@@ AVOID ERROR SOMEWHERE IN CODE:
  104.     // At quit: 1 in list of USED TProgress
  105.     FreeIfObject(gProgressCache); gProgressCache = nil;
  106. #endif
  107. }
  108.