home *** CD-ROM | disk | FTP | other *** search
/ PC Media 4 / PC MEDIA CD04.iso / share / prog / gcoope10 / char.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-22  |  3.0 KB  |  156 lines

  1.  
  2. /*
  3.  
  4.     Char class definition for GCOOPE Version 1.0
  5.  
  6.           7/13/94 by Brian Lee Price
  7.  
  8.     Released as Public Domain   July, 1994.
  9.  
  10.     This is a flag class.  (Uses the object handle for instance
  11.     variable storage).
  12.  
  13.     Compatible with strong typing option.
  14.  
  15. */
  16.  
  17. #define CLASS Char
  18.  
  19. #include "gcoope10.h"
  20.  
  21. #include <stdio.h>
  22.  
  23. object CLASS;
  24.  
  25. extern object String;
  26. extern object ShortInt;
  27. extern object LongInt;
  28. extern object Unsigned;
  29.  
  30. USEGEN(changeVal);
  31. USEGEN(valueOf);
  32. USEGEN(asString);
  33. USEGEN(asHexStr);
  34. USEGEN(asShortInt);
  35. USEGEN(asLongInt);
  36. USEGEN(asUnsigned);
  37. USEGEN(asChar);
  38.  
  39. cmethod object m4New(object instance, char initVal)
  40. {
  41. if(((objHndl *) &instance)->fext)
  42.     {
  43.     char * ivptr;
  44.     if(NULL==(ivptr=getIVptr(instance))) return 0;
  45.     *ivptr=initVal;
  46.     }
  47. else
  48.     {
  49.     ((objHndl *) &instance)->fext=(tag)instance | ~SIGNMASK;
  50.     (tag) instance=0;
  51.     (char) instance=initVal;
  52.     }
  53. return instance;
  54. }
  55.  
  56.  
  57. imethod object m4changeVal(object instance, char newVal)
  58. {
  59. if(instance>=0)
  60.     {
  61.     char * ivptr;
  62.     if(NULL==(ivptr=getIVptr(instance))) return FUNCFAIL;
  63.     *ivptr=newVal;
  64.     }
  65. else (char) instance=newVal;
  66. return FUNCOKAY;
  67. }
  68.  
  69.  
  70. imethod char m4valueOf(object instance)
  71. {
  72. if(instance>=0)
  73.     {
  74.     char * ivptr;
  75.     ivptr=getIVptr(instance);
  76.     return *ivptr;
  77.     }
  78. else return (char) instance;
  79. }
  80.  
  81.  
  82. imethod object m4asString(object instance)
  83. {
  84. char strBuf[16];
  85. char a;
  86.  
  87. if(instance>=0) a=*((char *) getIVptr(instance));
  88. else a=(char) instance;
  89. sprintf(strBuf,"%d",(int) a);
  90. return g(New)(String,strBuf);
  91. }
  92.  
  93.  
  94. imethod object m4asHexStr(object instance)
  95. {
  96. char strBuf[16];
  97. char a;
  98.  
  99. if(instance>=0) a=*((char *) getIVptr(instance));
  100. else a=(char) instance;
  101. sprintf(strBuf, "%x", (unsigned) a);
  102. return g(New)(String,strBuf);
  103. }
  104.  
  105.  
  106. imethod object m4asShortInt(object instance)
  107. {
  108. char a;
  109.  
  110. if(instance>=0) a=*((char *) getIVptr(instance));
  111. else a=(char) instance;
  112. return g(New)(ShortInt,(short) a);
  113. }
  114.  
  115.  
  116. imethod object m4asLongInt(object instance)
  117. {
  118. char a;
  119.  
  120. if(instance>=0) a=*((char *) getIVptr(instance));
  121. else a=(char) instance;
  122. return g(New)(LongInt,(long) a);
  123. }
  124.  
  125.  
  126. imethod object m4asUnsigned(object instance)
  127. {
  128. char a;
  129.  
  130. if(instance>=0) a=*((char *) getIVptr(instance));
  131. else a=(char) instance;
  132. return g(New)(Unsigned,(unsigned short) a);
  133. }
  134.  
  135.  
  136. CLASS_INSTALL
  137. {
  138. stat x=FUNCFAIL;
  139.  
  140. if(END==(CLASS=g(New)(Class, 0, sizeof(char), END)))
  141.     goto end;
  142. if(addGMthd(CLASS, New, (method) m4New)) goto end;
  143. if(addGMthd(CLASS, GEN(changeVal), (method) m4changeVal)) goto end;
  144. if(addGMthd(CLASS, GEN(valueOf), (method) m4valueOf)) goto end;
  145. if(addGMthd(CLASS, GEN(asString), (method) m4asString)) goto end;
  146. if(addGMthd(CLASS, GEN(asHexStr), (method) m4asHexStr)) goto end;
  147. if(addGMthd(CLASS, GEN(asShortInt), (method) m4asShortInt)) goto end;
  148. if(addGMthd(CLASS, GEN(asLongInt), (method) m4asLongInt)) goto end;
  149. if(addGMthd(CLASS, GEN(asUnsigned), (method) m4asUnsigned)) goto end;
  150. if(addGMthd(CLASS, GEN(asChar), bounceBack)) goto end;
  151. x=FUNCOKAY;
  152.  
  153. end:
  154. return x;
  155. }
  156.