home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / docs / som.inf (.txt) < prev    next >
Encoding:
OS/2 Help File  |  1993-06-29  |  196.2 KB  |  7,926 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. How to Use the SOM Reference ΓòÉΓòÉΓòÉ
  3.  
  4. The OS/2* 2.0 SOM Reference is a detailed technical reference for application 
  5. programmers.  It gives reference information and code examples to enable you to 
  6. write source code that uses SOM. 
  7.  
  8. Before you begin to use this information, it would be helpful to understand how 
  9. you can: 
  10.  
  11. o Expand the Contents to see all available topics 
  12. o Obtain additional information for a highlighted word or phrase 
  13. o Use action bar choices 
  14. o Use the programming information. 
  15.  
  16. How to Use the Contents 
  17.  
  18. When the Contents window first appears, some topics have a plus (+) sign beside 
  19. them. The plus sign indicates that additional topics are available. 
  20.  
  21. To expand the Contents if you are using a mouse, click on the plus sign.  If 
  22. you are using the keyboard, use the Up or Down Arrow key to highlight the 
  23. topic, and press the plus (+) key. For example, SOM Compiler has a plus sign 
  24. beside it. To see additional topics for that heading, click on the plus sign or 
  25. highlight that topic and press the plus (+) key. 
  26.  
  27. To view a topic, double-click on the topic (or press the Up or Down Arrow key 
  28. to highlight the topic, and then press the Enter key). 
  29.  
  30. How to Obtain Additional Information 
  31.  
  32. After you select a topic, the information for that topic appears in a window. 
  33. Highlighted words or phrases indicate that additional information is available. 
  34. You will notice that certain words and phrases are highlighted in green 
  35. letters, or in white letters on a black background.  These are called hypertext 
  36. terms. If you are using a mouse, double-click on the highlighted word.  If you 
  37. are using a keyboard, press the Tab key to move to the highlighted word, and 
  38. then press the Enter key.  Additional information then appears in a window. 
  39.  
  40. How to Use Action Bar Choices 
  41.  
  42. Several choices are available for managing information presented in the OS/2* 
  43. 2.0 SOM Reference.  There are three pull-down menus on the action bar:  the 
  44. Services menu, the Options menu, and the Help menu. 
  45.  
  46. The actions that are selectable from the Services menu operate on the active 
  47. window currently displayed on the screen. These actions include the following: 
  48.  
  49. Bookmark 
  50.    Allows you to set a placeholder so you can retrieve information of interest 
  51.    to you. 
  52.  
  53.    When you place a bookmark on a topic, it is added to a list of bookmarks you 
  54.    have previously set.  You can view the list, and you can remove one or all 
  55.    bookmarks from the list.  If you have not set any bookmarks, the list is 
  56.    empty. 
  57.  
  58.    To set a bookmark, do the following: 
  59.  
  60.     1. Select a topic from the Contents. 
  61.  
  62.     2. When that topic appears, choose the Bookmark option from the Services 
  63.        pull-down. 
  64.  
  65.     3. If you want to change the name used for the bookmark, type the new name 
  66.        in the field. 
  67.  
  68.     4. Click on the Place radio button (or press the Up or Down Arrow key to 
  69.        select it). 
  70.  
  71.     5. Click on OK (or select it and press Enter). The bookmark is then added 
  72.        to the bookmark list. 
  73.  
  74. Search 
  75.    Allows you to find occurrences of a word or phrase in the current topic, 
  76.    selected topics, or all topics. 
  77.  
  78.    You can specify a word or phrase to be searched.  You can also limit the 
  79.    search to a set of topics by first marking the topics in the Contents list. 
  80.  
  81.    To search for a word or phrase in all topics, do the following: 
  82.  
  83.     1. Choose the Search option from the Services pull-down. 
  84.  
  85.     2. Type the word or words to be searched for. 
  86.  
  87.     3. Click on All sections (or press the Up or Down Arrow keys to select it). 
  88.  
  89.     4. Click on Search (or select it and press Enter) to begin the search. 
  90.  
  91.     5. The list of topics where the word or phrase appears is displayed. 
  92.  
  93. Print 
  94.    Allows you to print one or more topics.  You can also print a set of topics 
  95.    by first marking the topics in the Contents list. 
  96.  
  97.    To print the document Contents list, do the following: 
  98.  
  99.     1. Choose Print from the Services pull-down. 
  100.  
  101.     2. Click on Contents (or press the Up or Down Arrow key to select it). 
  102.  
  103.     3. Click on Print (or select it and press Enter). 
  104.  
  105.     4. The Contents list is printed on your printer. 
  106.  
  107. Copy 
  108.    Allows you to copy a topic that you are viewing to the System Clipboard or 
  109.    to a file that you can edit. You will find this particularly useful for 
  110.    copying syntax definitions and program samples into the application that you 
  111.    are developing. 
  112.  
  113.    You can copy a topic that you are viewing in two ways: 
  114.  
  115.    o Copy copies the topic that you are viewing into the System Clipboard.  If 
  116.      you are using a Presentation Manager* (PM) editor (for example, the System 
  117.      Editor) that copies or cuts (or both) to the System Clipboard, and pastes 
  118.      to the System Clipboard, you can easily add the copied information to your 
  119.      program source module. 
  120.  
  121.    o Copy to file copies the topic that you are viewing into a temporary file 
  122.      named TEXT.TMP.  You can later edit that file by using any editor.  You 
  123.      will find TEXT.TMP in the directory where your viewable document resides. 
  124.  
  125.      To copy a topic, do the following: 
  126.  
  127.        1. Expand the Contents list and select a topic. 
  128.  
  129.        2. When the topic appears, choose Copy to file from the Services 
  130.           pull-down. 
  131.  
  132.        3. The system puts the text pertaining to that topic into the temporary 
  133.           file named TEXT.TMP. 
  134.  
  135.    For information on one of the other choices in the Services pull-down, 
  136.    highlight the choice and press the F1 key. 
  137.  
  138. The actions that are selectable from the Options menu allow you to change the 
  139. way your Contents list is displayed. To expand the Contents and show all levels 
  140. for all topics, choose Expand all from the Options pull-down. You can also 
  141. press the Ctrl and * keys together. For information on one of the other choices 
  142. in the Options pull-down, highlight the choice and press the F1 key. 
  143.  
  144. The actions that are selectable from the Help menu allow you to select 
  145. different types of help information.  You can also press the F1 key for help 
  146. information about the Information Presentation Facility (IPF). 
  147.  
  148. How to Use the Programming Information 
  149.  
  150. The SOM Reference consists of reference information that provides a detailed 
  151. description of each aspect of SOM. 
  152.  
  153. SOM programming information is presented by subject, such as Object Interface 
  154. Definition Language, SOM Compiler, SOM Bindings for C, and Methods Reference, 
  155. for example: 
  156.  
  157.      ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  158.      Γöé            Contents                     Γöé
  159.      Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  160.      Γöé                                         Γöé
  161.      Γöé  + Object Interface Definition Language Γöé
  162.      Γöé  + SOM Compiler                         Γöé
  163.      Γöé  + SOM Bindings for C                   Γöé
  164.      Γöé  + Methods Reference                    Γöé
  165.      Γöé                                         Γöé
  166.      ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  167.  
  168. By clicking on the plus sign beside 'Methods Reference', you see an alphabetic 
  169. list of the SOM methods. Selecting a method takes you directly into the 
  170. reference information for that method. 
  171.  
  172. Units of reference information are presented in selectable multiple windows or 
  173. viewports. A viewport is a Presentation Manager window that can be sized, 
  174. moved, minimized, maximized, or closed.  By selecting a unit (in this case, an 
  175. entry on the Contents list), you will see two windows displayed: 
  176.  
  177.     ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  178.     Γöé Unit Title   Γöé   Selection Title           Γöé
  179.     Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  180.     Γöé Topics:      Γöé                             Γöé
  181.     Γöé    .         Γöé                             Γöé
  182.     Γöé    .         Γöé                             Γöé
  183.     Γöé    .         Γöé                             Γöé
  184.     Γöé Example      Γöé                             Γöé
  185.     Γöé Error codes  Γöé                             Γöé
  186.     Γöé Glossary     Γöé                             Γöé
  187.     Γöé              Γöé                             Γöé
  188.     Γöé              Γöé                             Γöé
  189.     ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  190.  
  191. The window on the left is the primary window.  It contains a list of items that 
  192. are always available to you.  The window on the right is the secondary window. 
  193. It contains a 'snapshot' of the unit information. For reference units (that is, 
  194. method descriptions), this window contains the Call Syntax. 
  195.  
  196. All of the information needed to understand a method is readily available to 
  197. you through the primary window. The information is divided into discrete 
  198. information groups, and only the appropriate information group appears for the 
  199. topic that you are viewing. 
  200.  
  201. The information groups for a method description can include the following: 
  202.  
  203. o Call Syntax 
  204. o Uses 
  205. o Parameters 
  206. o Error codes 
  207. o Return Values 
  208. o Notes 
  209. o Related Methods 
  210. o Example 
  211. o Glossary 
  212.  
  213. This list may vary.  Uses, Notes, Related Methods, and Example may be omitted 
  214. when they do not apply. 
  215.  
  216. Information groups are displayed in separate viewports that are usually stacked 
  217. in a third window location that overlaps the secondary window. By selecting an 
  218. item (information group) in the primary window, the item is displayed in the 
  219. third window location: 
  220.  
  221.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  222.   Γöé Unit Title   Γöé   Selection TiΓöé   Parameters  Γöé
  223.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  224.   Γöé Topics:      Γöé               Γöé  receiver     Γöé
  225.   Γöé              Γöé               Γöé    .          Γöé
  226.   Γöé    .         Γöé               Γöé  classId      Γöé
  227.   Γöé    .         Γöé               Γöé    .          Γöé
  228.   Γöé    .         Γöé               Γöé    .          Γöé
  229.   Γöé Example      Γöé               Γöé    .          Γöé
  230.   Γöé Error codes  Γöé               Γöé    .          Γöé
  231.   Γöé Glossary     Γöé               Γöé               Γöé
  232.   Γöé              Γöé               Γöé               Γöé
  233.   Γöé              Γöé               Γöé               Γöé
  234.   ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  235.  
  236. By selecting successive items from the primary window, additional windows are 
  237. displayed on top of the previous windows displayed in the third window 
  238. location.  For example, in a method description, Uses and Parameters are items 
  239. listed in the primary window.  When selected, they appear one on top of the 
  240. other in the third window location. Because of this, you may move the first 
  241. selected (topmost) window to the left before selecting the next item. This 
  242. allows simultaneous display of two related pieces of information from the 
  243. 'stack' of windows in the third window location: 
  244.  
  245.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  246.   Γöé Unit Title   Γöé   Parameters  Γöé     Uses      Γöé
  247.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  248.   Γöé Topics:      Γöé  receiver     Γöé               Γöé
  249.   Γöé              Γöé    .          Γöé    .          Γöé
  250.   Γöé    .         Γöé  classId      Γöé    .          Γöé
  251.   Γöé    .         Γöé    .          Γöé    .          Γöé
  252.   Γöé    .         Γöé    .          Γöé    .          Γöé
  253.   Γöé Example      Γöé    .          Γöé    .          Γöé
  254.   Γöé Error codes  Γöé    .          Γöé    .          Γöé
  255.   Γöé Glossary     Γöé               Γöé               Γöé
  256.   Γöé              Γöé               Γöé               Γöé
  257.   Γöé              Γöé               Γöé               Γöé
  258.   ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  259.  
  260. Each window can be individually closed from its system menu.  All windows are 
  261. closed when you close the primary window. 
  262.  
  263. Some secondary windows may have the appearance of a split screen. For example, 
  264. an illustration may appear in the left half of the window, and scrollable, 
  265. explanatory information may appear in the right half of the window.  Because 
  266. illustrations may not necessarily fit into the small window size on your 
  267. screen, you may maximize the secondary window for better readability. 
  268.  
  269.  
  270. ΓòÉΓòÉΓòÉ <hidden> IBM Trademark ΓòÉΓòÉΓòÉ
  271.  
  272. Trademark of the IBM Corporation. 
  273.  
  274.  
  275. ΓòÉΓòÉΓòÉ <hidden> Stepstone Trademark ΓòÉΓòÉΓòÉ
  276.  
  277. Objective-C is a trademark of the Stepstone Corporation. 
  278.  
  279.  
  280. ΓòÉΓòÉΓòÉ <hidden> ANSI C Standard ΓòÉΓòÉΓòÉ
  281.  
  282. ANSI C refers to American National Standard X3.159-1989. 
  283.  
  284.  
  285. ΓòÉΓòÉΓòÉ 2. Object Interface Definition Language ΓòÉΓòÉΓòÉ
  286.  
  287. SOM Object Interface Definition Language (OIDL) files provide the basis for 
  288. generating binding files that enable programming languages to use and provide 
  289. SOM objects and their definitions (referred to as classes). Each OIDL file 
  290. defines the complete interface to a class of SOM objects. 
  291.  
  292. OIDL files come in different forms for different languages. The different forms 
  293. enable a class implementer to specify additional language-specific information 
  294. that allows the SOM OIDL Compiler (or SOM Compiler, for short) to provide 
  295. support for constructing the class. Each of these different forms shares a 
  296. common core language that specifies the exact information that a user must know 
  297. to use a class. One of the facilities of the SOM Compiler is the extraction of 
  298. the common core part of a class definition. Thus, the class implementer can 
  299. maintain a language-specific OIDL file for a class, and use the SOM Compiler to 
  300. produce the language-neutral core definition as needed. 
  301.  
  302. This section describes OIDL with the extensions to support C-language 
  303. programming. 
  304.  
  305. As indicated above, OIDL files are compiled by the SOM Compiler to produce a 
  306. set of language-specific or use-specific binding files. The SOM Compiler can 
  307. produce any of eleven different files: 
  308.  
  309. o C and C++ public header files that provide "usage bindings" for C and C++ 
  310.   programs that wish to use public methods supported by a given SOM class on 
  311.   instances of this class, or its subclasses. 
  312.  
  313. o C and C++ private header files that provide "usage bindings" for C and C++ 
  314.   programs that wish to use private as well as public methods supported by a 
  315.   given SOM class on instances of this class, or its subclasses. 
  316.  
  317. o C and C++ implementation header files, which provide macros, data structure 
  318.   definitions, and procedures used to allow C and C++ programmers to easily 
  319.   implement SOM classes without knowledge of the runtime SOM API used to create 
  320.   and initialize SOM classes. 
  321.  
  322. o C and C++ implementation template files, which include the appropriate 
  323.   implementation header, and provide default implementations for the methods 
  324.   supported by a SOM class. 
  325.  
  326. o A language-neutral core definition (as discussed above). 
  327.  
  328. o A private language-neutral core file, which contains private parts of the 
  329.   class' interface. 
  330.  
  331. o An OS/2* .DEF file that can be used to package the class in the form of an 
  332.   OS/2* DLL. 
  333.  
  334. OIDL files can contain the following sections. Required sections are designated 
  335. by (R); optional by (O): 
  336.  
  337. I.    Include section (O) 
  338. II.   Class section (R) 
  339. III.  Release Order section (O) 
  340. IV.   Metaclass section (O) 
  341. V.    Parent Class section (R) 
  342. VI.   Passthru section (O) 
  343. VII.  Data section (O) 
  344. VIII. Methods section (O) 
  345.  
  346. The SOM Compiler is somewhat flexible about the order of the sections, but the 
  347. order listed above is highly recommended. The following describes the purpose 
  348. and form of each of these sections. 
  349.  
  350. The discussion of each section begins with a brief description of its purpose 
  351. followed by a section-specific syntax diagram. Syntax diagram constants appear 
  352. in boldface (for example, #include, ,, =, ;, >, and "), while meta symbols 
  353. appear in the standard font (for example, [...]). User-supplied elements appear 
  354. in italics (for example, filename). 
  355.  
  356. Meta symbols have the following meanings: 
  357.  
  358. o Parentheses (( )) indicate grouped parts of the syntax (for example, ( 
  359.   #include ...)). 
  360.  
  361. o Square brackets ([ ]) indicate optional parts (for example, [, parent]). 
  362.  
  363. o An asterisk (*) designates multiples from 0 or more (for example, [, name]*). 
  364.  
  365. o A plus sign (+) designates multiples from 1 or more (for example, 
  366.   [description3]+). 
  367.  
  368. o A vertical bar (|) indicates alternatives. Within a set of alternatives, an 
  369.   underscore will indicate the default if one is defined. (for example, global 
  370.   | local). 
  371.  
  372. Each syntax diagram is followed by a simple example. 
  373.  
  374. Finally, the parts of the section to be supplied by the user are individually 
  375. described. Each user-input item is labeled "required" or "optional.". If 
  376. designated "optional," its default will be given following the explanation. 
  377.  
  378.  
  379. ΓòÉΓòÉΓòÉ 2.1. Include Section ΓòÉΓòÉΓòÉ
  380.  
  381. This required section contains an include statement that is a directive to the 
  382. OIDL preprocessor telling the compiler where to find the class interface 
  383. definition for this class' parent class, the class' metaclass if the class 
  384. specifies one, and the private interface files for any ancestor class for which 
  385. this class overrides one or more of its private methods. 
  386.  
  387. Note:  The include statements must appear in the order shown below. In 
  388.        addition, the ancestor include statements must be in inheritance order 
  389.        (from the root down). 
  390.  
  391. The syntax for an include statement is: 
  392.  
  393. [#include ( <ancestor> | "ancestor" )]* 
  394. #include ( <parent> | "parent" ) 
  395. [#include ( <metaclass> | "metaclass" )] 
  396.  
  397. Example: 
  398.  
  399. #include "barfile.sc"
  400. #include "foofile.sc"
  401. #include <metafile.sc>
  402.  
  403. where: 
  404.  
  405. <ancestor> [optional] is the name of the OIDL file containing the private part 
  406.           of an ancestor class' interface needed in the definition of this 
  407.           class. If ancestor is enclosed in angle brackets (<>), the search for 
  408.           the file will begin in system-specific locations. If parent is 
  409.           enclosed in double quotation marks (""), the search for the file will 
  410.           begin in the local context, then move to the system-specific 
  411.           locations. 
  412.  
  413. <parent>  [required] is the name of the OIDL file containing the parent class 
  414.           of the class for which the include statement is provided. If parent 
  415.           is enclosed in angle brackets (<>), the search for the file will 
  416.           begin in system-specific locations. If parent is enclosed in double 
  417.           quotation marks (""), the search for the file will begin in the local 
  418.           context, then move to the system-specific locations. 
  419.  
  420. <metaclass> [optional] is the OIDL file containing the metaclass of the class 
  421.           for which the include statement is provided. If metaclass is enclosed 
  422.           in angle brackets (<>), the search for the file will begin in 
  423.           system-specific locations. If metaclass is enclosed in double 
  424.           quotation marks (""), the search for the file will begin in the local 
  425.           context, then move to the system-specific locations. Refer to the 
  426.           note under Metaclass Section for additional information about when a 
  427.           metaclass include may be omitted. 
  428.  
  429.  
  430. ΓòÉΓòÉΓòÉ 2.2. Class Section ΓòÉΓòÉΓòÉ
  431.  
  432. This required section introduces the class, giving its name, attributes, and 
  433. optionally a description of the class as a whole. 
  434.  
  435. The syntax for a class statement is: 
  436.  
  437. class: name 
  438.     [, file stem = stem] 
  439.     [, external stem = stem] 
  440.     [, function prefix = prefix | 
  441.      , external prefix = prefix] 
  442.      , classprefix = prefix] 
  443.     [, major version = number] 
  444.     [, minor version = number] 
  445.     [, global | local]; 
  446.     [, classinit = function]; 
  447. [description] 
  448.  
  449. Example: 
  450.  
  451. class: Foo,
  452.        local,
  453.        file stem = foofile,
  454.        external prefix = xx_,
  455.        major version = 1,
  456.        minor version = 3;
  457. -- This is the Foo class. It does nothing.
  458.  
  459. where: 
  460.  
  461. <name>    [required] is the name for this class. 
  462.  
  463. file stem = stem [optional] is an attribute that specifies how the compiler is 
  464.           to construct file names for various generated files. The constructed 
  465.           file names will all begin with stem. 
  466.  
  467.           Note:  This value is also used as the class library name in any 
  468.                  generated .DEF file. 
  469.  
  470.           This attribute defaults to the name of the file containing the 
  471.           class-interface definition. 
  472.  
  473. external stem = stem [optional] is an attribute that governs the formation of 
  474.           external names that appear in the text of the generated output files. 
  475.           On some systems, external names are limited in length to a small 
  476.           number of characters. The SOM Compiler uses the value stem as the 
  477.           basis for generating short external names. A suffix is appended to 
  478.           stem for each external name. Because OS/2* 2.0 external names may be 
  479.           up to 255 characters in length, short external names are generally 
  480.           not used. 
  481.  
  482.           This attribute defaults to the same value given (or defaulted) by 
  483.           file stem. 
  484.  
  485. function prefix = prefix [optional] is an attribute that directs the compiler 
  486.           to construct method function names by prefixing method names with 
  487.           prefix. For example, function prefix = xx_ would result in a function 
  488.           name of xx_foo for a method called foo. 
  489.  
  490.           Note:  It is an error to specify both function prefix and external 
  491.                  prefix as attributes of the same class. 
  492.  
  493.           This attribute has no default. 
  494.  
  495. external prefix = prefix [optional] is an attribute that is similar to function 
  496.           prefix except this attribute will also cause each method function to 
  497.           be an external name, whereas  method functions usually are local to 
  498.           the module in which they are defined. Making method functions 
  499.           external can be useful in development environments whose debuggers 
  500.           have difficulty dealing with local procedures. 
  501.  
  502.           Note:  It is an error to specify both external prefix and function 
  503.                  prefix as attributes of the same class. 
  504.  
  505.           This attribute has no default. 
  506.  
  507. classprefix = prefix [optional] is similar to the function prefix attribute, 
  508.           but applies only to methods that have the class attribute. If you use 
  509.           the class attribute (for any methods in the current class 
  510.           definition), you are required to supply a classprefix value within 
  511.           the class statement. 
  512.  
  513.           This attribute has no default. 
  514.  
  515. major version = number [optional] is an attribute that specifies the major 
  516.           version number of this class definition. Number must be in the range 
  517.           of 0 to (2**31)-1. This will produce bindings that will verify that 
  518.           any code that purports to implement this class has the same major 
  519.           version number, unless number is 0, in which case no test is made. 
  520.  
  521.           This attribute defaults to major version = 0. 
  522.  
  523. minor version = number [optional] is an attribute that specifies the minor 
  524.           version number of this class definition. Number must be in the range 
  525.           of 0 to (2**31)-1. This will produce bindings that will verify that 
  526.           any code that purports to implement this class has the same or higher 
  527.           minor version number, unless number is 0, in which case no test is 
  528.           made. 
  529.  
  530.           This attribute defaults to minor version = 0. 
  531.  
  532. global | local [optional] is an attribute that indicates how binding files are 
  533.           to be linked together. Local means link to other files in the local 
  534.           context first. Global means bypass the local context. For example, 
  535.           local will result in C-language statements like: 
  536.  
  537.               #include "file.h" 
  538.  
  539.           Global will result in statements like: 
  540.  
  541.               #include <file.h> 
  542.  
  543.           This attribute defaults to global. 
  544.  
  545. classinit = function [optional] allows you to provide user-written code that 
  546.           participates in the construction of your class. function designates a 
  547.           function you supply that is called when your class is created. This 
  548.           function receives one argument-a pointer to your newly created class 
  549.           object. You can use this function to perform any supplemental 
  550.           processing that you need. If you specify this attribute in your class 
  551.           definition, a template for this function will be provided 
  552.           automatically in the generated .C file. 
  553.  
  554.           By default, your class will not have a user-written classinit 
  555.           function. 
  556.  
  557. description [optional] is a description of the class as a whole and must be in 
  558.           the form of a comment. Several comment styles are supported 
  559.           including: 
  560.  
  561.                        /*
  562.                         * line1
  563.                         * line2
  564.                         */
  565.  
  566.                        -- line 1 (starts with 2 consecutive dashes)
  567.                        -- line 2
  568.  
  569.                        // line 1
  570.                        // line 2
  571.  
  572.           Because OIDL files are used to generate language bindings, comments 
  573.           must be strictly associated with particular syntactic elements, so 
  574.           they will appear at the appropriate points in the output files. 
  575.           Therefore, comments must be placed in OIDL files with more care than 
  576.           in some programming languages. If you do not place your comments with 
  577.           strict adherence to the OIDL section syntax, the comments probably 
  578.           will not appear where you expect to see them. 
  579.  
  580.           A fourth style for OIDL comments is referred to as throw-away 
  581.           comments. They may be placed anywhere in an OIDL file, because they 
  582.           are not intended to appear in any binding files.  Throw-away comments 
  583.           start with the character (#) and end at the end of the line. You can 
  584.           use throw-away comments to "comment-out" sections of an OIDL file. 
  585.  
  586.                        #
  587.                        # This is an example of a throw-away comment
  588.                        #
  589.  
  590.           Note:  Comments will appear in files produced by the SOM Compiler in 
  591.                  various forms appropriate to the intended use of the file. 
  592.                  Sometimes these files are intended as input to a 
  593.                  programming-language compiler. Therefore, it is best to avoid 
  594.                  using characters in the body of comments that are not 
  595.                  generally allowed in most programming-language comments. For 
  596.                  example, the C language does not allow "*/" to occur in a 
  597.                  comment, so its use is to be avoided. 
  598.  
  599.           Refer to SOM Compiler Command Syntax for information about the effect 
  600.           of global attributes on OIDL comments. 
  601.  
  602.  
  603. ΓòÉΓòÉΓòÉ 2.3. Release Order Section ΓòÉΓòÉΓòÉ
  604.  
  605. This optional section contains a release order statement that forces the 
  606. compiler to build certain critical data structures with their items arranged in 
  607. the order specified. This allows the class interface and implementation to be 
  608. evolved without requiring programs that use this class be recompiled. 
  609.  
  610. Release order applies to all method names and public or private (that is, 
  611. non-internal) data items. If the release order of some method or non-internal 
  612. data item is not specified, it will default to an implementation-specific order 
  613. based on its occurrence in the OIDL file. The introduction of new public or 
  614. private data items or methods might cause the default ordering of other public 
  615. or private data items or methods to change; programs using the class would then 
  616. need to be recompiled. The SOM Compiler has a "pretty print" mode in which it 
  617. will reproduce a class definition in a nicely formatted manner with release 
  618. order specified for all relevant items. Programmers are advised to use this 
  619. facility to update the release order statement whenever they make significant 
  620. additions to a class. 
  621.  
  622. The syntax for a release order statement is: 
  623.  
  624. release order: name [, name ]* ; 
  625.  
  626. Example: 
  627.  
  628. release order: m1, m2, pd1, m3;
  629.  
  630. where: 
  631.  
  632. name [, name ]* [optional] contains all method names introduced by this class 
  633.           (whether public or private), and the names of any non-internal 
  634.           instance variables. It must not contain the names of any inherited 
  635.           methods (even if they are to be overridden), except as noted below. 
  636.           As the class evolves, new names can be added to the end of this list, 
  637.           but once a name is on this list, it must not be reordered or removed. 
  638.           Doing either will require the recompilation of programs that use this 
  639.           class. If a method named on the list is to be moved up in the class 
  640.           hierarchy (for example, to the parent class of this class), its name 
  641.           should remain just as it is on the current list, but it also must be 
  642.           added to the release-order list for the class that will now introduce 
  643.           it. 
  644.  
  645.  
  646. ΓòÉΓòÉΓòÉ 2.4. Metaclass Section ΓòÉΓòÉΓòÉ
  647.  
  648. This optional section specifies the class' metaclass, giving its name and, 
  649. optionally, a description of the reason for the metaclass, or other comments 
  650. about its role in this class' interface. If a metaclass is specified, its 
  651. definition must be included in the include section. If no metaclass is 
  652. specified, the metaclass of this class' parent class will be used. Therefore, 
  653. if you intend the metaclass of this class' parent class to be used, it is 
  654. generally best not to specify the metaclass. 
  655.  
  656. A class' metaclass can also be implicitly defined through the use of the class 
  657. attribute in the data section or the class attribute in the method section. If 
  658. you use either of these attributes you must bypass (that is, omit) the 
  659. metaclass section altogether. In this case, your implied metaclass will be a 
  660. subclass of the metaclass of your parent class. 
  661.  
  662. The syntax for a metaclass description statement is: 
  663.  
  664. metaclass: name; 
  665. [description] 
  666.  
  667. Example: 
  668.  
  669. metaclass: FooMeta;
  670. /*
  671.  * This is the metaclass for the Foo class.
  672.  * Note that several forms of comment are allowed.
  673.  */
  674.  
  675. where: 
  676.  
  677. name      [optional] is the name of the metaclass to be used to create the 
  678.           class object for this class. 
  679.  
  680.           This attribute defaults to the parent's metaclass. 
  681.  
  682. description [optional] is a description of the metaclass and must be in the 
  683.           form of a comment (see Class Section for the discussion about comment 
  684.           styles). 
  685.  
  686. Note:  You can add the attributes major version, minor version, file stem, and 
  687.        global | local to the metaclass statement. If you include at least file 
  688.        stem, you do not have to include the metaclass definition in the include 
  689.        section. 
  690.  
  691.  
  692. ΓòÉΓòÉΓòÉ 2.5. Parent Class Section ΓòÉΓòÉΓòÉ
  693.  
  694. This required section specifies the class' parent class, giving its name and, 
  695. optionally, a description of the role of the parent class in this class' 
  696. interface. 
  697.  
  698. The syntax for a parent class description statement is: 
  699.  
  700. parent [class]: name; 
  701. description 
  702.  
  703. Example: 
  704.  
  705. parent: SOMObject;
  706.  
  707. // Foo will be directly descended from the SOM root class, SOMObject.
  708. // Note, this is yet another style of comment.
  709.  
  710. where: 
  711.  
  712. name      [required] is the name of the class of which this class is a 
  713.           subclass. 
  714.  
  715. description [optional] is a description of the parent class and must be in the 
  716.           form of a comment (see Class Section for the discussion about comment 
  717.           styles). 
  718.  
  719. Note:  You may add the attributes major version, minor version, file stem, and 
  720.        global | local to the parent class statement. 
  721.  
  722.  
  723. ΓòÉΓòÉΓòÉ 2.6. Passthru Section ΓòÉΓòÉΓòÉ
  724.  
  725. This optional section provides blocks of code to be passed by the compiler into 
  726. various binding files. The contents of the passed lines are essentially ignored 
  727. by the compiler and can contain anything that needs to be placed near the 
  728. beginning of a binding file. 
  729.  
  730. Note:  Even comments contained in passthru lines are processed without 
  731.        modification. 
  732.  
  733. The syntax for the passthru section is: 
  734.  
  735. [passthru: language.suffix, [ before | after ]; 
  736. line 1 
  737. line 2 
  738. ... 
  739. endpassthru; [description]]* 
  740.  
  741. Example: 
  742.  
  743. passthru: C.h:
  744. typedef int *foobar;
  745. #define SIZE 89
  746. endpassthru;
  747. -- The two lines above will be placed in the public binding file for all C
  748. -- language users of this class. Note: the next passthru clause has no
  749. -- comment.
  750. passthru: C.ih;
  751. static char *name;
  752. endpassthru;
  753.  
  754. where: 
  755.  
  756. language  [required] is the programming language whose binding files are to be 
  757.           affected. Currently only the C language is supported. In the future 
  758.           other languages might be supported. 
  759.  
  760. suffix    [required] specifies which binding file is to be affected. For C, the 
  761.           currently supported binding files are: 
  762.  
  763.    .H        The binding file for all users of the class 
  764.  
  765.    .PH       The binding file for users with access to private methods of the 
  766.              class 
  767.  
  768.    .IH       The binding file for implementers of the class 
  769.  
  770.    .C        The program template file used in implementing the class 
  771.  
  772.    .SC       The language-neutral core version of the OIDL file 
  773.  
  774.    .PSC      Additional language-neutral information about the private methods 
  775.              in the class 
  776.  
  777.    .CS2      A "pretty printed" version of the OIDL file 
  778.  
  779.           Note:  In general, you would not normally place passthru lines into a 
  780.           .C file, because a .C file is usually generated only once and then 
  781.           filled in with source code by a programmer. Subsequent updates to a 
  782.           .C file by the SOM Compiler consist only of the addition of new 
  783.           method templates at the end of the file. Place passthru lines needed 
  784.           by the class' implementation code in the .IH file instead. Because 
  785.           the .IH file can be completely regenerated each time the OIDL class 
  786.           definition is compiled, changes to your passthru lines will be 
  787.           automatically included. 
  788.  
  789. before | after [optional] is the attribute that indicates whether passthru 
  790.           lines should precede or follow any include statements at the 
  791.           beginning of the binding file. This attribute defaults to before. 
  792.  
  793. line      [optional] is a line to be placed near the beginning of the binding 
  794.           file exactly as written. 
  795.  
  796. description [optional] is a description of the purpose of the passthru lines. 
  797.  
  798.  
  799. ΓòÉΓòÉΓòÉ 2.7. Data Section ΓòÉΓòÉΓòÉ
  800.  
  801. This optional section lists the instance variables for this class. This section 
  802. is generally present only in the language-specific version of the class 
  803. interface definition (a .CSC file). However, it must be present in the public 
  804. form of the class interface definition if the class contains public instance 
  805. variables. ANSI C syntax is used to describe these variables. 
  806.  
  807. The syntax for the data section is: 
  808.  
  809. data: 
  810. [description1] 
  811. [declaration [, private | , public | , internal] [, class]; 
  812. [description2]]* 
  813.  
  814. Example: 
  815.  
  816. data:
  817. -- This is the instance data for the Foo class.
  818. int FooSize, public;
  819. -- FooSize is a public instance variable.  This means that all users of the
  820. -- Foo class will have access to FooSize.
  821. char *fooName;
  822. -- fooName is a private instance variable; therefore, only the implementer of
  823. -- the Foo class will have access to it.
  824.  
  825. where: 
  826.  
  827. description1 [optional] is a description of the instance data as a whole and 
  828.           must be in the form of a comment (see Class Section for the 
  829.           discussion about comment styles). 
  830.  
  831. declaration [optional] is an ANSI C declaration for an instance variable. 
  832.  
  833. private | public | internal is the attribute that controls the type of binding 
  834.           (if any) to be exported for the instance data item. Internal prevents 
  835.           any binding from being exported. Private causes the binding to be 
  836.           part of private-usage binding files, and public causes the binding to 
  837.           be placed in public-usage binding files. For C, the exported binding 
  838.           is a macro of the form get_name(obj), where name is the name of the 
  839.           instance data item, and obj is an object containing the item. The 
  840.           macro returns an expression representing the item, which may be used 
  841.           on the left- or right-hand side of assignment statements. 
  842.  
  843.           This attribute defaults to internal. 
  844.  
  845. class     is an attribute that designates that the data item belongs to an 
  846.           implicitly defined metaclass. Data items having this attribute do not 
  847.           appear in instances of the class, but instead appear in the class 
  848.           itself. Methods defined in the methods section to have the class 
  849.           attribute can be created to manipulate class items. If you use this 
  850.           attribute your class definition cannot also contain an explicit 
  851.           metaclass section. 
  852.  
  853.           By default, data items are not considered as class data. 
  854.  
  855. description2 is an optional description of the instance variable and must be in 
  856.           the form of a comment (see Class Section for the discussion about 
  857.           comment styles). 
  858.  
  859.  
  860. ΓòÉΓòÉΓòÉ 2.8. Methods Section ΓòÉΓòÉΓòÉ
  861.  
  862. This optional section lists the methods to be supported by this class. ANSI C 
  863. function-prototype syntax is used to define the calling sequence to each 
  864. method. 
  865.  
  866. The syntax for the methods section is: 
  867.  
  868. methods: 
  869. [description1] 
  870. [[group: name; 
  871.     [description2]] 
  872. [method prototype 
  873.     [, public | , private] 
  874.     [, method | , procedure] 
  875.     [, class] 
  876.     [, offset | , name lookup] 
  877.     [, local | , external] 
  878.     [, use = name]; 
  879.     [description3]]* 
  880. [override: method name 
  881.     [, public | , private] 
  882.     [, class] 
  883.     [, local | , external] 
  884.     [, use = name]; 
  885.     [description4]]* 
  886.  
  887. Example: 
  888.  
  889. methods:
  890. -- This section lists all the methods that are to be
  891. -- introduced by the Foo class, as well as all the
  892. -- methods that Foo inherits and wants to override.
  893. void m1 (int parm1, char parm2);
  894. -- m1 is a public method with a fixed calling sequence.
  895. -- It does not return a value.
  896. int m2 (), private;
  897. -- m2 is a private method with no arguments (except
  898. -- for its target object) that returns an int.
  899. long m3 (int parm1), procedure;
  900. -- m3 will be a simple procedure.  It cannot be overridden.
  901. -- It will still have a "somSelf" argument like any other method.
  902. group: g2;
  903. -- The rest of the methods listed in this section are
  904. -- in group "g2".
  905. int m4 (int numargs, ...);
  906. -- m4 is a public method that has one required argument
  907. -- and any number of additional arguments that can be
  908. -- of any types.
  909. override: somInit;
  910. -- This class will override the implementation of
  911. -- somInit that it inherits from one of its ancestor
  912. -- classes.
  913. override: m6, private;
  914. int m5 (int p1, /* first parameter */
  915.         int p2, /* second parameter */
  916.         char *p3 /* last parameter */);
  917. -- Note how comments can be embedded in the method
  918. -- prototype.
  919.  
  920. where: 
  921.  
  922. description1 [optional] is a description of this class' methods as a whole and 
  923.           must be in the form of a comment (see Class Section for the 
  924.           discussion about comment styles). 
  925.  
  926. name      [required in each group statement] is the name of this group. 
  927.           Currently, groups serve no purpose except to improve the readability 
  928.           of the object interface definition. 
  929.  
  930. description2 [optional] is a description of this group of methods as a whole 
  931.           and must be in the form of a comment (see Class Section for the 
  932.           discussion about comment styles). 
  933.  
  934. <method prototype> [required in each method specification] is the ANSI C 
  935.           function prototype that defines the calling sequence to this new 
  936.           method with the two exceptions below: 
  937.  
  938.     1. Even though the first parameter to each method is the target object, 
  939.        this object is not mentioned in the method prototype. 
  940.  
  941.     2. Each parameter can be preceded by one of, IN, INOUT, or OUT, indicating 
  942.        whether it is an input, input/output, or output parameter. 
  943.  
  944.           Comments can occur after the separating comma between parameter 
  945.           specifications and after the last parameter, but before the closing 
  946.           parenthesis (see the declaration of m5 in the example above). 
  947.  
  948. public | private [optional] is an attribute that indicates to the compiler 
  949.           whether or not this method is part of the public interface to this 
  950.           class. There is no real difference between public and private 
  951.           methods, but the compiler will separate the bindings to these two 
  952.           classes of methods so that bindings for public methods can be 
  953.           distributed without distributing bindings for private methods. 
  954.  
  955.           This attribute defaults to public. 
  956.  
  957. local | external [optional] is an attribute that directs the compiler to 
  958.           declare the method function for this method as an external name or as 
  959.           a local name (directly accessible only to the compilation unit in 
  960.           which it occurs). 
  961.  
  962.           When specified, this attribute overrides the class default for method 
  963.           functions (see the descriptions for function prefix and external 
  964.           prefix under Class Section). 
  965.  
  966.           This attribute defaults to the class default. 
  967.  
  968.           This attribute has not been implemented at this time. 
  969.  
  970. use = name [optional] is an attribute that tells the compiler that the method 
  971.           function for this method is to have the name name. This overrides any 
  972.           class prefix specification. 
  973.  
  974.           This attribute has no default. 
  975.  
  976.           This attribute has not been implemented at this time. 
  977.  
  978. method | procedure [optional] is an attribute that indicates whether or not 
  979.           this method can be overridden by a subclass. 
  980.  
  981.           If method is specified, the method will operate on instances of the 
  982.           class and can be overridden by a method in a subclass. 
  983.  
  984.           If procedure is specified, the method will be a simple procedure. 
  985.           None of the normal method resolution mechanisms will be used in 
  986.           invoking the method procedure; it will be called directly. 
  987.  
  988.           This attribute defaults to method. 
  989.  
  990. class     is an attribute that specifies whether the method operates on 
  991.           instances or the class itself. 
  992.  
  993.           If class is specified the method is considered to be associated with 
  994.           an implicit metaclass. In this case the method will operate directly 
  995.           on the class itself and not on its instances. This is a convenient 
  996.           way of defining constructors or factory methods that can be invoked 
  997.           when no object instances exist. The implicit metaclass is considered 
  998.           to be a subclass of the parent class' metaclass. If you use the class 
  999.           attribute you cannot also define an explicit metaclass section. In 
  1000.           addition, you must also supply a classprefix value in the class 
  1001.           statement (see Class Section). 
  1002.  
  1003.           If this attribute is omitted, the method is assumed to operate on 
  1004.           object instances rather than the class. 
  1005.  
  1006. offset | name lookup [optional] is an attribute that indicates the preferred 
  1007.           invocation binding to be used for this method. Generally, methods are 
  1008.           invoked on the basis of information provided by the class that 
  1009.           introduces the method definition (called offset resolution). However, 
  1010.           this requires that the class of the method's target object be known 
  1011.           at compile time. Sometimes a method definition is introduced by 
  1012.           several classes. For such methods, name lookup (which invokes the 
  1013.           method using the method's name as a key) is a more appropriate 
  1014.           choice. 
  1015.  
  1016.           This attribute defaults to offset. 
  1017.  
  1018. description3 [optional] is a description of the method and must be in the form 
  1019.           of a comment (see Class Section for the discussion about comment 
  1020.           styles). 
  1021.  
  1022. method name [optional] is the name of a method introduced by an ancestor class 
  1023.           that this class will re-implement. Attributes on an override method 
  1024.           have the same meaning as previously stated for new methods. 
  1025.  
  1026. description4 [optional] is a description of the override method or of your 
  1027.           reason for overriding it, or both, and must be in the form of a 
  1028.           comment (see Class Section for the discussion about comment styles). 
  1029.  
  1030.  
  1031. ΓòÉΓòÉΓòÉ 2.9. Sample VECTOR.CSC file in OIDL ΓòÉΓòÉΓòÉ
  1032.  
  1033. #include <somobj.sc>   # Include the parent class definition
  1034.  
  1035. class: Vector,
  1036.         file stem = vector,
  1037.         external prefix = vect,
  1038.         classprefix = mvec,
  1039.         major version = 1,
  1040.         minor version = 0;
  1041.  
  1042. -- Demo class definition that implements a simple vector-of-integers
  1043. -- object. Vector elements are numbered from 0.  The size of the
  1044. -- vector must be set before using the array (otherwise it raises an
  1045. -- error) and cannot be changed once it is set.
  1046. -- This is a comment.
  1047.  
  1048. parent: SOMObject;
  1049.  
  1050. passthru: C.h;
  1051. /* something to put in the VECTOR.H file */
  1052. endpassthru;
  1053.  
  1054. passthru: C.ph;
  1055. /* something to put in the VECTOR.PH file */
  1056. endpassthru;
  1057.  
  1058. passthru: C.ih;
  1059. /* something to put in the VECTOR.IH file */
  1060. endpassthru;
  1061.  
  1062. data:
  1063.  
  1064.     integer4 (*body)[], public;
  1065.  
  1066.     -- <body> is a public instance variable, and therefore accessible in
  1067.     -- any code that has access to this class.  It is accessed via a macro
  1068.     -- of the form get_body(obj) where obj is the object whose instance of
  1069.     -- body you are accessing.  The macro expression can be used on the
  1070.     -- right- or left-hand side of an assignment.
  1071.  
  1072.     int size;
  1073.  
  1074.     -- <size> is an internal instance variable, and therefore accessible
  1075.     -- only in the code that participates in the implementation of this
  1076.     -- class.
  1077.  
  1078. methods:
  1079.  
  1080. SOMAny *newVectorOfSize(int size), class;
  1081.  
  1082. -- Creates a new instance of Vector and sets its size to <size>.
  1083.  
  1084. integer4 get (int i);
  1085.  
  1086. -- Returns the <i>th element in the vector.  Raises an error if
  1087. -- this vector does not have an <i>th element.
  1088.  
  1089. void set (int i, integer4 value);
  1090.  
  1091. -- Set the <i>th element of this vector.  Raises an error if
  1092. -- this vector does not have an <i>th element.
  1093.  
  1094. void setMany (int start, int num, ...);
  1095.  
  1096. -- Set several elements at once.  You must provide <num> elements, and
  1097. -- they will be assigned to vector elements starting with <start>.
  1098. -- Raises an error if this vector does not include each of the positions
  1099. -- covered by the assignment.
  1100.  
  1101. void setAll (integer4 value),
  1102.         private;
  1103.  
  1104. -- Sets all the elements in this vector to <value>.
  1105. -- Note: This is a private method and is not available for use unless
  1106. -- one has access to the private header file.  It would not appear in
  1107. -- the VECTOR.SC file.
  1108.  
  1109. void setSize (int size)
  1110.  
  1111. -- Set the size of a vector;
  1112. -- Use this method to establish the capacity of any Vector instance
  1113. -- created by the VectorNew macro (as opposed to instances created
  1114. -- with the newVectorOfSize constructor), before putting anything in
  1115. -- the vector.
  1116.  
  1117. override somInit;
  1118. -- Method prototype:
  1119. -- void somInit(Vector *somSelf);
  1120.  
  1121. -- Add initialization of the vector instance data.
  1122.  
  1123. override somDumpSelfInt;
  1124. -- Method prototype:
  1125. -- void somDumpSelfInt(Vector *somSelf, int level);
  1126.  
  1127. -- Add output of the vector instance data.
  1128.  
  1129.  
  1130. ΓòÉΓòÉΓòÉ 3. SOM Compiler ΓòÉΓòÉΓòÉ
  1131.  
  1132. The SOM Compiler translates the OIDL source definition of a SOM class into a 
  1133. set of bindings appropriate for a particular programming language. The SOM 
  1134. Compiler supplied with the OS/2* 2.0 Toolkit produces a complete set of 
  1135. bindings for the C and C++ programming languages. 
  1136.  
  1137. The compiler operates in two phases-a precompile phase and an emission phase. 
  1138. In the first phase a precompiler (SPC.EXE) reads and analyzes a user-supplied 
  1139. class definition and produces intermediate output files containing binary class 
  1140. information, comments, and passthru lines). In the second phase, one or more 
  1141. "emitter" programs (EMITC.EXE, EMITH.EXE, EMITIH.EXE, EMITPH.EXE, EMITDEF.EXE, 
  1142. EMITSC.EXE, EMITPSC.EXE, and EMITCSC.EXE) run to produce C-language binding 
  1143. files. 
  1144.  
  1145. The C++ language bindings come in the form of C++ proxy classes for the 
  1146. creation and use of instances of SOM classes, and implementation bindings that 
  1147. allow C++ code to implement SOM classes described using .CSC files.  These 
  1148. bindings are included in appropriate C++ source files, which are then compiled 
  1149. by a C++ compiler to produce executable code. 
  1150.  
  1151. Two additional programs (SPP.EXE and SPP2.EXE) serve as preprocessors for the 
  1152. SOM precompiler phase. The sequencing and execution of all of these programs is 
  1153. directed by the SOM Compiler (SC.EXE). 
  1154.  
  1155. The output from the emitters, plus user-supplied logic for the class' methods, 
  1156. are subsequently compiled by the C compiler and linked by the OS/2* 2.0 linker 
  1157. to create an executable program. Executable code can be packaged in 
  1158. self-contained .EXE files or placed in a DLL so the class can be used from many 
  1159. programs. 
  1160.  
  1161. The emitters for C produce the following output files: 
  1162.  
  1163. Output File    Contents 
  1164.  
  1165. <class-stem>.C A template for a C source program that implements a class. If 
  1166.                you are implementing a SOM class in C, this will become your 
  1167.                primary source file. It contains stub procedures for all of the 
  1168.                methods defined in the <class-stem>.CSC file. Once you have 
  1169.                supplied your own logic for these methods, subsequent processing 
  1170.                by the .C emitter will make only "incremental" updates to your 
  1171.                source file, based on changes that you make to the class 
  1172.                definition. These incremental updates consist of additional 
  1173.                method templates that are appended to the end of your .C file if 
  1174.                you have subsequently defined new methods in your class 
  1175.                definition. 
  1176.  
  1177.                The generated .C source file contains an include statement for 
  1178.                the .IH file described below. 
  1179.  
  1180.                If you are writing only "client" code that accesses a SOM class 
  1181.                someone else has implemented, you do not need to generate a .C 
  1182.                file. 
  1183.  
  1184. <class-stem>.H This is the public include file for all C-language programs that 
  1185.                need to access the SOM class. It contains a tailored set of C 
  1186.                macros for accessing the public methods and the public instance 
  1187.                data of the class. It also contains a macro for creating new 
  1188.                instances of the class, and includes several other header files 
  1189.                (based on the class definition), such as the .H files for the 
  1190.                parent class and the metaclass, as well as the principal header 
  1191.                file for SOM (SOM.H). 
  1192.  
  1193. <class-stem>.IH This file is referred to as the implementation header. It is 
  1194.                included from the <class-stem>.C file and contains most of the 
  1195.                automatically generated implementation details about your class. 
  1196.                The information found here includes: 
  1197.  
  1198.    o A C struct defining your class' instance data. 
  1199.  
  1200.    o C macros for accessing your internal instance data. 
  1201.  
  1202.    o C macros for invoking parent methods that your class has overridden. 
  1203.  
  1204.    o A <className>GetData macro used by the method stubs in your .C file to set 
  1205.      the "somThis" pointer. 
  1206.  
  1207.    o An apply stub for each of the new methods in the class. 
  1208.  
  1209.    o A <className>NewClass procedure for constructing your class object at run 
  1210.      time. 
  1211.  
  1212. <class-stem>.PH This file contains use macros for any private methods defined 
  1213.                in the class (the .IH file will have a #include for this file if 
  1214.                your class has private methods), as well as macros for any 
  1215.                instance data items designated as private. This file should be 
  1216.                distributed only to users who need knowledge of (and access to) 
  1217.                your private methods. 
  1218.  
  1219. <class-stem>.DEF This file can be used by the OS/2* 2.0 linker to package your 
  1220.                class in a DLL. If you want to combine several classes into a 
  1221.                single DLL, merge the exports statements from each of their .DEF 
  1222.                files into a single .DEF file for the entire DLL. When placing 
  1223.                multiple classes in one DLL you also must write a simple C 
  1224.                procedure named "SOMInitModule" and include it in the export 
  1225.                list. This procedure will be called by the SOM Class Manager 
  1226.                whenever your DLL is dynamically loaded, and it should call the 
  1227.                <className>NewClass routine of each class in your DLL. Like all 
  1228.                SOM functions and methods, your "SOMInitModule" routine should 
  1229.                adhere to OS/2* 2.0 system linkage conventions. 
  1230.  
  1231. <class-stem>.SC The language-neutral form of the SOM class definition. It is a 
  1232.                proper subset of the .CSC file with all private implementation 
  1233.                detail removed. If you wish to publish your class for others to 
  1234.                use, this is the form of the OIDL class definition that you 
  1235.                should publish. A .SC file also can be used as input by the SOM 
  1236.                Compiler, which can use it to generate a .H file for use by 
  1237.                programs that are clients of the class. 
  1238.  
  1239. <class-stem>.PSC A supplement to the language-neutral .SC file that contains 
  1240.                information about the private methods of a class. The .PSC file 
  1241.                contains everything needed for subsequently generating a .PH 
  1242.                file. 
  1243.  
  1244. <class-stem>.CS2 A "pretty-printed" form of your original .CSC file, with all 
  1245.                of the elements arranged in a canonical form. If you want the 
  1246.                SOM Compiler to produce a release order section for you 
  1247.                automatically, you can obtain it from this file. The .CS2 file 
  1248.                will have the same content as the original .CSC file except that 
  1249.                its release order statement will always be complete (even if the 
  1250.                release order statement in the .CSC file is not), and a 
  1251.                consistent comment style will appear throughout. 
  1252.  
  1253. Of the files discussed here, two of them (the .CSC file and the .C file) should 
  1254. be treated as primary source materials and kept in your development library. 
  1255. The remaining files can be generated from your .CSC file whenever your class is 
  1256. built, or whenever its definition changes. 
  1257.  
  1258.  
  1259. ΓòÉΓòÉΓòÉ 3.1. Running the SOM Compiler ΓòÉΓòÉΓòÉ
  1260.  
  1261. The SOM Compiler is actually a precompiler and a collection of code emitters 
  1262. that take the intermediate output from the precompiler and produce files for a 
  1263. variety of purposes and in several forms including, C header files, a C 
  1264. implementation template, and language-neutral core interface files. 
  1265.  
  1266. Assume that you have defined the interface for a class called Example and that 
  1267. you placed the definition in a file called EXAMPLE.CSC (.CSC is the standard 
  1268. extension for the C-specific form of an OIDL file). Then you might execute the 
  1269. following statement: 
  1270.  
  1271.     SC EXAMPLE
  1272.  
  1273. to compile EXAMPLE.CSC and produce the desired C-language binding files. SC.EXE 
  1274. uses three user-defined environment variables to control its operation and 
  1275. determine which emitters to execute: SMINCLUDE, SMEMIT, and SMTMP. 
  1276.  
  1277.  
  1278. ΓòÉΓòÉΓòÉ 3.1.1. The SMINCLUDE Environment Variable ΓòÉΓòÉΓòÉ
  1279.  
  1280. The SOM Compiler uses an environment variable named SMINCLUDE to locate 
  1281. included class definitions. Because every SOM class will have an include for 
  1282. its parent class definition, you will need to set this variable before running 
  1283. the SOM Compiler. It is similar in form to the OS/2* PATH or DPATH environment 
  1284. variables, in that it can consist of one or more directory names separated by a 
  1285. semicolon (;). Directory names can be specified with absolute or relative path 
  1286. names. For example 
  1287.  
  1288.     SET SMINCLUDE=.;..\MYSCDIR;C:\TOOLKT20\C\INCLUDE;
  1289.  
  1290.  
  1291. ΓòÉΓòÉΓòÉ 3.1.2. The SMEMIT Environment Variable ΓòÉΓòÉΓòÉ
  1292.  
  1293. SMEMIT is used to indicate which emitter programs should be executed. Like the 
  1294. SMINCLUDE environment variable it can consist of a list of items separated by 
  1295. semicolons. Each item designates a particular emitter by the name of the file 
  1296. extension the emitter produces. For example 
  1297.  
  1298.     SET SMEMIT=H;IH;PH;SC;DEF;
  1299.  
  1300. indicates that the EMITH.EXE, EMITIH.EXE, EMITPH.EXE, EMITSC.EXE and 
  1301. EMITDEF.EXE programs should be executed to produce .H, .IH, .PH, .SC, and .DEF 
  1302. files, respectively. By default all emitted output files are placed in the same 
  1303. directory as the input file named in the SC command. If the SMEMIT environment 
  1304. variable is not defined, the SOM Compiler will perform a syntax check of your 
  1305. class definition but no output will be produced. 
  1306.  
  1307.  
  1308. ΓòÉΓòÉΓòÉ 3.1.3. The SMTMP Environment Variable ΓòÉΓòÉΓòÉ
  1309.  
  1310. The SMTMP environment variable specifies the name of a directory that the SOM 
  1311. Compiler uses to hold intermediate output files. For example, 
  1312.  
  1313.     SET SMTMP=%TMP%
  1314.  
  1315. tells SC.EXE to use the same directory for temporary files as given by the 
  1316. setting of the TMP environment variable. 
  1317.  
  1318. As a general rule, the directory indicated by SMTMP should never coincide with 
  1319. the directory used by the SOM Compiler for its input or the emitted output 
  1320. files. If you do not give a setting for the SMTMP environment variable, SC will 
  1321. use the root directory of the current drive for temporary files. 
  1322.  
  1323.  
  1324. ΓòÉΓòÉΓòÉ 3.2. SOM Compiler Command Syntax ΓòÉΓòÉΓòÉ
  1325.  
  1326. The syntax of the command for running the SOM Compiler (SC.EXE) is: 
  1327.  
  1328.     SC [-options] file[.CSC] 
  1329.  
  1330. where options can be specified individually, as a string of option characters, 
  1331. or a combination of both. Any option that takes an argument either must be 
  1332. specified individually or appear as the final option in a string of option 
  1333. characters. 
  1334.  
  1335. The file specified with the SC command refers to the file containing the OIDL 
  1336. class definition to be compiled. Typically this file will have a .CSC or .SC 
  1337. extension, but this is not required. If a file exists with the given name, that 
  1338. file will be used. If no such file exists, a .CSC extension is assumed. 
  1339.  
  1340. The available options are 
  1341.  
  1342. -C n        set the size of the comment buffer (default: 32767). 
  1343.  
  1344. -S n        set the total amount of string space for names and passthru lines 
  1345.             (default: 32767). 
  1346.  
  1347. -V          display version information. 
  1348.  
  1349. -a name[=value] add a global attribute. The currently supported attributes are 
  1350.             defined below (at the end of this section). 
  1351.  
  1352. -d directory specify a directory where all files emitted during the execution 
  1353.             of this command should be placed. If the -d option is not used, all 
  1354.             emitted output files are placed in the same directory as the input 
  1355.             .CSC file. 
  1356.  
  1357. -h or -?    provide usage information for reference. 
  1358.  
  1359. -i filename specify the name of the OIDL class definition file. Use this option 
  1360.             to override the built-in assumption that the input file will have a 
  1361.             .CSC extension. Any filename you supply with the -i option is used 
  1362.             exactly as you provide it. 
  1363.  
  1364. -r          check that all release-order entries actually exist (default: 
  1365.             FALSE). 
  1366.  
  1367. -s string   substitute string in place of the contents of the SMEMIT 
  1368.             environment variable for the duration of the current SC command. If 
  1369.             you supply a list of values, you must enclose the list with double 
  1370.             quotation marks (""). You can use the -s option as a convenient way 
  1371.             to override the SMEMIT environment variable. For example: 
  1372.  
  1373.                 SC -s "h;sc" EXAMPLE 
  1374.  
  1375.             is equivalent to the following sequence of commands: 
  1376.  
  1377.                 SET OLDSMEMIT=%SMEMIT% 
  1378.                 SET SMEMIT=h;sc 
  1379.                 SC EXAMPLE 
  1380.                 SET SMEMIT=%OLDSMEMIT% 
  1381.  
  1382. -w          suppress warning messages (default: FALSE). 
  1383.  
  1384. The only global attributes currently supported by SC.EXE are: 
  1385.  
  1386. comment=comment string where comment string can be one of the following: "/*", 
  1387.             "--", or "//". This indicates that comments marked in the indicated 
  1388.             way are to be completely ignored by SC.EXE and not retained for 
  1389.             subsequent processing by one of the emitters. 
  1390.  
  1391.             Note:  Comments indicated by lines whose first non-white-space 
  1392.             character is a # are always ignored by SC.EXE. Also note that 
  1393.             comments of any form in passthru lines are passed through. 
  1394.  
  1395. cstyle=comment style controls the form of emitted comments. Comment style must 
  1396.             be one of s, c, or + to cause emitted comments to be in "--", "/* 
  1397.             */", or "//" form, respectively. The default form is s. 
  1398.  
  1399. ibmc        causes EMITC, EMITH, EMITIH, EMITPH, and EMITDEF to generate code 
  1400.             with pragmas specifically intended for the IBM C Set/2 Compiler. 
  1401.             This attribute is specified by default. 
  1402.  
  1403. cl386       causes EMITC, EMITH, EMITIH, EMITPH, and EMITDEF not to generate 
  1404.             code with pragmas specifically intended for the IBM C Set/2 
  1405.             Compiler. 
  1406.  
  1407.  
  1408. ΓòÉΓòÉΓòÉ 4. SOM bindings for C ΓòÉΓòÉΓòÉ
  1409.  
  1410. The form of the SOM Application Programming Interface (API) varies depending on 
  1411. the programming language that you are using.  The API described here 
  1412. corresponds to the form that a C-language programmer would use. 
  1413.  
  1414. Three of the output files produced by the SOM Compiler can be considered as 
  1415. C-language binding files. 
  1416.  
  1417. <class stem>.H The public-usage binding file. This file must be included in a 
  1418.             C-language program in order to use objects of the class. 
  1419.  
  1420. <class stem>.PH The private-usage binding file. This file must be included in a 
  1421.             C-language program in order to use the private parts of the class' 
  1422.             interface. 
  1423.  
  1424.             Note:  This file includes the <class stem>.H file. 
  1425.  
  1426. <class stem>.IH The implementation binding file. This file must be included in 
  1427.             the source file that implements the class. 
  1428.  
  1429.             Note:  This file includes the <class stem>.PH file, if one exists, 
  1430.             otherwise it includes the <class stem>.H file. 
  1431.  
  1432. In addition, compilation of a .CSC file for a class can produce or update the 
  1433. <class stem>.C file that contains the class' implementation. 
  1434.  
  1435. All C-language binding files produced by the SOM Compiler are protected with an 
  1436. appropriate #ifndef so that they can be included in a C-language compilation 
  1437. unit more than once without harm. 
  1438.  
  1439.  
  1440. ΓòÉΓòÉΓòÉ 4.1. API for Class Clients ΓòÉΓòÉΓòÉ
  1441.  
  1442. Programs that use or subclass a class are referred to as client programs.  To 
  1443. be a client of a class, your C-language program must include the <classstem>.H 
  1444. file generated by the SOM Compiler. This header contains a customized set of 
  1445. macros for using all of the class' public methods and accessing all of its 
  1446. public instance variables from a C-language program. 
  1447.  
  1448. A special header (SOM.H) contains, or includes, all of the usage macros for the 
  1449. classes and methods supplied as part of SOM itself. This header is 
  1450. automatically included by any generated <classstem>.H file, or can be included 
  1451. explicitly. 
  1452.  
  1453.  
  1454. ΓòÉΓòÉΓòÉ 4.1.1. <className>NewClass ΓòÉΓòÉΓòÉ
  1455.  
  1456. The C-language interface to a class also includes a function whose name is 
  1457. <className>NewClass. This is a standard C function (not a method) produced by 
  1458. the SOM Compiler for creating the actual SOM class object.  Its interface is 
  1459. given by: 
  1460.  
  1461.     SOMAny *<className>NewClass (int majorVersion, int minorVersion);
  1462.  
  1463. This function will create the class object (if it does not already exist), and 
  1464. return a pointer to it.  If the SOM run time has not yet been initialized, this 
  1465. function will initialize it prior to constructing the class.  The user-supplied 
  1466. version numbers are checked against the version information built into the 
  1467. class to determine if the class is compatible with the user's expectations.  If 
  1468. the class is not compatible, an error condition is raised and (*SOMError)() is 
  1469. invoked. See the discussion under "somCheckVersion" in the Methods Reference 
  1470. section for more information about version number-checking. 
  1471.  
  1472. Note:  Constructing a class might also cause the dynamic loading or 
  1473.        construction of its parent class or classes and its metaclass. After the 
  1474.        first call to this routine, subsequent invocations bypass the class 
  1475.        construction and simply return a pointer to the existing class object. 
  1476.  
  1477.  
  1478. ΓòÉΓòÉΓòÉ 4.1.2. <className>New ΓòÉΓòÉΓòÉ
  1479.  
  1480. This macro can be used to create an instance of class <className>.  It takes no 
  1481. arguments and returns a pointer to a new object instance.  If the class object 
  1482. does not already exist, this macro first creates the class object.  Its 
  1483. interface is given by: 
  1484.  
  1485.     SOMAny *<className>New();
  1486.  
  1487. If a new instance cannot be created an error condition is raised and 
  1488. (*SOMError)() is invoked.  This macro is a convenient shorthand for applying 
  1489. the built-in somNew method to the appropriate class object, as in 
  1490.  
  1491.     SOMAny *aNewInstance;
  1492.     aNewInstance = _somNew(<className>NewClass());
  1493.  
  1494.  
  1495. ΓòÉΓòÉΓòÉ 4.1.3. <className>Renew ΓòÉΓòÉΓòÉ
  1496.  
  1497. The <className>Renew macro can be used to create an instance of class 
  1498. <className> in a block of memory supplied by the calling program.  Its 
  1499. operation is identical to the <className>New macro, except that no memory is 
  1500. allocated for the new object instance. 
  1501.  
  1502.     SOMAny *<className>Renew(SOMAny *buf);
  1503.  
  1504. The argument buf must point to a block of storage large enough to hold an 
  1505. instance of class <className> (you can used the built-in SOM method, 
  1506. somGetInstanceSize, to determine the amount of memory required). 
  1507.  
  1508.  
  1509. ΓòÉΓòÉΓòÉ 4.1.4. _<className> ΓòÉΓòÉΓòÉ
  1510.  
  1511. This macro serves as a convenient way to refer to the class object created by 
  1512. the <className>NewClass macro. You need to be certain that the class has been 
  1513. created prior to any use of this macro. 
  1514.  
  1515.  
  1516. ΓòÉΓòÉΓòÉ 4.1.5. Method Macros ΓòÉΓòÉΓòÉ
  1517.  
  1518. The C-language macro form of a SOM method invocation consists of an underscore 
  1519. character (_) immediately followed by the method name. This token, when 
  1520. combined with an argument list using standard C function syntax, indicates a 
  1521. method call. 
  1522.  
  1523. All SOM methods require at least one argument-a pointer to the receiving 
  1524. object, followed by additional arguments, if any, appropriate to the particular 
  1525. method to be invoked. 
  1526.  
  1527. Note:  This first argument (the receiving object) is not listed when the method 
  1528.        definition is specified in the class definition, because this is more an 
  1529.        artifact of the method resolution mechanism than a logical argument to 
  1530.        the method. However, when the method is actually invoked, the receiving 
  1531.        object must be passed to the method as the first parameter. This 
  1532.        argument designates the object to which the method applies. 
  1533.  
  1534. If you use a C expression to represent or compute this argument, you must 
  1535. confine your usage to expressions without side-effects, as this first argument 
  1536. is actually evaluated twice by the macro expansion. In particular, the 
  1537. following usage is always incorrect: 
  1538.  
  1539.     HPS targetPresentationSpace;
  1540.     SOMClass *VisualObject;
  1541.     ...
  1542.     _displayYourself (_somNew(VisualObject), targetPresentationSpace);
  1543.     /* _somNew() is incorrect in this context */
  1544.  
  1545. Instead, code: 
  1546.  
  1547.     SOMAny *temp;
  1548.     ...
  1549.     temp = _somNew (VisualObject);
  1550.     _displayYourself (temp, targetPresentationSpace);
  1551.  
  1552. The correct code above replaces an expression with side-effects (_somNew()), 
  1553. with one that can be harmlessly evaluated multiple times (temp). 
  1554.  
  1555. For a typical example of method invocation in C, consider these methods from 
  1556. the sample VECTOR.CSC file: 
  1557.  
  1558.     methods:
  1559.  
  1560.         SOMAny *newVectorWithSize(int size), class;
  1561.         void set (int i, integer4 value);
  1562.         integer4 get (int i);
  1563.         void setMany (int start, int num, ...);
  1564.  
  1565. The first three of these could be invoked using the following code sequence: 
  1566.  
  1567.     SOMAny aVector;
  1568.     int i;
  1569.  
  1570.     VectorNewClass(1,0); /* Ensure that the class exists */
  1571.     aVector = _newVectorOfSize(_Vector,5);
  1572.  
  1573.     /* Set aVector to the 1st 5 even numbers */
  1574.     for (i=0; i<5; i++)
  1575.         _set(aVector, i, i*2);
  1576.  
  1577.     printf("The value of the 3rd element is %ld\n",
  1578.            _get(aVector,2)); /* Elements are 0-origin */
  1579.  
  1580. The _newVectorOfSize method is a constructor for Vector objects (indicated by 
  1581. the class attribute in its definition in VECTOR.CSC). Because this method 
  1582. operates on the Vector class rather than on an instance the receiving object is 
  1583. indicated as _Vector. The other methods in this example then operate on the 
  1584. newly created instance, aVector. 
  1585.  
  1586. Methods that are defined to take a varying number of arguments can also be 
  1587. invoked using macros like those shown above. In addition, the SOM Compiler 
  1588. generates a special function for each method requiring a variable argument 
  1589. list. These functions have "va_" as a prefix to the method name. The setMany 
  1590. method shown above could be invoked in either of the following ways 
  1591.  
  1592.     _setSize(aVector,7);
  1593.     _setMany(aVector, 2, 5, 4L, 6L, 8L, 10L, 12L);
  1594.  
  1595.     or
  1596.  
  1597.     _setSize(aVector,7);
  1598.     va_setMany(aVector, 2, 5, 4L, 6L, 8L, 10L, 12L);
  1599.  
  1600. Note:  SOM uses the convention that all method names begin with a lowercase 
  1601.        letter; uppercase characters are used to emphasize word boundaries 
  1602.        within the method name.  However, you are free to use any convention you 
  1603.        like for methods that you define. Another SOM convention is that all 
  1604.        public static methods that have the same name, also should have a common 
  1605.        signature. That is, they should return values of the same type, and take 
  1606.        arguments that agree in number and type. Consequently, it is good 
  1607.        practice to use a unique prefix or suffix whenever practical to avoid 
  1608.        accidental duplication of method names. 
  1609.  
  1610.  
  1611. ΓòÉΓòÉΓòÉ 4.1.6. SOM_Resolve and SOM_ResolveNoCheck ΓòÉΓòÉΓòÉ
  1612.  
  1613. In addition to the individual C-language macros for invoking methods, SOM 
  1614. supplies two macros (SOM_Resolve and SOM_ResolveNoCheck) that can be used to 
  1615. invoke any static method (static methods are those accessible through offset 
  1616. resolution). The difference between these two macros is that SOM_Resolve 
  1617. performs consistency checking on its arguments while SOM_ResolveNoCheck, which 
  1618. is faster, does not. Both macros require the same three arguments as shown 
  1619. below: 
  1620.  
  1621.     SOM_Resolve(<receiver>,<className>,<methodName>)
  1622.     SOM_ResolveNoCheck(<receiver>,<className>,<methodName>)
  1623.  
  1624. <receiver> is the object to which the method will apply. As with the method 
  1625. macros, <receiver> should be given as an expression without side-effects. 
  1626. <className> is the name of the class of the receiving object, and <methodName> 
  1627. is the name of the desired method. These names are supplied as simple tokens 
  1628. rather than strings. The macro evaluates to an expression that represents the 
  1629. actual entry-point address of the method procedure.  This value can be stored 
  1630. in a variable and retained so that subsequent method resolutions directed to 
  1631. the same receiving object can be bypassed altogether. Cast this result to be of 
  1632. the same type as the method procedure to which it refers. 
  1633.  
  1634.  
  1635. ΓòÉΓòÉΓòÉ 4.1.7. Public or Private Instance Variable Macros ΓòÉΓòÉΓòÉ
  1636.  
  1637. Instance variables that have been declared to be public or private can be 
  1638. accessed directly by clients of a class, using a macro of the form: 
  1639.  
  1640.     get_<instanceVariableName>(<targetObject>)
  1641.  
  1642. Here, <instanceVariableName> is the name of the public or private instance 
  1643. variable to access, and <targetObject> is a pointer to the object where the 
  1644. instance variable resides.  This macro can be used on either side of the equal 
  1645. sign (=) in a C assignment statement. 
  1646.  
  1647. (The macros for accessing private instance data items are only found in the .PH 
  1648. file, whereas the public instance data macros appear in the class' .H file.) 
  1649.  
  1650.  
  1651. ΓòÉΓòÉΓòÉ 4.2. API for Class Implementers ΓòÉΓòÉΓòÉ
  1652.  
  1653. Programmers who implement SOM classes in C can use all of the client programmer 
  1654. APIs, as well as several additional macros that are not available in client 
  1655. programs. 
  1656.  
  1657. The C-language implementation of a SOM class is contained in one or more .C 
  1658. files. If more than one .C file is needed, one (and only one) of them is 
  1659. considered the "primary" file and includes the following #define statement: 
  1660.  
  1661.     #define <className>_Class_Source
  1662.  
  1663. This is used in the SOM-generated .IH file to determine when to define various 
  1664. functions associated with the class, such as the <className>NewClass function. 
  1665. As a matter of course, all .C files must include the .IH file.  The skeletal .C 
  1666. files generated by the SOM Compiler contain a #include statement for the .IH 
  1667. file; any additional .C files you create for the class should be modelled after 
  1668. these. 
  1669.  
  1670.  
  1671. ΓòÉΓòÉΓòÉ 4.2.1. Implementation Conventions for Methods ΓòÉΓòÉΓòÉ
  1672.  
  1673. The macros that the SOM Compiler produces for use by method implementers 
  1674. presume certain conventions. Because each SOM method always receives at least 
  1675. one argument-a pointer to the object that the method should apply to, this 
  1676. argument is given the name "somSelf." 
  1677.  
  1678. "somSelf" is defined to be a pointer to an object that is an instance of class 
  1679. <className> or an instance of one of its descendent classes. Consequently, the 
  1680. object pointed to by "somSelf" can contain sections with instance data from any 
  1681. number of classes related through inheritance. A local variable named "somThis" 
  1682. is used by each method implementation to access the instance data in its class' 
  1683. section of the object. 
  1684.  
  1685. The "somSelf" pointer is always passed to the method procedure as an argument; 
  1686. the "somThis" pointer must be set by each method that needs access to instance 
  1687. data. A custom macro, <className>GetData, is provided for each class in its .IH 
  1688. file to derive the appropriate value for the "somThis" pointer from the 
  1689. "somSelf" pointer. This housekeeping is performed automatically in the method 
  1690. stubs generated by the SOM Compiler, but you need to be aware of this 
  1691. convention. You can use the "somThis" pointer either explicitly to manipulate 
  1692. your instance data, or implicitly by using custom macros for each item of 
  1693. instance data. 
  1694.  
  1695.  
  1696. ΓòÉΓòÉΓòÉ 4.2.2. <className>GetData Macro ΓòÉΓòÉΓòÉ
  1697.  
  1698. If you are implementing a class that contains instance variables most of the 
  1699. methods in your class will need addressability to the instance data.  The SOM 
  1700. Compiler generates a C typedef with the name <className>Data for the structure 
  1701. that it uses to hold your instance data.  Methods that will access the data 
  1702. then use the <className>GetData macro to establish addressability.  This macro 
  1703. must be one of the first executable lines of code in each method, and the value 
  1704. it returns should be assigned to a local variable named "somThis." The SOM 
  1705. Compiler automatically generates the code that accomplishes this in each method 
  1706. stub in a .C file. 
  1707.  
  1708. Here is a sample method implementation from the .C file derived from the sample 
  1709. VECTOR.CSC class definition. 
  1710.  
  1711.     #pragma linkage (system, get)                    /* Generated line */
  1712.     static long SOMLINK get(Vector *somSelf, int i)  /* Generated line */
  1713.     {                                                /* Generated line */
  1714.         VectorData *somThis = VectorGetData(somSelf);/* Generated line */
  1715.         VectorMethodDebug("Vector","get");           /* Generated line */
  1716.  
  1717.         if (i<_size)                      /* These lines were supplied */
  1718.             return (*_body)[i];           /* by the implementer of the */
  1719.         else                              /* method.                   */
  1720.             SOM_Error (10+SOM_Fatal);     /*                           */
  1721.  
  1722.         return ((long) 0);                           /* Generated line */
  1723.     }                                                /* Generated line */
  1724.  
  1725. The above example shows a typical usage of the <className>GetData macro.  It 
  1726. takes a single argument, <somSelf>, defined to be a pointer to the object 
  1727. "receiving" the method call, and returns a pointer to the portion of the object 
  1728. that contains the instance data structure for class <className>. 
  1729.  
  1730.  
  1731. ΓòÉΓòÉΓòÉ 4.2.3. Instance Variable Macros ΓòÉΓòÉΓòÉ
  1732.  
  1733. If your instance data consists of items with the names <a, b, c> the .IH file 
  1734. produced by the SOM Compiler will have custom macros formed by prefixing an 
  1735. underscore character (_) to each item, resulting in macro names of <_a, _b, 
  1736. _c>. These macros assume that a local variable named "somThis" has been set to 
  1737. point to the portion of the object instance where your instance data is kept. 
  1738. You can use these macro names for your data items anywhere one of the original 
  1739. names would have been valid. 
  1740.  
  1741.  
  1742. ΓòÉΓòÉΓòÉ 4.2.4. Parent Method Macros ΓòÉΓòÉΓòÉ
  1743.  
  1744. If you define methods in your class that override those inherited from one of 
  1745. your parent classes, you will frequently want to write your own logic as 
  1746. incremental changes to the parent methods' behavior. That is, at some point 
  1747. within your method, you will need to invoke the parent method to perform its 
  1748. own processing.  This could occur at the beginning of your method code, at the 
  1749. very end, or at some point in the middle, depending on the nature of the 
  1750. inherited method and how you intend to supplement or modify its behavior. 
  1751.  
  1752. To be certain that the method-resolution mechanism will bypass your 
  1753. (overriding) method and invoke the parent method instead, macros are provided 
  1754. in the <className>.IH file (for each overridden method) that start with the 
  1755. prefix "parent_". For example, if you have methods <m1> and <m2> that override 
  1756. parent methods, the macros <parent_m1> and <parent_m2> can be used in your code 
  1757. to invoke the parent methods when needed. 
  1758.  
  1759.  
  1760. ΓòÉΓòÉΓòÉ 4.2.5. SOM_ParentResolve ΓòÉΓòÉΓòÉ
  1761.  
  1762. Just as SOM_Resolve is available to clients of a class, the SOM_ParentResolve 
  1763. macro can be used by class implementers, within the body of a method procedure, 
  1764. to obtain the entry-point address of a parent-method procedure. This value can 
  1765. be saved and subsequently used to bypass the method-resolution process when 
  1766. invoking a parent method. Like SOM_Resolve it applies only to static methods. 
  1767. It requires three arguments as shown below: 
  1768.  
  1769.     SOM_ParentResolve(<parentClassName>,<className>,<methodName>)
  1770.  
  1771. <parentClassName> is the name of the parent class, <className> is the name of 
  1772. the class where the macro appears, and <methodName> is the name of the desired 
  1773. parent method. These names are supplied as simple tokens rather than strings. 
  1774. The macro evaluates to an expression that represents the actual entry-point 
  1775. address of the parent-method procedure. Cast this result to be of the same type 
  1776. as the method procedure to which it refers. 
  1777.  
  1778.  
  1779. ΓòÉΓòÉΓòÉ 4.3. API for General Usage ΓòÉΓòÉΓòÉ
  1780.  
  1781. The interfaces described here can be used both in programs that are are clients 
  1782. of a SOM class and programs that implement SOM classes. To use the 
  1783. general-purpose SOM macros, you need to include <SOM.H>, or any .H file 
  1784. produced from the SOM Compiler. 
  1785.  
  1786.  
  1787. ΓòÉΓòÉΓòÉ 4.3.1. ID Manipulation ΓòÉΓòÉΓòÉ
  1788.  
  1789. IDs are essentially numbers that uniquely represent strings. They are used in 
  1790. SOM to identify method names, class names, and descriptors. All SOM ID 
  1791. manipulations are case-insensitive, although the original case is always 
  1792. preserved. A set of macros to do convenient ID manipulation is provided as part 
  1793. of the SOM C bindings. The syntax of the ID macros is shown below: 
  1794.  
  1795.     #include <som.h> /* or any SOM class .h file */
  1796.     SOM_CheckId(id)
  1797.     SOM_CompareIds(id1,id2)
  1798.     SOM_StringFromId(id)
  1799.     SOM_IdFromString(str)
  1800.  
  1801. An ID starts as a pointer to a string (that is, a pointer to a pointer to an 
  1802. array of zero-terminated characters). During its first use with any of the 
  1803. above macros, it is automatically converted to an internal id representation. 
  1804. You can perform this transformation explicitly yourself using the SOM_CheckId 
  1805. macro. Because the representation of an ID changes during this process, a 
  1806. special SOM typedef (somId) is provided to declare IDs. You can statically 
  1807. declare an ID, or generate one dynamically from a string. Here is an example of 
  1808. a statically declared ID and a dynamically created one: 
  1809.  
  1810.     /* Statically declared ID */
  1811.  
  1812.     zString example = "exampleMethodName";
  1813.     somId exampleId = &example;
  1814.  
  1815.     /* Dynamically created ID */
  1816.  
  1817.     somId myClassId;
  1818.     myClassId = SOM_IdFromString ("MyClassName");
  1819.  
  1820. SOM_CompareIds is a fast and efficient way to determine whether the strings the 
  1821. IDs represent are equal. 
  1822.  
  1823. There are also a set of functions included in the SOM run-time library that 
  1824. allow you to exert finer control over the creation and use of IDs. These are: 
  1825.  
  1826.     int           somRegisterId(somId id);
  1827.     unsigned long somUniqueKey(somId id);
  1828.     unsigned long somTotalRegIds(void);
  1829.     void          somSetExpectedIds(unsigned long numIds);
  1830.     void          somBeginPersistentIds(void);
  1831.     void          somEndPersistentIds(void);
  1832.  
  1833. somRegisterId is identical to the SOM_CheckId macro, but, in addition, returns 
  1834. an indication of whether the string associated with the argument ID was already 
  1835. known (1 indicates that the string was already known; 0 that it has been newly 
  1836. registered). 
  1837.  
  1838. somUniqueKey returns a numeric value that uniquely represents the string 
  1839. associated with the argument ID. 
  1840.  
  1841. somTotalRegIds returns the number of IDs that have been registered so far. You 
  1842. can use this value to advise the SOM run time about expected ID usage in later 
  1843. executions of your program by specifying it in a call to somSetExpectedIds 
  1844.  
  1845. somSetExpectedIds, if used, must be called prior to any explicit or implicit 
  1846. invocation of somEnvironmentNew. It allows you to specify the number of unique 
  1847. IDs you expect to use during the execution of your program. This has the 
  1848. potential of slightly improving your program's space and time utilization (if 
  1849. the value you specify is accurate). 
  1850.  
  1851. Note:  This is the one and only SOM function that can be invoked prior to 
  1852.        somEnvironmentNew. 
  1853.  
  1854. The somBeginPersistentIds and somEndPersistentIds functions are used to delimit 
  1855. an interval of time for the current thread during which any new IDs that are 
  1856. used (by SOM_CheckId, SOM_IdFromString, or the somRegisterId function) are 
  1857. guaranteed to refer only to static strings that will not be subsequently freed. 
  1858. (Under normal usage the only time a static string would be freed is when a .DLL 
  1859. in which it resides is unloaded). IDs that are registered within a "persistent 
  1860. ID" interval can be handled quicker and more efficiently because there is no 
  1861. need to create a copy of the strings they reference. 
  1862.  
  1863.  
  1864. ΓòÉΓòÉΓòÉ 4.3.2. Debugging Facilities ΓòÉΓòÉΓòÉ
  1865.  
  1866. The SOM run time has several facilities for conditionally generating 
  1867. stream-oriented character output.  All output characters generated by these 
  1868. facilities ultimately pass through a replaceable procedure called 
  1869. SOMOutCharRoutine. The default version of this routine simply writes the 
  1870. character output to stdout, but you can replace this procedure with one that 
  1871. routes its output to a window or any other destination of your choice. 
  1872.  
  1873. Depending on the macros employed, debugging output can be conditionally 
  1874. suppressed or produced based on the setting of three global variables: 
  1875. SOM_TraceLevel, SOM_WarnLevel, or SOM_AssertLevel. 
  1876.  
  1877. Variable              Macros/Functions 
  1878.  
  1879. SOM_TraceLevel        <className>MethodDebug 
  1880.  
  1881. SOM_WarnLevel         SOM_WarnMsg, SOM_TestC, SOM_Expect 
  1882.  
  1883. SOM_AssertLevel       SOM_Assert 
  1884.  
  1885. [Unconditional]       somPrintf 
  1886.  
  1887. <className>MethodDebug 
  1888.  
  1889.     char *class;
  1890.     char *method;
  1891.  
  1892.     <className>MethodDebug (class, method);
  1893.  
  1894. This custom macro is generated as part of the method stubs produced by the .C 
  1895. emitter.  It takes two arguments-a class name and a method name-and if 
  1896. SOM_TraceLevel has the value 1 or 2, produces a message each time a method is 
  1897. entered.  (Setting SOM_TraceLevel to 2 also causes the methods supplied as part 
  1898. of the SOM run time to generate method trace output.)  To suppress the 
  1899. generation of method tracing code, place a line similar to the following in 
  1900. your .C file after the #include statement for <classStem>.IH: 
  1901.  
  1902.     #define <className>MethodDebug(c,m) SOM_NoTrace(c,m)
  1903.  
  1904. SOM_TestC 
  1905.  
  1906.     SOM_TestC (condition);
  1907.  
  1908. This macro takes an arbitrary Boolean expression as an argument. If the 
  1909. expression evaluates as true (non-zero), execution continues; otherwise 
  1910. SOM_Error is invoked with a warning-level error code. If SOM_WarnLevel is set 
  1911. to 1 or 2, a warning message also is produced (the value 2 will include warning 
  1912. messages produced by the SOM run time code). 
  1913.  
  1914. SOM_WarnMsg 
  1915.  
  1916.     char *msg;
  1917.  
  1918.     SOM_WarnMsg (msg);
  1919.  
  1920. This macro writes out the string msg if SOM_WarnLevel is set to a value of 1 or 
  1921. 2 (a value of 2 also results in warning messages generated from the SOM 
  1922. run-time code). 
  1923.  
  1924. SOM_Assert 
  1925.  
  1926.     integer4 errorCode;
  1927.  
  1928.     SOM_Assert (condition, errorCode);
  1929.  
  1930. This macro allows you to place assertions in your code.  The assertion is 
  1931. expressed as an arbitrary Boolean expression that is required to evaluate as 
  1932. true (non-zero).  If the assertion fails, the SOM_Error macro is invoked using 
  1933. the error code you supply here. 
  1934.  
  1935. SOM_Expect 
  1936.  
  1937.     SOM_Expect (condition);
  1938.  
  1939. This macro is similar to SOM_Assert, except that if the condition indicated is 
  1940. not true, a SOM_WarnMsg macro is used to produce a warning message to that 
  1941. effect. 
  1942.  
  1943. somPrintf 
  1944.  
  1945.     int charCount;
  1946.     zString fmt;
  1947.  
  1948.     charCount = somPrintf (fmt, ...);
  1949.  
  1950. somPrintf is a function that unconditionally generates character stream output 
  1951. and passes it to (*SOMOutCharRtn)().  The interface to somPrintf is identical 
  1952. to that for the printf C library routine. 
  1953.  
  1954. Validity-Checking Method Calls 
  1955.  
  1956. In addition to the explicit use of debugging macros, the SOM C-language 
  1957. bindings produce code that automatically performs basic validity checking at 
  1958. run time for all SOM method invocations.  If any of these basic checks fail, 
  1959. the SOM_Error macro is used to end the process. Once you have tested your code 
  1960. to your satisfaction and are confident that it is working correctly, you can 
  1961. remove the automatic validity checking by placing the following #define in your 
  1962. .C source file prior to the #include statement for the <className>.IH file. 
  1963.  
  1964.     #define SOM_NoTest
  1965.  
  1966.  
  1967. ΓòÉΓòÉΓòÉ 4.3.3. Error-Handling Facilities ΓòÉΓòÉΓòÉ
  1968.  
  1969. SOM error handling is performed by a user-replaceable procedure that produces a 
  1970. message and an error code and can, if appropriate, end the process where the 
  1971. error occurred. See SOMError for specifics about the interface to the 
  1972. error-handling procedure. 
  1973.  
  1974. Each error is associated with a unique integer value referred to as an error 
  1975. code. Errors detected by the SOM run-time environment, and their associated 
  1976. error codes, are listed in the Error Codes Appendix. 
  1977.  
  1978. Errors reported through SOM fall into 3 categories: 
  1979.  
  1980. SOM_Ignore    This classification represents an informational event; it is 
  1981.               considered normal, and could be ignored or logged at a user's 
  1982.               discretion. 
  1983.  
  1984. SOM_Warn      This category is for unusual conditions that are not considered 
  1985.               to be normal events, but that are not severe enough in themselves 
  1986.               to require abnormal termination of a program. 
  1987.  
  1988. SOM_Fatal     Errors classified as fatal represent conditions that either 
  1989.               should not occur or that would result in an intolerable loss of 
  1990.               system integrity if processing were allowed to continue.  These 
  1991.               errors should typically cause the termination of the process in 
  1992.               which they occur. 
  1993.  
  1994. These error classifications are each assigned a single numeric value carried in 
  1995. the low-order digit of the error code. 
  1996.  
  1997. SOM_Error Macro 
  1998.  
  1999.     int errorCode;
  2000.  
  2001.     SOM_Error (errorCode);
  2002.  
  2003. The SOM_Error macro takes a SOM error code and invokes the error-handling 
  2004. function passing the error code, the name of the source file, and the line 
  2005. number within the source file where the macro was invoked. The default 
  2006. error-handling function supplied with SOM will provide this information in the 
  2007. form of a message routed through SOMOutCharRoutine. Additionally, if the 
  2008. low-order digit of the error code indicates a serious error (value SOM_Fatal), 
  2009. the process also is ended; otherwise, control returns to the invoking routine. 
  2010.  
  2011. SOM_Test 
  2012.  
  2013.     SOM_Test (condition);
  2014.  
  2015. This macro takes an arbitrary Boolean expression as an argument. If the 
  2016. expression evaluates as true (non-zero), execution continues; otherwise, 
  2017. SOM_Error is invoked with a fatal error code. 
  2018.  
  2019.  
  2020. ΓòÉΓòÉΓòÉ 4.3.4. SOM_GetClass ΓòÉΓòÉΓòÉ
  2021.  
  2022.     SOMAny *object;
  2023.     SOMClass *class;
  2024.  
  2025.     class = SOM_GetClass (object);
  2026.  
  2027. This macro takes a single argument that is a pointer to an arbitrary SOM object 
  2028. and returns a pointer to its class object.  All SOM class objects support a 
  2029. variety of methods that return information about the content and 
  2030. characteristics of the objects they can create.  See "SOMClass" in the Classes 
  2031. Reference section for further information. 
  2032.  
  2033.  
  2034. ΓòÉΓòÉΓòÉ 4.3.5. SomEnvironmentNew ΓòÉΓòÉΓòÉ
  2035.  
  2036.     SOMClassMgr *SomEnvironmentNew ();
  2037.  
  2038. This is a procedure that can be used to initialize the SOM run-time environment 
  2039. explicitly. Although no other SOM facilities can be used until this has been 
  2040. accomplished (see ID Manipulation for a minor exception to this rule), it is 
  2041. not generally necessary to call this procedure overtly, because all 
  2042. <className>NewClass procedures, as well as all <className>New and 
  2043. <className>Renew macros invoke this function implicitly if it is needed. Upon 
  2044. completion somEnvironmentNew returns SOMClassMgrObject. This object is the 
  2045. single instance of SOMClassMgr class that is present in every SOM run-time 
  2046. environment. 
  2047.  
  2048.  
  2049. ΓòÉΓòÉΓòÉ 5. SOM bindings for C++ ΓòÉΓòÉΓòÉ
  2050.  
  2051. The form of the SOM Application Programming Interface (API) varies depending on 
  2052. the programming language bindings that are used.  The API described here is 
  2053. that provided by a particular form of C++ language bindings, called "static 
  2054. bindings".  The overall philosophy of use for these bindings is similar to that 
  2055. of the C-language bindings.  Accordingly, SOM objects (including SOM classes) 
  2056. are made available to the C++ programmer as C++ objects via "usage" bindings, 
  2057. and new SOM classes may be defined by the C++ programmer using OIDL and the 
  2058. "implementation" bindings that are generated from OIDL class descriptions. 
  2059.  
  2060. Usage bindings are provided by the EMITXH and EMITXPH emitters, and make it 
  2061. possible for C++ code to create and use typed SOM objects as C++ objects. 
  2062.  
  2063. The implementation bindings are provided by two emitters, EMITXC and EMITXIH, 
  2064. whose output makes it easy for a C++ programmer to implement SOM classes that 
  2065. have been described using OIDL.  EMITXC produces a class implementation file 
  2066. containing default C++ method procedures for the SOM class's introduced 
  2067. methods.  EMITXIH produces a C++ include file (included by the class 
  2068. implementation file) that defines the derived class as a runtime object in the 
  2069. SOM object model and supports the SOM API for registry of classes and object 
  2070. methods. 
  2071.  
  2072. Thus, given a SOM class description expressed in OIDL, the following C++ 
  2073. specific files can be produced by specifying that the SOM Compiler use the 
  2074. appropriate emitter: 
  2075.  
  2076. <file stem>.XH The public-usage binding file.  Either this file or the 
  2077.             following private-usage binding file should be included in a C++ 
  2078.             program that wants to use SOM objects of a given class.  The SOM 
  2079.             compiler command sc -s "xph" foo produces the C++ public-usage 
  2080.             binding for the class described in the file foo.CSC. 
  2081.  
  2082. <file stem>.XPH The private-usage binding file. This file should be included in 
  2083.             a C++ program in order to access both public and private interfaces 
  2084.             to SOM objects of a given class.  The SOM compiler command sc -s 
  2085.             "xph" foo produces the C++ private-usage binding for the class 
  2086.             described in foo.CSC. 
  2087.  
  2088. <file stem>.XIH The implementation binding file. If you want to use C++ to 
  2089.             implement a SOM class described using OIDL, then this file should 
  2090.             be generated (using the EMITXIH emitter), and should be included in 
  2091.             the C++ source file that implements the class.  The SOM compiler 
  2092.             command sc -s "xih" foo produces the C++ implementation binding for 
  2093.             the class described in foo.CSC. The .XIH file includes the .XH 
  2094.             usage binding file, or, if private methods have been declared, the 
  2095.             .XPH usage binding file is included. 
  2096.  
  2097. <file stem>.CPP The default class implementation file. The EMITXC emitter can 
  2098.             be used to produce a default C++ class implementation file named 
  2099.             <file stem>.CPP.  For example, sc -s "xc" foo will produce a file 
  2100.             named foo.CPP, containing a default implementation for the class 
  2101.             described in foo.CSC.  Also, the EMITXC emitter can be used 
  2102.             incrementally, to add new method procedures to an existing C++ SOM 
  2103.             class implementation file, without changing existing method 
  2104.             procedures. 
  2105.  
  2106. All C++ binding files produced by the SOM Compiler are protected with an 
  2107. appropriate #ifndef so that they can be included in a C++ compilation unit more 
  2108. than once without harm.  See the discussion, below, on Public and Private 
  2109. Methods for guidance on how to include C++ usage bindings for various SOM 
  2110. classes in your programs.  If only public usage bindings are required by a 
  2111. program, then the order in which bindings are included is not important. 
  2112.  
  2113.  
  2114. ΓòÉΓòÉΓòÉ 5.1. A Brief SOM Programming Primer for C++ ΓòÉΓòÉΓòÉ
  2115.  
  2116. This section briefly presents information on using a class and its object and 
  2117. methods procedures. 
  2118.  
  2119.  
  2120. ΓòÉΓòÉΓòÉ 5.1.1. Using a Class and Its Objects ΓòÉΓòÉΓòÉ
  2121.  
  2122. Using the SOM C++ bindings for a class and its objects involves declaring and 
  2123. initializing object variables, and invoking object methods. 
  2124.  
  2125. Declaring Object Variables 
  2126.  
  2127.     <class> *obj;
  2128.  
  2129. declares obj to be a pointer to an instance of <class>.  Because the sizes of 
  2130. SOM objects are not known at compile time, they must be dynamically allocated. 
  2131. Therefore, it is never correct to code a declaration like: 
  2132.  
  2133.     <class> obj;  /* never correct */
  2134.  
  2135. Creating Instances 
  2136.  
  2137. Instances are created using the C++ new operator in a statement like: 
  2138.  
  2139.     <class> *obj = new <class>;
  2140.  
  2141. or 
  2142.  
  2143.     <class> *obj;
  2144.     ...
  2145.     obj = new <class>;
  2146.  
  2147. Sometimes it is important to pre-allocate space and then convert the space into 
  2148. an object.  The Renew method provided by class objects allows this.  The C++ 
  2149. usage bindings for a class provide access to the <class> class object via the 
  2150. expression <class>.  Thus, for example, the following sequence creates an array 
  2151. of object instances pointed to by an array of pointers. 
  2152.  
  2153.     <class> *obj[10]; /* space for 10 pointers */
  2154.     unsigned char *buffer;
  2155.     int i;
  2156.     int size = <class>->somGetInstanceSize();
  2157.  
  2158.     buffer = malloc(10*size); /* space for 10 instances */
  2159.     for (i=0; i<10; i++)
  2160.         obj[i] = <class>->somRenew(buffer+(i*size));
  2161.  
  2162. Such a sequence can be more efficient than many separate memory allocations 
  2163. when a large number of object instances are involved. 
  2164.  
  2165. Note:  <class> is a macro that expands to the expression 
  2166.        <class>ClassData.classObject. <class>ClassData is a global structure 
  2167.        required by the SOM API, created for each class by its implementation 
  2168.        bindings, and made available by usage bindings.  It is initialized when 
  2169.        the class is created. 
  2170.  
  2171. Invoking Methods 
  2172.  
  2173. The Normal Case: 
  2174.  
  2175. The above example illustrates (on class objects) the normal way to invoke a 
  2176. method on a SOM object via the C++ usage bindings; simply use a C++ method 
  2177. call.  For example, if the method foo is available on a class of objects, and 
  2178. the variable obj is a pointer to an instance of this class, then (assuming that 
  2179. foo takes a single integer argument) an appropriate invocation would be: 
  2180.  
  2181.     obj->foo(42);
  2182.  
  2183. Invoking Methods by Name: 
  2184.  
  2185. The above examples use the static type interface to SOM objects provided by the 
  2186. C++ bindings.  Due to restrictions imposed by static typing, it can sometimes 
  2187. be useful to invoke a particular method "by name," or dynamically, because a 
  2188. static interface for the method is not provided by the type declared for an 
  2189. object.  Dynamic method invocation is possible on all SOM objects. 
  2190.  
  2191. To invoke a method dynamically, convert the name of the desired method into a 
  2192. somId and then use one of the methods in the public SOMClass interface that 
  2193. accepts a method id and return a pointer to the method procedure that 
  2194. implements the indicated method on its instances. This method procedure can 
  2195. then be invoked on the desired arguments. 
  2196.  
  2197. Note:  The methods that locate a method procedure in this way are provided by 
  2198.        class objects, so they are invoked on an object's class. All SOM objects 
  2199.        support a method that returns (a pointer to) their class, so the 
  2200.        necessary class object is always available. 
  2201.  
  2202. For example, to dynamically invoke the foo method (whose static invocation was 
  2203. just previously illustrated) the following code would be appropiate.  In this 
  2204. code, obj is statically known only as a (pointer to a) SOMObject, and the foo 
  2205. method is not included in the static SOMObject interface.  In spite of this, 
  2206. the programmer has reason for believing that obj does support foo, thus dynamic 
  2207. invocation of foo is called for: 
  2208.  
  2209.     SOMObject *obj;
  2210.     char *mname = "foo";
  2211.     somId mid = SOM_IdFromString(mname);
  2212.     somMethodProc *mp;
  2213.  
  2214.     mp = (obj->somGetClass())->somFindMethod(mid); /* find the method procedure */
  2215.     (((void (*)(SOMObject *, int))(mp))    /* cast and apply the procedure */
  2216.         (obj, 42));                           /* to its arguments */
  2217.  
  2218. Note:  In addition to the numeric method argument, the address of the object on 
  2219.        which to execute the method is passed as the first argument.  Without 
  2220.        exception, all procedures that implement SOM methods require this extra, 
  2221.        initial argument, whose purpose in SOM is similar to this in C++. 
  2222.        Within a method procedure, the initial argument always identifies the 
  2223.        specific object on which the method has been invoked.  When the static 
  2224.        C++ usage bindings are used, the invoked object's address is 
  2225.        automatically passed by the bindings.  But whenever a method procedure 
  2226.        is called directly (as in this example), the programmer must explicitly 
  2227.        provide the invoked object's address. 
  2228.  
  2229. Note:  In fact, the above example is not quite complete.  This is because the 
  2230.        cast of the method procedure pointer mp in the above example does not 
  2231.        indicate system linkage (and all SOM method procedures need to be called 
  2232.        according to system-defined linkage conventions).  Unfortunately, system 
  2233.        linkage for procedure pointers is done in different ways, depending on 
  2234.        the compiler used.  Furthermore, because system linkage is usually NOT 
  2235.        the default chosen by compilers for calling procedures, attempting to 
  2236.        call SOM method procedures without explicitly indicating system linkage 
  2237.        will usually result in runtime errors.  C++ usage bindings for a SOM 
  2238.        class always provide typedefs for the method procedures used to support 
  2239.        its introduced methods, however, and these may be used by C++ 
  2240.        programmers.  The form of the typedef name is as follows: 
  2241.  
  2242. somTD_<className>_<methodName> 
  2243.  
  2244. Thus, in the above example, if class ZZZ introduces the method foo, then the 
  2245. method procedure pointer cast can be written as: 
  2246.  
  2247. ((somTD_ZZZ_foo) (mp)) 
  2248.  
  2249. The following sections describe how a new class is declared, and illustrate the 
  2250. method procedures used to support method calls on SOM objects. 
  2251.  
  2252.  
  2253. ΓòÉΓòÉΓòÉ 5.1.2. Declaring a Class ΓòÉΓòÉΓòÉ
  2254.  
  2255. One of the capabilities of the SOM Compiler is to produce an initial 
  2256. implementation for a class containing method procedure templates, and to add 
  2257. additional method procedures whenever you add more methods to your class' OIDL 
  2258. declaration. For example, suppose the file SIMPLE.CSC contains the following 
  2259. declaration of the class, Simple: 
  2260.  
  2261.     #include <SOMOBJ.XH>
  2262.     class: Simple;
  2263.     parent: SOMObject;
  2264.     data:
  2265.        int x;
  2266.     methods:
  2267.        int setX(int x);
  2268.  
  2269. The SOM Compiler command sc -s "xc" SIMPLE will produce an initial 
  2270. implementation file, named SIMPLE.CPP, whose contents are as follows: 
  2271.  
  2272.     #define Simple_Class_Source
  2273.     #include "SIMPLE.XIH"
  2274.  
  2275.     SOM_Scope int SOMLINK setX(Simple *somSelf, int x)
  2276.     {
  2277.         SimpleData *somThis = SimpleGetData(somSelf);
  2278.         SimpleMethodDebug("Simple","setX");
  2279.  
  2280.         return ((int)0);
  2281.     }
  2282.  
  2283.  
  2284. ΓòÉΓòÉΓòÉ 5.1.3. Method Procedures ΓòÉΓòÉΓòÉ
  2285.  
  2286. As is the case for all C++ method procedures produced by the SOM compiler, the 
  2287. above template for setX is type-correct, executable C++ code.  SOM thus 
  2288. provides an initial implementation for classes without the programmer having to 
  2289. write a line of code.  Of course, method procedure templates must be modified 
  2290. to implement the desired semantics for methods, but this approach automates 
  2291. much of the startup procedure for defining classes. 
  2292.  
  2293. The first argument to the setX method procedure is the object address, whose 
  2294. use was just previously explained -- somSelf identifies the object on which 
  2295. setX will operate.  The first line of the method procedure illustrates how a 
  2296. method uses this information to gain access to instance data.  The reason this 
  2297. is done is now explained. 
  2298.  
  2299. Classes normally introduce both methods and instance data, and the procedures 
  2300. used to support the methods introduced by a class in general require access to 
  2301. the instance data introduced by the class. For example, Simple introduces the 
  2302. method setX and the instance variable x, and the procedure used to implement 
  2303. the setX method will (presumably) require access to the x instance variable. 
  2304.  
  2305. Creating a new object therefore involves allocating storage space for holding 
  2306. its instance data -- that is, the instance variables introduced by the object's 
  2307. class and the instance variables inherited from this class's ancestors. 
  2308.  
  2309. In order to provide upwards binary compatability of method procedures in the 
  2310. face of changes (perhaps additions) to ancestor class's instance data, the 
  2311. contributions to the overall object size made by different class's instance 
  2312. data cannot be statically bound into SOM method procedures, so method 
  2313. procedures in SOM that require access to instance data must dynamically 
  2314. determine the location of this data within objects.  This is what the first 
  2315. line of setX's definition accomplishes. 
  2316.  
  2317. The statement 
  2318.  
  2319.         SimpleData *somThis = SimpleGetData(somSelf);
  2320.  
  2321. initializes the local variable, somThis, to point to a C++ struct with a data 
  2322. member for each of the instance variables introduced by Simple (here, this 
  2323. structure contains the single member, x). 
  2324.  
  2325. SimpleGetData() is a macro defined in SIMPLE.XIH.  It locates Simple's instance 
  2326. data in the larger block of data that contains the complete state of an 
  2327. instance of the Simple class, or an instance of some other class derived from 
  2328. Simple.  Once this has been done, direct access to instance data from within a 
  2329. method procedure is possible. 
  2330.  
  2331. Thus, in the SetX method procedure, the expression somThis->x denotes the x 
  2332. instance variable of the object pointed to by somSelf.  To refine the default 
  2333. implementation template illustrated above, a C++ programmer might replace the 
  2334. return statement with the following: 
  2335.  
  2336.         return somThis->x = x; /* load and return the value of x */
  2337.  
  2338. The second line of setX's definition: 
  2339.  
  2340.         SimpleMethodDebug("Simple","setX");
  2341.  
  2342. is a call to another macro generated for each class.  The default definition of 
  2343. this macro produces method-tracing information whenever the global variable 
  2344. SOM_TraceLevel is set to a non-zero value.  You may, however, assign other 
  2345. definitions of your own devising (for whatever purpose you like) to this macro 
  2346. by placing your definition before the #include "SIMPLE.XIH" statement. 
  2347. Alternatively, part of the SOM development package is a simple macro 
  2348. (SOM_NoTrace) that you can assign to macros like SimpleMethodDebug, to 
  2349. completely eliminate the generation of any method-tracing code. 
  2350.  
  2351.  
  2352. ΓòÉΓòÉΓòÉ 5.2. API for Class Clients ΓòÉΓòÉΓòÉ
  2353.  
  2354. Programs that use a SOM class to create and access SOM objects (that is, 
  2355. instances of the class) are referred to as client programs.  C++ client 
  2356. programs should include the C++ usage bindings for the desired SOM classes, 
  2357. since this will enable the program to use and create SOM objects as if they 
  2358. were C++ objects.  The usage bindings (generated by the EMITXH and EMITXPH 
  2359. emitters) contain a C++ class definition that "wraps" the SOM class as a C++ 
  2360. class. 
  2361.  
  2362. Note:  There is an important restriction placed on the use of the C++ classes 
  2363.        defined by the static usage bindings: under no circumstances can these 
  2364.        classes be subclassed in C++.  These classes can only be used to declare 
  2365.        variables that hold pointers to SOM objects, or used as arguments to the 
  2366.        new operator in C++, to create wrapped SOM objects. 
  2367.  
  2368. Subclassing of SOM classes can only be done in SOM -- either by using OIDL to 
  2369. describe the desired subclass to the SOM compiler, which can then generate 
  2370. implementation and usage bindings for the class; or by interacting directly 
  2371. with SOM class objects to create new SOM class objects (which is what the 
  2372. implementation bindings generated by the compiler do). Although it is possible 
  2373. to wrap SOM classes in a way that allows subclassing in C++ (this still 
  2374. requires subclassing in SOM, but it is hidden by the wrapping), the approach 
  2375. involves space and performance overheads avoided by the static bindings 
  2376. described here. 
  2377.  
  2378. The top-level aspects related to C++ use of SOM classes and class instances 
  2379. have been previously discussed.  The following sections provide a few 
  2380. additional details. 
  2381.  
  2382.  
  2383. ΓòÉΓòÉΓòÉ 5.2.1. Name Lookup Methods ΓòÉΓòÉΓòÉ
  2384.  
  2385. The example given previously for invoking methods by name required explicit 
  2386. interaction with a class object to obtain a pointer to the appropriate method 
  2387. procedure, and a cast of this pointer to the appropriate type before the method 
  2388. procedure could be invoked.  The C++ usage bindings can ease this process.  In 
  2389. particular, if a method introduced by a given class is given the "name lookup" 
  2390. modifier when it is declared (in OIDL), then, in addition to the static 
  2391. bindings normally provided for methods, the usage bindings for that class will 
  2392. also include a macro that supports invoking the specified method by name.  This 
  2393. macro will be named lookup_<methodName>, and is used as if it were a direct 
  2394. call of a method procedure.  Thus, as in the earlier example, the first 
  2395. argument to this macro will always be a pointer to the object on which the 
  2396. method is being applied. For example, if the method foo is declared in class 
  2397. bar using the "name lookup" modifier, the following example code segment (based 
  2398. on assumptions made in the earlier example) is possible. 
  2399.  
  2400.    #include <bar.xh>
  2401.    ...
  2402.    void name_lookup_example(SOMObject *obj)
  2403.    {
  2404.       if obj->somRespondsTo("foo")
  2405.          lookup_foo(obj,42);
  2406.    }
  2407.  
  2408. Note:  The static interface to all SOM objects includes the somRespondsTo 
  2409.        method, so, as done here, it is always possible to check whether an 
  2410.        object actually supports a method before invoking the method by name. 
  2411.        This is useful in preventing runtime errors. 
  2412.  
  2413.  
  2414. ΓòÉΓòÉΓòÉ 5.2.2. Public and Private Methods ΓòÉΓòÉΓòÉ
  2415.  
  2416. As determined by modifiers used when declaring methods in OIDL, a method may be 
  2417. either public or private.  For any given SOM class, the corresponding public 
  2418. usage bindings (contained in the .XH file for the class) make available as C++ 
  2419. method calls the public methods of the class and its ancestor classes.  In 
  2420. contrast, the private usage bindings (contained in the .XPH file for the class) 
  2421. make available both the public and private methods introduced by the class, as 
  2422. well as the methods inherited from ancestor classes.  The methods that are 
  2423. inherited from ancestor classes depend on whether public or private usage 
  2424. bindings for ancestor classes are used.  The next paragraph explains how to 
  2425. control this aspect of inheritance when using the C++ usage bindings for SOM 
  2426. classes. 
  2427.  
  2428. The .XH and .XPH usage binding files for any class always include the .XH file 
  2429. for the parent class. Because usage bindings are chained together by including 
  2430. public usage bindings for parents, it is necessary to use some care when 
  2431. including private usage bindings.  In particular, if a private usage binding is 
  2432. desired for a given class, then this binding must be included before including 
  2433. the usage bindings of any class derived from it. 
  2434.  
  2435. Note:  A SOM class has no concept of public or private methods. The facility 
  2436.        for distinguishing methods in this way is provided by OIDL, and is 
  2437.        supported only by the language bindings.  In particular, every SOM class 
  2438.        supports methods by which all the methods available on its instances 
  2439.        (both public and private) may be dynamically determined and used.  This 
  2440.        approach can be viewed as equating a public interface with what is 
  2441.        guaranteed to be true of an object, even though runtime examination of 
  2442.        the object might reveal more. 
  2443.  
  2444.  
  2445. ΓòÉΓòÉΓòÉ 5.2.3. Public and Private Instance Variables ΓòÉΓòÉΓòÉ
  2446.  
  2447. There are three different kinds of instance variables provided by OIDL: public, 
  2448. private, and internal.  Public instance variables are available to clients of a 
  2449. class that use the public-usage bindings.  Both public and private instance 
  2450. variables are available to class clients that use private-usage bindings. 
  2451. Finally, internal instance variables are available only to the method 
  2452. procedures that implement methods. 
  2453.  
  2454. In contrast with the situation for methods (which, as far as SOM classes are 
  2455. concerned, are always public), instance variables in the SOM runtime are always 
  2456. internal.  A SOM class (that is, the runtime class object) knows nothing about 
  2457. instance variables other than how much storage space they require, and how to 
  2458. locate the structures that hold them.  Thus, it is again the language bindings 
  2459. that implement capabilities reflected by OIDL.  In the C++ usage bindings, 
  2460. method calls are used to access public or private instance variables in SOM 
  2461. objects. 
  2462.  
  2463. Note:  The interface to instance variables provided by usage bindings is 
  2464.        different from that provided by the implementation bindings (which 
  2465.        provide method procedures with direct access to all instance variables 
  2466.        introduced by a class). 
  2467.  
  2468. For any given public or private instance variable <ivar> to which a client has 
  2469. access, the C++ usage bindings provide a C++ method with no arguments, named 
  2470. <ivar>_ptr().  This method returns a pointer to the indicated instance 
  2471. variable, thus both access and storage into instance variables is possible. 
  2472.  
  2473. For example, if the instance variable x in the class Simple, above, had been 
  2474. declared as a public instance variable (instead of internal, which is the 
  2475. default), then any client of Simple that includes the SIMPLE.XH file would be 
  2476. able to load x within instances of Simple (or one of its subclasses) as 
  2477. follows: 
  2478.  
  2479.  Simple *obj = new Simple;
  2480.  *(obj->x_ptr) = 42;
  2481.  
  2482. If x had been declared private, then a client of Simple would have to include 
  2483. the SIMPLE.XPH file to do this. 
  2484.  
  2485.  
  2486. ΓòÉΓòÉΓòÉ 5.3. API for Class Implementors ΓòÉΓòÉΓòÉ
  2487.  
  2488. Programmers who implement SOM classes in C++ can use all of the client 
  2489. programmer APIs, as well as additional macros not available to client programs 
  2490. (these provide direct access to introduced instance variables, and provide 
  2491. access to "parent" method calls). These macros are described next, after 
  2492. reviewing the overall class implementation approach. 
  2493.  
  2494.  
  2495. ΓòÉΓòÉΓòÉ 5.3.1. Implementation Conventions for Methods ΓòÉΓòÉΓòÉ
  2496.  
  2497. The first step in implementing a SOM class in C++ is to describe the new class 
  2498. to the SOM compiler using OIDL. 
  2499.  
  2500. Next, the SOM compiler is used to generate implementation bindings for the 
  2501. desired implementation language (in this case, C++), and also usage bindings 
  2502. for this language, since the implementation bindings require these. 
  2503.  
  2504. The programmer then modifies the default implementation of the class by editing 
  2505. its method procedures. During this process, it is important that the 
  2506. implementor of a class understand the distinction between somSelf and somThis 
  2507. within method procedures.  The somSelf variable is always passed as the first 
  2508. argument to a SOM method procedure, and points to the object on which the 
  2509. method is to be invoked.  If a method procedure requires access to instance 
  2510. data introduced by the class being implemented, somThis can be loaded by using 
  2511. the <className>GetData() macro, passing somSelf as its single argument.  The 
  2512. result returned by the macro is a pointer to the structure containing the 
  2513. instance variables introduced by the class being defined.  The 
  2514. <className>GetData() macro was illustrated above, in the example implementation 
  2515. of the Simple class. 
  2516.  
  2517.  
  2518. ΓòÉΓòÉΓòÉ 5.3.2. Instance Data Access Macros ΓòÉΓòÉΓòÉ
  2519.  
  2520. As a programming convenience for the implementor of a class, each instance 
  2521. variable introduced by a class is supported with an access macro defined within 
  2522. the corresponding .XIH file. This macro hides the use of somThis.  For example, 
  2523. in the case of the Simple class, the following macro is defined: 
  2524.  
  2525.  #define _x somThis->x
  2526.  
  2527. Thus, within method procedures for Simple, _x and somThis->x mean the same 
  2528. thing. 
  2529.  
  2530.  
  2531. ΓòÉΓòÉΓòÉ 5.3.3. Method Macros ΓòÉΓòÉΓòÉ
  2532.  
  2533. Also as a programming convenience for the implementor of a class, each method 
  2534. appropriate for invocation on somSelf is supported with an invocation macro 
  2535. defined within the corresponding .XIH file.  This macro hides the use of 
  2536. somSelf.  For example, in the case of the Simple class, the defined invocation 
  2537. macros include those for methods inherited from SOMObject, and those for the 
  2538. methods introduced by Simple.  One such macro definition would be: 
  2539.  
  2540.  #define _somGetClass somSelf->somGetClass
  2541.  
  2542. Note:  To some extent, the instance data access macros and the method 
  2543.        invocation macros provided for class implementors remove the need for 
  2544.        explicit concern for the distinction between somThis (in the case of 
  2545.        data access) and somSelf (in the case of method invocation). 
  2546.        Nevertheless, it is important that a class implementor understand this 
  2547.        distinction. 
  2548.  
  2549.  
  2550. ΓòÉΓòÉΓòÉ 5.3.4. Parent Method Macros ΓòÉΓòÉΓòÉ
  2551.  
  2552. If you define methods in your class that override those inherited from one of 
  2553. your parent classes, you will frequently want to write your own logic as 
  2554. incremental changes to the parent methods' behavior. That is, at some point 
  2555. within your method, you will need to invoke the parent method to perform its 
  2556. own processing.  This could occur at the beginning of your method code, at the 
  2557. very end, or at some point in the middle, depending on the nature of the 
  2558. inherited method and how you intend to supplement or modify its behavior. 
  2559.  
  2560. To allow this, SOM supports a special form of method-resolution used by the 
  2561. implementation bindings to define (for each method overridden by a class) a 
  2562. macro that will perform the desired parent method call.  For any given 
  2563. overridden method <methodName>, the corresponding parent method call macro is 
  2564. named parent_<methodName>  This macro is used as if it were a direct call of 
  2565. the method procedure, so its first argument will always be somSelf (that is, 
  2566. the object to which the method is applied). 
  2567.  
  2568. For example, if you override the inherited methods m1 and m2, the macros 
  2569. parent_m1 and parent_m2 will be defined by the implementation bindings of your 
  2570. class, and can be used in your method procedures to invoke the original parent 
  2571. methods when needed. 
  2572.  
  2573.  
  2574. ΓòÉΓòÉΓòÉ 5.4. API for General Usage ΓòÉΓòÉΓòÉ
  2575.  
  2576. The interfaces described here can be used both in programs that are are clients 
  2577. of a SOM class and programs that implement SOM classes. To use the 
  2578. general-purpose SOM macros from C++, you need to include <SOM.XH>. 
  2579. Alternatively, any C++ usage binding file produced by the SOM Compiler provides 
  2580. these macros. 
  2581.  
  2582.  
  2583. ΓòÉΓòÉΓòÉ 5.4.1. ID Manipulation ΓòÉΓòÉΓòÉ
  2584.  
  2585. IDs are essentially numbers that uniquely represent strings. They are used in 
  2586. SOM to identify method names, class names, and descriptors. All SOM ID 
  2587. manipulations are case-insensitive, although the original case is always 
  2588. preserved. A set of macros to do convenient ID manipulation is provided as part 
  2589. of the SOM C bindings. The syntax of the ID macros follows: 
  2590.  
  2591.     #include <som.h> /* or any SOM class .h file */
  2592.     SOM_CheckId(id)
  2593.     SOM_CompareIds(id1,id2)
  2594.     SOM_StringFromId(id)
  2595.     SOM_IdFromString(str)
  2596.  
  2597. An ID starts as a pointer to a string (that is, a pointer to a pointer to an 
  2598. array of zero-terminated characters). During its first use with any of the 
  2599. above macros, it is automatically converted to an internal id representation. 
  2600. You can perform this transformation explicitly yourself using the SOM_CheckId 
  2601. macro. Because the representation of an ID changes during this process, a 
  2602. special SOM typedef (somId) is provided to declare IDs. You can statically 
  2603. declare an ID, or generate one dynamically from a string. Here is an example of 
  2604. a statically declared ID and a dynamically created one: 
  2605.  
  2606.     /* Statically declared ID */
  2607.  
  2608.     zString example = "exampleMethodName";
  2609.     somId exampleId = &example;
  2610.  
  2611.     /* Dynamically created ID */
  2612.  
  2613.     somId myClassId;
  2614.     myClassId = SOM_IdFromString ("MyClassName");
  2615.  
  2616. SOM_CompareIds is a fast and efficient way to determine whether the strings the 
  2617. IDs represent are equal. 
  2618.  
  2619. There are also a set of functions included in the SOM run-time library that 
  2620. allow you to exert finer control over the creation and use of IDs. These are: 
  2621.  
  2622.     int           somRegisterId(somId id);
  2623.     unsigned long somUniqueKey(somId id);
  2624.     unsigned long somTotalRegIds(void);
  2625.     void          somSetExpectedIds(unsigned long numIds);
  2626.     void          somBeginPersistentIds(void);
  2627.     void          somEndPersistentIds(void);
  2628.  
  2629. somRegisterId is identical to the SOM_CheckId macro, but, in addition, returns 
  2630. an indication of whether the string associated with the argument ID was already 
  2631. known (1 indicates that the string was already known; 0 that it has been newly 
  2632. registered). 
  2633.  
  2634. somUniqueKey returns a numeric value that uniquely represents the string 
  2635. associated with the argument ID. 
  2636.  
  2637. somTotalRegIds returns the number of IDs that have been registered so far. You 
  2638. can use this value to advise the SOM run time about expected ID usage in later 
  2639. executions of your program by specifying it in a call to somSetExpectedIds 
  2640.  
  2641. somSetExpectedIds, if used, must be called prior to any explicit or implicit 
  2642. invocation of somEnvironmentNew (see SomEnvironmentNew). It allows you to 
  2643. specify the number of unique IDs you expect to use during the execution of your 
  2644. program. This has the potential of slightly improving your program's space and 
  2645. time utilization (if the value you specify is accurate). 
  2646.  
  2647. Note:  This is the one and only SOM function that can be invoked prior to 
  2648.        somEnvironmentNew. 
  2649.  
  2650. The somBeginPersistentIds and somEndPersistentIds functions are used to delimit 
  2651. an interval of time for the current thread during which any new IDs that are 
  2652. used (by SOM_CheckId, SOM_IdFromString, or the somRegisterId function) are 
  2653. guaranteed to refer only to static strings that will not be subsequently freed. 
  2654. (Under normal usage the only time a static string would be freed is when a .DLL 
  2655. in which it resides is unloaded).  IDs that are registered within a "persistent 
  2656. ID" interval can be handled quicker and more efficiently because there is no 
  2657. need to create a copy of the strings they reference. 
  2658.  
  2659.  
  2660. ΓòÉΓòÉΓòÉ 5.4.2. Debugging Facilities ΓòÉΓòÉΓòÉ
  2661.  
  2662. The SOM run time has several facilities for conditionally generating 
  2663. stream-oriented character output.  All output characters generated by these 
  2664. facilities ultimately pass through a replaceable procedure called 
  2665. SOMOutCharRoutine. The default version of this routine simply writes the 
  2666. character output to stdout, but you can replace this procedure with one that 
  2667. routes its output to a window or any other destination of your choice. 
  2668.  
  2669. Depending on the macros employed, debugging output can be conditionally 
  2670. suppressed or produced based on the setting of three global variables: 
  2671. SOM_TraceLevel, SOM_WarnLevel, or SOM_AssertLevel. 
  2672.  
  2673. Variable              Macros/Functions 
  2674.  
  2675. SOM_TraceLevel        <className>MethodDebug 
  2676.  
  2677. SOM_WarnLevel         SOM_WarnMsg, SOM_TestC, SOM_Expect 
  2678.  
  2679. SOM_AssertLevel       SOM_Assert 
  2680.  
  2681. [Unconditional]       somPrintf 
  2682.  
  2683. <className>MethodDebug 
  2684.  
  2685.     char *class;
  2686.     char *method;
  2687.  
  2688.     <className>MethodDebug (class, method);
  2689.  
  2690. This custom macro is generated as part of the method stubs produced by the .C 
  2691. emitter.  It takes two arguments- a class name and a method name- and if 
  2692. SOM_TraceLevel has the value 1 or 2, produces a message each time a method is 
  2693. entered.  (Setting SOM_TraceLevel to 2 also causes the methods supplied as part 
  2694. of the SOM run time to generate method trace output.)  To suppress the 
  2695. generation of method tracing code, place a line similar to the following in 
  2696. your .C file after the #include statement for <classStem>.IH: 
  2697.  
  2698.     #define <className>MethodDebug(c,m) SOM_NoTrace(c,m)
  2699.  
  2700. SOM_TestC 
  2701.  
  2702.     SOM_TestC (condition);
  2703.  
  2704. This macro takes an arbitrary Boolean expression as an argument. If the 
  2705. expression evaluates as true (non-zero), execution continues; otherwise 
  2706. SOM_Error is invoked with a warning-level error code. If SOM_WarnLevel is set 
  2707. to 1 or 2, a warning message also is produced (the value 2 will include warning 
  2708. messages produced by the SOM run time code). 
  2709.  
  2710. SOM_WarnMsg 
  2711.  
  2712.     char *msg;
  2713.  
  2714.     SOM_WarnMsg (msg);
  2715.  
  2716. This macro writes out the string msg if SOM_WarnLevel is set to a value of 1 or 
  2717. 2 (a value of 2 also results in warning messages generated from the SOM 
  2718. run-time code). 
  2719.  
  2720. SOM_Assert 
  2721.  
  2722.     integer4 errorCode;
  2723.  
  2724.     SOM_Assert (condition, errorCode);
  2725.  
  2726. This macro allows you to place assertions in your code.  The assertion is 
  2727. expressed as an arbitrary Boolean expression that is required to evaluate as 
  2728. true (non-zero).  If the assertion fails, the SOM_Error macro is invoked using 
  2729. the error code you supply here. 
  2730.  
  2731. SOM_Expect 
  2732.  
  2733.     SOM_Expect (condition);
  2734.  
  2735. This macro is similar to SOM_Assert, except that if the condition indicated is 
  2736. not true, a SOM_WarnMsg macro is used to produce a warning message to that 
  2737. effect. 
  2738.  
  2739. somPrintf 
  2740.  
  2741.     int charCount;
  2742.     zString fmt;
  2743.  
  2744.     charCount = somPrintf (fmt, ...);
  2745.  
  2746. somPrintf is a function that unconditionally generates character stream output 
  2747. and passes it to (*SOMOutCharRoutine)().  The interface to somPrintf is 
  2748. identical to that for the printf C library routine. 
  2749.  
  2750. Validity-Checking Method Calls 
  2751.  
  2752. In addition to the explicit use of debugging macros, the SOM C++ bindings 
  2753. produce code that automatically performs basic validity checking at run time 
  2754. for all SOM method invocations.  If any of these basic checks fail, the 
  2755. SOM_Error macro is used to end the process. Once you have tested your code to 
  2756. your satisfaction and are confident that it is working correctly, you can 
  2757. remove the automatic validity checking by placing the following #define in your 
  2758. .C source file prior to the #include statement for the <className>.XIH file. 
  2759.  
  2760.     #define SOM_NoTest
  2761.  
  2762.  
  2763. ΓòÉΓòÉΓòÉ 5.4.3. Error-Handling Facilities ΓòÉΓòÉΓòÉ
  2764.  
  2765. SOM error handling is performed by a user-replaceable procedure that produces a 
  2766. message and an error code and can, if appropriate, end the process where the 
  2767. error occurred.  See Error-Handling Function for specifics about the interface 
  2768. to the error-handling procedure. 
  2769.  
  2770. Each error is associated with a unique integer value referred to as an error 
  2771. code. Errors detected by the SOM run-time environment, and their associated 
  2772. error codes, are listed in the Error Codes Appendix. 
  2773.  
  2774. Errors reported through SOM fall into 3 categories: 
  2775.  
  2776. SOM_Ignore    This classification represents an informational event; it is 
  2777.               considered normal, and could be ignored or logged at a user's 
  2778.               discretion. 
  2779.  
  2780. SOM_Warn      This category is for unusual conditions that are not considered 
  2781.               to be normal events, but that are not severe enough in themselves 
  2782.               to require abnormal termination of a program. 
  2783.  
  2784. SOM_Fatal     Errors classified as fatal represent conditions that either 
  2785.               should not occur or that would result in an intolerable loss of 
  2786.               system integrity if processing were allowed to continue.  These 
  2787.               errors should typically cause the termination of the process in 
  2788.               which they occur. 
  2789.  
  2790. These error classifications are each assigned a single numeric value carried in 
  2791. the low-order digit of the error code. 
  2792.  
  2793. SOM_Error Macro 
  2794.  
  2795.     int errorCode;
  2796.  
  2797.     SOM_Error (errorCode);
  2798.  
  2799. The SOM_Error macro takes a SOM error code and invokes the error-handling 
  2800. function passing the error code, the name of the source file, and the line 
  2801. number within the source file where the macro was invoked.  The default 
  2802. error-handling function supplied with SOM will provide this information in the 
  2803. form of a message routed through SOMOutCharRoutine.  Additionally, if the 
  2804. low-order digit of the error code indicates a serious error (value SOM_Fatal), 
  2805. the process also is ended; otherwise, control returns to the invoking routine. 
  2806.  
  2807. SOM_Test 
  2808.  
  2809.     SOM_Test (condition);
  2810.  
  2811. This macro takes an arbitrary Boolean expression as an argument. If the 
  2812. expression evaluates as true (non-zero), execution continues; otherwise, 
  2813. SOM_Error is invoked with a fatal error code. 
  2814.  
  2815.  
  2816. ΓòÉΓòÉΓòÉ 5.4.4. SOM_GetClass ΓòÉΓòÉΓòÉ
  2817.  
  2818.     SOMAny *object;
  2819.     SOMClass *class;
  2820.  
  2821.     class = SOM_GetClass (object);
  2822.  
  2823. This macro takes a single argument that is a pointer to an arbitrary SOM object 
  2824. and returns a pointer to its class object.  All SOM class objects support a 
  2825. variety of methods that return information about the content and 
  2826. characteristics of the objects they can create. See "SOMClass" in the Classes 
  2827. Reference section for further information. 
  2828.  
  2829.  
  2830. ΓòÉΓòÉΓòÉ 5.4.5. SomEnvironmentNew ΓòÉΓòÉΓòÉ
  2831.  
  2832.     SOMClassMgr *SomEnvironmentNew ();
  2833.  
  2834. This is a procedure that can be used to initialize the SOM run-time environment 
  2835. explicitly. Although  no other SOM  facilities can be used until this has been 
  2836. accomplished, it is not generally necessary to call this procedure overtly, 
  2837. because any use of the C++ new operator on a SOM class name automatically 
  2838. invokes this function if it is needed.  The result returned by 
  2839. somEnvironmentNew is a pointer to the SOM class manager object, which (in the 
  2840. C++ usage bindings) has type SOMClassMgr * This object is the single instance 
  2841. of the SOMClassMgr class that is present in every SOM run-time environment. 
  2842.  
  2843.  
  2844. ΓòÉΓòÉΓòÉ 6. Customization features ΓòÉΓòÉΓòÉ
  2845.  
  2846. SOM is designed to be policy free and highly adaptable. Most of the SOM 
  2847. behavior can be customized by subclassing the built-in classes and overriding 
  2848. methods, but the SOM run time also makes use of a small number of OS/2* 2.0 
  2849. facilities. You can override any use of OS/2* system facilities in the SOM run 
  2850. time by supplying your own replacements for the default SOM system-interface 
  2851. routines. You can substitute your replacement routine by placing its 
  2852. entry-point address in one of the following external variables. Because SOM 
  2853. operates within a process, your replacement routine will affect only the active 
  2854. process. 
  2855.  
  2856. Replacement routines should be written in C and adhere to standard OS/2* 2.0 
  2857. system calling conventions. 
  2858.  
  2859. Replaceable entry points: 
  2860.  
  2861. SOMCalloc 
  2862. SOMClassInitFuncName 
  2863. SOMDeleteModule 
  2864. SOMError 
  2865. SOMFree 
  2866. SOMLoadModule 
  2867. SOMMalloc 
  2868. SOMOutCharRoutine 
  2869. SOMRealloc 
  2870.  
  2871.  
  2872. ΓòÉΓòÉΓòÉ 6.1. Memory-Management Functions ΓòÉΓòÉΓòÉ
  2873.  
  2874. The memory management functions used by the SOM run-time environment are a 
  2875. subset of those supplied in the ANSI C standard library. They have the same 
  2876. calling interface and return the same types of results as their ANSI C 
  2877. equivalents, but include some supplemental error checking. Errors detected in 
  2878. these functions result in the invocation of the (*SOMError)() function with an 
  2879. appropriate error code. 
  2880.  
  2881. The correspondence between the SOM memory-management procedure variables and 
  2882. their ANSI standard library equivalents is given in Table 1 below. 
  2883.  
  2884.  
  2885. SOM Procedure     ANSI Standard      Return   Argument
  2886.   Variable      C Library Routine     type     types
  2887.  
  2888.   SOMCalloc          calloc          void *   size_t, size_t
  2889.   SOMFree            free            void     void *
  2890.   SOMMalloc          malloc          void *   size_t
  2891.   SOMRealloc         realloc         void *   void *, size_t
  2892.  
  2893. Table 1 - Memory-Management Functions
  2894.  
  2895. Note:  Generally speaking, all of these routines should be replaced as a unit. 
  2896.        That is, if you wish to supply your own version of SOMMalloc that did 
  2897.        all of its allocations as suballocations in a shared memory heap (for 
  2898.        instance), you also should supply corresponding SOMCalloc, SOMFree, and 
  2899.        SOMRealloc functions that conformed to this same style of memory 
  2900.        management. 
  2901.  
  2902.  
  2903. ΓòÉΓòÉΓòÉ 6.2. DLL Management Functions ΓòÉΓòÉΓòÉ
  2904.  
  2905. The SOM run time uses three routines to manage the loading and unloading of 
  2906. DLLs. You can modify the rules that govern the loading and unloading of DLLs by 
  2907. replacing these functions with alternative implementations. 
  2908.  
  2909. SOMClassInitFuncName 
  2910.  
  2911.   zString (*SOMClassInitFuncName) (void);
  2912.  
  2913. This function returns the name of the function that will initialize all of the 
  2914. classes that are packaged together in a single DLL. The SOM-supplied version of 
  2915. this function returns the string "SOMInitModule." Hence, unless you supply your 
  2916. own alternative to this function, in order to package more than one SOM class 
  2917. in a single OS/2* DLL, you should write a C-language function named 
  2918. "SOMInitModule" that initializes each class in the DLL. For example, if you 
  2919. wanted to create a DLL that had three classes (A, B, and C), your SOMInitModule 
  2920. function would look something like this: 
  2921.  
  2922.   #include <a.h>
  2923.   #include <b.h>
  2924.   #include <c.h>
  2925.   #pragma linkage (SOMInitModule, system)
  2926.   void SOMInitModule (integer4 majorVersion, integer4 minorVersion)
  2927.       {
  2928.       ANewClass (1,0); /* Pass major and minor version numbers */
  2929.       BNewClass (2,1); /*  appropriate to each class           */
  2930.       CNewClass (majorVersion, minorVersion);
  2931.       }
  2932.  
  2933. Be sure to include SOMInitModule as an exported entry point in your .DEF file 
  2934. when creating your DLL. 
  2935.  
  2936. SOMDeleteModule 
  2937.  
  2938.   int (*SOMDeleteModule) (IN somToken modHandle);
  2939.  
  2940. This function deletes the DLL designated by the value of the parameter, 
  2941. modHandle, and returns 0 for success or a non-zero system-specific error code. 
  2942. The parameter, modHandle, contains a value returned from SOMLoadModule (the DLL 
  2943. loading routine). The default version of this function supplied with SOM 
  2944. returns the OS/2* module handle for the loaded DLL. The default SOMDeleteModule 
  2945. routine uses this DLL module handle to invoke the OS/2* 2.0 DosFreeModule 
  2946. function. The result is used as the return value. 
  2947.  
  2948. SOMLoadModule 
  2949.  
  2950.   int (*SOMLoadModule) (IN zString className,
  2951.           IN zString fileName,
  2952.           IN zString functionName,
  2953.           IN integer4 majorVersion,
  2954.           IN integer4 minorVersion,
  2955.           OUT somToken *modHandle);
  2956.  
  2957. This function should load the DLL containing the SOM class className and return 
  2958. the value 0 for success or a non-zero system-specific error code. The output 
  2959. argument modHandle should be used to return a token that can be subsequently 
  2960. used by the SOMDeleteModule routine to unload the DLL. The default 
  2961. SOMLoadModule routine supplied with SOM passes back the OS/2* DLL module handle 
  2962. in this argument. The remaining arguments are used as follows: 
  2963.  
  2964. Argument          Usage 
  2965.  
  2966. fileName          This argument has the DLL file name, suitable for use with 
  2967.                   the OS/2* 2.0 DosLoadModule function. It can be either a 
  2968.                   simple name or a fully qualified name. 
  2969.  
  2970. functionName      This is the name of the routine to be called if the DLL can 
  2971.                   be successfully loaded. This routine is responsible for 
  2972.                   creating the SOM class or classes contained in the DLL. 
  2973.                   Typically this argument will have the value "SOMInitModule" 
  2974.                   obtained from SOMClassInitFuncName described above. If no 
  2975.                   "SOMInitModule" entry exists in the DLL, the default version 
  2976.                   of SOMLoadModule looks for a routine with the name 
  2977.                   <className>NewClass instead. If neither entry point can be 
  2978.                   found the SOMLoadModule function will fail. 
  2979.  
  2980. majorVersion      The major version number should be passed to the class 
  2981.                   initialization function in the DLL. 
  2982.  
  2983. minorVersion      The minor version number should be passed to the class 
  2984.                   initialization function in the DLL. 
  2985.  
  2986.  
  2987. ΓòÉΓòÉΓòÉ 6.3. Character Output Function ΓòÉΓòÉΓòÉ
  2988.  
  2989. This routine is invoked from the SOM run-time environment whenever a character 
  2990. is generated by one of the SOM error-handling or debugging macros. The default 
  2991. version of this routine supplied with SOM simply writes the character to stdout 
  2992. and returns a 1, if successful, or a 0 if not. You might wish to supply a 
  2993. replacement routine to: 
  2994.  
  2995. o Direct the output to stderr 
  2996.  
  2997. o Record the output in a log file 
  2998.  
  2999. o Collect characters and handle them in larger chunks 
  3000.  
  3001. o Send the output to a PM window to display it 
  3002.  
  3003. o Place the output in the PM clipboard 
  3004.  
  3005. o Or some combination of these 
  3006.  
  3007. Use a coding construct similar to the following to install your replacement 
  3008. routine. 
  3009.  
  3010.     #include <som.h>
  3011.     /* Define your replacement routine */
  3012.     int myReplacementForSOMOutChar (char c)
  3013.     {
  3014.         (Your code goes here)
  3015.     }
  3016.     ...
  3017.     /* After the next stmt all output */
  3018.     /* will be sent to your routine   */
  3019.     SOMOutCharRoutine = myReplacementForSOMOutChar;
  3020.  
  3021.  
  3022. ΓòÉΓòÉΓòÉ 6.4. Error-Handling Function ΓòÉΓòÉΓòÉ
  3023.  
  3024. SOMError 
  3025.  
  3026.   void (*SOMError)(int errorCode, zString fileName, int lineNum);
  3027.  
  3028. This function inspects the errorCode argument and takes appropriate action. The 
  3029. last decimal digit of errorCode indicates whether the classification of the 
  3030. error is SOM_Fatal, SOM_Warn, or SOM_Ignore (see Error-Handling Facilities for 
  3031. a discussion of error classifications). In the default SOMError fatal errors 
  3032. will end the current process. The remaining two arguments (fileName and 
  3033. lineNum) indicate the name of the file and the line number within the file 
  3034. where the error was detected. 
  3035.  
  3036. All error conditions that originate within the classes supplied as part of the 
  3037. SOM run time, leave SOM in an internally consistent state. If you wish to trap 
  3038. them with your error-handling function and resume with some other type of 
  3039. processing, you can do so knowing that all of the methods supplied with SOM 
  3040. behave atomically. That is, they either complete or fail, but if they fail, 
  3041. partial effects are backed out wherever possible so that all SOM methods remain 
  3042. useable and can be re-executed. 
  3043.  
  3044. Within your own error-handling function you may wish to: 
  3045.  
  3046. o Record errors in a way appropriate to your application. 
  3047.  
  3048. o Inform the user through your application's user interface. 
  3049.  
  3050. o Attempt application level recovery by restarting at a known point. 
  3051.  
  3052. o Shut down your particular application. 
  3053.  
  3054.  
  3055. ΓòÉΓòÉΓòÉ 7. SOMObject ΓòÉΓòÉΓòÉ
  3056.  
  3057. Class:         SOMObject 
  3058.  
  3059. Parent:        <none> 
  3060.  
  3061. Metaclass:     SOMClass 
  3062.  
  3063. File stem      SOMOBJ 
  3064.  
  3065. Definition:    SOMOBJ.SC 
  3066.  
  3067. Header file:   SOMOBJ.H (always included from SOM.H) 
  3068.  
  3069. Description:   SOMObject is the root class for all SOM classes. It defines the 
  3070.                essential behavior common to all SOM objects. As SOMObject has 
  3071.                no instance data, it contributes nothing to the size of derived 
  3072.                classes. 
  3073.  
  3074. Notes on subclassing: All SOM classes are expected to derive from SOMObject. 
  3075.                Three methods would typically be overridden by any subclass that 
  3076.                has instance data-somInit, somUninit, and somDumpSelfInt. See 
  3077.                the descriptions of these methods for further information. 
  3078.  
  3079. New methods:   [Initialization/Termination Group] 
  3080.  
  3081.                somFree 
  3082.                somInit 
  3083.                somUninit 
  3084.  
  3085.                [Access Group] 
  3086.  
  3087.                somGetClass 
  3088.                somGetClassName 
  3089.                somGetSize 
  3090.  
  3091.                [Testing Group] 
  3092.  
  3093.                somIsA 
  3094.                somIsInstanceOf 
  3095.                somRespondsTo 
  3096.  
  3097.                [Dynamic Group] 
  3098.  
  3099.                somDispatchA 
  3100.                somDispatchD 
  3101.                somDispatchL 
  3102.                somDispatchV 
  3103.  
  3104.                [Development Support Group] 
  3105.  
  3106.                somDumpSelf 
  3107.                somDumpSelfInt 
  3108.                somPrintSelf 
  3109.  
  3110. Inherited methods: None 
  3111.  
  3112. Overridden methods: None 
  3113.  
  3114.  
  3115. ΓòÉΓòÉΓòÉ 7.1. SOMClass ΓòÉΓòÉΓòÉ
  3116.  
  3117. Class:         SOMClass 
  3118.  
  3119. Parent:        SOMObject 
  3120.  
  3121. Metaclass:     SOMClass (only class with itself as metaclass) 
  3122.  
  3123. File stem      SOMCLS 
  3124.  
  3125. Definition:    SOMCLS.SC 
  3126.  
  3127. Header file:   SOMCLS.H (always included from SOM.H) 
  3128.  
  3129. Description:   SOMClass is the root class for all SOM metaclasses. It defines 
  3130.                the essential behavior common to all SOM classes, In particular, 
  3131.                it has two generic methods for manufacturing object instances 
  3132.                (somNew and somRenew), and a suite of methods for constructing 
  3133.                classes. It also has methods that can be used to dynamically 
  3134.                obtain (or augment) information about a class and its methods at 
  3135.                run time. 
  3136.  
  3137. Notes on subclassing: All SOM classes are expected to have SOMClass or a class 
  3138.                derived from SOMClass as their metaclass.  Metaclasses define 
  3139.                "class" methods (sometimes called "factory" methods or 
  3140.                "constructors") that can be used to manufacture objects of any 
  3141.                class for which they are the metaclass.  If you wish to define 
  3142.                your own class methods for your objects, or impart specialized 
  3143.                behavior to the generic class methods supplied in SOMClass, you 
  3144.                will need to define your own metaclass by subclassing SOMClass 
  3145.                or one of its other subclasses.  Three methods that SOMClass 
  3146.                inherits and overrides from SOMObject would typically be 
  3147.                overridden by any metaclass that has instance data - somInit, 
  3148.                somUninit, and somDumpSelfInt.  See the descriptions of these 
  3149.                methods in SOMObject for further information.  The new methods 
  3150.                introduced in SOMClass that might frequently be overridden are 
  3151.                somNew, somNewNoInit, somRenew, somRenewNoInit, and 
  3152.                somClassReady. 
  3153.  
  3154.                Other reasons that you may want to create your own metaclass 
  3155.                include tracking object instances, automatic garbage collection, 
  3156.                interfacing to a persistent object store, or providing/managing 
  3157.                information that is global to a set of object instances. 
  3158.  
  3159. New methods:   [Initialization/Termination Group] 
  3160.  
  3161.                somAddStaticMethod 
  3162.                somClassReady 
  3163.                somInitClass 
  3164.                somOverrideSMethod 
  3165.  
  3166.                [Instance Creation (Factory) Group] 
  3167.  
  3168.                somNew 
  3169.                somNewNoInit 
  3170.                somRenew 
  3171.                somRenewNoInit 
  3172.  
  3173.                [Access Group] 
  3174.  
  3175.                somGetApplyStub 
  3176.                somGetClassData 
  3177.                somGetClassMtab 
  3178.                somGetInstanceOffset 
  3179.                somGetInstancePartSize 
  3180.                somGetInstanceSize 
  3181.                somGetName 
  3182.                somGetNumMethods 
  3183.                somGetNumStaticMethods 
  3184.                somGetParent 
  3185.                somGetPClsMtab 
  3186.                somSetClassData 
  3187.  
  3188.                [Testing Group] 
  3189.  
  3190.                somCheckVersion 
  3191.                somDescendedFrom 
  3192.                somSupportsMethod 
  3193.  
  3194.                [Dynamic Group] 
  3195.  
  3196.                somFindMethod 
  3197.                somFindMethodOk 
  3198.  
  3199. Inherited methods: somDispatchA 
  3200.                somDispatchD 
  3201.                somDispatchL 
  3202.                somDispatchV 
  3203.                somDumpSelf 
  3204.                somFree 
  3205.                somGetClassName 
  3206.                somGetClass 
  3207.                somGetSize 
  3208.                somIsA 
  3209.                somIsInstanceOf 
  3210.                somPrintSelf 
  3211.                somRespondsTo 
  3212.  
  3213. Overridden methods: somDumpSelfInt 
  3214.                somInit 
  3215.                somUninit 
  3216.  
  3217.  
  3218. ΓòÉΓòÉΓòÉ 7.2. SOMClassMgr ΓòÉΓòÉΓòÉ
  3219.  
  3220. Class:         SOMClassMgr 
  3221.  
  3222. Parent:        SOMObject 
  3223.  
  3224. Metaclass:     SOMClass 
  3225.  
  3226. File stem      SOMCM 
  3227.  
  3228. Definition:    SOMCM.SC 
  3229.  
  3230. Header file:   SOMCM.H (always included from SOM.H) 
  3231.  
  3232. Description:   One instance of SOMClassMgr is created during SOM 
  3233.                initialization. It acts as a run-time registry for all SOM class 
  3234.                objects that have been created or dynamically loaded by the 
  3235.                current process. Each SOM class automatically registers itself 
  3236.                with the SOMClassMgr instance (pointed to by the global 
  3237.                variable, SOMClassMgrObject) during the final stage of its 
  3238.                initialization. 
  3239.  
  3240. Notes on subclassing: You can subclass SOMClassMgr to augment the functionality 
  3241.                of its registry (to make it persistent, for example, or to 
  3242.                coordinate the name of a class with the location of its code in 
  3243.                the file system).  If you want your subclass to replace the 
  3244.                SOM-supplied SOMClassMgrObject, you can use the somMergeInto 
  3245.                method to place the existing registry information from 
  3246.                SOMClassMgrObject into your new class-manager object as a final 
  3247.                step in the creation of an instance of your subclass. The former 
  3248.                SOMClassMgrObject is then freed, and the address of your new 
  3249.                class manager is placed in this global variable. 
  3250.  
  3251. New methods:   [Basic Functions Group] 
  3252.  
  3253.                somLoadClassFile 
  3254.                somLocateClassFile 
  3255.                somRegisterClass 
  3256.                somUnloadClassFile 
  3257.                somUnregisterClass 
  3258.  
  3259.                [Access Group] 
  3260.  
  3261.                somGetInitFunction 
  3262.  
  3263.                [Dynamic Group] 
  3264.  
  3265.                somClassFromId 
  3266.                somFindClass 
  3267.                somFindClsInFile 
  3268.                somMergeInto 
  3269.  
  3270. Inherited methods: somDispatchA 
  3271.                somDispatchD 
  3272.                somDispatchL 
  3273.                somDispatchV 
  3274.                somDumpSelf 
  3275.                somFree 
  3276.                somGetClass 
  3277.                somGetClassName 
  3278.                somGetSize 
  3279.                somIsA 
  3280.                somIsInstanceOf 
  3281.                somPrintSelf 
  3282.                somRespondsTo 
  3283.  
  3284. Overridden methods: somDumpSelfInt 
  3285.                somInit 
  3286.                somUninit 
  3287.  
  3288.  
  3289. ΓòÉΓòÉΓòÉ 8. Methods Reference ΓòÉΓòÉΓòÉ
  3290.  
  3291.  
  3292. ΓòÉΓòÉΓòÉ 8.1. somAddStaticMethod ΓòÉΓòÉΓòÉ
  3293.  
  3294.  
  3295. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  3296.  
  3297. Topics: 
  3298.  
  3299. Call Syntax 
  3300. Uses 
  3301. Parameters 
  3302. Return Value 
  3303. Errors 
  3304. Notes 
  3305. Related Methods 
  3306. Example 
  3307. Glossary 
  3308.  
  3309.  
  3310. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  3311.  
  3312.   /* Class:  SOMClass
  3313.   * Method: somAddStaticMethod
  3314.   *
  3315.   * Add a static method to a class or
  3316.   * override a parent static method
  3317.   */
  3318.   #include <som.h>
  3319.  
  3320.   SOMClass *receiver;
  3321.   somId methodId;
  3322.   zString methodDescriptor;
  3323.   somMethodProc *method;
  3324.   somMethodProc *redispatchStub;
  3325.   somMethodProc *applyStub;
  3326.  
  3327.   int offset;
  3328.  
  3329.   offset = _somAddStaticMethod (receiver,
  3330.                  methodId,
  3331.                  methodDescriptor,
  3332.                  method, redispatchStub,
  3333.                  applyStub);
  3334.  
  3335.  
  3336. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  3337.  
  3338. Adds or overrides the indicated method to the receiving class. The 
  3339. somAddStaticMethod method is used by the procedure that constructs the SOM 
  3340. class object. 
  3341.  
  3342.  
  3343. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  3344.  
  3345. receiver    The SOM class that should add this (static) method. 
  3346.  
  3347. methodId    A somId that represents the name of this method. 
  3348.  
  3349. methodDescriptor A string that describes the types of arguments and the 
  3350.             returned value (if any) associated with this method. 
  3351.  
  3352. method      The actual method procedure for this method. 
  3353.  
  3354. redispatchStub A procedure with the same calling sequence as this method that 
  3355.             re-dispatches the method to one of this class's dispatch functions. 
  3356.  
  3357. applyStub   A procedure that applies a standard data structure for a variable 
  3358.             argument list to its target object by calling this method with 
  3359.             arguments derived from the data structure.  Its calling sequence is 
  3360.             the same as that of the dispatch methods defined in SOMObject. 
  3361.             This stub supports the dispatch methods used in some classes. In 
  3362.             classes where the dispatch functions do not need such a function, 
  3363.             this parameter can be null. 
  3364.  
  3365.  
  3366. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  3367.  
  3368. The offset into the class's static method table for this method is returned. 
  3369. This value can be used subsequently as an index for offset method resolution. 
  3370.  
  3371.  
  3372. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  3373.  
  3374. In general, C-language programmers do not need to use this method, because the 
  3375. SOM Compiler generates all of the code to construct a class in the .IH file for 
  3376. the class. 
  3377.  
  3378.  
  3379. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  3380.  
  3381. somInitClass 
  3382. somOverrideSMethod 
  3383.  
  3384.  
  3385. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  3386.  
  3387.    /* New Method: newMethod1 */
  3388.  
  3389.    void newMethod1(XXX *somSelf, int arg1);
  3390.    static char *somMN_newMethod1 = "newMethod1";
  3391.    static somId somId_newMethod1 = &somMN_newMethod1;
  3392.    static void  somRD_newMethod1(XXX *somSelf, int arg1)
  3393.    {
  3394.       va_somDispatchV(somSelf, somId_newMethod1,
  3395.               somMD_XXX_newMethod1,arg1);
  3396.    }
  3397.    static void somAP_newMethod1(XXX *somSelf, somId id,
  3398.               char *desc, va_list ap)
  3399.    {
  3400.       int arg1 = va_arg(ap, int);
  3401.       _newMethod1(somSelf,arg1);
  3402.    }
  3403.  
  3404.    XXXClassData.newMethod1 = (integer2)
  3405.      _somAddStaticMethod (XXXClassData.classObject,
  3406.            somId_newMethod1,
  3407.            somMD_XXX_newMethod1,
  3408.            (somMethodProc *) newMethod1,
  3409.            (somMethodProc *) somRD_newMethod1,
  3410.            (somMethodProc *) somAP_newMethod1);
  3411.  
  3412.  
  3413. ΓòÉΓòÉΓòÉ 8.2. somCheckVersion ΓòÉΓòÉΓòÉ
  3414.  
  3415.  
  3416. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  3417.  
  3418. Topics: 
  3419.  
  3420. Call Syntax 
  3421. Uses 
  3422. Parameters 
  3423. Return Value 
  3424. Errors 
  3425. Notes 
  3426. Related Methods 
  3427. Example 
  3428. Glossary 
  3429.  
  3430.  
  3431. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  3432.  
  3433.   /* Class:  SOMClass
  3434.   * Method: somCheckVersion
  3435.   *
  3436.   * Check to see that a class is compatible
  3437.   * with the specified version information.
  3438.   */
  3439.   #include <som.h>
  3440.  
  3441.   SOMClass *receiver;
  3442.   integer4 majorVersion;
  3443.   integer4 minorVersion;
  3444.  
  3445.   int result;
  3446.  
  3447.   result = _somCheckVersion (receiver,
  3448.                majorVersion,
  3449.                minorVersion);
  3450.  
  3451.  
  3452. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  3453.  
  3454. Check the receiving class for compatibility with the specified major and minor 
  3455. version numbers. An implementation is compatible with the specified version 
  3456. numbers if it has the same major version number and a minor version number that 
  3457. is equal to or greater than minorVersion. The major, minor version number pair 
  3458. (0,0) is considered to match any version. 
  3459.  
  3460.  
  3461. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  3462.  
  3463. receiver    The SOM class whose version information should be checked. 
  3464.  
  3465. majorVersion This value usually changes only when a significant enhancement or 
  3466.             incompatible change is made to a class. 
  3467.  
  3468. minorVersion This value changes whenever minor enhancements or fixes are made 
  3469.             to a class.  Downward compatibility is generally maintained across 
  3470.             changes in the minorVersion number. 
  3471.  
  3472.  
  3473. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  3474.  
  3475. Returns 1 (true) if the implementation of this class is compatible with the 
  3476. specified major and minor version number, and false (0) if otherwise. 
  3477.  
  3478.  
  3479. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  3480.  
  3481. This method is usually called immediately after creating the class object to 
  3482. verify that a dynamically loaded class definition is compatible with a using 
  3483. application. 
  3484.  
  3485.  
  3486. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  3487.  
  3488. somInitClass 
  3489.  
  3490.  
  3491. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  3492.  
  3493.    #include "animal.h"
  3494.    main()
  3495.    {
  3496.      Animal *myAnimal;
  3497.      myAnimal = AnimalNew();
  3498.  
  3499.      if (_somCheckVersion(_Animal, 0, 0))
  3500.         somPrintf("Animal IS compatible with 0.0\n");
  3501.      else
  3502.         somPrintf("Animal IS NOT compatible with 0.0\n");
  3503.  
  3504.      if (_somCheckVersion(_Animal, 1, 1))
  3505.         somPrintf("Animal IS compatible with 1.1\n");
  3506.      else
  3507.         somPrintf("Animal IS NOT compatible with 1.1\n");
  3508.    }
  3509.    /*
  3510.    Output from this program:
  3511.  
  3512.    Animal IS compatible with 0.0
  3513.    Animal IS NOT compatible with 1.1
  3514.    */
  3515.  
  3516.  
  3517. ΓòÉΓòÉΓòÉ 8.3. somClassFromId ΓòÉΓòÉΓòÉ
  3518.  
  3519.  
  3520. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  3521.  
  3522. Topics: 
  3523.  
  3524. Call Syntax 
  3525. Uses 
  3526. Parameters 
  3527. Return Value 
  3528. Errors 
  3529. Notes 
  3530. Related Methods 
  3531. Example 
  3532. Glossary 
  3533.  
  3534.  
  3535. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  3536.  
  3537.   /* Class:  SOMClassMgr
  3538.   * Method: somClassFromId
  3539.   *
  3540.   * Find a class, given its ID
  3541.   */
  3542.   #include <som.h>
  3543.  
  3544.   SOMClassMgr *receiver;
  3545.   somId classId;
  3546.  
  3547.   SOMClass *class;
  3548.  
  3549.   class = _somClassFromId (receiver, classId);
  3550.  
  3551.  
  3552. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  3553.  
  3554. Finds the class object, given its ID, if it already exists. Does not load the 
  3555. class. 
  3556.  
  3557.  
  3558. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  3559.  
  3560. receiver    Usually SOMClassMgrObject (or an instance of a user-supplied 
  3561.             subclass of SOMClassMgr). 
  3562.  
  3563. classId     The ID to use as a key to find the class. 
  3564.  
  3565.  
  3566. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  3567.  
  3568. Returns NULL if the class object does not yet exist; otherwise, a pointer to 
  3569. the class is returned. 
  3570.  
  3571.  
  3572. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  3573.  
  3574. Use this method instead of somFindClass when you do NOT wish the class to be 
  3575. automatically loaded if it does not already exist in the current process. 
  3576.  
  3577.  
  3578. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  3579.  
  3580. somFindClass 
  3581. somFindClsInFile 
  3582.  
  3583.  
  3584. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  3585.  
  3586.    # include  " som . h "
  3587.  
  3588.    SOMClass  * myClass ;
  3589.    char  * myClassName  =  " SampleClass " ;
  3590.  
  3591.    myClass  =  _ somClassFromId ( SOMClassMgrObject ,
  3592.                              SOM _ IdFromString ( myClassName ) ) ;
  3593.    if  ( ! myClass )
  3594.        somPrintf ( " Class  % s  has  not  yet  been  loaded . \ n " ,  myClassName ) ;
  3595.  
  3596.  
  3597. ΓòÉΓòÉΓòÉ 8.4. somClassReady ΓòÉΓòÉΓòÉ
  3598.  
  3599.  
  3600. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  3601.  
  3602. Topics: 
  3603.  
  3604. Call Syntax 
  3605. Uses 
  3606. Parameters 
  3607. Return Value 
  3608. Errors 
  3609. Notes 
  3610. Related Methods 
  3611. Glossary 
  3612.  
  3613.  
  3614. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  3615.  
  3616.   /* Class:  SOMClass
  3617.   * Method: somClassReady
  3618.   *
  3619.   * Indicate that a class has been constructed
  3620.   * and is ready for normal use.
  3621.   */
  3622.   #include <som.h>
  3623.  
  3624.   SOMClass *receiver;
  3625.  
  3626.   _somClassReady (receiver);
  3627.  
  3628.  
  3629. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  3630.  
  3631. This method is invoked when all of the static initialization for the class is 
  3632. finished.  The default implementation simply registers the newly constructed 
  3633. class with SOMClassMgrObject. Metaclasses can override this method to augment 
  3634. the class construction sequence in any way that they wish. 
  3635.  
  3636.  
  3637. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  3638.  
  3639. receiver    The class object that has just been constructed. 
  3640.  
  3641.  
  3642. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  3643.  
  3644. None. 
  3645.  
  3646.  
  3647. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  3648.  
  3649. If you have special processing to do when your class is first created, you can 
  3650. define a metaclass for your class that overrides this method. Typically, the 
  3651. final statement in any overriding method is parent_somClassReady (somSelf) to 
  3652. ensure that your class is properly registered with SOMClassMgrObject. 
  3653.  
  3654. Never invoke this method yourself; it is invoked automatically at the 
  3655. appropriate time during class construction. 
  3656.  
  3657.  
  3658. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  3659.  
  3660. somInitClass 
  3661.  
  3662.  
  3663. ΓòÉΓòÉΓòÉ 8.5. somDescendedFrom ΓòÉΓòÉΓòÉ
  3664.  
  3665.  
  3666. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  3667.  
  3668. Topics: 
  3669.  
  3670. Call Syntax 
  3671. Uses 
  3672. Parameters 
  3673. Return Value 
  3674. Errors 
  3675. Notes 
  3676. Related Methods 
  3677. Example 
  3678. Glossary 
  3679.  
  3680.  
  3681. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  3682.  
  3683.   /* Class:  SOMClass
  3684.   * Method: somDescendedFrom
  3685.   *
  3686.   * Test whether the receiving class is derived
  3687.   * from the specified class.
  3688.   */
  3689.  
  3690.   #include <som.h>
  3691.  
  3692.   SOMClass *receiver;
  3693.   SOMClass *aClassObj;
  3694.  
  3695.   int result = _somDescendedFrom (receiver, aClassObj);
  3696.  
  3697.  
  3698. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  3699.  
  3700. For programs that use classes as types, this method can be used to ascertain if 
  3701. the type of an object is a subtype of another. 
  3702.  
  3703.  
  3704. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  3705.  
  3706. receiver    The class object to be tested. 
  3707.  
  3708. aClassObj   The potential ancestor class. 
  3709.  
  3710.  
  3711. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  3712.  
  3713. Returns 1 (true) if the receiving class is a descendent class of the argument 
  3714. class, and 0 (false) if otherwise. 
  3715.  
  3716.  
  3717. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  3718.  
  3719. A class object is considered to be descended from itself for the purpose of 
  3720. this method. 
  3721.  
  3722.  
  3723. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  3724.  
  3725. somIsA 
  3726. somIsInstanceOf 
  3727.  
  3728.  
  3729. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  3730.  
  3731. #include "animal.h"
  3732. #include "dog.h"
  3733. /* ---------------------------------------------------
  3734.    Note: Dog is a subclass of Animal.
  3735.    --------------------------------------------------- */
  3736. main()
  3737. {
  3738.   AnimalNewClass(1,1);
  3739.   DogNewClass(1,1);
  3740.  
  3741.   if (_somDescendedFrom (_Dog, _Animal))
  3742.      somPrintf("dog IS descended from animal\n");
  3743.   else
  3744.      somPrintf("dog is NOT descended from animal\n");
  3745.   if (_somDescendedFrom (_Animal, _Dog))
  3746.      somPrintf("animal IS descended from dog\n");
  3747.   else
  3748.      somPrintf("animal is NOT descended from dog\n");
  3749. }
  3750. /*
  3751. Output from this program:
  3752. dog IS descended from animal
  3753. animal is NOT descended from dog
  3754. */
  3755.  
  3756.  
  3757. ΓòÉΓòÉΓòÉ 8.6. somDispatchX ΓòÉΓòÉΓòÉ
  3758.  
  3759.  
  3760. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  3761.  
  3762. Topics: 
  3763.  
  3764. Call Syntax 
  3765. Uses 
  3766. Parameters 
  3767. Return Value 
  3768. Errors 
  3769. Notes 
  3770. Related Methods 
  3771. Example 
  3772. Glossary 
  3773.  
  3774.  
  3775. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  3776.  
  3777.   /* Class:  SOMObject
  3778.   * Method: somDispatchX
  3779.   *
  3780.   * Invoke a method using a dispatch mechanism.
  3781.   */
  3782.   #include <som.h>
  3783.  
  3784.   SOMAny *receiver;
  3785.   somId  methodId;
  3786.   somId  descriptor;
  3787.  
  3788.   void *ptr;
  3789.   float8 rnum;
  3790.   integer4 inum;
  3791.  
  3792.   ptr  = _somDispatchA (receiver, methodId, descriptor, ...);
  3793.   rnum = _somDispatchD (receiver, methodId, descriptor, ...);
  3794.   inum = _somDispatchL (receiver, methodId, descriptor, ...);
  3795.       _somDispatchV (receiver, methodId, descriptor, ...);
  3796.  
  3797.  
  3798. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  3799.  
  3800. The somDispatchX methods are used to invoke a designated method using a 
  3801. dispatching algorithm appropriate for the class of the specified receiving 
  3802. object. The actual object that will receive the designated method is determined 
  3803. by the particular dispatching algorithm associated with the class. 
  3804.  
  3805. All SOM objects permit the use of a dispatch mechanism to perform method 
  3806. resolution for any method. The default dispatch algorithm supplied in the 
  3807. SOMObject class always selects the specified receiving object as the target of 
  3808. the call and invokes the "apply stub" for the designated method. 
  3809.  
  3810.  
  3811. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  3812.  
  3813. receiver    The object that represents the context in which the dispatch method 
  3814.             resolution will occur. 
  3815.  
  3816. methodId    An ID that represents the name of the method to be dispatched. 
  3817.  
  3818. descriptor  An ID that represents a string that describes the arguments (and 
  3819.             their types) associated with the target method. 
  3820.  
  3821. ...         The remaining arguments are any that are needed for the method to 
  3822.             be dispatched. 
  3823.  
  3824.  
  3825. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  3826.  
  3827. Four families of return values are supported, corresponding to the four forms 
  3828. of the somdispatchX method. Within each of the four families, only the largest 
  3829. representation is supported. The four families are: 
  3830.  
  3831. Pointer   This type of result is returned from somDispatchA. It can be cast to 
  3832.           be a pointer to a specific type appropriate for the method that is 
  3833.           being dispatched. 
  3834.  
  3835. Floating point This result is returned from somDispatchD as a float8. 
  3836.  
  3837. Integer   This result is returned from somDispatchL as an integer4. 
  3838.  
  3839. Void      somDispatchV is used for any method that does not return a result. 
  3840.  
  3841.  
  3842. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  3843.  
  3844. These methods make it easier for dynamic domains to bind to the SOM-object 
  3845. protocol boundary. In addition, they determine the appropriate method 
  3846. procedure, then call it with the arguments specified. The default 
  3847. implementations of these methods provided in this class simply look up the 
  3848. apply stub associated with the method and call it. However, other classes can 
  3849. choose to implement any form of lookup they wish. For example, one could 
  3850. provide an implementation of these methods that used the CLOS (Common Lisp 
  3851. Object System) form of method resolution. For domains that can do so, it 
  3852. generally will be much faster to invoke their methods directly rather than 
  3853. going through a dispatch method. However, all methods can be reached through 
  3854. the dispatch methods. 
  3855.  
  3856. These methods are declared to take a variable-length argument list, but as with 
  3857. all such methods, SOM requires that the variable part of the argument list be 
  3858. assembled into the standard data structure for variable argument lists before 
  3859. the method is actually invoked. This can be very useful in domains that need to 
  3860. construct the argument list at run time, because they can invoke methods 
  3861. without being able to put the constructed arguments in the normal form for a 
  3862. call. Usually such an operation is impossible in most high-level languages, and 
  3863. the use of assembler language routines would otherwise be necessary. 
  3864.  
  3865.  
  3866. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  3867.  
  3868. somGetApplyStub 
  3869.  
  3870.  
  3871. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  3872.  
  3873. #include "animal.h"
  3874. void main()
  3875. {
  3876.    Animal *myAnimal;
  3877.    char *myNoise = "Roar!!!";
  3878.    somId somId_setSound;
  3879.  
  3880.    myAnimal = AnimalNew();
  3881. /* --------------------------------------
  3882.    Note: Next two lines are equivalent to
  3883.    _setSound(myAnimal, myNoise);
  3884.    -------------------------------------- */
  3885.    somId_setSound = SOM_IdFromString("setSound");
  3886.    _somDispatchV(myAnimal, somId_setSound , (void *) 0, &myNoise);
  3887.  
  3888.    _display(myAnimal);
  3889.    _somFree(myAnimal);
  3890. }
  3891. /*
  3892. Program Output:
  3893. This Animal says
  3894. Roar!!!
  3895. */
  3896.  
  3897.  
  3898. ΓòÉΓòÉΓòÉ 8.7. somDumpSelf ΓòÉΓòÉΓòÉ
  3899.  
  3900.  
  3901. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  3902.  
  3903. Topics: 
  3904.  
  3905. Call Syntax 
  3906. Uses 
  3907. Parameters 
  3908. Return Value 
  3909. Errors 
  3910. Notes 
  3911. Related Methods 
  3912. Example 
  3913. Glossary 
  3914.  
  3915.  
  3916. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  3917.  
  3918.   /* Class:  SOMObject
  3919.   * Method: somDumpSelf
  3920.   *
  3921.   * Writes a detailed description of the receiving
  3922.   * object to (*SOMOutCharRoutine)(char);
  3923.   */
  3924.  
  3925.   #include <som.h>
  3926.  
  3927.   SOMAny *receiver;
  3928.   int level;
  3929.  
  3930.   _somDumpSelf (receiver, level);
  3931.  
  3932.  
  3933. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  3934.  
  3935. Uses SOMOutCharRoutine to write a detailed description of this object and its 
  3936. current state. The default implementation produces a header line identifying 
  3937. the receiving object and its class, then invokes somDumpSelfInt to format any 
  3938. instance data in the object. 
  3939.  
  3940.  
  3941. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  3942.  
  3943. receiver    The object to be dumped. 
  3944.  
  3945. level       The nesting level for describing compound objects. It must be 
  3946.             greater than or equal to 0. All lines in the description will be 
  3947.             preceded by "2 X level" spaces. 
  3948.  
  3949.  
  3950. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  3951.  
  3952. None. 
  3953.  
  3954.  
  3955. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  3956.  
  3957. This routine writes only the data that concerns the object as a whole, such as 
  3958. class, and uses somDumpSelfInt to describe the object's current state. This 
  3959. approach allows readable descriptions of compound objects to be constructed. 
  3960.  
  3961. Generally, it is not necessary to override this method, but if it IS overridden 
  3962. it typically will need to be replaced completely. 
  3963.  
  3964.  
  3965. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  3966.  
  3967. somDumpSelfInt 
  3968. somPrintSelf 
  3969.  
  3970.  
  3971. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  3972.  
  3973. #include "animal.h"
  3974. main()
  3975. {
  3976.   Animal *myAnimal;
  3977.   myAnimal = AnimalNew();
  3978.   /* ... */
  3979.   _somDumpSelf(myAnimal, 0);
  3980. }
  3981.  
  3982.  
  3983. ΓòÉΓòÉΓòÉ 8.8. somDumpSelfInt ΓòÉΓòÉΓòÉ
  3984.  
  3985.  
  3986. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  3987.  
  3988. Topics: 
  3989.  
  3990. Call Syntax 
  3991. Uses 
  3992. Parameters 
  3993. Return Value 
  3994. Errors 
  3995. Notes 
  3996. Related Methods 
  3997. Glossary 
  3998.  
  3999.  
  4000. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  4001.  
  4002.   /* Class:  SOMObject
  4003.   * Method: somDumpSelfInt
  4004.   *
  4005.   * Writes the internal state of the receiving
  4006.   * object to (*SOMOutCharRoutine)(char);
  4007.   */
  4008.  
  4009.   #include <som.h>
  4010.  
  4011.   SOMAny *receiver;
  4012.   int level;
  4013.  
  4014.   _somDumpSelfInt (receiver, level);
  4015.  
  4016.  
  4017. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  4018.  
  4019. somDumpSelf invokes this method to write out the instance data stored in the 
  4020. receiving object. The default implementation does nothing (SOMObject has no 
  4021. instance data). Overriding methods can use SOMOutCharRoutine to write instance 
  4022. data in a readable format to the SOM output destination. 
  4023.  
  4024.  
  4025. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  4026.  
  4027. receiver    The object to be dumped. 
  4028.  
  4029. level       The nesting level for describing compound objects. It must be 
  4030.             greater than or equal to 0. All lines in the description will be 
  4031.             preceded by "2 X level" spaces. 
  4032.  
  4033.  
  4034. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  4035.  
  4036. None. 
  4037.  
  4038.  
  4039. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  4040.  
  4041. Uses (*SOMOutCharRoutine)() to write out the current state of this object. If 
  4042. your class has instance data, override this method. Begin by calling the parent 
  4043. class form of this method, then write out a description of your class's 
  4044. instance data. This will result in a description of all the object's instance 
  4045. data, from its root ancestor class to its specific class. 
  4046.  
  4047. This method generally is not invoked directly. Use somDumpSelf instead, which 
  4048. will invoke somDumpSelfInt. 
  4049.  
  4050.  
  4051. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  4052.  
  4053. somDumpSelf 
  4054. somPrintSelf 
  4055.  
  4056.  
  4057. ΓòÉΓòÉΓòÉ 8.9. somFindClass ΓòÉΓòÉΓòÉ
  4058.  
  4059.  
  4060. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  4061.  
  4062. Topics: 
  4063.  
  4064. Call Syntax 
  4065. Uses 
  4066. Parameters 
  4067. Return Value 
  4068. Errors 
  4069. Notes 
  4070. Related Methods 
  4071. Example 
  4072. Glossary 
  4073.  
  4074.  
  4075. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  4076.  
  4077.   /* Class:  SOMClassMgr
  4078.   * Method: somFindClass
  4079.   *
  4080.   * Finds the class object when given its ID.
  4081.   * If the class does not exist, dynamically
  4082.   * loads it.
  4083.   */
  4084.   #include <som.h>
  4085.  
  4086.   SOMClassMgr *receiver;
  4087.   somId classId;
  4088.   int majorVersion;
  4089.   int minorVersion;
  4090.   SOMClass *class;
  4091.  
  4092.   class = _somFindClass (receiver, classId, majorVersion, minorVersion);
  4093.  
  4094.  
  4095. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  4096.  
  4097. Returns the class object for the specified class.  This may result in dynamic 
  4098. loading.  This method first uses somLocateClassFile to obtain the name of the 
  4099. file where the class' code resides, then uses somFindClsInFile. 
  4100.  
  4101.  
  4102. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  4103.  
  4104. receiver    Usually SOMClassMgrObject (or an instance of a user-supplied 
  4105.             subclass of SOMClassMgr). 
  4106.  
  4107. classId     The ID to use as a key to find the class. 
  4108.  
  4109. majorVersion The class's major version number. 
  4110.  
  4111. minorVersion The class's minor version number. 
  4112.  
  4113. If majorVersion and minorVersion are not both zero, they are used to check the 
  4114. class version information against the caller's expectations. 
  4115.  
  4116.  
  4117. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  4118.  
  4119. A pointer to the requested class object, or NULL if the class could not be 
  4120. created. 
  4121.  
  4122.  
  4123. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  4124.  
  4125. If the requested class has not yet been created this routine will attempt to 
  4126. load the class dynamically by loading its .DLL and invoking its "new class" 
  4127. procedure. 
  4128.  
  4129.  
  4130. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  4131.  
  4132. somFindClsInFile 
  4133. somLocateClassFile 
  4134.  
  4135.  
  4136. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  4137.  
  4138. #include "animal.h"
  4139.  
  4140. void main()
  4141. {
  4142.    Animal *bigAnimal;
  4143.    SOMClass *myClass;
  4144.    char *animalName = "Animal";
  4145.  
  4146.    bigAnimal = AnimalNew();
  4147.    myClass = _somFindClass (SOMClassMgrObject,
  4148.                             SOM_IdFromString(animalName),
  4149.                             0, 0);
  4150.    somPrintf("myClass: %s\n", _somGetName(myClass));
  4151.    _somFree(bigAnimal);
  4152. }
  4153. /*
  4154. Output from this program:
  4155. myClass: Animal
  4156. */
  4157.  
  4158.  
  4159. ΓòÉΓòÉΓòÉ 8.10. somFindClsInFile ΓòÉΓòÉΓòÉ
  4160.  
  4161.  
  4162. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  4163.  
  4164. Topics: 
  4165.  
  4166. Call Syntax 
  4167. Uses 
  4168. Parameters 
  4169. Return Value 
  4170. Errors 
  4171. Notes 
  4172. Related Methods 
  4173. Example 
  4174. Glossary 
  4175.  
  4176.  
  4177. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  4178.  
  4179.   /* Class:  SOMClassMgr
  4180.   * Method: somFindClsInFile
  4181.   *
  4182.   * Same as somFindClass, except the caller provides the
  4183.   * file name to be used if dynamic loading is needed.
  4184.   *
  4185.   */
  4186.   #include <som.h>
  4187.  
  4188.   SOMClassMgr *receiver;
  4189.   somId classId;
  4190.   int majorVersion;
  4191.   int minorVersion;
  4192.   zString file;
  4193.   SOMClass *class;
  4194.  
  4195.   class = _somFindClsInFile (receiver, classId, majorVersion, minorVersion, file);
  4196.  
  4197.  
  4198. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  4199.  
  4200. Returns the class object for the specified class.  This can result in dynamic 
  4201. loading.  This method uses the passed parameter file as the name of the .DLL 
  4202. containing the class. 
  4203.  
  4204.  
  4205. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  4206.  
  4207. receiver    Usually SOMClassMgrObject (or an instance of a user-supplied 
  4208.             subclass of SOMClassMgr). 
  4209.  
  4210. classId     The ID to use as a key to find the class. 
  4211.  
  4212. majorVersion The class's major version number. 
  4213.  
  4214. minorVersion The class's minor version number. 
  4215.  
  4216. file        The name of the .DLL file containing the class. 
  4217.  
  4218. If majorVersion and minorVersion are not both zero, they are used to check the 
  4219. class version information against the caller's expectations. 
  4220.  
  4221.  
  4222. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  4223.  
  4224. A pointer to the requested class object, or NULL if the class could not be 
  4225. loaded and created. 
  4226.  
  4227.  
  4228. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  4229.  
  4230. If the requested class has not yet been created this routine will attempt to 
  4231. load the class dynamically by loading its .DLL and invoking its "new class" 
  4232. procedure. 
  4233.  
  4234.  
  4235. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  4236.  
  4237. somFindClass 
  4238.  
  4239.  
  4240. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  4241.  
  4242. #include "som.h"
  4243. /*
  4244.  *  This program loads a class and creates
  4245.  *  an instance of it without having any
  4246.  *  external references to it.
  4247.  *
  4248.  */
  4249. void main()
  4250. {
  4251.    SOMAny *myAnimal;
  4252.    SOMClass *animalClass;
  4253.    char *animalName = "Animal";
  4254.    char *animalFile = "C:\\MYDLLS\\ANIMAL.DLL";
  4255.  
  4256.    animalClass = _somFindClsInFile (SOMClassMgrObject,
  4257.                                     SOM_IdFromString(animalName),
  4258.                                     0, 0,
  4259.                                     animalFile);
  4260.    myAnimal = _somNew (animalClass);
  4261.    somPrintf("The class of myAnimal is %s.\n",
  4262.        _somGetClassName(myAnimal));
  4263.    _somFree(myAnimal);
  4264. }
  4265. /*
  4266. Output from this program:
  4267. The class of myAnimal is Animal.
  4268. */
  4269.  
  4270.  
  4271. ΓòÉΓòÉΓòÉ 8.11. somFindMethod ΓòÉΓòÉΓòÉ
  4272.  
  4273.  
  4274. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  4275.  
  4276. Topics: 
  4277.  
  4278. Call Syntax 
  4279. Uses 
  4280. Parameters 
  4281. Return Value 
  4282. Errors 
  4283. Notes 
  4284. Related Methods 
  4285. Example 
  4286. Glossary 
  4287.  
  4288.  
  4289. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  4290.  
  4291.   /* Class:  SOMClass
  4292.   * Method: somFindMethod
  4293.   *
  4294.   * Given a methodId, returns a procedure address
  4295.   * and an indication of whether it represents
  4296.   * a direct method call or a dispatching function.
  4297.   */
  4298.   #include <som.h>
  4299.  
  4300.   SOMClass *receiver;
  4301.   somId methodId;
  4302.   somMethodProc **m;
  4303.   int directFlag;
  4304.  
  4305.   directFlag = _somFindMethod (SOMClass *receiver, methodId, m);
  4306.  
  4307.  
  4308. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  4309.  
  4310. Finds the method procedure associated with methodId for the receiving class and 
  4311. sets *m to it. 
  4312.  
  4313.  
  4314. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  4315.  
  4316. receiver    The class object whose method is desired. 
  4317.  
  4318. methodId    An ID that represents the name of the desired method. 
  4319.  
  4320. m           A pointer to a pointer to a somMethodProc. *m is set either to NULL 
  4321.             (if the method does not exist), or to a value that can be called. 
  4322.  
  4323.  
  4324. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  4325.  
  4326. Returns 1 (true) when the method procedure can be called directly, and 0 
  4327. (false) when the method procedure is a dispatch function. 
  4328.  
  4329.  
  4330. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  4331.  
  4332. If the class does not support the specified method, then *m is set to NULL and 
  4333. the return value is meaningless. Returning a dispatch function does not 
  4334. guarantee that a class supports the specified method; the dispatch might fail. 
  4335.  
  4336. If a dispatch function is returned (directFlag == 0) the calling sequence is 
  4337. slightly different than that for a direct method; two additional parameters are 
  4338. required-methodId and descriptorId. 
  4339.  
  4340.  
  4341. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  4342.  
  4343. somFindMethodOk 
  4344. somSupportsMethod 
  4345.  
  4346.  
  4347. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  4348.  
  4349. #include "animal.h"
  4350. void main()
  4351. {
  4352.    Animal *myAnimal;
  4353.    somId somId_setSound;
  4354.    somMethodPtr methodPtr;
  4355.    myAnimal = AnimalNew();
  4356. /* ----------------------------------------
  4357.    Note: Next three lines are equivalent to
  4358.        _setSound(myAnimal, "Roar!!!");
  4359.    ---------------------------------------- */
  4360.    somId_setSound = SOM_IdFromString("setSound");
  4361.    _somFindMethod (_somGetClass(myAnimal),
  4362.                    somId_setSound, &methodPtr);
  4363.    methodPtr(myAnimal, "Roar!!!");
  4364. /* ---------------------------------------- */
  4365.    _display(myAnimal);
  4366.    _somFree(myAnimal);
  4367. }
  4368. /*
  4369. Program Output:
  4370. This Animal says
  4371. Roar!!!
  4372. */
  4373.  
  4374.  
  4375. ΓòÉΓòÉΓòÉ 8.12. somFindMethodOk ΓòÉΓòÉΓòÉ
  4376.  
  4377.  
  4378. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  4379.  
  4380. Topics: 
  4381.  
  4382. Call Syntax 
  4383. Uses 
  4384. Parameters 
  4385. Return Value 
  4386. Errors 
  4387. Notes 
  4388. Related Methods 
  4389. Example 
  4390. Glossary 
  4391.  
  4392.  
  4393. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  4394.  
  4395.   /* Class:  SOMClass
  4396.   * Method: somFindMethodOk
  4397.   *
  4398.   * Given a methodId, returns a procedure address
  4399.   * and an indication of whether it represents
  4400.   * a direct method call or a dispatching function.
  4401.   */
  4402.   #include <som.h>
  4403.  
  4404.   SOMClass *receiver;
  4405.   somId methodId;
  4406.   somMethodProc **m;
  4407.   int directFlag;
  4408.  
  4409.   directFlag = _somFindMethodOk (SOMClass *receiver, methodId, m);
  4410.  
  4411.  
  4412. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  4413.  
  4414. Finds the method procedure associated with methodId for the receiving class and 
  4415. sets *m to it. If methodId is not supported, an error is raised and execution 
  4416. is halted. 
  4417.  
  4418.  
  4419. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  4420.  
  4421. receiver    The class object whose method is desired. 
  4422.  
  4423. methodId    An ID that represents the name of the desired method. 
  4424.  
  4425. m           A pointer to a pointer to a somMethodProc. *m is set either to NULL 
  4426.             (if the method does not exist), or to a value that can be called. 
  4427.  
  4428.  
  4429. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  4430.  
  4431. Returns 1 (true) when the method procedure can be called directly, and 0 
  4432. (false) when the method procedure is a dispatch function. 
  4433.  
  4434.  
  4435. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  4436.  
  4437. If the class does not support the specified method then *m is set to NULL and 
  4438. the return value is meaningless. Returning a dispatch function does not 
  4439. guarantee that a class supports the specified method; the dispatch might fail. 
  4440.  
  4441. If a dispatch function is returned (directFlag == 0), the calling sequence is 
  4442. slightly different than that of a direct method; two additional parameters are 
  4443. required-methodId and descriptorId. 
  4444.  
  4445.  
  4446. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  4447.  
  4448. somFindMethod 
  4449. somSupportsMethod 
  4450.  
  4451.  
  4452. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  4453.  
  4454. #include "animal.h"
  4455. void main()
  4456. {
  4457.    Animal *myAnimal;
  4458.    somId somId_setSound;
  4459.    somMethodPtr methodPtr;
  4460.    myAnimal = AnimalNew();
  4461. /* ----------------------------------------
  4462.    Note: Next three lines are equivalent to
  4463.        _setSound(myAnimal, "Roar!!!");
  4464.    ---------------------------------------- */
  4465.    somId_setSound = SOM_IdFromString("setSound");
  4466.    _somFindMethodOk (_somGetClass(myAnimal),
  4467.                      somId_setSound, &methodPtr);
  4468.    methodPtr(myAnimal, "Roar!!!");
  4469. /* ---------------------------------------- */
  4470.    _display(myAnimal);
  4471.    _somFree(myAnimal);
  4472. }
  4473. /*
  4474. Program Output:
  4475. This Animal says
  4476. Roar!!!
  4477. */
  4478.  
  4479.  
  4480. ΓòÉΓòÉΓòÉ 8.13. somFree ΓòÉΓòÉΓòÉ
  4481.  
  4482.  
  4483. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  4484.  
  4485. Topics: 
  4486.  
  4487. Call Syntax 
  4488. Uses 
  4489. Parameters 
  4490. Return Value 
  4491. Errors 
  4492. Notes 
  4493. Related Methods 
  4494. Example 
  4495. Glossary 
  4496.  
  4497.  
  4498. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  4499.  
  4500.   /* Class:  SOMObject
  4501.   * Method: somFree
  4502.   *
  4503.   * Release the storage used by the receiver
  4504.   * and free the object.
  4505.   */
  4506.   #include <som.h>
  4507.  
  4508.   SOMAny *receiver;
  4509.  
  4510.   _somFree (receiver);
  4511.  
  4512.  
  4513. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  4514.  
  4515. Releases the storage associated with the receiving object, assuming that it was 
  4516. created originally by somNew or somNewNoInit (or another class method that used 
  4517. either of these methods to allocate its objects). No future references should 
  4518. be made to the receiving object. This method calls somUninit before releasing 
  4519. storage. 
  4520.  
  4521.  
  4522. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  4523.  
  4524. receiver    The object to be freed. 
  4525.  
  4526.  
  4527. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  4528.  
  4529. None. 
  4530.  
  4531.  
  4532. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  4533.  
  4534. This method must be called only on objects that were originally created by 
  4535. somNew (or somNewNoInit), and never on objects created by somRenew (or 
  4536. somRenewNoInit). It is not necessary to override this method (override 
  4537. somUninit instead). 
  4538.  
  4539.  
  4540. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  4541.  
  4542. somNew 
  4543. somNewNoInit 
  4544. somRenew 
  4545. somRenewNoInit 
  4546. somUninit 
  4547.  
  4548.  
  4549. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  4550.  
  4551. #include "animal.h"
  4552.  
  4553. void main()
  4554. {
  4555.    Animal *myAnimal;
  4556.    /*
  4557.     * Create an object.
  4558.     */
  4559.    myAnimal = AnimalNew();
  4560.  
  4561.    /* ... */
  4562.  
  4563.    /*
  4564.     * Free it when finished.
  4565.     */
  4566.    _somFree(myAnimal);
  4567. }
  4568.  
  4569.  
  4570. ΓòÉΓòÉΓòÉ 8.14. somGetApplyStub ΓòÉΓòÉΓòÉ
  4571.  
  4572.  
  4573. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  4574.  
  4575. Topics: 
  4576.  
  4577. Call Syntax 
  4578. Uses 
  4579. Parameters 
  4580. Return Value 
  4581. Errors 
  4582. Notes 
  4583. Related Methods 
  4584. Example 
  4585. Glossary 
  4586.  
  4587.  
  4588. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  4589.  
  4590.   /* Class:  SOMClass
  4591.   * Method: somGetApplyStub
  4592.   *
  4593.   * Obtain the apply stub for a given method
  4594.   */
  4595.   #include <som.h>
  4596.  
  4597.   SOMClass *receiver;
  4598.   somId methodId;
  4599.   somMethodProc *applyStub;
  4600.  
  4601.   applyStub = _somGetApplyStub (receiver, methodId);
  4602.  
  4603.  
  4604. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  4605.  
  4606. This method returns the address of an "apply stub" for the indicated method. 
  4607. An apply stub is a special procedure that accepts the arguments for a 
  4608. particular method in the form of a standard varargs data structure.  It 
  4609. extracts the arguments, then invokes the method, subsequently returning its 
  4610. result to the original caller. Apply stubs are useful in situations when a 
  4611. static method invocation cannot be constructed at compile time. 
  4612.  
  4613.  
  4614. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  4615.  
  4616. receiver    The class object whose method is desired. 
  4617.  
  4618. methodId    An ID that represents the name of the desired method. 
  4619.  
  4620.  
  4621. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  4622.  
  4623. Returns the apply stub associated with the specified method. NULL is returned 
  4624. if the method is not supported by this class. 
  4625.  
  4626.  
  4627. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  4628.  
  4629. The calling sequence for any apply stub is shown below. 
  4630.  
  4631.     #include <stdarg.h>
  4632.  
  4633.     somMethodProc *applyStub;
  4634.     SOMAny *receiver;
  4635.     somId methodId;
  4636.     somId descriptor;
  4637.     va_list arglist;
  4638.     resultType result;
  4639.  
  4640.     result = (*applyStub)(receiver, methodId, descriptor, arglist);
  4641.  
  4642.  
  4643. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  4644.  
  4645. None. 
  4646.  
  4647.  
  4648. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  4649.  
  4650. #include "animal.h"
  4651. void main()
  4652. {
  4653.    Animal *myAnimal;
  4654.    char *myNoise = "Roar!!!";
  4655.    somId somId_setSound;
  4656.    somMethodPtr applyStub;
  4657.  
  4658.    myAnimal = AnimalNew();
  4659. /* ----------------------------------------
  4660.    Note: Next three lines are equivalent to
  4661.        _setSound(myAnimal, myNoise);
  4662.    ---------------------------------------- */
  4663.    somId_setSound = SOM_IdFromString("setSound");
  4664.    applyStub = _somGetApplyStub(
  4665.       _somGetClass(myAnimal), somId_setSound);
  4666.    applyStub (myAnimal, somId_setSound , (void *) 0, &myNoise);
  4667. /* ---------------------------------------- */
  4668.    _display(myAnimal);
  4669.    _somFree(myAnimal);
  4670. }
  4671. /*
  4672. Program Output:
  4673. This Animal says
  4674. Roar!!!
  4675. */
  4676.  
  4677.  
  4678. ΓòÉΓòÉΓòÉ 8.15. somGetClass ΓòÉΓòÉΓòÉ
  4679.  
  4680.  
  4681. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  4682.  
  4683. Topics: 
  4684.  
  4685. Call Syntax 
  4686. Uses 
  4687. Parameters 
  4688. Return Value 
  4689. Errors 
  4690. Notes 
  4691. Related Methods 
  4692. Example 
  4693. Glossary 
  4694.  
  4695.  
  4696. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  4697.  
  4698.   /* Class:  SOMObject
  4699.   * Method: somGetClass
  4700.   *
  4701.   * Get a pointer to an object's class object
  4702.   */
  4703.   #include <som.h>
  4704.  
  4705.   SOMAny *receiver;
  4706.   SOMClass *class;
  4707.  
  4708.   class = _somGetClass (receiver);
  4709.  
  4710.  
  4711. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  4712.  
  4713. Obtain a pointer to the receiver's class object. 
  4714.  
  4715.  
  4716. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  4717.  
  4718. receiver    is the object whose class is desired. 
  4719.  
  4720.  
  4721. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  4722.  
  4723. A pointer to the object's class object is returned. 
  4724.  
  4725.  
  4726. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  4727.  
  4728. A slightly faster macro form of this method (SOM_GetClass) also is available. 
  4729. This method is not typically overridden. 
  4730.  
  4731.  
  4732. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  4733.  
  4734. somGetClassName 
  4735.  
  4736.  
  4737. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  4738.  
  4739. #include "animal.h"
  4740. main()
  4741. {
  4742.   Animal *myAnimal;
  4743.   int numMethods;
  4744.   SOMClass *animalClass;
  4745.  
  4746.   myAnimal = AnimalNew ();
  4747.   animalClass = _somGetClass (myAnimal);
  4748.   numMethods = _somGetNumMethods (animalClass);
  4749.   somPrintf ("Number of methods supported by Animal: %d\n", numMethods);
  4750.   _somFree (myAnimal);
  4751. }
  4752. /*
  4753. Output from this program:
  4754. Number of methods supported by Animal: 24
  4755. */
  4756.  
  4757.  
  4758. ΓòÉΓòÉΓòÉ 8.16. somGetClassData ΓòÉΓòÉΓòÉ
  4759.  
  4760.  
  4761. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  4762.  
  4763. Topics: 
  4764.  
  4765. Call Syntax 
  4766. Uses 
  4767. Parameters 
  4768. Return Value 
  4769. Errors 
  4770. Notes 
  4771. Related Methods 
  4772. Glossary 
  4773.  
  4774.  
  4775. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  4776.  
  4777.   /* Class:  SOMClass
  4778.   * Method: somGetClassData
  4779.   *
  4780.   * Obtain a pointer to the global ClassData
  4781.   * structure associated with the class.
  4782.   */
  4783.   #include <som.h>
  4784.  
  4785.   SOMClass *receiver;
  4786.   somClassDataStructure *cds
  4787.  
  4788.   cds = _somGetClassData (receiver);
  4789.  
  4790.  
  4791. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  4792.  
  4793. This method returns the address of the global ClassData structure associated 
  4794. with the class. Every SOM class has an external data structure named 
  4795. <className>ClassData that holds a pointer to the class object and information 
  4796. about the relative offsets of method table entries. This structure can be used 
  4797. by language bindings to assist in the method resolution process. 
  4798.  
  4799.  
  4800. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  4801.  
  4802. receiver    The class object whose ClassData structure is desired. 
  4803.  
  4804.  
  4805. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  4806.  
  4807. Returns a pointer to the ClassData structure for this class. 
  4808.  
  4809.  
  4810. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  4811.  
  4812. This method is not generally overridden. It is provided for use by the SOM 
  4813. run-time environment. 
  4814.  
  4815.  
  4816. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  4817.  
  4818. somSetClassData 
  4819.  
  4820.  
  4821. ΓòÉΓòÉΓòÉ 8.17. somGetClassMtab ΓòÉΓòÉΓòÉ
  4822.  
  4823.  
  4824. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  4825.  
  4826. Topics: 
  4827.  
  4828. Call Syntax 
  4829. Uses 
  4830. Parameters 
  4831. Return Value 
  4832. Errors 
  4833. Notes 
  4834. Related Methods 
  4835. Example 
  4836. Glossary 
  4837.  
  4838.  
  4839. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  4840.  
  4841.   /* Class:  SOMClass
  4842.   * Method: somGetClassMtab
  4843.   *
  4844.   * Obtain a pointer to the class' method table.
  4845.   */
  4846.   #include <som.h>
  4847.  
  4848.   SOMClass *receiver;
  4849.   somMethodTab *mtab;
  4850.  
  4851.   mtab = _somGetClassMtab (receiver);
  4852.  
  4853.  
  4854. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  4855.  
  4856. This method returns the address of the class' method table. The method table is 
  4857. a structure containing a pointer to the class object followed by an array of 
  4858. procedure entry addresses, with one entry for each static method defined in 
  4859. this class or any of its parent classes. 
  4860.  
  4861.  
  4862. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  4863.  
  4864. receiver    The class object whose method table is desired. 
  4865.  
  4866.  
  4867. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  4868.  
  4869. Returns a pointer to the method table of this class. 
  4870.  
  4871.  
  4872. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  4873.  
  4874. This method is not generally overridden. 
  4875.  
  4876. Whenever possible you should avoid writing code that accesses the method table 
  4877. directly, since the specifics of this structure may change in a future release 
  4878. of SOM. 
  4879.  
  4880.  
  4881. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  4882.  
  4883. somGetNumStaticMethods 
  4884. somGetPClsMtab 
  4885.  
  4886.  
  4887. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  4888.  
  4889. #include "animal.h"
  4890. void main()
  4891. {
  4892.    Animal *myAnimal;
  4893.    somId somId_setSound;
  4894.    somMethodPtr methodPtr;
  4895.    somMethodTab *methodTable;
  4896.    int offset;
  4897.    myAnimal = AnimalNew();
  4898. /* ---------------------------------------
  4899.    Note: Next five lines are equivalent to
  4900.        _setSound(myAnimal, "Roar!!!");
  4901.    --------------------------------------- */
  4902.    somId_setSound = SOM_IdFromString("setSound");
  4903.    methodTable = _somGetClassMtab(_somGetClass(myAnimal));
  4904.    offset = _somGetMethodOffset(_somGetClass(myAnimal), somId_setSound);
  4905.    methodPtr = methodTable->entries[offset];
  4906.    methodPtr(myAnimal, "Roar!!!");
  4907. /* --------------------------------------- */
  4908.    _display(myAnimal);
  4909.    _somFree(myAnimal);
  4910. }
  4911. /*
  4912. Program Output:
  4913. This Animal says
  4914. Roar!!!
  4915. */
  4916.  
  4917.  
  4918. ΓòÉΓòÉΓòÉ 8.18. somGetClassName ΓòÉΓòÉΓòÉ
  4919.  
  4920.  
  4921. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  4922.  
  4923. Topics: 
  4924.  
  4925. Call Syntax 
  4926. Uses 
  4927. Parameters 
  4928. Return Value 
  4929. Errors 
  4930. Notes 
  4931. Related Methods 
  4932. Example 
  4933. Glossary 
  4934.  
  4935.  
  4936. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  4937.  
  4938.   /* Class:  SOMObject
  4939.   * Method: somGetClassName
  4940.   *
  4941.   * Obtain the name of the class of an object.
  4942.   */
  4943.   #include <som.h>
  4944.  
  4945.   SOMAny *receiver;
  4946.   zString className;
  4947.  
  4948.   className = _somGetClassName (receiver);
  4949.  
  4950.  
  4951. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  4952.  
  4953. This method returns the address of a zero-terminated string that gives the name 
  4954. of the class of the receiving object. 
  4955.  
  4956.  
  4957. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  4958.  
  4959. receiver    The object whose class name is desired. 
  4960.  
  4961.  
  4962. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  4963.  
  4964. Returns a pointer to the name of the class. 
  4965.  
  4966.  
  4967. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  4968.  
  4969. This method is not generally overridden. The address returned is valid until 
  4970. the object's class object is unregistered or freed. 
  4971.  
  4972.  
  4973. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  4974.  
  4975. somGetClass 
  4976.  
  4977.  
  4978. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  4979.  
  4980. #include "animal.h"
  4981. main()
  4982. {
  4983.   Animal *myAnimal;
  4984.   SOMClass *animalClass;
  4985.   char *className;
  4986.  
  4987.   myAnimal = AnimalNew();
  4988.   className = _somGetClassName(myAnimal);
  4989.   somPrintf("Class name: %s\n", className);
  4990.   _somFree(myAnimal);
  4991. }
  4992. /*
  4993. Output from this program:
  4994. Class name: Animal
  4995. */
  4996.  
  4997.  
  4998. ΓòÉΓòÉΓòÉ 8.19. somGetInitFunction ΓòÉΓòÉΓòÉ
  4999.  
  5000.  
  5001. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  5002.  
  5003. Topics: 
  5004.  
  5005. Call Syntax 
  5006. Uses 
  5007. Parameters 
  5008. Return Value 
  5009. Errors 
  5010. Notes 
  5011. Related Methods 
  5012. Glossary 
  5013.  
  5014.  
  5015. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  5016.  
  5017.   /* Class:  SOMClassMgr
  5018.   * Method: somGetInitFunction
  5019.   *
  5020.   * Obtain the name of the function that
  5021.   * initializes the SOM classes in a DLL.
  5022.   */
  5023.   #include <som.h>
  5024.  
  5025.   SOMClassMgr *receiver;
  5026.   zString initFunction;
  5027.  
  5028.   initFunction = _somGetInitFunction (receiver);
  5029.  
  5030.  
  5031. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  5032.  
  5033. Supplies the name of the initialization function for a DLL containing more than 
  5034. one SOM class. 
  5035.  
  5036.  
  5037. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  5038.  
  5039. receiver    Usually SOMClassMgrObject (or an instance of a user-supplied 
  5040.             subclass of SOMClassMgr). 
  5041.  
  5042.  
  5043. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  5044.  
  5045. This method returns the zero-terminated string obtained from 
  5046. (*SOMClassInitFuncName)(). By default, this exit is set to return the value, 
  5047. "SOMInitModule". 
  5048.  
  5049.  
  5050. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  5051.  
  5052. This method is used by SOMClassMgrObject when it loads a DLL. If the DLL 
  5053. contains an entry point with a matching name, that function is invoked to 
  5054. initialize all of the SOM classes in the DLL.  If the DLL does not contain a 
  5055. matching entry point, an entry-point name of the form <className>NewClass is 
  5056. invoked.  Here <className> is the name of the class known to exist in the DLL. 
  5057.  
  5058. Because of this behavior, if you place only a single SOM class in a DLL, its 
  5059. "NewClass" routine (produced by the SOM Compiler) will be invoked automatically 
  5060. to build the class object when the DLL is loaded. If you package more than one 
  5061. SOM class in a single DLL, you must also supply a C-language function named 
  5062. SOMInitModule (or whatever name is ultimately supplied by the 
  5063. somGetInitFunction method) to invoke the class creation routines for all of the 
  5064. classes packaged in the DLL. 
  5065.  
  5066. Generally speaking, this is not a method that you would ever invoke yourself. 
  5067. But if you were creating a class derived from SOMClassMgr, you might wish to 
  5068. override this method to define your own convention for functions that 
  5069. initialize class DLLs. 
  5070.  
  5071.  
  5072. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  5073.  
  5074. somFindClass 
  5075. somFindClsInFile 
  5076.  
  5077.  
  5078. ΓòÉΓòÉΓòÉ 8.20. somGetInstanceOffset ΓòÉΓòÉΓòÉ
  5079.  
  5080.  
  5081. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  5082.  
  5083. Topics: 
  5084.  
  5085. Call Syntax 
  5086. Uses 
  5087. Parameters 
  5088. Return Value 
  5089. Errors 
  5090. Notes 
  5091. Related Methods 
  5092. Example 
  5093. Glossary 
  5094.  
  5095.  
  5096. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  5097.  
  5098.   /* Class:  SOMClass
  5099.   * Method: somGetInstanceOffset
  5100.   *
  5101.   * Obtain the offset of a class' instance data
  5102.   * in all of its object instances.
  5103.   */
  5104.   #include <som.h>
  5105.  
  5106.   SOMClass *receiver;
  5107.   integer4 offset;
  5108.  
  5109.   offset = _somGetInstanceOffset (receiver);
  5110.  
  5111.  
  5112. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  5113.  
  5114. This method returns the offset in the body portion of all objects of this class 
  5115. where the class' instance data can be found. 
  5116.  
  5117.  
  5118. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  5119.  
  5120. receiver    The class object whose instance-data offset is desired. 
  5121.  
  5122.  
  5123. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  5124.  
  5125. Returns the offset (within any object of the receiving class) of the class' 
  5126. instance data. More precisely, this method returns the offset in the body part 
  5127. of instances of this class for the instance data introduced by this class, as 
  5128. the distance in bytes along the class' "left-hand" derivation path. This value 
  5129. is only meaningful For classes in a single-inheritance hierarchy. 
  5130.  
  5131. If a class has no instance data, the value 0 is returned. Use 
  5132. somGetInstancePartSize to determine if any instance data actually exists. 
  5133.  
  5134.  
  5135. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  5136.  
  5137. This method is not generally overridden. Whenever possible avoid relying on 
  5138. this type of mechanism to access an object's instance data.  Such "back door" 
  5139. access to the internals of an object weakens its ability to encapsulate its 
  5140. implementation, and will not extend in any meaningful way to future class 
  5141. hierarchies which may may use of multiple inheritance. The method is provided 
  5142. for the internal use by the SOM run-time. 
  5143.  
  5144.  
  5145. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  5146.  
  5147. somGetInstancePartSize 
  5148. somGetInstanceSize 
  5149.  
  5150.  
  5151. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  5152.  
  5153. #include "animal.h"
  5154. main()
  5155. {
  5156.   Animal *myAnimal;
  5157.   SOMClass *animalClass;
  5158.   int instanceSize;
  5159.   int instanceOffset;
  5160.   int instancePartSize;
  5161.  
  5162.   myAnimal = AnimalNew ();
  5163.   animalClass = _somGetClass (myAnimal);
  5164.   instanceSize = _somGetInstanceSize (animalClass);
  5165.   instanceOffset = _somGetInstanceOffset (animalClass);
  5166.   instancePartSize = _somGetInstancePartSize (animalClass);
  5167.   somPrintf ("Instance Size: %d\n", instanceSize);
  5168.   somPrintf ("Instance Offset: %d\n", instanceOffset);
  5169.   somPrintf ("Instance Part Size: %d\n", instancePartSize);
  5170.   _somFree (myAnimal);
  5171. }
  5172. /*
  5173. Output from this program:
  5174. Instance Size: 8
  5175. Instance Offset: 0
  5176. Instance Part Size: 4
  5177. */
  5178.  
  5179.  
  5180. ΓòÉΓòÉΓòÉ 8.21. somGetInstancePartSize ΓòÉΓòÉΓòÉ
  5181.  
  5182.  
  5183. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  5184.  
  5185. Topics: 
  5186.  
  5187. Call Syntax 
  5188. Uses 
  5189. Parameters 
  5190. Return Value 
  5191. Errors 
  5192. Notes 
  5193. Related Methods 
  5194. Example 
  5195. Glossary 
  5196.  
  5197.  
  5198. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  5199.  
  5200.   /* Class:  SOMClass
  5201.   * Method: somGetInstancePartSize
  5202.   *
  5203.   * Obtain the size of a class' instance-data
  5204.   * section in all of its object instances.
  5205.   */
  5206.   #include <som.h>
  5207.  
  5208.   SOMClass *receiver;
  5209.   integer4 size;
  5210.  
  5211.   size = _somGetInstancePartSize (receiver);
  5212.  
  5213.  
  5214. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  5215.  
  5216. This method returns the amount of space needed in an object of this class to 
  5217. contain the class' instance data. 
  5218.  
  5219.  
  5220. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  5221.  
  5222. receiver    The class object whose instance-data size is desired. 
  5223.  
  5224.  
  5225. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  5226.  
  5227. Returns the size, in bytes, of the instance data required for this class. This 
  5228. does not include the instance-data space required for this class's ancestor or 
  5229. descendent classes. 
  5230.  
  5231. If a class has no instance data, 0 is returned. 
  5232.  
  5233.  
  5234. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  5235.  
  5236. This method is not generally overridden. 
  5237.  
  5238.  
  5239. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  5240.  
  5241. somGetInstanceOffset 
  5242. somGetInstanceSize 
  5243.  
  5244.  
  5245. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  5246.  
  5247. #include "animal.h"
  5248. main()
  5249. {
  5250.   Animal *myAnimal;
  5251.   SOMClass *animalClass;
  5252.   int instanceSize;
  5253.   int instanceOffset;
  5254.   int instancePartSize;
  5255.  
  5256.   myAnimal = AnimalNew ();
  5257.   animalClass = _somGetClass (myAnimal);
  5258.   instanceSize = _somGetInstanceSize (animalClass);
  5259.   instanceOffset = _somGetInstanceOffset (animalClass);
  5260.   instancePartSize = _somGetInstancePartSize (animalClass);
  5261.   somPrintf ("Instance Size: %d\n", instanceSize);
  5262.   somPrintf ("Instance Offset: %d\n", instanceOffset);
  5263.   somPrintf ("Instance Part Size: %d\n", instancePartSize);
  5264.   _somFree (myAnimal);
  5265. }
  5266. /*
  5267. Output from this program:
  5268. Instance Size: 8
  5269. Instance Offset: 0
  5270. Instance Part Size: 4
  5271. */
  5272.  
  5273.  
  5274. ΓòÉΓòÉΓòÉ 8.22. somGetInstanceSize ΓòÉΓòÉΓòÉ
  5275.  
  5276.  
  5277. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  5278.  
  5279. Topics: 
  5280.  
  5281. Call Syntax 
  5282. Uses 
  5283. Parameters 
  5284. Return Value 
  5285. Errors 
  5286. Notes 
  5287. Related Methods 
  5288. Example 
  5289. Glossary 
  5290.  
  5291.  
  5292. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  5293.  
  5294.   /* Class:  SOMClass
  5295.   * Method: somGetInstanceSize
  5296.   *
  5297.   * Obtain the size of an instance of
  5298.   * the receiving class
  5299.   */
  5300.   #include <som.h>
  5301.  
  5302.   SOMClass *receiver;
  5303.   integer4 size;
  5304.  
  5305.   size = _somGetInstanceSize (receiver);
  5306.  
  5307.  
  5308. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  5309.  
  5310. This method returns the total amount of space needed in an object of this 
  5311. class. 
  5312.  
  5313.  
  5314. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  5315.  
  5316. receiver    The class object whose instance size is desired. 
  5317.  
  5318.  
  5319. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  5320.  
  5321. Returns the size, in bytes, of each instance of this class. This includes the 
  5322. instance-data space required for this class and all of its ancestor classes. 
  5323.  
  5324.  
  5325. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  5326.  
  5327. This method is not generally overridden. 
  5328.  
  5329.  
  5330. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  5331.  
  5332. somGetInstanceOffset 
  5333. somGetInstancePartSize 
  5334.  
  5335.  
  5336. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  5337.  
  5338. #include "animal.h"
  5339. main()
  5340. {
  5341.   Animal *myAnimal;
  5342.   SOMClass *animalClass;
  5343.   int instanceSize;
  5344.   int instanceOffset;
  5345.   int instancePartSize;
  5346.  
  5347.   myAnimal = AnimalNew ();
  5348.   animalClass = _somGetClass (myAnimal);
  5349.   instanceSize = _somGetInstanceSize (animalClass);
  5350.   instanceOffset = _somGetInstanceOffset (animalClass);
  5351.   instancePartSize = _somGetInstancePartSize (animalClass);
  5352.   somPrintf ("Instance Size: %d\n", instanceSize);
  5353.   somPrintf ("Instance Offset: %d\n", instanceOffset);
  5354.   somPrintf ("Instance Part Size: %d\n", instancePartSize);
  5355.   _somFree (myAnimal);
  5356. }
  5357. /*
  5358. Output from this program:
  5359. Instance Size: 8
  5360. Instance Offset: 0
  5361. Instance Part Size: 4
  5362. */
  5363.  
  5364.  
  5365. ΓòÉΓòÉΓòÉ 8.23. somGetName ΓòÉΓòÉΓòÉ
  5366.  
  5367.  
  5368. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  5369.  
  5370. Topics: 
  5371.  
  5372. Call Syntax 
  5373. Uses 
  5374. Parameters 
  5375. Return Value 
  5376. Errors 
  5377. Notes 
  5378. Related Methods 
  5379. Example 
  5380. Glossary 
  5381.  
  5382.  
  5383. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  5384.  
  5385.   /* Class:  SOMClass
  5386.   * Method: somGetName
  5387.   *
  5388.   * Obtain the name of a class.
  5389.   */
  5390.   #include <som.h>
  5391.  
  5392.   SOMClass *receiver;
  5393.   zString className;
  5394.  
  5395.   className = _somGetName (receiver);
  5396.  
  5397.  
  5398. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  5399.  
  5400. This method returns the address of a zero-terminated string that gives the name 
  5401. of the receiving class. 
  5402.  
  5403.  
  5404. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  5405.  
  5406. receiver    The class whose name is desired. 
  5407.  
  5408.  
  5409. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  5410.  
  5411. Returns a pointer to the name of the class. 
  5412.  
  5413.  
  5414. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  5415.  
  5416. This method is not generally overridden. The returned address is valid until 
  5417. the class object is unregistered or freed. 
  5418.  
  5419.  
  5420. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  5421.  
  5422. somGetClass 
  5423. somGetClassName 
  5424.  
  5425.  
  5426. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  5427.  
  5428. #include "animal.h"
  5429. main()
  5430. {
  5431.   Animal *myAnimal;
  5432.   SOMClass *animalClass;
  5433.   char *className;
  5434.  
  5435.   myAnimal = AnimalNew();
  5436.   animalClass = _somGetClass(myAnimal);
  5437.   className = _somGetName(animalClass);
  5438.   somPrintf("Class Name: %s\n", className);
  5439.   _somFree(myAnimal);
  5440. }
  5441. /*
  5442. Output from this program:
  5443. Class Name: Animal
  5444. */
  5445.  
  5446.  
  5447. ΓòÉΓòÉΓòÉ 8.24. somGetNumMethods ΓòÉΓòÉΓòÉ
  5448.  
  5449.  
  5450. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  5451.  
  5452. Topics: 
  5453.  
  5454. Call Syntax 
  5455. Uses 
  5456. Parameters 
  5457. Return Value 
  5458. Errors 
  5459. Notes 
  5460. Related Methods 
  5461. Example 
  5462. Glossary 
  5463.  
  5464.  
  5465. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  5466.  
  5467.   /* Class:  SOMClass
  5468.   * Method: somGetNumMethods
  5469.   *
  5470.   * Obtain the number of methods
  5471.   * available for the receiving class.
  5472.   */
  5473.   #include <som.h>
  5474.  
  5475.   SOMClass *receiver;
  5476.   int methodCount;
  5477.  
  5478.   methodCount = _somGetNumMethods (receiver);
  5479.  
  5480.  
  5481. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  5482.  
  5483. This method returns the number of methods currently supported by this class, 
  5484. including inherited methods (both static and dynamic). 
  5485.  
  5486.  
  5487. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  5488.  
  5489. receiver    The class object whose method count is desired. 
  5490.  
  5491.  
  5492. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  5493.  
  5494. The total number of methods that are currently available for the receiving 
  5495. class. 
  5496.  
  5497.  
  5498. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  5499.  
  5500. The value returned by this method is the total number of methods currently 
  5501. registered in the receiving class, including static and dynamic methods, 
  5502. whether defined in this class or inherited from a parent class. Because SOM 
  5503. classes are dynamic, other dynamic methods can be added to the class. 
  5504. Furthermore, if the class uses dispatch method resolution, all dynamic methods 
  5505. available in this class might not be formally registered.  That is, the 
  5506. dispatch function can permit access to additional methods. 
  5507.  
  5508. This method is not generally overridden. 
  5509.  
  5510.  
  5511. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  5512.  
  5513. somGetNumStaticMethods 
  5514.  
  5515.  
  5516. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  5517.  
  5518. #include "animal.h"
  5519. main()
  5520. {
  5521.   Animal *myAnimal;
  5522.   int numMethods;
  5523.  
  5524.   myAnimal = AnimalNew();
  5525.   numMethods = _somGetNumMethods(_Animal);
  5526.   somPrintf("Number of methods supported by class: %d\n", numMethods);
  5527.   _somFree(myAnimal);
  5528. }
  5529. /*
  5530. Output from this program:
  5531. Number of methods supported by class: 24
  5532. */
  5533.  
  5534.  
  5535. ΓòÉΓòÉΓòÉ 8.25. somGetNumStaticMethods ΓòÉΓòÉΓòÉ
  5536.  
  5537.  
  5538. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  5539.  
  5540. Topics: 
  5541.  
  5542. Call Syntax 
  5543. Uses 
  5544. Parameters 
  5545. Return Value 
  5546. Errors 
  5547. Notes 
  5548. Related Methods 
  5549. Example 
  5550. Glossary 
  5551.  
  5552.  
  5553. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  5554.  
  5555.   /* Class:  SOMClass
  5556.   * Method: somGetNumStaticMethods
  5557.   *
  5558.   * Obtain the number of static methods
  5559.   * available for the receiving class.
  5560.   */
  5561.   #include <som.h>
  5562.  
  5563.   SOMClass *receiver;
  5564.   int methodCount;
  5565.  
  5566.   methodCount = _somGetNumStaticMethods (receiver);
  5567.  
  5568.  
  5569. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  5570.  
  5571. This method returns the number of static methods available in this class, 
  5572. including inherited ones. 
  5573.  
  5574.  
  5575. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  5576.  
  5577. receiver    The class object whose static method count is desired. 
  5578.  
  5579.  
  5580. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  5581.  
  5582. The total number of static methods that are available for the receiving class. 
  5583.  
  5584.  
  5585. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  5586.  
  5587. Static methods are those that can be accessed through the offset resolution 
  5588. mechanism. 
  5589.  
  5590. This method is not generally overridden. 
  5591.  
  5592.  
  5593. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  5594.  
  5595. somGetNumMethods 
  5596.  
  5597.  
  5598. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  5599.  
  5600. #include "animal.h"
  5601. main()
  5602. {
  5603.   Animal *myAnimal;
  5604.   SOMClass *animalClass;
  5605.   int nStaticMethods;
  5606.  
  5607.   myAnimal = AnimalNew();
  5608.   animalClass = _somGetClass(myAnimal);
  5609.   nStaticMethods = _somGetNumStaticMethods(animalClass);
  5610.   somPrintf("Number of static methods: %d\n", nStaticMethods);
  5611.   _somFree(myAnimal);
  5612. }
  5613. /*
  5614. Output from this program:
  5615. Number of static methods: 24
  5616. */
  5617.  
  5618.  
  5619. ΓòÉΓòÉΓòÉ 8.26. somGetParent ΓòÉΓòÉΓòÉ
  5620.  
  5621.  
  5622. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  5623.  
  5624. Topics: 
  5625.  
  5626. Call Syntax 
  5627. Uses 
  5628. Parameters 
  5629. Return Value 
  5630. Errors 
  5631. Notes 
  5632. Related Methods 
  5633. Example 
  5634. Glossary 
  5635.  
  5636.  
  5637. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  5638.  
  5639.   /* Class:  SOMClass
  5640.   * Method: somGetParent
  5641.   *
  5642.   * Get a pointer to the class' parent class.
  5643.   */
  5644.   #include <som.h>
  5645.  
  5646.   SOMClass *receiver;
  5647.   SOMClass *parent;
  5648.  
  5649.   parent = _somGetParent (receiver);
  5650.  
  5651.  
  5652. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  5653.  
  5654. Obtain a pointer to the parent class of the receiver (if a parent exists) and 
  5655. NULL otherwise. If a class has multiple parents, this method returns the parent 
  5656. class along the "left-hand" derivation path. 
  5657.  
  5658.  
  5659. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  5660.  
  5661. receiver    The class whose parent class is desired. 
  5662.  
  5663.  
  5664. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  5665.  
  5666. Returns the parent class of the receiver, if one exists, and NULL otherwise. 
  5667.  
  5668.  
  5669. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  5670.  
  5671. Because all SOM objects inherit from SOMObject, only the class SOMObject will 
  5672. return NULL. 
  5673.  
  5674.  
  5675. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  5676.  
  5677. somGetClass 
  5678.  
  5679.  
  5680. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  5681.  
  5682. /* Note: dog is derived from animal. */
  5683. #include "dog.h"
  5684. main()
  5685. {
  5686.   Dog *myDog;
  5687.   SOMClass *dogClass;
  5688.   SOMClass *parentClass;
  5689.   char *parentName;
  5690.  
  5691.   myDog = DogNew();
  5692.   dogClass = _somGetClass(myDog);
  5693.   parentClass = _somGetParent(dogClass);
  5694.   parentName = _somGetName(parentClass);
  5695.   somPrintf("Name of Parent Class: %s\n", parentName);
  5696.   _somFree(myDog);
  5697. }
  5698. /*
  5699. Output from this program:
  5700. Name of Parent Class: Animal
  5701. */
  5702.  
  5703.  
  5704. ΓòÉΓòÉΓòÉ 8.27. somGetPClsMtab ΓòÉΓòÉΓòÉ
  5705.  
  5706.  
  5707. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  5708.  
  5709. Topics: 
  5710.  
  5711. Call Syntax 
  5712. Uses 
  5713. Parameters 
  5714. Return Value 
  5715. Errors 
  5716. Notes 
  5717. Related Methods 
  5718. Example 
  5719. Glossary 
  5720.  
  5721.  
  5722. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  5723.  
  5724.   /* Class:  SOMClass
  5725.   * Method: somGetPClsMtab
  5726.   *
  5727.   * Obtain a pointer to the parent class' method table
  5728.   */
  5729.   #include <som.h>
  5730.  
  5731.   SOMClass *receiver;
  5732.   somMethodTab *mtab;
  5733.  
  5734.   mtab = _somGetPClsMtab (receiver);
  5735.  
  5736.  
  5737. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  5738.  
  5739. This method returns the address of the method table for the receiver's parent 
  5740. class. 
  5741.  
  5742.  
  5743. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  5744.  
  5745. receiver    The class object whose parent's method table is desired. 
  5746.  
  5747.  
  5748. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  5749.  
  5750. Returns a pointer to the method table of the parent class of the receiving 
  5751. class. If this class is a root class (SOMObject), NULL is returned. 
  5752.  
  5753.  
  5754. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  5755.  
  5756. This method is equivalent to: 
  5757.  
  5758.     _somGetClassMtab (_somGetParent (receiver))
  5759.  
  5760. This method is not generally overridden. 
  5761.  
  5762. Whenever possible you should avoid writing code that accesses the method table 
  5763. directly, since the specifics of this structure may change in a future release 
  5764. of SOM. 
  5765.  
  5766.  
  5767. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  5768.  
  5769. somGetClassMtab 
  5770. somGetNumStaticMethods 
  5771.  
  5772.  
  5773. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  5774.  
  5775. /* --------------------------------
  5776.    Note: Dog is derived from Animal
  5777.    -------------------------------- */
  5778. #include "dog.h"
  5779. #include "animal.h"
  5780. void main()
  5781. {
  5782.    Dog *myDog;
  5783.    somId somId_setSound;
  5784.    somMethodPtr methodPtr;
  5785.    somMethodTab *methodTable;
  5786.    int offset;
  5787.    myDog = DogNew();
  5788. /* ---------------------------------------
  5789.    Note: Next five lines are equivalent to
  5790.        _setSound(myDog, "Woof");
  5791.    --------------------------------------- */
  5792.    somId_setSound = SOM_IdFromString ("setSound");
  5793.    methodTable = _somGetPClsMtab (_somGetClass (myDog));
  5794.    offset = _somGetMethodOffset (_somGetParent (_somGetClass(myDog)),
  5795.                                  somId_setSound);
  5796.    methodPtr = methodTable->entries[offset];
  5797.    methodPtr(myDog, "Woof");
  5798. /* --------------------------------------- */
  5799.    _display(myDog);
  5800.    _somFree(myDog);
  5801. }
  5802. /*
  5803. Program Output:
  5804. This Animal says
  5805. Woof
  5806. */
  5807.  
  5808.  
  5809. ΓòÉΓòÉΓòÉ 8.28. somGetSize ΓòÉΓòÉΓòÉ
  5810.  
  5811.  
  5812. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  5813.  
  5814. Topics: 
  5815.  
  5816. Call Syntax 
  5817. Uses 
  5818. Parameters 
  5819. Return Value 
  5820. Errors 
  5821. Notes 
  5822. Related Methods 
  5823. Example 
  5824. Glossary 
  5825.  
  5826.  
  5827. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  5828.  
  5829.   /* Class:  SOMObject
  5830.   * Method: somGetSize
  5831.   *
  5832.   * Obtain the size of an object.
  5833.   */
  5834.   #include <som.h>
  5835.  
  5836.   SOMAny *receiver;
  5837.   integer4 size;
  5838.  
  5839.   size = _somGetSize (receiver);
  5840.  
  5841.  
  5842. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  5843.  
  5844. This method returns the total amount of contiguous space used by the receiving 
  5845. object. 
  5846.  
  5847.  
  5848. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  5849.  
  5850. receiver    The object whose size is desired. 
  5851.  
  5852.  
  5853. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  5854.  
  5855. Returns the size in bytes of the receiver. 
  5856.  
  5857.  
  5858. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  5859.  
  5860. The value returned reflects only the amount of storage needed to hold the SOM 
  5861. representation of the object.  The object might actually be using or managing 
  5862. additional space outside of this area. 
  5863.  
  5864. This method is not generally overridden. 
  5865.  
  5866.  
  5867. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  5868.  
  5869. somGetInstancePartSize 
  5870. somGetInstanceSize 
  5871.  
  5872.  
  5873. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  5874.  
  5875. #include "animal.h"
  5876. void main()
  5877. {
  5878.   Animal *myAnimal;
  5879.   int animalSize;
  5880.   myAnimal = AnimalNew();
  5881.   animalSize = _somGetSize(myAnimal);
  5882.   somPrintf("Size of animal (in bytes): %d\n", animalSize);
  5883.   _somFree(myAnimal);
  5884. }
  5885. /*
  5886. Output from this program:
  5887. Size of animal (in bytes): 8
  5888. */
  5889.  
  5890.  
  5891. ΓòÉΓòÉΓòÉ 8.29. somInit ΓòÉΓòÉΓòÉ
  5892.  
  5893.  
  5894. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  5895.  
  5896. Topics: 
  5897.  
  5898. Call Syntax 
  5899. Uses 
  5900. Parameters 
  5901. Return Value 
  5902. Errors 
  5903. Notes 
  5904. Related Methods 
  5905. Example 
  5906. Glossary 
  5907.  
  5908.  
  5909. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  5910.  
  5911.   /* Class:  SOMObject
  5912.   * Method: somInit
  5913.   *
  5914.   * Initializes instance data in a newly created object.
  5915.   */
  5916.   #include <som.h>
  5917.  
  5918.   SOMAny *receiver;
  5919.  
  5920.   _somInit (receiver);
  5921.  
  5922.  
  5923. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  5924.  
  5925. This method is invoked to cause a newly created object to initialize its 
  5926. instance data. 
  5927.  
  5928.  
  5929. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  5930.  
  5931. receiver    The object to be initialized. 
  5932.  
  5933.  
  5934. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  5935.  
  5936. None. 
  5937.  
  5938.  
  5939. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  5940.  
  5941. This method initializes instance data in the receiving object. Because 
  5942. instances of SOMObject do not have any instance data, the default 
  5943. implementation does nothing. It is provided to induce consistency among 
  5944. subclasses that require initialization. This method is called automatically as 
  5945. a side effect of object creation by somNew or somRenew. 
  5946.  
  5947. A companion method (somUninit) is called whenever an object is freed. These two 
  5948. methods should be designed to work together, with somInit priming an object for 
  5949. its first use, and somUninit preparing the object for subsequent release. 
  5950.  
  5951. In general, if objects of your class contain instance-data items, override the 
  5952. somInit method to set your instance data to an appropriate initial state. When 
  5953. overriding this method, always call the parent-class version of this method 
  5954. before doing your own initialization. 
  5955.  
  5956.  
  5957. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  5958.  
  5959. somNew 
  5960. somRenew 
  5961. somUninit 
  5962.  
  5963.  
  5964. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  5965.  
  5966. #  animal2.csc:
  5967.    include <somobj.sc>
  5968.    class: Animal2, local;
  5969.    parent: SOMObject;
  5970.    data:
  5971.      char *sound;
  5972.    methods:
  5973.       void display();
  5974.       override somInit;
  5975.       override somUninit;
  5976.  
  5977. /* animal2.c: */
  5978.    #define Animal2_Class_Source
  5979.    #include "animal2.ih"
  5980.    #include <string.h>
  5981.  
  5982.    SOM_Scope void SOMLINK display (Animal2 *somSelf)
  5983.    {
  5984.        Animal2Data *somThis = Animal2GetData(somSelf);
  5985.    }
  5986.    SOM_Scope void SOMLINK somInit (Animal2 *somSelf)
  5987.    {
  5988.        Animal2Data *somThis = Animal2GetData (somSelf);
  5989.        parent_somInit (somSelf);
  5990.        _sound = (*SOMMalloc)(100);
  5991.        strcpy (_sound, "Unknown Noise");
  5992.        somPrintf ("New Animal Initialized\n");
  5993.    }
  5994.    SOM_Scope void SOMLINK somUninit (Animal2 *somSelf)
  5995.    {
  5996.        Animal2Data *somThis = Animal2GetData (somSelf);
  5997.        (*SOMFree)(_sound);
  5998.        somPrintf ("Animal Uninitialized\n");
  5999.        parent_somUninit (somSelf);
  6000.    }
  6001.  
  6002. /* main program */
  6003.    #include "animal2.h"
  6004.    void main()
  6005.    {
  6006.       Animal2 *myAnimal;
  6007.       myAnimal = Animal2New ();
  6008.       _somFree (myAnimal);
  6009.    }
  6010.  
  6011. /*
  6012. Program output:
  6013. New Animal Initialized
  6014. Animal Uninitialized
  6015. */
  6016.  
  6017.  
  6018. ΓòÉΓòÉΓòÉ 8.30. somInitClass ΓòÉΓòÉΓòÉ
  6019.  
  6020.  
  6021. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  6022.  
  6023. Topics: 
  6024.  
  6025. Call Syntax 
  6026. Uses 
  6027. Parameters 
  6028. Return Value 
  6029. Errors 
  6030. Notes 
  6031. Related Methods 
  6032. Example 
  6033. Glossary 
  6034.  
  6035.  
  6036. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  6037.  
  6038.   /* Class:  SOMClass
  6039.   * Method: somInitClass
  6040.   *
  6041.   * Initializes a newly created class object.
  6042.   */
  6043.   #include <som.h>
  6044.  
  6045.   SOMClass *receiver;
  6046.   SOMClass *parentClass;
  6047.   integer4 instanceSize;
  6048.   int maxStaticMethods;
  6049.   integer4 majorVersion;
  6050.   integer4 minorVersion;
  6051.  
  6052.   _somInitClass (receiver, parentClass, instanceSize,
  6053.           maxStaticMethods, majorVersion, minorVersion);
  6054.  
  6055.  
  6056. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  6057.  
  6058. This method is invoked to complete the construction of a newly created class 
  6059. object. 
  6060.  
  6061.  
  6062. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  6063.  
  6064. receiver    The class to be initialized. 
  6065.  
  6066. parentClass The class that the newly created class will inherit from. If NULL 
  6067.             is specified, this value defaults to SOMObject. Parent classes must 
  6068.             be created prior to the creation of any of their descendant 
  6069.             classes. 
  6070.  
  6071. instanceSize The amount of space needed to hold the instance data defined for 
  6072.             the newly created class.  This value should not include any space 
  6073.             required by parent class(es). 
  6074.  
  6075. maxStaticMethods The number of static methods defined for the new class. It 
  6076.             should not include any static methods defined in the parent 
  6077.             classes, even if some of them have been overridden in this class. 
  6078.  
  6079. majorVersion The major version number associated with the current 
  6080.             implementation of the new class. 
  6081.  
  6082. minorVersion The minor version number associated with the current 
  6083.             implementation of the new class. 
  6084.  
  6085.  
  6086. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  6087.  
  6088. None. 
  6089.  
  6090.  
  6091. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  6092.  
  6093. This method is ordinarily invoked from the <Classname>NewClass procedure 
  6094. generated by the SOM Compiler from the OIDL class definition. Overriding this 
  6095. method with one of your own is not recommended. 
  6096.  
  6097. Generally speaking, most programmers would never make any direct use of this 
  6098. method. It is provided for use by the C-language bindings produced by the SOM 
  6099. Compiler. 
  6100.  
  6101.  
  6102. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  6103.  
  6104. somClassReady 
  6105. somRegisterClass 
  6106.  
  6107.  
  6108. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  6109.  
  6110.    #include <som.h>
  6111.    SOMClass *myParentClass;
  6112.    struct {
  6113.       int a, b, c;
  6114.    } myClassInstanceData;
  6115.    #define MyClass_MaxMethods 4
  6116.    #define MyClass_MajorVersion 2
  6117.    #define MyClass_MinorVersion 1
  6118.    extern struct MyClassClassDataStructure {
  6119.         SOMAny *classObject;
  6120.         somMOffset myMethod1;
  6121.         somMOffset myMethod2;
  6122.         somMOffset myMethod3;
  6123.         somMOffset myMethod4;
  6124.    } MyClassClassData;
  6125.  
  6126.    /* ... */
  6127.    _somInitClass (MyClassClassData.classObject,
  6128.                "Animal",
  6129.                myParentClass,
  6130.                sizeof (myClassInstanceData),
  6131.                MyClass_MaxMethods,
  6132.                MyClass_MajorVersion,
  6133.                MyClass_MinorVersion);
  6134.  
  6135.  
  6136. ΓòÉΓòÉΓòÉ 8.31. somIsA ΓòÉΓòÉΓòÉ
  6137.  
  6138.  
  6139. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  6140.  
  6141. Topics: 
  6142.  
  6143. Call Syntax 
  6144. Uses 
  6145. Parameters 
  6146. Return Value 
  6147. Errors 
  6148. Notes 
  6149. Related Methods 
  6150. Example 
  6151. Glossary 
  6152.  
  6153.  
  6154. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  6155.  
  6156.   /* Class:  SOMObject
  6157.   * Method: somIsA
  6158.   *
  6159.   * Determine if an object is an instance of a given
  6160.   * class (or of one of its descendant classes).
  6161.   */
  6162.   #include <som.h>
  6163.  
  6164.   SOMAny *receiver;
  6165.   SOMClass *aClass;
  6166.   int result;
  6167.  
  6168.   result = _somIsA (receiver, aClass);
  6169.  
  6170.  
  6171. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  6172.  
  6173. Use this method to determine if an object can be treated like an instance of 
  6174. aClass. 
  6175.  
  6176.  
  6177. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  6178.  
  6179. receiver    The object to be tested. 
  6180.  
  6181. aClass      The class that the object should be tested against. 
  6182.  
  6183.  
  6184. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  6185.  
  6186. Returns 1 (true) if the receiving object is an instance of the specified class 
  6187. or of any of its descendant classes, and 0 (false) if otherwise. 
  6188.  
  6189.  
  6190. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  6191.  
  6192. A class object is considered to be descended from itself for the purposes of 
  6193. this method. 
  6194.  
  6195. Because classes are frequently used as a static typing mechanism, this test is 
  6196. really a way of ascertaining if an object is of a particular static type. 
  6197.  
  6198.  
  6199. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  6200.  
  6201. somIsDescendedFrom 
  6202. somIsInstanceOf 
  6203.  
  6204.  
  6205. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  6206.  
  6207. #include "animal.h"
  6208. #include "dog.h"
  6209. /* --------------------------------
  6210.    Note: Dog is derived from Animal.
  6211.    -------------------------------- */
  6212. main()
  6213. {
  6214.   Animal *myAnimal;
  6215.   Dog *myDog;
  6216.   SOMClass *animalClass;
  6217.   SOMClass *dogClass;
  6218.  
  6219.   myAnimal = AnimalNew();
  6220.   myDog = DogNew();
  6221.   animalClass = _somGetClass (myAnimal);
  6222.   dogClass = _somGetClass (myDog);
  6223.   if (_somIsA (myDog, animalClass))
  6224.      somPrintf ("myDog IS an Animal\n");
  6225.   else
  6226.      somPrintf ("myDog IS NOT an Animal\n");
  6227.   if (_somIsA (myAnimal, dogClass))
  6228.      somPrintf ("myAnimal IS a Dog\n");
  6229.   else
  6230.      somPrintf ("myAnimal IS NOT a Dog\n");
  6231.   _somFree (myAnimal);
  6232. }
  6233. /*
  6234. Output from this program:
  6235. myDog IS an Animal
  6236. myAnimal IS NOT a Dog
  6237. */
  6238.  
  6239.  
  6240. ΓòÉΓòÉΓòÉ 8.32. somIsInstanceOf ΓòÉΓòÉΓòÉ
  6241.  
  6242.  
  6243. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  6244.  
  6245. Topics: 
  6246.  
  6247. Call Syntax 
  6248. Uses 
  6249. Parameters 
  6250. Return Value 
  6251. Errors 
  6252. Notes 
  6253. Related Methods 
  6254. Example 
  6255. Glossary 
  6256.  
  6257.  
  6258. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  6259.  
  6260.   /* Class:  SOMObject
  6261.   * Method: somIsInstanceOf
  6262.   *
  6263.   * Determine if an object is an instance of a
  6264.   * specific class.
  6265.   */
  6266.   #include <som.h>
  6267.  
  6268.   SOMAny *receiver;
  6269.   SOMClass *aClass;
  6270.   int result;
  6271.  
  6272.   result = _somIsInstanceOf (receiver, aClass);
  6273.  
  6274.  
  6275. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  6276.  
  6277. Use this method to determine if an object is an instance of a specific class. 
  6278.  
  6279.  
  6280. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  6281.  
  6282. receiver    The object to be tested. 
  6283.  
  6284. aClass      The class that the object should be an instance of. 
  6285.  
  6286.  
  6287. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  6288.  
  6289. Returns 1 (true) if the receiving object is an instance of the specified class, 
  6290. and 0 (false) if otherwise. 
  6291.  
  6292.  
  6293. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  6294.  
  6295. This method tests an object for inclusion in one specific class. It is 
  6296. equivalent to the expression: 
  6297.  
  6298.     (aClass == somGetClass (receiver))
  6299.  
  6300.  
  6301. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  6302.  
  6303. somIsDescendedFrom 
  6304. somIsA 
  6305.  
  6306.  
  6307. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  6308.  
  6309. #include "animal.h"
  6310. #include "dog.h"
  6311. /* --------------------------------
  6312.    Note: Dog is derived from Animal.
  6313.    -------------------------------- */
  6314. main()
  6315. {
  6316.   Animal *myAnimal;
  6317.   Dog *myDog;
  6318.   SOMClass *animalClass;
  6319.   SOMClass *dogClass;
  6320.  
  6321.   myAnimal = AnimalNew ();
  6322.   myDog = DogNew ();
  6323.   animalClass = _somGetClass (myAnimal);
  6324.   dogClass = _somGetClass (myDog);
  6325.   if (_somIsInstanceOf (myDog, animalClass))
  6326.      somPrintf ("myDog is an instance of Animal\n");
  6327.   if (_somIsInstanceOf (myDog, dogClass))
  6328.      somPrintf ("myDog is an instance of Dog\n");
  6329.   if (_somIsInstanceOf (myAnimal, animalClass))
  6330.      somPrintf ("myAnimal is an instance of Animal\n");
  6331.   if (_somIsInstanceOf (myAnimal, dogClass))
  6332.      somPrintf ("myAnimal is an instance of Dog\n");
  6333.   _somFree (myAnimal);
  6334.   _somFree (myDog);
  6335. }
  6336. /*
  6337. Output from this program:
  6338. myDog is an instance of Dog
  6339. myAnimal is an instance of Animal
  6340. */
  6341.  
  6342.  
  6343. ΓòÉΓòÉΓòÉ 8.33. somLoadClassFile ΓòÉΓòÉΓòÉ
  6344.  
  6345.  
  6346. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  6347.  
  6348. Topics: 
  6349.  
  6350. Call Syntax 
  6351. Uses 
  6352. Parameters 
  6353. Return Value 
  6354. Errors 
  6355. Notes 
  6356. Related Methods 
  6357. Glossary 
  6358.  
  6359.  
  6360. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  6361.  
  6362.   /* Class:  SOMClassMgr
  6363.   * Method: somLoadClassFile
  6364.   *
  6365.   * Dynamically load a class.
  6366.   */
  6367.   #include <som.h>
  6368.  
  6369.   SOMClassMgr *receiver;
  6370.   somId classId;
  6371.   int majorVersion;
  6372.   int minorVersion;
  6373.   zString file;
  6374.   SOMClass *class;
  6375.  
  6376.   class = _somLoadClassFile (receiver, classId, majorVersion,
  6377.                minorVersion, file);
  6378.  
  6379.  
  6380. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  6381.  
  6382. The SOMClassMgr object uses this method to load a class dynamically during the 
  6383. processing of somFindClass or somFindClsInFile. A SOM class object representing 
  6384. the class is expected to be created and registered as a result of this action. 
  6385.  
  6386.  
  6387. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  6388.  
  6389. receiver    Usually SOMClassMgrObject (or an instance of a user-supplied 
  6390.             subclass of SOMClassMgr). 
  6391.  
  6392. classId     The ID representing the name of the class to load. 
  6393.  
  6394. majorVersion The major version number used to check the compatibility of the 
  6395.             class' implementation with the caller's expectations. 
  6396.  
  6397. minorVersion The minor version number used to check the compatibility of the 
  6398.             class' implementation with the caller's expectations. 
  6399.  
  6400. file        The name of the DLL file containing the class. The name can be 
  6401.             either a simple, unqualified name, without any extension (in which 
  6402.             case the OS/2* LIBPATH is searched for a file with the extension, 
  6403.             .DLL) or a fully-qualified file name (in which case the OS/2* 
  6404.             LIBPATH is not searched). 
  6405.  
  6406.  
  6407. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  6408.  
  6409. Returns a pointer to the class object, or NULL if the class could not be 
  6410. loaded, or the class object could not be created. 
  6411.  
  6412.  
  6413. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  6414.  
  6415. You can override this method to load or create classes dynamically using your 
  6416. own mechanisms, rather than using the DLL approach supplied with SOM. If you 
  6417. simply wish to change the name of the DLL procedure that is called to 
  6418. initialize the classes in the DLL, override somGetInitFunction instead. 
  6419.  
  6420. Generally speaking, you will probably never need to make any direct use of this 
  6421. method. Use somFindClass or somFindClsInFile instead. 
  6422.  
  6423.  
  6424. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  6425.  
  6426. somFindClass 
  6427. somFindClsInFile 
  6428. somGetInitFunction 
  6429. somUnloadClassFile 
  6430.  
  6431.  
  6432. ΓòÉΓòÉΓòÉ 8.34. somLocateClassFile ΓòÉΓòÉΓòÉ
  6433.  
  6434.  
  6435. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  6436.  
  6437. Topics: 
  6438.  
  6439. Call Syntax 
  6440. Uses 
  6441. Parameters 
  6442. Return Value 
  6443. Errors 
  6444. Notes 
  6445. Related Methods 
  6446. Glossary 
  6447.  
  6448.  
  6449. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  6450.  
  6451.   /* Class:  SOMClassMgr
  6452.   * Method: somLocateClassFile
  6453.   *
  6454.   * Determine the file that holds a
  6455.   * class to be dynamically loaded.
  6456.   */
  6457.   #include <som.h>
  6458.  
  6459.   SOMClassMgr *receiver;
  6460.   somId classId;
  6461.   int majorVersion;
  6462.   int minorVersion;
  6463.   zString file;
  6464.  
  6465.   file = _somLocateClassFile (receiver, classId, majorVersion,
  6466.                 minorVersion);
  6467.  
  6468.  
  6469. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  6470.  
  6471. The SOMClassMgr object uses this method during somFindclass processing to 
  6472. obtain the name of a file to use when dynamically loading a class. 
  6473.  
  6474.  
  6475. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  6476.  
  6477. receiver    Usually SOMClassMgrObject (or an instance of a user-supplied 
  6478.             subclass of SOMClassMgr). 
  6479.  
  6480. classId     The ID representing the name of the class to locate. 
  6481.  
  6482. majorVersion The major version number used to check the compatibility of the 
  6483.             class' implementation with the caller's expectations. 
  6484.  
  6485. minorVersion The minor version number used to check the compatibility of the 
  6486.             class' implementation with the caller's expectations. 
  6487.  
  6488.  
  6489. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  6490.  
  6491. Returns the name of the DLL file containing the class. The default 
  6492. implementation in SOMClassMgr simply returns the name of the class. 
  6493.  
  6494.  
  6495. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  6496.  
  6497. If you override this method in a user-supplied subclass the name you return can 
  6498. be either a simple, unqualified name without any extension (in which case the 
  6499. OS/2* LIBPATH is searched for a file with the extension, .DLL) or a 
  6500. fully-qualified file name (in which case the OS/2* LIBPATH is not searched). 
  6501.  
  6502. Generally speaking, you would not invoke this method directly. It is provided 
  6503. to permit customization of SOMClassMgr through subclassing. 
  6504.  
  6505.  
  6506. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  6507.  
  6508. somFindClass 
  6509. somFindClsInFile 
  6510. somGetInitFunction 
  6511. somLoadClassFile 
  6512. somUnloadClassFile 
  6513.  
  6514.  
  6515. ΓòÉΓòÉΓòÉ 8.35. somMergeInto ΓòÉΓòÉΓòÉ
  6516.  
  6517.  
  6518. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  6519.  
  6520. Topics: 
  6521.  
  6522. Call Syntax 
  6523. Uses 
  6524. Parameters 
  6525. Return Value 
  6526. Errors 
  6527. Notes 
  6528. Related Methods 
  6529. Example 
  6530. Glossary 
  6531.  
  6532.  
  6533. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  6534.  
  6535.   /* Class:  SOMClassMgr
  6536.   * Method: somMergeInto
  6537.   *
  6538.   * Transfers SOM class registry to
  6539.   * another SOMClassMgr instance.
  6540.   */
  6541.   #include <som.h>
  6542.  
  6543.   SOMClassMgr *receiver;
  6544.   SOMClassMgr *target;
  6545.  
  6546.   _somMergeInto (receiver, target);
  6547.  
  6548.  
  6549. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  6550.  
  6551. This method transfers the SOMClassMgr registry information from the receiver to 
  6552. the target. The target object is required to be an instance of SOMClassMgr or 
  6553. one of its subclasses. At the completion of this operation, the target object 
  6554. can function as a replacement for the receiver; the receiver object (which is 
  6555. then in a newly uninitialized state) is freed. If the receiving object is the 
  6556. distinguished instance pointed to from the global variable, SOMClassMgrObject, 
  6557. SOMCLassMgrObject is then reassigned to point to the target object. 
  6558.  
  6559.  
  6560. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  6561.  
  6562. receiver    Usually SOMClassMgrObject (or an instance of a user-supplied 
  6563.             subclass of SOMClassMgr). 
  6564.  
  6565. target      Another instance of SOMClassMgr or one of its subclasses. 
  6566.  
  6567.  
  6568. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  6569.  
  6570. None. 
  6571.  
  6572.  
  6573. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  6574.  
  6575. Subclasses that override this method should also transfer their section of the 
  6576. object, then pass this method to their parent as the final step. 
  6577.  
  6578. Use this method only if you are creating your own special-purpose SOMClassMgr 
  6579. with a derived class. Invoke somMergeInto from your override of the SOMClassMgr 
  6580. somNew method. 
  6581.  
  6582.  
  6583. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  6584.  
  6585. None. 
  6586.  
  6587.  
  6588. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  6589.  
  6590.    /*
  6591.     * The following example is a hypothetical
  6592.     * implementation of an override of the somNew method
  6593.     * in a subclass of SOMClassMgr.  It illustrates the
  6594.     * proper use of the somMergeInto method.
  6595.     */
  6596.    SOM_Scope SOMAny * SOMLINK somNew (MySOMClassMgr *somSelf)
  6597.    {
  6598.        SOMAny *newInstance;
  6599.        static int firstTime = 1;
  6600.        /*
  6601.         * Permit only one instance of MySOMClassMgr to be created.
  6602.         */
  6603.        if (!firstTime)
  6604.           return (SOMClassMgrObject);
  6605.        newInstance = parent_somNew (somSelf);
  6606.        /*
  6607.         * The next line will transfer the class registry
  6608.         * information from SOMClassMgrObject into our
  6609.         * new instance.
  6610.         */
  6611.        _somMergeInto (SOMClassMgrObject, newInstance);
  6612.        /* As a result of the above operation
  6613.         * SOMClassMgrObject is now set to point to the
  6614.         * new instance of MySOMClassMgr.
  6615.         */
  6616.        firstTime = 0;
  6617.        return (newInstance);
  6618.    }
  6619.  
  6620.  
  6621. ΓòÉΓòÉΓòÉ 8.36. somNew ΓòÉΓòÉΓòÉ
  6622.  
  6623.  
  6624. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  6625.  
  6626. Topics: 
  6627.  
  6628. Call Syntax 
  6629. Uses 
  6630. Parameters 
  6631. Return Value 
  6632. Errors 
  6633. Notes 
  6634. Related Methods 
  6635. Example 
  6636. Glossary 
  6637.  
  6638.  
  6639. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  6640.  
  6641.   /* Class:  SOMClass
  6642.   * Method: somNew
  6643.   *
  6644.   * Create a new object instance.
  6645.   */
  6646.   #include <som.h>
  6647.  
  6648.   SOMClass *receiver;
  6649.   SOMAny *newObject;
  6650.  
  6651.   newObject = _somNew (receiver);
  6652.  
  6653.  
  6654. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  6655.  
  6656. This method creates a new initialized instance of the receiving class. 
  6657.  
  6658.  
  6659. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  6660.  
  6661. receiver    The class object that is to create a new instance. 
  6662.  
  6663.  
  6664. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  6665.  
  6666. A pointer to the newly created object. 
  6667.  
  6668.  
  6669. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  6670.  
  6671. When this method is applied to the class, SOMClass, or to any other metaclass 
  6672. object, it produces a new class object; when applied to a regular class object, 
  6673. it produces an instance of that class. 
  6674.  
  6675. If the allocation of a new object instance fails, an error condition is raised, 
  6676. and the (*SOMError)() routine is called. 
  6677.  
  6678. The somInit method is automatically invoked on the newly created object to 
  6679. allow it in properly initialize itself. 
  6680.  
  6681. The C-language bindings produced by the SOM Compiler contain a macro of the 
  6682. form ClassnameNew (in the .H file for each class). This is a convenient 
  6683. shorthand for _somNew(_<Classname>). 
  6684.  
  6685.  
  6686. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  6687.  
  6688. somInit 
  6689. somNewNoInit 
  6690. somRenew 
  6691. somRenewNoInit 
  6692.  
  6693.  
  6694. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  6695.  
  6696. #include "animal.h"
  6697. void main(int argc)
  6698. {
  6699.    Animal *myAnimal;
  6700. /* -------------------------------------------------
  6701.    Note: next 2 lines are functionally equivalent to
  6702.        myAnimal = AnimalNew();
  6703.    ------------------------------------------------- */
  6704.    AnimalNewClass(0,0);
  6705.    myAnimal = _somNew(_Animal);
  6706.    /* ... */
  6707.    _somFree(myAnimal);
  6708. }
  6709.  
  6710.  
  6711. ΓòÉΓòÉΓòÉ 8.37. somNewNoInit ΓòÉΓòÉΓòÉ
  6712.  
  6713.  
  6714. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  6715.  
  6716. Topics: 
  6717.  
  6718. Call Syntax 
  6719. Uses 
  6720. Parameters 
  6721. Return Value 
  6722. Errors 
  6723. Notes 
  6724. Related Methods 
  6725. Example 
  6726. Glossary 
  6727.  
  6728.  
  6729. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  6730.  
  6731.   /* Class:  SOMClass
  6732.   * Method: somNewNoInit
  6733.   *
  6734.   * Create a new object instance.
  6735.   */
  6736.   #include <som.h>
  6737.  
  6738.   SOMClass *receiver;
  6739.   SOMAny *newObject;
  6740.  
  6741.   newObject = _somNewNoInit (receiver);
  6742.  
  6743.  
  6744. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  6745.  
  6746. This method creates a new instance of the receiving class, without invoking the 
  6747. somInit method to perform object initialization. 
  6748.  
  6749.  
  6750. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  6751.  
  6752. receiver    The class object that is to create a new instance. 
  6753.  
  6754.  
  6755. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  6756.  
  6757. A pointer to the newly created object. 
  6758.  
  6759.  
  6760. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  6761.  
  6762. This method is identical to somNew, except that the somInit method is not 
  6763. invoked on the newly created object. If you are writing your own class methods 
  6764. or constructors, using somNewNoInit permits you to separate the actions 
  6765. involved in object creation and initialization to suit your own needs. 
  6766.  
  6767.  
  6768. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  6769.  
  6770. somNew 
  6771. somRenew 
  6772. somRenewNoInit 
  6773.  
  6774.  
  6775. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  6776.  
  6777. #include "animal.h"
  6778. void main(int argc)
  6779. {
  6780.    Animal *myAnimal;
  6781. /* -------------------------------------------------
  6782.    Note: next 3 lines are functionally equivalent to
  6783.        myAnimal = AnimalNew();
  6784.    ------------------------------------------------- */
  6785.    AnimalNewClass(0,0);
  6786.    myAnimal = _somNewNoInit(_Animal);
  6787.    _somInit(myAnimal);
  6788.    /* ... */
  6789.    _somFree(myAnimal);
  6790. }
  6791.  
  6792.  
  6793. ΓòÉΓòÉΓòÉ 8.38. somOverrideSMethod ΓòÉΓòÉΓòÉ
  6794.  
  6795.  
  6796. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  6797.  
  6798. Topics: 
  6799.  
  6800. Call Syntax 
  6801. Uses 
  6802. Parameters 
  6803. Return Value 
  6804. Errors 
  6805. Notes 
  6806. Related Methods 
  6807. Example 
  6808. Glossary 
  6809.  
  6810.  
  6811. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  6812.  
  6813.   /* Class:  SOMClass
  6814.   * Method: somOverrideSMethod
  6815.   *
  6816.   * Add a method to a class that
  6817.   * overrides a parent method.
  6818.   */
  6819.   #include <som.h>
  6820.  
  6821.   SOMClass *receiver;
  6822.   somId methodId;
  6823.   somMethodProc *method;
  6824.  
  6825.   _somOverrideSMethod (receiver, methodId, method);
  6826.  
  6827.  
  6828. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  6829.  
  6830. This method can be used instead of somAddStaticMethod when it is known that the 
  6831. class' parent class already supports this method. This method does not require 
  6832. the method descriptor and stub methods that the others do. 
  6833.  
  6834.  
  6835. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  6836.  
  6837. receiver    The class to which the method should be added. 
  6838.  
  6839. methodId    An ID specifying the name of the method to override. 
  6840.  
  6841. method      The procedure entry address for the method. 
  6842.  
  6843.  
  6844. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  6845.  
  6846. None. 
  6847.  
  6848.  
  6849. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  6850.  
  6851. This method is ordinarily invoked from the <Classname>NewClass procedure 
  6852. generated by the SOM Compiler from the OIDL class definition. Overriding this 
  6853. method with one of your own is not recommended. 
  6854.  
  6855. Generally speaking, you would never use this method directly. It is provided 
  6856. for the use of the C-language binding code produced by the SOM Compiler. 
  6857.  
  6858.  
  6859. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  6860.  
  6861. somAddStaticMethod 
  6862. somInitClass 
  6863.  
  6864.  
  6865. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  6866.  
  6867. You will find examples of this method in code generated by the SOM Compiler if 
  6868. you look in the .IH file of any class with overriding methods. 
  6869.  
  6870.  
  6871. ΓòÉΓòÉΓòÉ 8.39. somPrintSelf ΓòÉΓòÉΓòÉ
  6872.  
  6873.  
  6874. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  6875.  
  6876. Topics: 
  6877.  
  6878. Call Syntax 
  6879. Uses 
  6880. Parameters 
  6881. Return Value 
  6882. Errors 
  6883. Notes 
  6884. Related Methods 
  6885. Example 
  6886. Glossary 
  6887.  
  6888.  
  6889. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  6890.  
  6891.   /* Class:  SOMObject
  6892.   * Method: somPrintSelf
  6893.   *
  6894.   * Writes a detailed description of the receiving
  6895.   * object to (*SOMOutCharRoutine)(char);
  6896.   */
  6897.  
  6898.   #include <som.h>
  6899.  
  6900.   SOMAny *receiver;
  6901.   SOMAny *rcvrSelf;
  6902.  
  6903.   rcvrSelf = _somPrintSelf (receiver);
  6904.  
  6905.  
  6906. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  6907.  
  6908. This method uses SOMOutCharRoutine to write a brief string with identifying 
  6909. information about the receiving object. The default implementation gives only 
  6910. the object's class name and its address in memory. 
  6911.  
  6912.  
  6913. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  6914.  
  6915. receiver    The object to be "printed." 
  6916.  
  6917.  
  6918. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  6919.  
  6920. The receiving object returns a pointer to itself. 
  6921.  
  6922.  
  6923. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  6924.  
  6925. None. 
  6926.  
  6927.  
  6928. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  6929.  
  6930. somDumpSelf 
  6931. somDumpSelfInt 
  6932.  
  6933.  
  6934. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  6935.  
  6936. #include "animal.h"
  6937. main()
  6938. {
  6939.   Animal *myAnimal;
  6940.   myAnimal = AnimalNew ();
  6941.   /* ... */
  6942.   _somPrintSelf (myAnimal);
  6943.   _somFree (myAnimal);
  6944. }
  6945. /*
  6946. Output from this program:
  6947. {An instance of class Animal at address 0001CEC0}
  6948. */
  6949.  
  6950.  
  6951. ΓòÉΓòÉΓòÉ 8.40. somRegisterClass ΓòÉΓòÉΓòÉ
  6952.  
  6953.  
  6954. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  6955.  
  6956. Topics: 
  6957.  
  6958. Call Syntax 
  6959. Uses 
  6960. Parameters 
  6961. Return Value 
  6962. Errors 
  6963. Notes 
  6964. Related Methods 
  6965. Glossary 
  6966.  
  6967.  
  6968. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  6969.  
  6970.   /* Class:  SOMClassMgr
  6971.   * Method: somRegisterClass
  6972.   *
  6973.   * Add a class object to the
  6974.   * SOM run-time class registry.
  6975.   */
  6976.   #include <som.h>
  6977.  
  6978.   SOMClassMgr *receiver;
  6979.   SOMClass *classObj;
  6980.  
  6981.   _somRegisterClass (receiver, classObj);
  6982.  
  6983.  
  6984. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  6985.  
  6986. This method adds a class object to the SOM run-time class registry maintained 
  6987. by SOMClassMgrObject. 
  6988.  
  6989.  
  6990. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  6991.  
  6992. receiver    Usually SOMClassMgrObject (or an instance of a user-supplied 
  6993.             subclass of SOMClassMgr). 
  6994.  
  6995. classObj    The class object to add to the SOM class registry. 
  6996.  
  6997.  
  6998. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  6999.  
  7000. None. 
  7001.  
  7002.  
  7003. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  7004.  
  7005. All SOM run-time class objects should be registered with SOMClassMgrObject. In 
  7006. the C-language bindings created by the SOM Compiler, this is done automatically 
  7007. within the <Classname>NewClass procedure generated for each class (during the 
  7008. execution of the somClassReady method). 
  7009.  
  7010. You never need to invoke this method directly. 
  7011.  
  7012.  
  7013. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  7014.  
  7015. somUnregisterClass 
  7016.  
  7017.  
  7018. ΓòÉΓòÉΓòÉ 8.41. somRenew ΓòÉΓòÉΓòÉ
  7019.  
  7020.  
  7021. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  7022.  
  7023. Topics: 
  7024.  
  7025. Call Syntax 
  7026. Uses 
  7027. Parameters 
  7028. Return Value 
  7029. Errors 
  7030. Notes 
  7031. Related Methods 
  7032. Example 
  7033. Glossary 
  7034.  
  7035.  
  7036. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  7037.  
  7038.   /* Class:  SOMClass
  7039.   * Method: somRenew
  7040.   *
  7041.   * Create a new object instance
  7042.   * using a passed block of storage.
  7043.   */
  7044.   #include <som.h>
  7045.  
  7046.   SOMClass *receiver;
  7047.   void *storageForObject
  7048.   SOMAny *newObject;
  7049.  
  7050.   newObject = _somRenew (receiver, storageForObject);
  7051.  
  7052.  
  7053. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  7054.  
  7055. This method creates a new instance of the receiving class, but uses the space 
  7056. pointed to by newObject rather than allocating new space for the object. The 
  7057. default implementation of somRenew automatically re-initializes the object by 
  7058. invoking its somInit method. 
  7059.  
  7060.  
  7061. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  7062.  
  7063. receiver    The class object that is to create a new instance. 
  7064.  
  7065. storageForObject A pointer to the space to be used to construct a new object. 
  7066.  
  7067.  
  7068. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  7069.  
  7070. The pointer supplied by the caller is returned, but is now a pointer to a 
  7071. valid, initialized object. 
  7072.  
  7073.  
  7074. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  7075.  
  7076. No check is made to ensure that the passed pointer addresses enough space to 
  7077. hold an instance of the receiving class. The caller can determine the amount of 
  7078. space necessary by using somGetInstanceSize. 
  7079.  
  7080. The C-language bindings produced by the SOM Compiler contain a macro of the 
  7081. form <Classname>Renew (in the .H file for each class). This is a convenient 
  7082. shorthand for _somRenew(_<Classname>). 
  7083.  
  7084.  
  7085. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  7086.  
  7087. somGetInstanceSize 
  7088. somInit 
  7089. somNew 
  7090. somNewNoInit 
  7091. somRenewNoInit 
  7092.  
  7093.  
  7094. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  7095.  
  7096. #include "animal.h"
  7097. #include <som.h>
  7098. #include <stdlib.h>
  7099. main()
  7100. {
  7101.   char *myAnimalCluster;
  7102.   Animal *animals[5];
  7103.   SOMClass *animalClass;
  7104.   int animalSize, i;
  7105.  
  7106.   animalClass = AnimalNewClass();
  7107.   animalSize = _somGetInstanceSize (animalClass);
  7108.   /* Round up to doubleword multiple */
  7109.   animalSize = ((animalSize+3)/4)*4;
  7110.   /*
  7111.    * Next line allocates room for 5 objects
  7112.    * in a "cluster" with a single memory-
  7113.    * allocation operation.
  7114.    */
  7115.   myAnimalCluster = (char *) malloc (5*animalSize);
  7116.   /*
  7117.    * The for-loop that follows creates 5 initialized
  7118.    * Animal instances within the memory cluster.
  7119.    */
  7120.   for (i=0; i<5; i++)
  7121.      animals[i] = _somRenew (animalClass, (void *)(myAnimalCluster+(i*animalSize)));
  7122.   /*
  7123.    * Finally, the next line frees all 5 animals
  7124.    * with one operation.
  7125.    */
  7126.   free ((void *)myAnimalCluster);
  7127. }
  7128.  
  7129.  
  7130. ΓòÉΓòÉΓòÉ 8.42. somRenewNoInit ΓòÉΓòÉΓòÉ
  7131.  
  7132.  
  7133. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  7134.  
  7135. Topics: 
  7136.  
  7137. Call Syntax 
  7138. Uses 
  7139. Parameters 
  7140. Return Value 
  7141. Errors 
  7142. Notes 
  7143. Related Methods 
  7144. Example 
  7145. Glossary 
  7146.  
  7147.  
  7148. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  7149.  
  7150.   /* Class:  SOMClass
  7151.   * Method: somRenewNoInit
  7152.   *
  7153.   * Create a new object instance
  7154.   * using a passed block of storage.
  7155.   */
  7156.   #include <som.h>
  7157.  
  7158.   SOMClass *receiver;
  7159.   void *storageForObject;
  7160.   SOMAny *newObject;
  7161.  
  7162.   newObject = _somRenewNoInit (receiver, storageForObject);
  7163.  
  7164.  
  7165. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  7166.  
  7167. This method creates a new instance of the receiving class, but uses the space 
  7168. pointed to by newObject rather than allocating new space for the object. 
  7169.  
  7170.  
  7171. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  7172.  
  7173. receiver    The class object that is to create a new instance. 
  7174.  
  7175. storageForObject A pointer to the space to be used to construct a new object. 
  7176.  
  7177.  
  7178. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  7179.  
  7180. The pointer supplied by the caller is returned, but is now a pointer to a 
  7181. valid, but un-initialized, object. 
  7182.  
  7183.  
  7184. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  7185.  
  7186. The default implementation of somRenewNoInit differs from somRenew only in that 
  7187. it does not invoke the somInit method to automatically re-initialize the new 
  7188. object. 
  7189.  
  7190.  
  7191. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  7192.  
  7193. somGetInstanceSize 
  7194. somInit 
  7195. somNew 
  7196. somNewNoInit 
  7197. somRenew 
  7198.  
  7199.  
  7200. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  7201.  
  7202. #include "animal.h"
  7203. #include <som.h>
  7204. #include <stdlib.h>
  7205. main()
  7206. {
  7207.   char *myAnimalCluster;
  7208.   Animal *animals[5];
  7209.   SOMClass *animalClass;
  7210.   int animalSize, i;
  7211.  
  7212.   animalClass = AnimalNewClass();
  7213.   animalSize = _somGetInstanceSize (animalClass);
  7214.   /* Round up to doubleword multiple */
  7215.   animalSize = ((animalSize+3)/4)*4;
  7216.   /*
  7217.    * Next line allocates room for 5 objects
  7218.    * in a "cluster" with a single memory-
  7219.    * allocation operation.
  7220.    */
  7221.   myAnimalCluster = (char *) malloc (5*animalSize);
  7222.   /*
  7223.    * The for-loop that follows creates 5 un-initialized
  7224.    * Animal instances within the memory cluster.
  7225.    */
  7226.   for (i=0; i<5; i++) {
  7227.      animals[i] = _somRenewNoInit (animalClass, (void *)(myAnimalCluster+(i*animalSize)));
  7228.   }
  7229.   /*
  7230.    * Finally, the next line frees all 5 animals
  7231.    * with one operation.
  7232.    */
  7233.   free ((void *)myAnimalCluster);
  7234. }
  7235.  
  7236.  
  7237. ΓòÉΓòÉΓòÉ 8.43. somRespondsTo ΓòÉΓòÉΓòÉ
  7238.  
  7239.  
  7240. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  7241.  
  7242. Topics: 
  7243.  
  7244. Call Syntax 
  7245. Uses 
  7246. Parameters 
  7247. Return Value 
  7248. Errors 
  7249. Notes 
  7250. Related Methods 
  7251. Example 
  7252. Glossary 
  7253.  
  7254.  
  7255. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  7256.  
  7257.   /* Class:  SOMObject
  7258.   * Method: somRespondsTo
  7259.   *
  7260.   * Indicates whether an object
  7261.   * supports a given method.
  7262.   */
  7263.   #include <som.h>
  7264.  
  7265.   SOMAny *receiver;
  7266.   somId methodId;
  7267.   int result;
  7268.  
  7269.   result = _somRespondsTo (receiver, methodId);
  7270.  
  7271.  
  7272. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  7273.  
  7274. Use this method to determine if an object supports a specified method. 
  7275.  
  7276.  
  7277. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  7278.  
  7279. receiver    The object to be tested. 
  7280.  
  7281. methodId    An ID that represents the name of the desired method. 
  7282.  
  7283.  
  7284. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  7285.  
  7286. Returns 1 (true) if the receiving object supports the specified method, and 0 
  7287. (false) if otherwise. 
  7288.  
  7289.  
  7290. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  7291.  
  7292. Dynamic typing mechanisms are sometimes based on protocol rather than 
  7293. inheritance. That is, an object is considered to be of the correct type if it 
  7294. can respond to an appropriate set of methods, regardless of its class or the 
  7295. parentage of its class. This method can be used as a basis for a dynamic typing 
  7296. system. 
  7297.  
  7298.  
  7299. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  7300.  
  7301. somSupportsMethod 
  7302.  
  7303.  
  7304. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  7305.  
  7306. /* -----------------------------------------------
  7307.    Note: Animal supports a setSound method;
  7308.          Animal does not support a doTrick method.
  7309.    ----------------------------------------------- */
  7310. #include "animal.h"
  7311. main()
  7312. {
  7313.   Animal *myAnimal;
  7314.   char *methodName1 = "setSound";
  7315.   char *methodName2 = "doTrick";
  7316.  
  7317.   myAnimal = AnimalNew();
  7318.   if (_somRespondsTo(myAnimal, SOM_IdFromString(methodName1)))
  7319.      somPrintf("myAnimal responds to %s\n", methodName1);
  7320.   if (_somRespondsTo(myAnimal, SOM_IdFromString(methodName2)))
  7321.      somPrintf("myAnimal responds to %s\n", methodName2);
  7322.   _somFree(myAnimal);
  7323. }
  7324. /*
  7325. Output from this program:
  7326. myAnimal responds to setSound
  7327. */
  7328.  
  7329.  
  7330. ΓòÉΓòÉΓòÉ 8.44. somSetClassData ΓòÉΓòÉΓòÉ
  7331.  
  7332.  
  7333. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  7334.  
  7335. Topics: 
  7336.  
  7337. Call Syntax 
  7338. Uses 
  7339. Parameters 
  7340. Return Value 
  7341. Errors 
  7342. Notes 
  7343. Related Methods 
  7344. Glossary 
  7345.  
  7346.  
  7347. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  7348.  
  7349.   /* Class:  SOMClass
  7350.   * Method: somSetClassData
  7351.   *
  7352.   * Sets the class' pointer to its global
  7353.   * ClassData structure.
  7354.   */
  7355.   #include <som.h>
  7356.  
  7357.   SOMClass *receiver;
  7358.   somClassDataStructure XyzClassData;
  7359.  
  7360.   _somSetClassData (receiver, &XyzClassData);
  7361.  
  7362.  
  7363. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  7364.  
  7365. This method sets the class' pointer to its global ClassData structure. Every 
  7366. SOM class has an external data structure named <className>ClassData that holds 
  7367. a pointer to the class object and information about the relative offsets of 
  7368. method table entries. 
  7369.  
  7370.  
  7371. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  7372.  
  7373. receiver    The class object whose ClassData structure pointer is to be set. 
  7374.  
  7375.  
  7376. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  7377.  
  7378. None. 
  7379.  
  7380.  
  7381. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  7382.  
  7383. This method is not generally overridden. It is provided for use by the SOM 
  7384. run-time environment. 
  7385.  
  7386.  
  7387. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  7388.  
  7389. somGetClassData 
  7390.  
  7391.  
  7392. ΓòÉΓòÉΓòÉ 8.45. somSupportsMethod ΓòÉΓòÉΓòÉ
  7393.  
  7394.  
  7395. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  7396.  
  7397. Topics: 
  7398.  
  7399. Call Syntax 
  7400. Uses 
  7401. Parameters 
  7402. Return Value 
  7403. Errors 
  7404. Related Methods 
  7405. Example 
  7406. Glossary 
  7407.  
  7408.  
  7409. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  7410.  
  7411.   /* Class:  SOMClass
  7412.   * Method: somSupportsMethod
  7413.   *
  7414.   * Indicates whether instances of this
  7415.   * class support a given method.
  7416.   */
  7417.   #include <som.h>
  7418.  
  7419.   SOMClass *receiver;
  7420.   somId methodId;
  7421.   int result;
  7422.  
  7423.   result = _somSupportsMethod (receiver, methodId);
  7424.  
  7425.  
  7426. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  7427.  
  7428. Use this method to determine if instances of the receiving class support a 
  7429. specified method. 
  7430.  
  7431.  
  7432. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  7433.  
  7434. receiver    The class object to be tested. 
  7435.  
  7436. methodId    An ID that represents the name of the desired method. 
  7437.  
  7438.  
  7439. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  7440.  
  7441. Returns 1 (true) if instances of the receiving class object support the 
  7442. specified method, and 0 (false) if otherwise. 
  7443.  
  7444.  
  7445. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  7446.  
  7447. somRespondsTo 
  7448.  
  7449.  
  7450. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  7451.  
  7452. /* -----------------------------------------------
  7453.    Note: animal supports a setSound method;
  7454.          animal does not support a doTrick method.
  7455.    ----------------------------------------------- */
  7456. #include "animal.h"
  7457. main()
  7458. {
  7459.   Animal *myAnimal;
  7460.   SOMClass *animalClass;
  7461.   char *methodName1 = "setSound";
  7462.   char *methodName2 = "doTrick";
  7463.  
  7464.   myAnimal = AnimalNew();
  7465.   animalClass = _somGetClass(myAnimal);
  7466.   if (_somSupportsMethod(animalClass, SOM_IdFromString(methodName1)))
  7467.      somPrintf("Animals respond to %s\n", methodName1);
  7468.   if (_somSupportsMethod(animalClass, SOM_IdFromString(methodName2)))
  7469.      somPrintf("Animals respond to %s\n", methodName2);
  7470.   _somFree(myAnimal);
  7471. }
  7472. /*
  7473. Output from this program:
  7474. Animals respond to setSound
  7475. */
  7476.  
  7477.  
  7478. ΓòÉΓòÉΓòÉ 8.46. somUninit ΓòÉΓòÉΓòÉ
  7479.  
  7480.  
  7481. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  7482.  
  7483. Topics: 
  7484.  
  7485. Call Syntax 
  7486. Uses 
  7487. Parameters 
  7488. Return Value 
  7489. Errors 
  7490. Notes 
  7491. Related Methods 
  7492. Example 
  7493. Glossary 
  7494.  
  7495.  
  7496. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  7497.  
  7498.   /* Class:  SOMObject
  7499.   * Method: somUninit
  7500.   *
  7501.   * Un-initializes the receiving object.
  7502.   */
  7503.   #include <som.h>
  7504.  
  7505.   SOMAny *receiver;
  7506.  
  7507.   _somUninit (receiver);
  7508.  
  7509.  
  7510. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  7511.  
  7512. This method performs the inverse of object initialization on the receiving 
  7513. object.  It must release any resources acquired by the object during its 
  7514. somInit processing. 
  7515.  
  7516.  
  7517. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  7518.  
  7519. receiver    The object to be un-initialized. 
  7520.  
  7521.  
  7522. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  7523.  
  7524. None. 
  7525.  
  7526.  
  7527. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  7528.  
  7529. Use this method to clean up anything necessary, such as dynamically allocated 
  7530. storage. However this method does not release the actual storage assigned to 
  7531. the object instance. This method is provided as a complement to somFree, which 
  7532. also releases the storage associated with a dynamically allocated object. 
  7533. Usually you would invoke only somFree (which always calls somUninit). However, 
  7534. in cases where somRenew was used to create an object instance, somFree cannot 
  7535. be called, and you must call somUninit explicitly. 
  7536.  
  7537. When overriding this method, always call the parent-class version of this 
  7538. method after doing your own un-initialization. 
  7539.  
  7540.  
  7541. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  7542.  
  7543. somInit 
  7544. somNew 
  7545. somRenew 
  7546.  
  7547.  
  7548. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  7549.  
  7550. #  animal2.csc:
  7551.    include <somobj.sc>
  7552.    class: Animal2, local;
  7553.    parent: SOMObject;
  7554.    data:
  7555.      char *sound;
  7556.    methods:
  7557.       void display();
  7558.       override somInit;
  7559.       override somUninit;
  7560.  
  7561. /* animal2.c: */
  7562.    #define Animal2_Class_Source
  7563.    #include "animal2.ih"
  7564.    #include <string.h>
  7565.  
  7566.    SOM_Scope void SOMLINK display (Animal2 *somSelf)
  7567.    {
  7568.        Animal2Data *somThis = Animal2GetData(somSelf);
  7569.    }
  7570.    SOM_Scope void SOMLINK somInit (Animal2 *somSelf)
  7571.    {
  7572.        Animal2Data *somThis = Animal2GetData (somSelf);
  7573.        parent_somInit (somSelf);
  7574.        _sound = (*SOMMalloc)(100);
  7575.        strcpy (_sound, "Unknown Noise");
  7576.        somPrintf ("New Animal Initialized\n");
  7577.    }
  7578.    SOM_Scope void SOMLINK somUninit (Animal2 *somSelf)
  7579.    {
  7580.        Animal2Data *somThis = Animal2GetData (somSelf);
  7581.        (*SOMFree)(_sound);
  7582.        somPrintf ("Animal Uninitialized\n");
  7583.        parent_somUninit (somSelf);
  7584.    }
  7585.  
  7586. /* main program */
  7587.    #include "animal2.h"
  7588.    void main()
  7589.    {
  7590.       Animal2 *myAnimal;
  7591.       myAnimal = Animal2New ();
  7592.       _somFree (myAnimal);
  7593.    }
  7594.  
  7595. /*
  7596. Program output:
  7597. New Animal Initialized
  7598. Animal Uninitialized
  7599. */
  7600.  
  7601.  
  7602. ΓòÉΓòÉΓòÉ 8.47. somUnloadClassFile ΓòÉΓòÉΓòÉ
  7603.  
  7604.  
  7605. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  7606.  
  7607. Topics: 
  7608.  
  7609. Call Syntax 
  7610. Uses 
  7611. Parameters 
  7612. Return Value 
  7613. Errors 
  7614. Notes 
  7615. Related Methods 
  7616. Glossary 
  7617.  
  7618.  
  7619. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  7620.  
  7621.   /* Class:  SOMClassMgr
  7622.   * Method: somUnloadClassFile
  7623.   *
  7624.   * Unloads a dynamically loaded
  7625.   * class and frees the class object.
  7626.   */
  7627.   #include <som.h>
  7628.  
  7629.   SOMClassMgr *receiver;
  7630.   SOMClass *class;
  7631.   int errorCode;
  7632.  
  7633.   errorCode = _somUnloadClassFile (receiver, class);
  7634.  
  7635.  
  7636. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  7637.  
  7638. The SOMClassMgr object uses this method to unload a dynamically loaded class 
  7639. during somUnregisterClass processing. 
  7640.  
  7641.  
  7642. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  7643.  
  7644. receiver    Usually SOMClassMgrObject (or an instance of a user-supplied 
  7645.             subclass of SOMClassMgr). 
  7646.  
  7647. class       The class to unload. 
  7648.  
  7649.  
  7650. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  7651.  
  7652. Returns 0 if the class was successfully unloaded, or a system-specific non-zero 
  7653. error code from DosFreeModule. 
  7654.  
  7655.  
  7656. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  7657.  
  7658. The class object is freed whether or not the class' DLL could be unloaded. If 
  7659. the class was not registered, an error condition is raised and (*SOMError)() is 
  7660. invoked. This method is provided to permit user-created subclasses of 
  7661. SOMClassMgr to handle the unloading of classes. 
  7662.  
  7663. Do not invoke this method directly; invoke somUnregisterClass instead. 
  7664.  
  7665.  
  7666. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  7667.  
  7668. somLoadClassFile 
  7669. somRegisterClass 
  7670. somUnregisterClass 
  7671.  
  7672.  
  7673. ΓòÉΓòÉΓòÉ 8.48. somUnregisterClass ΓòÉΓòÉΓòÉ
  7674.  
  7675.  
  7676. ΓòÉΓòÉΓòÉ <hidden> Instructions ΓòÉΓòÉΓòÉ
  7677.  
  7678. Topics: 
  7679.  
  7680. Call Syntax 
  7681. Uses 
  7682. Parameters 
  7683. Return Value 
  7684. Errors 
  7685. Notes 
  7686. Related Methods 
  7687. Example 
  7688. Glossary 
  7689.  
  7690.  
  7691. ΓòÉΓòÉΓòÉ <hidden> Call Syntax ΓòÉΓòÉΓòÉ
  7692.  
  7693.   /* Class:  SOMClassMgr
  7694.   * Method: somUnregisterClass
  7695.   *
  7696.   * Removes a class object from
  7697.   * the SOM run-time class registry.
  7698.   */
  7699.   #include <som.h>
  7700.  
  7701.   SOMClassMgr *receiver;
  7702.   SOMClass *class;
  7703.   int errorCode;
  7704.  
  7705.   errorCode = _somUnregisterClass (receiver, class);
  7706.  
  7707.  
  7708. ΓòÉΓòÉΓòÉ <hidden> Uses ΓòÉΓòÉΓòÉ
  7709.  
  7710. This method unregisters a SOM class, unloads its DLL (if it was dynamically 
  7711. loaded), and frees the class object. 
  7712.  
  7713.  
  7714. ΓòÉΓòÉΓòÉ <hidden> Parameters ΓòÉΓòÉΓòÉ
  7715.  
  7716. receiver    Usually SOMClassMgrObject (or an instance of a user-supplied 
  7717.             subclass of SOMClassMgr). 
  7718.  
  7719. class       The class to unregister. 
  7720.  
  7721.  
  7722. ΓòÉΓòÉΓòÉ <hidden> Return Value ΓòÉΓòÉΓòÉ
  7723.  
  7724. This method returns 0 for a successful completion, or non-zero for a failure. 
  7725.  
  7726.  
  7727. ΓòÉΓòÉΓòÉ <hidden> Notes ΓòÉΓòÉΓòÉ
  7728.  
  7729. This method uses somUnloadClassfile to delete a dynamically loaded class. 
  7730.  
  7731.  
  7732. ΓòÉΓòÉΓòÉ <hidden> Related Methods ΓòÉΓòÉΓòÉ
  7733.  
  7734. somLoadClassFile 
  7735. somRegisterClass 
  7736. somUnloadClassFile 
  7737.  
  7738.  
  7739. ΓòÉΓòÉΓòÉ <hidden> Example ΓòÉΓòÉΓòÉ
  7740.  
  7741.    #include <som.h>
  7742.  
  7743.    int rc;
  7744.    /*
  7745.     * Assume variable "class" points to
  7746.     * a class object to be unregistered
  7747.     */
  7748.    SOMClass *class;
  7749.  
  7750.    rc = _somUnregisterClass (SOMClassMgrObject, class);
  7751.    if (rc)
  7752.       somPrintf ("Could not unregister %s, error code was: %d.\n,
  7753.          _somGetName (class), rc);
  7754.  
  7755.  
  7756. ΓòÉΓòÉΓòÉ 9. Appendix A: Error Codes ΓòÉΓòÉΓòÉ
  7757.  
  7758. Value     Symbolic Name and Description 
  7759.  
  7760. 20011     SOMERROR_CCNullClass 
  7761.           Explanation: The somDescendedFrom method was passed a null class 
  7762.           argument. 
  7763.  
  7764. 20029     SOMERROR_SompntOverflow 
  7765.           Explanation: The internal buffer used in somPrintf overflowed. 
  7766.  
  7767. 20039     SOMERROR_MethodNotFound 
  7768.           Explanation: somFindMethodOk failed to find the indicated method. 
  7769.  
  7770. 20049     SOMERROR_StaticMethodTableOverflow 
  7771.           Explanation: A Method-table overflow occurred in somAddStaticMethod. 
  7772.  
  7773. 20059     SOMERROR_DefaultMethod 
  7774.           Explanation: The somDefaultMethod was called; a defined method 
  7775.           probably was not added before it was invoked. 
  7776.  
  7777. 20069     SOMERROR_MissingMethod 
  7778.           Explanation: The specified method was not defined on the target 
  7779.           object. 
  7780.  
  7781. 20079     SOMERROR_BadVersion 
  7782.           Explanation: An attempt to load, create, or use a version of a 
  7783.           class-object implementation is incompatible with the using program. 
  7784.  
  7785. 20089     SOMERROR_NullId 
  7786.           SOM_CheckId was given a null ID to check 
  7787.  
  7788. 20099     SOMERROR_OutOfMemory 
  7789.           Explanation: Memory is exhausted. 
  7790.  
  7791. 20109     SOMERROR_TestObjectFailure 
  7792.           Explanation: somObjectTest found problems with the object it was 
  7793.           testing. 
  7794.  
  7795. 20119     SOMERROR_FailedTest 
  7796.           Explanation: somTest detected a failure; generated only by test code. 
  7797.  
  7798. 20121     SOMERROR_ClassNotFound 
  7799.           Explanation: somFindClass could not find the requested class. 
  7800.  
  7801. 20131     SOMERROR_OldMethod 
  7802.           Explanation: An old-style method name was used; change to an 
  7803.           appropriate name. 
  7804.  
  7805. 20149     SOMERROR_CouldNotStartup 
  7806.           Explanation: somEnvironmentNew failed to complete. 
  7807.  
  7808. 20159     SOMERROR_NotRegistered 
  7809.           Explanation: somUnloadClassFile argument was not a registered class. 
  7810.  
  7811. 20169     SOMERROR_BadOverride 
  7812.           Explanation: somOverrideSMethod was invoked for a method that was not 
  7813.           defined in a parent class. 
  7814.  
  7815. 20179     SOMERROR_NotImplementedYet 
  7816.           Explanation: The method raising the error message is not implemented 
  7817.           yet. 
  7818.  
  7819. 20189     SOMERROR_MustOverride 
  7820.           Explanation: The method raising the error message should have been 
  7821.           overridden. 
  7822.  
  7823. 20199     SOMERROR_BadArgument 
  7824.           Explanation: An argument to a core SOM method failed a validity test. 
  7825.  
  7826. 20219     SOMERROR_NoParentClass 
  7827.           Explanation: During the creation of a class object, the parent class 
  7828.           could not be found. 
  7829.  
  7830. 20229     SOMERROR_NoMetaClass 
  7831.           Explanation: During the creation of a class object, the metaclass 
  7832.           object could not be found. 
  7833.  
  7834.  
  7835. ΓòÉΓòÉΓòÉ 10. Glossary ΓòÉΓòÉΓòÉ
  7836.  
  7837. class       A way of categorizing objects based on their behavior and shape.  A 
  7838.             class is, in effect, a definition of a generic object. In SOM, a 
  7839.             class is a special kind of object that can manufacture other 
  7840.             objects that all have a common shape and exhibit similar behavior 
  7841.             (more precisely, all of the objects manufactured by a class have 
  7842.             the same memory layout and share a common set of methods). New 
  7843.             classes can be defined in terms of existing classes through a 
  7844.             technique known as inheritance. 
  7845.  
  7846. class method (Also known as factory method or constructor). A class method of 
  7847.             class <X> is a method provided by the metaclass of class <X>. Class 
  7848.             methods are executed without requiring any instances of class <X> 
  7849.             to exist, and are frequently used to create instances. 
  7850.  
  7851. constructor See class method. 
  7852.  
  7853. dynamic method A method for which offset resolution is not available. 
  7854.  
  7855. factory method See class method. 
  7856.  
  7857. ID          A pointer to a unique value that represents a string. 
  7858.  
  7859. inheritance The technique of specifying the shape and behavior of one class 
  7860.             (called a subclass) as incremental differences from another class 
  7861.             (called the parent class or superclass). The subclass inherits the 
  7862.             superclass' state representation and methods, and can provide 
  7863.             additional data elements and methods. The subclass also can provide 
  7864.             new functions with the same method names used by the superclass. 
  7865.             Such a subclass method is said to override the superclass method, 
  7866.             and will be selected automatically by method resolution on subclass 
  7867.             instances. An overriding method can elect to call upon the 
  7868.             superclass' method as part of its own implementation. 
  7869.  
  7870. instance    (Or object instance).  A specific object, as distinguished from the 
  7871.             abstract definition of an object referred to as its class. 
  7872.  
  7873. instance method A method valid for a particular object. 
  7874.  
  7875. metaclass   A class whose instances are all classes. In SOM, any class 
  7876.             descended from SOMClass is a metaclass. The methods of a metaclass 
  7877.             are sometimes called "class" methods (Smalltalk) or "factory" 
  7878.             methods (Objective-C). 
  7879.  
  7880. method      One of the units that makes up the behavior of an object. A method 
  7881.             is a combination of a function and a name, such that many different 
  7882.             functions can have the same name. Which function the name refers to 
  7883.             at any point in time depends on the object that is to execute the 
  7884.             method and is the subject of method resolution. Functions that have 
  7885.             a common method name should also share a common signature. 
  7886.  
  7887. method resolution The process of selecting a particular function, given a 
  7888.             method name and an object instance. The process results in 
  7889.             selecting the particular function that implements the abstract 
  7890.             method in a way appropriate for the designated object. SOM supports 
  7891.             a variety of method-resolution mechanisms. 
  7892.  
  7893. object      The elements of data and function that programs create, manipulate, 
  7894.             pass as arguments, and so forth. An object is a way of associating 
  7895.             specific data values with a specific set of named functions (called 
  7896.             methods) for a period of time (referred to as the lifetime of the 
  7897.             object). The data values of an object are referred to as its state. 
  7898.             In SOM, objects are created by other objects called classes. The 
  7899.             specification of what comprises the set of functions and data 
  7900.             elements that make up an object is referred to as the definition of 
  7901.             a class. 
  7902.  
  7903.             SOM objects offer a high degree of encapsulation. This property 
  7904.             permits many aspects of the implementation of an object to change 
  7905.             without affecting client programs that depend on the object's 
  7906.             behavior. 
  7907.  
  7908. object definition See class. 
  7909.  
  7910. object instance See instance. 
  7911.  
  7912. signature   The collection of types associated with a method (the type of its 
  7913.             return value, if any, as well as the number, order, and type of 
  7914.             each of its arguments). All SOM methods that have the same name 
  7915.             should also have the same signature. 
  7916.  
  7917. static method Any method that can be accessed through SOM offset resolution. 
  7918.  
  7919. subclass    A class that inherits from another class. See inheritance. 
  7920.  
  7921. superclass  A class from which another class inherits. See inheritance. 
  7922.  
  7923.  
  7924. ΓòÉΓòÉΓòÉ <hidden>  ΓòÉΓòÉΓòÉ
  7925.  
  7926. See ID Manipulation for a minor exception to this rule