home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / OWLINC.PAK / APPDICT.H next >
C/C++ Source or Header  |  1995-08-29  |  3KB  |  128 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1991, 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Defines class TAppDictionary. This class manages associations between
  6. //   processes/tasks and TApplication pointers.
  7. //----------------------------------------------------------------------------
  8. #if !defined(OWL_APPDICT_H)
  9. #define OWL_APPDICT_H
  10.  
  11. #if !defined(OWL_OWLDEFS_H)
  12. # include <owl/owldefs.h>
  13. #endif
  14. class _OWLCLASS TApplication;
  15.  
  16. #if !defined(BI_PLAT_WIN32)
  17.   inline unsigned GetCurrentProcessId() {return (unsigned)GetCurrentTask();}
  18. #endif
  19.  
  20. //
  21. //  class TAppDictionary
  22. //  ----- --------------
  23. //
  24. class _OWLCLASS TAppDictionary {
  25.   public:
  26.     struct TEntry {
  27.       unsigned       Pid;
  28.       TApplication*  App;
  29.     };
  30.     typedef void (*TEntryIterator)(TEntry&);
  31.  
  32.   public:
  33.     TAppDictionary();
  34.    ~TAppDictionary();
  35.  
  36.     TApplication* GetApplication(unsigned pid = 0);  // default to current pid
  37.  
  38.     void          Add(TApplication* app, unsigned pid = 0);
  39.     void          Remove(TApplication* app);
  40.     void          Remove(unsigned pid);
  41.     void          Condemn(TApplication* app);
  42.  
  43.     bool          DeleteCondemned();
  44.     void          Iterate(TEntryIterator iter);
  45.  
  46.   private:
  47. #if defined(BI_APP_DLL) || defined(_OWLDLL) || defined(BI_PLAT_WIN32)
  48.     class TAppDictImp*  Imp;
  49. #else
  50.     TEntry        E;
  51. #endif
  52. };
  53.  
  54. //
  55. // Global exported TAppDictionary in Owl. User Component DLLs should have a
  56. // similar 'AppDictionary'.
  57. //
  58. extern TAppDictionary _OWLDATA OwlAppDictionary;
  59.  
  60. //
  61. // Global function that calls GetApplication() on owl's app-dictionary.
  62. // Used by EXEs, or DLLs statically linking Owl. Never returns 0, will make
  63. // an alias app if needed. Primarily for compatibility
  64. //
  65. TApplication* _OWLFUNC GetApplicationObject(unsigned pid = 0);
  66.  
  67. //
  68. // Convenient macro to define a 'AppDictionary' ref and object as needed
  69. // for use in component DLLs and EXEs
  70. //
  71. #if defined(BI_APP_DLL) && defined(_OWLDLL)
  72. # define DEFINE_APP_DICTIONARY(AppDictionary)    \
  73.    TAppDictionary  AppDictionary
  74. #else
  75. # define DEFINE_APP_DICTIONARY(AppDictionary)    \
  76.    TAppDictionary& AppDictionary = ::OwlAppDictionary
  77. #endif
  78.  
  79.  
  80. //----------------------------------------------------------------------------
  81. // inlines
  82.  
  83. #if !defined(BI_APP_DLL) && !defined(_OWLDLL) && !defined(BI_PLAT_WIN32)
  84.  
  85. inline TAppDictionary::TAppDictionary() {
  86.   E.App = 0;
  87.   E.Pid = 0;
  88. }
  89.  
  90. inline TAppDictionary::~TAppDictionary() {DeleteCondemned();}
  91.  
  92. inline TApplication* TAppDictionary::GetApplication(unsigned /*pid*/) {
  93.   return E.App;
  94. }
  95.  
  96. inline void TAppDictionary::Add(TApplication* app, unsigned pid) {
  97.   E.App = app;
  98.   E.Pid = pid;
  99. }
  100.  
  101. inline void TAppDictionary::Remove(TApplication* /*app*/) {
  102.   E.App = 0;
  103. }
  104.  
  105. inline void TAppDictionary::Remove(unsigned /*pid*/) {
  106.   E.App = 0;
  107. }
  108.  
  109. inline void TAppDictionary::Condemn(TApplication* /*app*/) {
  110.   E.Pid = 0;
  111. }
  112.  
  113. inline bool TAppDictionary::DeleteCondemned() {
  114.   if (!E.Pid) {
  115.     delete E.App;
  116.     E.App = 0;
  117.   }
  118.   return false;
  119. }
  120.  
  121. inline void TAppDictionary::Iterate(TEntryIterator iter) {
  122.   (*iter)(E);
  123. }
  124.  
  125. #endif // !defined(BI_APP_DLL) && !defined(_OWLDLL)
  126.  
  127. #endif  // OWL_APPDICT_H
  128.