home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dokpr1.zip / stream.h < prev    next >
C/C++ Source or Header  |  1995-11-08  |  7KB  |  194 lines

  1. /**************************************************************************
  2.  *                                                                        *
  3.  *                                                                        *
  4.  *          This code is copyright (c) 1994                               *
  5.  *                     Athena Design, Inc.                                *
  6.  *                                                                        *
  7.  *                                                                        *
  8.  *                ALL RIGHTS RESERVED                                     *
  9.  *                                                                        *
  10.  *                                                                        *
  11.  *                                                                        *
  12.  *                                                                        *
  13.  *                                                                        *
  14.  **************************************************************************/
  15.  
  16. /*
  17.         the header file for the platform independant streaming protocal
  18.         3-9-94 dpp
  19.         
  20.         94-08-30 dpp added support for MFILE_FRAME and changed the defines to const's
  21. */
  22.  
  23. #ifndef _MH_stream
  24.  
  25. #define _MH_stream
  26.  
  27. #include "except.h"
  28. #include "object.h"
  29.  
  30. class MStream : public MObject
  31. {
  32.     public:
  33.  
  34.     MStream(); // initialize as a memory stream
  35.  
  36.     // MStream(MException *,void *,int);
  37.     // MStream(MException *,int,const char *); // initialize to a file
  38.     virtual ~MStream();
  39.  
  40.  
  41.     // in order to get this class to read from your stream of choice
  42.     // implement the following 5 methods and you're all set
  43.     virtual int getPos() = 0; // get the position within the stream
  44.     virtual int getStreamLen() = 0; // gets the total size of the stream
  45.     virtual int seek(int) = 0; // goes to a position within the stream
  46.     virtual int write(const void *,int) = 0; // write a bunch of bytes to the stream
  47.     virtual int read(void *,int) = 0; // read a bunch of bytes from the stream
  48.     virtual int isEOF() = 0; // are we at the end of the file?
  49.     
  50.     virtual void setMesaAttributes() {};
  51.     virtual void setAttributes(const char *) {};
  52.  
  53.     // write an integer to the stream
  54.     void writeInt(int i) {write(&i,sizeof(i));};
  55.     
  56.     // read an integer from the stream
  57.     int readInt() {read(&tmpInt,sizeof(tmpInt)); return tmpInt;};
  58.     long readLong() {read(&tmpLong,sizeof(tmpLong)); return tmpLong;};
  59.     unsigned long readULong() {unsigned long i = 0; read(&i,sizeof(i)); return i;};
  60.     // read a short from the stream
  61.     short readShort() {read(&tmpShort,sizeof(tmpShort)); return tmpShort;};
  62.     // read an unsigned short from the stream
  63.     unsigned short readUShort() {read(&tmpUShort,sizeof(tmpUShort)); return tmpUShort;};
  64.     // read an unsigned character
  65.     int readUChar() {read(&tmpUChar,1); return tmpUChar;};
  66.     // read a character
  67.     int readChar() {read(&tmpChar,1); return tmpChar;};
  68.     long double readLongDouble() { read(&tmpLDouble,sizeof(tmpLDouble)); return tmpLDouble;};
  69.     // reads a double
  70.     double readNumber() {read(&tmpDouble,sizeof(tmpDouble)); return tmpDouble;};
  71.  
  72.     // write a short to the stream
  73.     void writeShort(short s) {write(&s,sizeof(s));};
  74.     void writeUChar(unsigned char c) {write(&c,1);};
  75.  
  76.     // writes a double
  77.     void writeNumber(double n) {write(&n,sizeof(n));};
  78.  
  79.     // read or write a pointer.  This is good only for
  80.     // pointers that will be IN THE SAME PLACE when the
  81.     // stream is read back!!!
  82.     void writePointer(void *vp) {write(&vp,sizeof(void *));};
  83.     const MException *getException() {return &exp;};
  84.     // file version info
  85.     int getVersion() {return version;};
  86.     void setVersion(int i) {version = i;};
  87.  
  88.     
  89.     // reading Excel data types
  90.     int readXLInt();
  91.     double readXLDouble();
  92.     double readXLRK();
  93.     void readXLString(char *);
  94.     
  95.  
  96.     
  97.     
  98.     void writeLongDouble( long double d ) {write(&d,10);};
  99.  
  100.     // read a character string from the stream
  101.     // returns a pointer to a null-terminated string that
  102.     // must be MFree'd
  103.     void *readPtr();
  104.  
  105.     // used to write a string pointer to the stream
  106.     void writePtr(const void *,int);
  107.     void writeString(const char *);
  108.  
  109.     // write a null terminated string to the stream
  110.     void writes(const char *);
  111.     // write an rtf string
  112.     void writeRTF(const char *);
  113.  
  114.     void writeStr(const char *s) {writeString(s);};
  115.     char *readString() {return (char *) readPtr();};
  116.     char *readStr() {return readString();};
  117.     void readString(char *);
  118.  
  119.     void *readPointer();
  120.  
  121.     int isError();
  122.     int getError();
  123.  
  124.     void setupWrite(int);
  125.     void endWrite();
  126.  
  127.     void setupXLWrite( int );
  128.     void endXLWrite();
  129.     
  130.     void setupWK3Write( int );
  131.     void endWK3Write();
  132.  
  133.     int setupRead();
  134.     void unsetRead();
  135.     void endRead();
  136.  
  137.         
  138.  
  139.     protected:
  140.     int type;
  141.     MException exp;
  142.     int nextPos,lastPos;
  143.     int version;
  144.     
  145.     // some temporary workspaces so we don't clog the stack with
  146.     // infrequently used temporary variables
  147.     int tmpInt;
  148.     long tmpLong;
  149.     short tmpShort;
  150.     unsigned short tmpUShort;
  151.     unsigned char tmpUChar;
  152.     char tmpChar;
  153.     long double tmpLDouble;
  154.     double tmpDouble; 
  155. };
  156.  
  157.  
  158. const int MSTREAM_READ = 1;
  159. const int MSTREAM_WRITE = 2;
  160.  
  161. const int ORG_VERSION = 0;
  162.  
  163. const int CURRENT_VERSION = 1;
  164.  
  165. /*
  166.     records in the file format
  167. */
  168.  
  169. const int MFILE_BOF = 1;  // marks the begining of a Mesa file
  170. const int MFILE_EOF = 2; // the last record in a Mesa file
  171. const int MFILE_CELL = 3; // the contents of a cell in a Mesa file
  172. const int MFILE_FORMAT = 4; // a format record
  173. const int MFILE_OLDLAYER = 5; // layer information including runs
  174. const int MFILE_COPY = 6; // the begining of a clipboard copy area
  175. const int MFILE_FONT = 7; // a font record
  176. const int MFILE_SCRIPT = 8; // a script record
  177. const int MFILE_FRAME = 9; // a graphics frame record
  178. const int MFILE_NUMFORMAT = 10; // info on number formats
  179. const int MFILE_LABELS = 11; // the named ranges
  180. const int MFILE_LAYER = 12; // the named ranges
  181. const int MFILE_RECALC = 13; // stuff relating to recalculation
  182. const int MFILE_DEFPRINTHEAD = 14; // the default print header info
  183. const int MFILE_POSITION = 15; // where are the windows?
  184. const int MFILE_NEWSCRIPT = 16; // a new script record
  185. const int MFILE_DDEITEM = 17; // a new script record
  186. const int MFILE_PASSWORD = 18;    // password information
  187. const int MFILE_ZOOM = 19;        // zoom/scale
  188. const int MFILE_BLOB = 20;        // blob storage
  189. const int MFILE_SIZE = 21;        // the number of cells in the array
  190. const int MFILE_TEXTSQUARE = 22;    // hack for 2.0.2/2.0.3 file compatibility
  191. const int MFILE_TABSET = 23;        // hack for 2.0.2/2.0.3 file compat.
  192. // ifndef _MH_stream
  193. #endif
  194.