home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tlx501.zip / SRC / MODINFO.CPP < prev    next >
C/C++ Source or Header  |  1996-07-08  |  5KB  |  171 lines

  1. /****************************************************************************
  2.     $Id: modinfo.cpp 501.0 1995/03/07 12:26:16 RON Exp $
  3.  
  4.     Copyright (c) 1991-95 Tarma Software Research. All rights reserved.
  5.  
  6.     Project:    Tarma Library for C++ V5.0
  7.     Author:    Ron van der Wal
  8.  
  9.     Implementation of class TLModuleInfo.
  10.  
  11.     $Log: modinfo.cpp $
  12.     Revision 501.0  1995/03/07 12:26:16  RON
  13.     Updated for TLX 5.01
  14.     Revision 1.3  1995/01/31 16:30:18  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.2  1995/01/06  15:58:04  ron
  18.     Corrected Revision keyword
  19.  
  20.     Revision 1.1  1994/11/16  15:41:20  ron
  21.     Initial revision
  22.  
  23. ****************************************************************************/
  24.  
  25. #include <tlx\501\_build.h>
  26.  
  27. TLX_MODULE_INFO("$Revision: 501.0 $");
  28.  
  29. #include <iostream.h>
  30. #include <iomanip.h>
  31.  
  32. /*---------------------------------------------------------------------------
  33.     Static variables
  34. ---------------------------------------------------------------------------*/
  35.  
  36. #ifdef _TLXDBG
  37. int32        TLModuleInfo::sModCount;    // Initialized to 0
  38. #endif
  39. TLModuleInfo *    TLModuleInfo::sChain;        // Initialized to 0
  40. TLModuleInfo     TLModuleInfo::sNullInfo("(No filename)", "(No version)",
  41.                     "(No date)");
  42.  
  43. /*-------------------------------------------------------------------------*/
  44.     TLModuleInfo::TLModuleInfo(
  45.         const char *aFile, const char *aVer, const char *aDT
  46.     )
  47.  
  48. /*  Constructor. Links the instance into the global chain of modules.
  49. ---------------------------------------------------------------------------*/
  50. {
  51.     TLX_ASSERT_PTR(aFile);
  52.     TLX_ASSERT_PTR(aVer);
  53.     TLX_ASSERT_PTR(aDT);
  54.  
  55.     mFilename = aFile;
  56.     mVersion  = aVer;
  57.     mDateTime = aDT;
  58.  
  59.     // Make this instance the new head of the global list. This will cause
  60.     // the modules to appear in reverse order of initialization, but that
  61.     // will make unlinking a lot cheaper (assuming that the order of
  62.     // destruction is the opposite of the construction order). It is also
  63.     // much faster to start with, which is important since this code will
  64.     // typically be executed as part of the global application initialization
  65.     // before any user code is run.
  66.     //
  67.     // We rely on the fact that the static 'sChain' pointer is statically
  68.     // initialized, before any dynamic initialization code is run.
  69.  
  70.     TLX_ASSERT(sModCount > 0 || sChain == 0);
  71.     mNext  = sChain;
  72.     sChain = this;
  73.     TLX_DEBUG_CODE(sModCount++;)
  74. }
  75.  
  76. /*-------------------------------------------------------------------------*/
  77.     TLModuleInfo::~TLModuleInfo()
  78.  
  79. /*  Destructor. Unlinks the current instance from the global chain.
  80. ---------------------------------------------------------------------------*/
  81. {
  82.     TLX_ASSERT(sModCount > 0);
  83.     TLX_ASSERT_PTR(sChain);
  84.  
  85.     // If the order of destruction is the exact opposite of the order of
  86.     // initialization, removal should be fast and simple: the currently
  87.     // destructed instance will always be the head of the chain.
  88.  
  89.     if (this == sChain)
  90.     sChain = mNext;
  91.     else
  92.     {
  93.     // Find the precursor to this instance, then bridge the instance
  94.     TLModuleInfo *rover;
  95.     for (rover = sChain; rover; rover = rover->mNext)
  96.     {
  97.         if (rover->mNext == this)
  98.         {
  99.         rover->mNext = mNext;
  100.         break;
  101.         }
  102.     }
  103.  
  104.     // Check that the instance was found
  105.     TLX_ASSERT_PTR(rover);
  106.     }
  107.  
  108.     mNext = 0;
  109.     TLX_DEBUG_CODE(sModCount--;)
  110. }
  111.  
  112. /*-------------------------------------------------------------------------*/
  113.     void TLModuleInfo::PrintAll(ostream &os)
  114.  
  115. /*  Static member function that prints information about all accessible
  116.     modules. Due to the way instances are linked at creation, the printed
  117.     order is the opposite of the initialization order.
  118. ---------------------------------------------------------------------------*/
  119. {
  120.     if (sChain)
  121.     {
  122.     TLX_DEBUG_CODE(int32 cnt = 0;)
  123.  
  124.     for (TLModuleInfo *rover = sChain; rover; rover = rover->mNext)
  125.     {
  126.         TLX_DEBUG_CODE(cnt++;)
  127.         if (rover == &sNullInfo)
  128.         continue;
  129.         rover->PrintOn(os) << "\n";
  130.     }
  131.     TLX_ASSERT(cnt == sModCount);
  132.     }
  133.     else
  134.     os << "(No modules found)\n";
  135. }
  136.  
  137. /*-------------------------------------------------------------------------*/
  138.     ostream &TLModuleInfo::PrintOn(ostream &os) const
  139.  
  140. /*  Prints information about the current module on the given stream.
  141. ---------------------------------------------------------------------------*/
  142. {
  143.     long oldf = os.setf(ios::left, ios::adjustfield);
  144.     os << setw(30) << Filename() << " " << setw(20) << Version()
  145.         << " " << DateTime();
  146.     os.setf(oldf, ios::adjustfield);
  147.     return os;
  148. }
  149.  
  150. #ifdef _TLXDBG
  151.  
  152. const char *TLModuleInfo::Filename() const
  153. {
  154.     TLX_ASSERT_PTR(mFilename);
  155.     return mFilename;
  156. }
  157.  
  158. const char *TLModuleInfo::Version() const
  159. {
  160.     TLX_ASSERT_PTR(mVersion);
  161.     return mVersion;
  162. }
  163.  
  164. const char *TLModuleInfo::DateTime() const
  165. {
  166.     TLX_ASSERT_PTR(mDateTime);
  167.     return mDateTime;
  168. }
  169.  
  170. #endif
  171.