home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / deans.zip / DEANSART.TXT < prev    next >
Text File  |  1994-09-14  |  7KB  |  154 lines

  1. This file contains the code for my OS/2 Developer Article:
  2.  
  3.         Issue: July/August 1994
  4.       Article: An Example OS/2 C++ Class Library System
  5.          Page: 52
  6.        Author: Dean Roddey
  7.    CompuServe: 72170,1614
  8.  
  9.  
  10. This file kind of contains a grab bag of code examples with some explanatory
  11. text. Keep in mind that they are pulled out of context from a large, very
  12. integrated system so it might not always be obvious what is going on. But,
  13. since I came to computers via music, I can type a blue streak and so tend to
  14. comment pretty heavily. Also keep in mind that this is a work in eternal
  15. progress, so the comments might occasionally not perfectly reflect the code
  16. and there might be some incomplete functionality in places.
  17.  
  18. Here are a few notes to help translate:
  19.  
  20. 1)  There are a number of .Dlls involved, but all of the code here will
  21.     come from CIDLib.Dll and CIDGui.Dll (the kernel and GUI encapsulating
  22.     Dlls.)
  23.  
  24. 2)  In my parlance, a Dll or Exe module is a Facility. For the most part
  25.     a Dll is just passive code to be used but also often needs a proactive
  26.     'agent' that offers more proactive services. These are called 'Facility
  27.     Objects', facCIDLib and facCIDGui in the examples.
  28.  
  29. 3)  All non class types exported from a facility are placed into a facility
  30.     types structure, tCIDLib and tCIDGui in the examples. So they would
  31.     be references (for example) as tCIDLib::CARD4 for a 4 byte cardinal
  32.     value.
  33.  
  34. 4)  My class system has a single root (except for a very few small
  35.     exceptions.) All derived classes override a couple of standard methods
  36.     (via a macro called STDVPUBMETHODS) that provide my own style of
  37.     runtime type identification. It provides the bIsA(), bIsDescendantOf(),
  38.     bIsSortable, clsIsA(), and clsParent() methods.
  39.  
  40. 5)  The logging system is very integrated. When a message is logged and
  41.     its severity is greater than APIFAILED, then it is stored on the
  42.     THREAD object of the calling thread. The called method will return a
  43.     FALSE, and the calling thread can examine the stored error if it cares
  44.     why the failure occured.
  45.  
  46.     If the severity is PROCESS_FATAL or higher, then the log call will
  47.     never return directly. Instead the logging method will throw the
  48.     error object (CIDERROR) as an exception. If the exception is not
  49.     handled, it will filter up to the start of the thead inside the
  50.     THREAD class and terminate the application.
  51.  
  52.     All classes can format info about themselves to a string, so the logging
  53.     system allows resource string loading, replacement of tokens in the
  54.     message with actual object info, storing of the error on the THREAD,
  55.     and exception throwing for fatal errors all in a single call.
  56.  
  57. 6)  WINDOW is the base class of the window system. All classes that are
  58.     encapsulations of PM classes are derived from PMCTRLBASE.
  59.  
  60. 7)  All of the development is under CSet/2++ and its associated development
  61.     tools (but not Workframe which I don't like.)
  62.  
  63. 8)  I am an ardent supporter of HPFS so all of the file names are long
  64.     and mixed case. But, I understand that you might not be in the same
  65.     position, so they have been renamed. The original names are in the
  66.     headers of each file. So the files listed below are by the original
  67.     names. For the zip file, I just tossed the CIDGui_ or CIDLib_ prefix
  68.     and used as much of the rest of the file name as possible.
  69.  
  70.  
  71.  
  72.  
  73. Here is a list of the files in this directory:
  74.  
  75. 1)  CIDGui_Base.Hpp/Cpp
  76.  
  77.     These files contain the POINT and AREA classes. These are very simple
  78.     but very useful.
  79.  
  80. 2)  CIDLib_Process.Hpp/Cpp
  81.  
  82.     These files contain the THREAD class. This is the kernel oriented
  83.     thread class. GUITHREAD is derived from it, but just provides a small
  84.     amount of extra functionality.
  85.  
  86. 3)  CIDLib_Exception_.Hpp/CIDLib_Exception.Cpp
  87.  
  88.     These files contain a nice exception handler that works in conjunction
  89.     with the THREAD class. Each new class object installs this exception
  90.     handler. It will trap serious exceptions and log them to disk along with
  91.     a trace of all the calls that it took to get there. This is a semi-
  92.     ripoff of an example on the Developers CD-ROM, but it is is very much
  93.     slimmed down to what it practical to do in the field without debug
  94.     info being available.
  95.  
  96. 4)  CIDGui_Paintbrush.Hpp/Cpp
  97.  
  98.     These files contain the PAINTBRUSH class, which is the wrapper around
  99.     the PM Presentation Space.
  100.  
  101. 5)  CIDGui_Window.Hpp/Cpp
  102.  
  103.     These files contain the WINDOW class.
  104.  
  105. 6)  CIDGui_Dialog.Hpp/Cpp
  106.  
  107.     These files contain the DIALOGWND class discussed at length in the
  108.     article.
  109.  
  110. 7)  Most classes have a nul reference defined, so WINDOW will have a define
  111.     that is:
  112.  
  113.         #define NUL_WINDOW      (*(WINDOW*)0)
  114.  
  115. 8)  There is a THREAD class and a GUITHREAD class, the latter of which is
  116.     allowed to do GUI oriented stuff. facCIDLib will return a pointer to
  117.     the calling thread's thread object as a THREAD. facCIDGui will return
  118.     a pointer to the calling threads thread object as a GUITHREAD (or log
  119.     a fatal error if the calling thread is not a GUI aware thread, which
  120.     prevents a common OS/2 problem with non-GUI aware threads calling
  121.     PM oriented APIs without being aware of it.)
  122.  
  123. 9)  I use hungarian notation (rare for C++ I guess.) However, the ability
  124.     to derive classes makes it needlessly worrisome to create a new
  125.     prefix for all derivatives (unless they offer radically unique
  126.     functionality), so I tend to use 'family prefixes.' So I often use
  127.     str for all string derivatives or wnd for all window derivatives. This
  128.     is also necessary since the whole point of C++ is to use polymorphism
  129.     to write to the lowest level class that provides the necessary
  130.     functionality.
  131.  
  132. 10) The ability to have a related popup menu is built into the WINDOW class
  133.     so that all windows have that capability.
  134.  
  135. 11) I don't use OS/2 or PM types directly outside of the facility that
  136.     encapsulates them and seldom inside them either. They are are all
  137.     redefined as enums or constants.
  138.  
  139. 12) You might find my style very funkey. I have spent a lot of time on
  140.     this issue and have never let habit drive the style of my system. It
  141.     is oriented towards readability and getting everything lined up
  142.     vertically as much as possible and getting everything on a tab stop
  143.     when possible.
  144.  
  145.  
  146. Feel free to drop me a note. I might not respond if I get too bogged down with
  147. it, because this is just a funtime sideline for me and I can't afford to spend
  148. massive amounts of time on it. But, if you have a legitimate question and
  149. need help or want to offer suggestions, then feel free.
  150.  
  151. This code is, of course, presented as is with no warranties of any kind. It
  152. cannot be used directly in a commercial product (difficult without the rest
  153. of the code anyway) but the ideas can freely be stolen for use.
  154.