home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / devtools / os2tk21j / c / samples / tp / textline.c__ / textline.c
Encoding:
C/C++ Source or Header  |  1993-03-12  |  3.5 KB  |  119 lines

  1. #ifndef lint
  2. static char *sccsid = "@(#)textline.c 1.3 1/22/92 16:11:00 [1/26/92] (c)IBM Corp. 1992";
  3. #endif
  4.  
  5. /*
  6.  * This class is adapted from the book
  7.  *   Class Construction in C and C++, Object Oriented Fundamentals
  8.  *   by Roger Sessions, Copyright (c) 1992 Prentice Hall.
  9.  * Reprinted with permission.
  10.  */
  11.  
  12. #define textLine_Class_Source
  13. #include "textline.ih"
  14. #include "helper.h"
  15. #include "tpword.h"
  16.  
  17. /* ************************************************************ */
  18. SOM_Scope void SOMLINK tlInit(textLine * somSelf,
  19.                    int newSize)
  20. {
  21.     textLineData *somThis = textLineGetData(somSelf);
  22.     textLineMethodDebug("textLine", "tlInit");
  23.     _totalChars = 0;
  24.     _maxSize = newSize;
  25. }
  26.  
  27. /* ************************************************************ */
  28. SOM_Scope int SOMLINK tlCharsInLine(textLine * somSelf)
  29. {
  30.     textLineData *somThis = textLineGetData(somSelf);
  31.     textLineMethodDebug("textLine", "tlCharsInLine");
  32.     return _totalChars;
  33.  
  34. }
  35.  
  36. /* ************************************************************ */
  37. SOM_Scope int SOMLINK tlCharsLeft(textLine * somSelf)
  38. {
  39.     textLineData *somThis = textLineGetData(somSelf);
  40.     textLineMethodDebug("textLine", "tlCharsLeft");
  41.     return _maxSize - _totalChars;
  42. }
  43.  
  44. /* ************************************************************ */
  45. SOM_Scope baseType *SOMLINK llAddTail(textLine * somSelf,
  46.                        baseType * newElement)
  47. {
  48.     textLineData *somThis = textLineGetData(somSelf);
  49.     TPWord *myWord = (TPWord *) newElement;
  50.     int newTotal;
  51.     textLineMethodDebug("textLine", "llAddTail");
  52.  
  53.     newTotal = _totalChars + _getLength(newElement);
  54.     if (newTotal <= _maxSize) {
  55.     _totalChars = newTotal;
  56.     return (parent_llAddTail(somSelf, newElement));
  57.     }
  58.     else
  59.     return newElement;
  60. }
  61.  
  62. /* ************************************************************ */
  63. SOM_Scope baseType *SOMLINK llAddHead(textLine * somSelf,
  64.                        baseType * newElement)
  65. {
  66.     textLineData *somThis = textLineGetData(somSelf);
  67.     TPWord *myWord = (TPWord *) newElement;
  68.     int newTotal;
  69.     textLineMethodDebug("textLine", "llAddHead");
  70.  
  71.     newTotal = _totalChars + _getLength(newElement);
  72.     if (newTotal <= _maxSize) {
  73.     _totalChars = newTotal;
  74.     return (parent_llAddHead(somSelf, newElement));
  75.     }
  76.     else
  77.     return newElement;
  78. }
  79.  
  80. /* ************************************************************ */
  81. SOM_Scope baseType *SOMLINK llReplace(textLine * somSelf,
  82.                        baseType * newElement)
  83. {
  84.     textLineData *somThis = textLineGetData(somSelf);
  85.     textLineMethodDebug("textLine", "llReplace");
  86.     shouldHaveOverridden(somSelf, "llReplace");
  87.     newElement;
  88.     return (baseType *) NULL;
  89. }
  90.  
  91. /* ************************************************************ */
  92. SOM_Scope void SOMLINK somInit(textLine * somSelf)
  93. {
  94.     textLineData *somThis = textLineGetData(somSelf);
  95.     textLineMethodDebug("textLine", "somInit");
  96.     parent_somInit(somSelf);
  97.     _maxSize = 0;
  98.     _totalChars = 0;
  99. }
  100.  
  101. /* ************************************************************ */
  102. SOM_Scope void SOMLINK somUninit(textLine * somSelf)
  103. {
  104.     textLineData *somThis = textLineGetData(somSelf);
  105.     textLineMethodDebug("textLine", "somUninit");
  106.  
  107.     parent_somUninit(somSelf);
  108. }
  109.  
  110. /* ************************************************************ */
  111. SOM_Scope void SOMLINK somDumpSelfInt(textLine * somSelf,
  112.                        int level)
  113. {
  114.     textLineData *somThis = textLineGetData(somSelf);
  115.     textLineMethodDebug("textLine", "somDumpSelfInt");
  116.  
  117.     parent_somDumpSelfInt(somSelf, level);
  118. }
  119.