home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / Programming / c-runtime / dispatch / RCS / record-inline.h,v < prev   
Encoding:
Text File  |  1992-08-18  |  6.2 KB  |  280 lines

  1. head    1.3;
  2. access;
  3. symbols;
  4. locks; strict;
  5. comment    @ * @;
  6.  
  7.  
  8. 1.3
  9. date    92.08.18.04.46.58;    author dglattin;    state Exp;
  10. branches;
  11. next    1.2;
  12.  
  13. 1.2
  14. date    92.04.13.11.43.08;    author dennisg;    state Exp;
  15. branches;
  16. next    1.1;
  17.  
  18. 1.1
  19. date    92.02.25.11.12.45;    author dennisg;    state Exp;
  20. branches;
  21. next    ;
  22.  
  23.  
  24. desc
  25. @Really just a temporary thing.
  26. Provides a OO technique to access an array.
  27. Its use was to provide a solid array interface rather than 
  28. blind indexing.  Worked well I might add.
  29. @
  30.  
  31.  
  32. 1.3
  33. log
  34. @Saving a working version before release.
  35. @
  36. text
  37. @/* -*-c-*- */
  38.  
  39. /* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
  40.  
  41. This file is part of GNU CC.
  42.  
  43. GNU CC is free software; you can redistribute it and/or modify
  44. it under the terms of the GNU General Public License as published by
  45. the Free Software Foundation; either version 2, or (at your option)
  46. any later version.
  47.  
  48. GNU CC is distributed in the hope that it will be useful,
  49. but WITHOUT ANY WARRANTY; without even the implied warranty of
  50. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  51. GNU General Public License for more details.
  52.  
  53. You should have received a copy of the GNU General Public License
  54. along with GNU CC; see the file COPYING.  If not, write to
  55. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  56.  
  57. /* As a special exception, if you link this library with files
  58.    compiled with GCC to produce an executable, this does not cause
  59.    the resulting executable to be covered by the GNU General Public License.
  60.    This exception does not however invalidate any other reasons why
  61.    the executable file might be covered by the GNU General Public License.  */
  62.  
  63. /* 
  64.  * $Header: /usr/user/dennis_glatting/ObjC/c-runtime/lib/RCS/objc-core.c,v 1.14
  65.  * 1992/01/03 02:55:03 dennisg Exp dennisg $ $Author: dennisg $ $Date:
  66.  * 1992/01/03 02:55:03 $ $Log: record-inline.h,v $
  67.  * Revision 1.2  1992/04/13  11:43:08  dennisg
  68.  * Check in after array version of run-time works.
  69.  * Expect more changes as hash version and other changes are made.
  70.  *
  71.  * Revision 1.1  1992/02/25  11:12:45  dennisg
  72.  * Initial revision
  73.  * 
  74.  */
  75.  
  76.  
  77. #ifndef _record_inline_INCLUDE_GNU
  78. #define _record_inline_INCLUDE_GNU
  79.  
  80. #include  <assert.h>
  81. #include  <stdlib.h>
  82. #include  <sys/types.h>
  83.  
  84.   /* Structure to hold records. */
  85.   typedef struct _Record {  
  86.     u_int capacity,
  87.           numEntries;
  88.     void* (*records)[];
  89.   } Record, *Record_t;
  90.   
  91.  
  92. /* Allocate, initialize and return a new record structure. */
  93. static inline Record_t
  94. record_new (void) {
  95.  
  96.   Record_t  newRecord;
  97.   
  98.   
  99.   newRecord = calloc (1, sizeof (Record));
  100.   assert(newRecord);
  101.   newRecord->capacity = 8;
  102.   newRecord->records = calloc (newRecord->capacity, sizeof (void*));
  103.   assert(newRecord->records);
  104.   
  105.   return newRecord;
  106. }
  107.  
  108.  
  109. /* Delete the record. */
  110. static inline void
  111. record_delete (Record_t record) {
  112.  
  113.   free (record->records);
  114.   free (record);
  115. }
  116.  
  117.  
  118. /* Return the number of entries in the reord. */
  119. static inline u_int
  120. record_entries (Record_t record) {
  121.  
  122.   return record->numEntries;
  123. }
  124.  
  125.  
  126. /* return the capacity of the record. */
  127. static inline u_int
  128. record_capacity (Record_t record) {
  129.  
  130.  
  131.   return record->capacity;
  132. }
  133.  
  134.  
  135. /* Store an entry at the specified record location. */
  136. static inline void
  137. record_store_at (u_int i, void* value, Record_t record) {
  138.  
  139.  
  140.   assert(i);
  141.   assert(i <= record_entries (record));
  142.  
  143.   (*record->records)[ i ] = value;
  144. }
  145.  
  146.  
  147. /* Make a record entry.  Expand the record's size if full. */
  148. static inline void
  149. record_store (void* value, Record_t record) {
  150.  
  151.  
  152.   ++record->numEntries;
  153.   if(record_entries (record) == record_capacity (record)) {
  154.     record->capacity *= 2;
  155.     record->records = 
  156.       realloc (record->records, (record_capacity (record) * sizeof (void*)));
  157.   }
  158.   record_store_at (record_entries (record), value, record);
  159. }
  160.  
  161.  
  162. /* get a value from the record. */
  163. static inline void*
  164. record_get (u_int i, Record_t record) {
  165.  
  166.  
  167.   assert( i );
  168.   assert( i <= record_entries (record));
  169.   return (*record->records)[ i ];
  170. }
  171.  
  172. #endif
  173.  
  174. @
  175.  
  176.  
  177. 1.2
  178. log
  179. @Check in after array version of run-time works.
  180. Expect more changes as hash version and other changes are made.
  181. @
  182. text
  183. @d1 27
  184. a27 22
  185. /*
  186.  * -*-c-*- The routines in this file are used to simplify record keeping in
  187.  * the run-time. 
  188.  *
  189.  * Generally each function does not include a documentation header before its
  190.  * implementation.  Such headers are found in interface header files. 
  191.  *
  192.  * Copyright (C) 1991 Threaded Technologies Inc. 
  193.  *
  194.  * This program is free software; you can redistribute it and/or modify it
  195.  * under the terms of the GNU General Public License as published by the Free
  196.  * Software Foundation; either version 1, or any later version. 
  197.  *
  198.  * This program is distributed in the hope that it will be useful, but WITHOUT
  199.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  200.  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  201.  * more details. 
  202.  *
  203.  * You should receive a copy of the GNU General Public License along with this
  204.  * program; if not, write to the Free Software Foundation, Inc., 675 Mass
  205.  * Ave, Cambridge, MA 02139, USA. 
  206.  *
  207. d31 4
  208. d44 3
  209. a46 3
  210. #include    <assert.h>
  211. #include    <stdlib.h>
  212. #include    <sys/types.h>
  213. d48 7
  214. a54 7
  215.     /* Structure to hold records. */
  216.     typedef struct _Record {    
  217.         u_int    capacity,
  218.                     numEntries;
  219.         void*    (*records)[];
  220.     } Record, *Record_t;
  221.     
  222. d60 10
  223. a69 10
  224.     Record_t    newRecord;
  225.     
  226.     
  227.     newRecord = calloc (1, sizeof (Record));
  228.     assert(newRecord);
  229.     newRecord->capacity = 8;
  230.     newRecord->records = calloc (newRecord->capacity, sizeof (void*));
  231.     assert(newRecord->records);
  232.     
  233.     return newRecord;
  234. d77 2
  235. a78 2
  236.     free (record->records);
  237.     free (record);
  238. d86 1
  239. a86 1
  240.     return record->numEntries;
  241. d95 1
  242. a95 1
  243.     return record->capacity;
  244. d104 2
  245. a105 2
  246.     assert(i);
  247.     assert(i <= record_entries (record));
  248. d107 1
  249. a107 1
  250.     (*record->records)[ i ] = value;
  251. d116 7
  252. a122 7
  253.     ++record->numEntries;
  254.     if(record_entries (record) == record_capacity (record)) {
  255.         record->capacity *= 2;
  256.         record->records = 
  257.             realloc (record->records, (record_capacity (record) * sizeof (void*)));
  258.     }
  259.     record_store_at (record_entries (record), value, record);
  260. d131 3
  261. a133 3
  262.     assert( i );
  263.     assert( i <= record_entries (record));
  264.     return (*record->records)[ i ];
  265. @
  266.  
  267.  
  268. 1.1
  269. log
  270. @Initial revision
  271. @
  272. text
  273. @d25 4
  274. a28 1
  275.  * 1992/01/03 02:55:03 $ $Log: objc-core.c,v $ 
  276. d56 1
  277. a56 1
  278.     newRecord->capacity = 128;
  279. @
  280.