home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / DynamicArrayObjects / CBigArray.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-02  |  3.9 KB  |  107 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  
  3.      BigArray
  4.      
  5.      This class implements arrays that can be more than 32K in size and store
  6.      any kind of element.
  7.      
  8.      By:    Eric Yiskis
  9.         
  10.  ******************************************************************************/
  11.  
  12. #define _H_CBigArray
  13.  
  14. #include <Global.h>                    /*  handy declarations                 */
  15. #include <CObject.h>                /* Interface for its superclass        */
  16. #include <CDataFile.h>
  17. #include <CApplication.h>
  18.  
  19. extern CApplication *gApplication;
  20.  
  21. /*-------------------------------------------------------------------------------*/                        
  22.  
  23. typedef struct {
  24.     long    nElements;            /* number of elements allocated        */
  25.     int        nElementSize;        /* length in bytes of each element     */
  26. } AMFData;                      /* Array Mapping Function data         */
  27.  
  28. /*-------------------------------------------------------------------------------*/                        
  29.  
  30. struct CBigArray : CObject {    
  31.  
  32.     /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/                        
  33.     /* Instance Variables */
  34.     
  35.     Handle        hData;
  36.     AMFData        amf;
  37.  
  38.     /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/                        
  39.     /* Instance Methods */
  40.     
  41.     /*-- Creation/Termination --*/
  42.     void    IBigArray(void);
  43.     /* pre - Object has been allocated but not initialized                    */
  44.     /* post- Object has been initialized                                    */
  45.     
  46.     Boolean    CreateData(long nElements,int nElementSizeIn,Handle hDataIn);
  47.     /* pre - Object has been initialized but not created by CreateData or    */
  48.     /*         LoadData.                                                        */
  49.     /*         hDataIn contains NULL or contains data that matches             */
  50.     /*         nMaxElements, and nElementSizeIn dimension parameters.            */
  51.     /* post- if hDataIn == NULL, returns TRUE if array matching the         */
  52.     /*         dimensions could be allocated, otherwise returns FALSE.         */
  53.     /*         if hDataIn != NULL, hDataIn is assumed to be an array that     */
  54.     /*         matches the dimension parameters.                                */
  55.     /* note- If loading an object from a file, use the LoadData method to    */
  56.     /*         instead.                                                        */ 
  57.     
  58.     Boolean    ResizeArray(long nNewNumberOfElements);
  59.     /* pre    Object has been loaded with CreateData or LoadData.                */
  60.     /* post    Elements are added or truncated util there are                     */
  61.     /*        nNewNumberOfElements in the array.  Returns FALSE if the         */
  62.     /*        resize was unsuccessful.                                        */
  63.     
  64.     void    Dispose(void);            /* OVERRIDE */
  65.     
  66.     
  67.     /*-- Element Manipulation --*/
  68.     void    SetValue(long nIndex,char *pSource);    
  69.     /* pre - Object has been created by CreateData or LoadData methods        */
  70.     /* post- data at pSource is copied into location nIndex                    */
  71.     
  72.     void    GetValue(long nIndex,char *pDestination);
  73.     /* pre - Object has been created by CreateData or LoadData methods        */
  74.     /* post- data at pSource is copied into location nIndex                    */
  75.     
  76.     /*-- I/O --*/
  77.     OSErr     LoadData(CDataFile *datafile);
  78.     /* pre - Object has been initialized but not created by CreateData or    */
  79.     /*         LoadData.                                                        */
  80.     /*         datafile is open.                                                */
  81.     /* post- returns the error condition of the attempt to read.            */
  82.     /*       if the error condition == NoErr then the object is                */
  83.     /*          initialized with the data from datafile.                         */
  84.     
  85.     OSErr    SaveData(CDataFile *datafile);
  86.     /* pre - Object has been created by CreateData or LoadData methods        */
  87.     /*         datafile is open.                                                */
  88.     /* post- returns the error condition of the attempt to write.            */
  89.     /*          if the error condition == NoErr then the data has been written */
  90.  
  91.     
  92.     /*-- Misc --*/
  93.     void    GetDimensions(long *nElements, int *nElementSizeOut);
  94.     /* pre - Object has been created by CreateData or LoadData methods        */
  95.     /* post- parameters contain dimensions of the array.                    */
  96.     
  97.     Handle    GetData(void);
  98.     /* pre - Object has been created by CreateData or LoadData methods        */
  99.     /* post- Returns a handle to the data.                                    */
  100.     
  101.     /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/    
  102.     /* private */
  103.     
  104.     long    Offset(long nIndex);     
  105.     /* returns offset (bytes) of element from the beginning of the data handle */
  106. };
  107.