home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP Advantage / NeXTstep_Advantage.img / YourCallServer / CallRecord.m < prev    next >
Text File  |  1993-04-14  |  3KB  |  169 lines

  1. /* You may freely copy, distribute and reuse the code in this example.
  2.  * NeXT disclaims any warranty of any kind, expressed or implied, as to
  3.  * its fitness for any particular use.
  4.  */ 
  5.  
  6. #import "CallRecord.h"
  7.  
  8. @implementation CallRecord : Object
  9.  
  10. /*
  11.  * Purpose: Set and access data fields in a CallRecord.
  12.  *
  13.  * Two types of methods are implemented for the fields in the CallRecord
  14.  *
  15.  *   Methods of the form -setName: accept a string as input, copy the string 
  16.  *   to a buffer, and set the instance variable to that buffer.
  17.  *
  18.  *   Methods of the form -name retrieve the data for 
  19.  *   the corresponding instance variable.  
  20.  */ 
  21.  
  22. - (const char *)name;
  23. {
  24.     return name;
  25. }
  26.  
  27. - setName:(const char *)theName;
  28. {
  29.     if (theName) {
  30.     name = NXCopyStringBuffer(theName);
  31.     }
  32.     return self;
  33. }
  34.  
  35. - (const char *)street;
  36. {
  37.     return street;
  38. }
  39.  
  40. - setStreet:(const char *)theStreet;
  41. {
  42.     if (theStreet) {
  43.     street = NXCopyStringBuffer(theStreet);
  44.     }
  45.     return self;
  46. }
  47.  
  48. - (const char *)city;
  49. {
  50.     return city;
  51. }
  52.  
  53. - setCity:(const char *)theCity;
  54. {
  55.     if (theCity) {
  56.     city = NXCopyStringBuffer(theCity);
  57.     }
  58.     return self;
  59. }
  60.  
  61. - (const char *)state
  62. {
  63.     return state;
  64. }
  65.  
  66. - setState:(const char *)theState;
  67. {
  68.     if (theState) {
  69.     state = NXCopyStringBuffer(theState);
  70.     }
  71.     return self;
  72. }
  73.  
  74. - (const char *)phone;
  75. {
  76.     return phone;
  77. }
  78.  
  79. - setPhone:(const char *)thePhone;
  80. {
  81.     if (thePhone){
  82.     phone = NXCopyStringBuffer(thePhone);
  83.     }
  84.     return self;
  85. }
  86.  
  87. - (const char *)question;
  88. {
  89.     return question;
  90. }
  91.  
  92. - setQuestion:(const char *)theQuestion;
  93. {
  94.     if (theQuestion) {
  95.     question = NXCopyStringBuffer(theQuestion);
  96.     }
  97.     return self;
  98. }
  99.  
  100. - (const char *)answer;
  101. {
  102.     return answer;
  103. }
  104.  
  105. - setAnswer:(const char *)theAnswer;
  106. {
  107.     if (theAnswer) {
  108.     answer = NXCopyStringBuffer(theAnswer);
  109.     }
  110.     return self;
  111. }
  112.  
  113.  
  114. /*
  115.  * Purpose: Read and write the CallRecord to a stream
  116.  *
  117.  * These standard methods for archiving are inherited from Object. 
  118.  * They're overridden by CallRecord for use in YourCall's data storage system. 
  119.  *
  120.  * When the HashTable containing CallRecords is read from the "call.log" file 
  121.  * in CallController's init method, the HashTable sends a read: message 
  122.  * to each CallRecord it contains. 
  123.  *
  124.  * When the HashTable containing CallRecords is written to the "call.log" file 
  125.  * in CallController's saveCall: method, the HashTable sends a write: message 
  126.  * to each CallRecord it contains. 
  127.  */
  128.  
  129. - read:(NXTypedStream *)stream
  130. {
  131.     [super read:stream];
  132.     NXReadTypes(stream, "*******", &name, &street, &city, &state, &phone, 
  133.     &question, &answer);
  134.     return self;
  135. }
  136.  
  137. - write:(NXTypedStream *)stream
  138. {
  139.     [super write:stream];
  140.     NXWriteTypes(stream, "*******", &name, &street, &city, &state, &phone, 
  141.     &question, &answer);
  142.     return self;
  143. }
  144.  
  145.  
  146. /*
  147.  * Purpose: Frees the CallRecord's storage
  148.  *
  149.  * Inherited from Object 
  150.  *
  151.  * This method is overridden by CallRecord to free storage 
  152.  * allocated by each of the set... methods.  
  153.  *
  154.  */
  155.  
  156. - free
  157. {
  158.     free(name);
  159.     free(street);
  160.     free(city);
  161.     free(state);
  162.     free(phone);
  163.     free(question);
  164.     free(answer);
  165.     return [super free];
  166. }
  167.  
  168. @end
  169.