home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c085 / 2.ddi / BCFILE.DOC < prev    next >
Encoding:
Text File  |  1991-04-25  |  15.6 KB  |  469 lines

  1. Win++ Version 2.00                                                  BCFILE.DOC
  2.  
  3.  
  4.                          BCFile Class Documentation
  5.  
  6.                                 Version 2.00
  7.                                April 25, 1991
  8.  
  9.  
  10.                            POSITION IN HIERARCHY
  11.  
  12. BCObject
  13.   BCDataObject
  14.   BCDevice
  15.   BCDispObject
  16.   BCFile           <--
  17.   BCGraphicObject
  18.   BCList
  19.  
  20.                                   SUMMARY
  21.  
  22. BCFile is an alternative to C++ streams and I/O streams.  Its member functions
  23. provide file input and output services for a variety of fundamental data types
  24. in a type-safe manner.
  25.  
  26.  
  27.                                 DECLARATION
  28.  
  29. BCFile is declared in the FILE.H header file.
  30.  
  31.    class BCFile : public BCObject
  32.    {
  33.        FILE *spFile;
  34.        CHAR caFileName[120];
  35.        WORD wMode;
  36.        BCModule *opModule;
  37.    public:
  38.        BCFile(CHAR     *cpFileName,
  39.               WORD      wOpenMode = 0,
  40.               BCModule *opMod     = (BCModule *)BCGetApp());
  41.        BCFile(CHAR     *cpFileName,
  42.               CHAR     *cpFileExt,
  43.               BOOL      blFrcExt  = FALSE,
  44.               WORD      wOpenMode = 0,
  45.               BCModule *opMod     = (BCModule *)BCGetApp());
  46.        BCFile(FILE     *spFilePtr,
  47.               CHAR     *cpFileName = NULL,
  48.               WORD      wOpenMode  = 0,
  49.               BCModule *opMod      = (BCModule *)BCGetApp());
  50.       ~BCFile(VOID);
  51.        BOOL      Open(WORD wOpenMode);
  52.        BOOL      Close(VOID);
  53.        WORD      Read(VOID *pBuf,WORD wCnt);
  54.        WORD      Write(VOID *pBuf,WORD wCnt);
  55.        LONG      GetPos(VOID);
  56.        LONG      SetPos(LONG lPos,WORD wMode);
  57.        LONG      GetLen(VOID);
  58.        BOOL      Flush(VOID);
  59.        BOOL      Delete(VOID);
  60.        INT       GetChr(VOID);
  61.        BOOL      GetBlk(VOID *pBlk,WORD wLen);
  62.        BOOL      GetStr(CHAR *cpBuf,WORD wMaxLen);
  63.        BOOL      PutBlk(VOID *pBlk,WORD wLen);
  64.        BOOL      PutChrs(INT iChr,WORD wCnt);
  65.        BOOL      PutChr(INT iChr);
  66.        BOOL      PutStr(CHAR *cpStr);
  67.        BOOL      FrmtPutStr(CHAR *cpFrmt,...);
  68.        BOOL      LoadByte(BYTE  bByte);
  69.        BOOL      LoadBool(BOOL  blBool);
  70.        BOOL      LoadInt(INT  iInt);
  71.        BOOL      LoadWord(WORD  wWord);
  72.        BOOL      LoadCoord(COORD  coCoord);
  73.        BOOL      LoadLong(LONG  lLong);
  74.        BOOL      LoadDblWord(DWORD  dwDblWord);
  75.        BOOL      LoadFloat(FLOAT  fFloat);
  76.        BOOL      LoadDouble(DOUBLE  dDouble);
  77.        BOOL      LoadPtr(VOID * pPtr);
  78.        BOOL      LoadString(CHAR *cpString);
  79.        BOOL      LoadStringPtr(CHAR * cpString);
  80.        LONG      LoadLength(VOID);
  81.        BOOL      LoadFarBlk(VOID HUGE *lpBlk,LONG lSize);
  82.        BOOL      SaveByte(BYTE bByte);
  83.        BOOL      SaveBool(BOOL blBool);
  84.        BOOL      SaveInt(INT iInt);
  85.        BOOL      SaveWord(WORD wWord);
  86.        BOOL      SaveCoord(COORD coCoord);
  87.        BOOL      SaveLong(LONG lLong);
  88.        BOOL      SaveDblWord(DWORD dwDblWord);
  89.        BOOL      SaveFloat(FLOAT fFloat);
  90.        BOOL      SaveDouble(DOUBLE dDouble);
  91.        BOOL      SavePtr(VOID *pPtr);
  92.        BOOL      SaveString(CHAR *cpString);
  93.        BOOL      SaveStringPtr(CHAR *cpString);
  94.        BOOL      SaveLength(DWORD dwLen);
  95.        BOOL      SaveFarBlk(VOID HUGE *lpBlk,LONG lSize);
  96.        FILE     *GetPtr(VOID);
  97.        CHAR     *GetName(VOID);
  98.        CHAR     *GetErrLocStr(LONG lOfs);
  99.        CHAR     *GetErrLocStr(VOID);
  100.        BOOL      IsOpen(VOID);
  101.        BCModule *GetModule(VOID) { return(opModule); }
  102.        VOID      SetModule(BCModule *opMod) { opModule = opMod; }
  103.    };
  104.    
  105.  
  106.  
  107.                                  CONSTANTS
  108.  
  109.         /* file open modes (from cdecls.h) */
  110.  
  111. #define BC_READ_OPEN       0x0001  /* open file for reading */
  112. #define BC_WRITE_OPEN      0x0002  /* open file for writing */
  113. #define BC_APPEND_FILE     0x0004  /* append file attribute */
  114. #define BC_TRUNC_FILE      0x0008  /* truncate file attribute */
  115. #define BC_BINARY_FILE     0x0010  /* binary file attribute */
  116.  
  117.  
  118.         /* SetPos mode codes (from cdecls.h) */
  119.  
  120. #define BC_REL_BOF    0       /* relative to beginning of file */
  121. #define BC_REL_CRNT   1       /* relative to current position */
  122. #define BC_REL_EOF    2       /* relative to end of file */
  123.  
  124.  
  125.  
  126.                                 CONSTRUCTORS
  127.  
  128. BCFile(CHAR     *cpFileName,
  129.        WORD      wOpenMode = 0,
  130.        BCModule *opMod     = (BCModule *)BCGetApp());
  131.  
  132.    This constructor accepts a complete filename and  optionally  accepts  open
  133.    mode flags.  These flags are defined in CDECLS.H.  If wOpenMode is nonzero,
  134.    then the file is opened by the constructor.
  135.  
  136. BCFile(CHAR     *cpFileName,
  137.        CHAR     *cpFileExt,
  138.        BOOL      blFrcExt  = FALSE,
  139.        WORD      wOpenMode = 0,
  140.        BCModule *opMod     = (BCModule *)BCGetApp());
  141.  
  142.    This  constructor  accepts  a  default  filename extension.  If blFrcExt is
  143.    FALSE and if the given filename  does  not  have  an  extension,  then  the
  144.    cpFileExt extension is appended to the name.  If blFrcExt is TRUE, then the
  145.    cpFileExt   extension   replaces  any  existing  filename  extension.   The
  146.    wOpenMode flags are defined in CDECLS.H.  If wOpenMode is nonzero, then the
  147.    file is opened by the constructor.
  148.  
  149. BCFile(FILE     *spFilePtr,
  150.        CHAR     *cpFileName = NULL,
  151.        WORD      wOpenMode  = 0,
  152.        BCModule *opMod      = (BCModule *)BCGetApp());
  153.  
  154.    This constructor creates a BCFile object from a pointer to an existing FILE
  155.    structure, which must pertain to an existing, open file.
  156.  
  157.  
  158.                                  DESTRUCTOR
  159.  
  160. ~BCFile(VOID);
  161.  
  162. This is the destructor.  It closes the file if it is open.
  163.  
  164.  
  165.                               MEMBER FUNCTIONS
  166.  
  167. BOOL Close(VOID);
  168.  
  169.    "Close" closes the file, which (of course) must already have  been  opened.
  170.    It returns TRUE if successful.
  171.  
  172. BOOL Delete(VOID);
  173.  
  174.    "Delete"  deletes  the  file, which should not be open.  It returns TRUE if
  175.    successful.
  176.  
  177. BOOL Flush(VOID);
  178.  
  179.    "Flush" flushes the file buffers.  It returns TRUE if successful.
  180.  
  181. BOOL FrmtPutStr(CHAR *cpFrmt,...);
  182.  
  183.    "FrmtPutStr" uses vfprintf() to format and write a string to the file.   It
  184.    returns TRUE if successful.
  185.  
  186. BOOL GetBlk(VOID *pBlk,WORD wLen);
  187.  
  188.    "GetBlk"  reads  a  block  of bytes from the file.  It returns TRUE if wLen
  189.    bytes were successfully read.
  190.  
  191. INT GetChr(VOID);
  192.  
  193.    "GetChr" reads and return the next character from the file.  It returns  -1
  194.    if EOF or an error is encountered.
  195.  
  196. CHAR *GetErrLocStr(LONG lOfs);
  197.  
  198.    "GetErrLocStr"  (this  version)  returns  a  pointer to a string "at offset
  199.    (ofs) in file (name)" using lOfs and the current filename.
  200.  
  201. CHAR *GetErrLocStr(VOID);
  202.  
  203.    "GetErrLocStr" (this version) returns a pointer  to  a  string  "at  offset
  204.    (ofs)  in  file  (name)"  using  the  current file position and the current
  205.    filename.
  206.  
  207. LONG GetLen(VOID);
  208.  
  209.    "GetLen" returns the length of the file, or -1L if error.
  210.  
  211. BCModule *GetModule(VOID);
  212.  
  213.    "GetModule" returns the BCModule object indicating the module that owns the
  214.    file.
  215.  
  216. CHAR *GetName(VOID);
  217.  
  218.    "GetName" returns a pointer to the filename.
  219.  
  220. LONG GetPos(VOID);
  221.  
  222.    "GetPos" returns a number representing the current position  in  the  file.
  223.    It returns -1L upon error.
  224.  
  225. FILE *GetPtr(VOID);
  226.  
  227.    "GetPtr"  returns  the  FILE  pointer for the file.  It returns NULL if the
  228.    file is not open.
  229.  
  230. BOOL GetStr(CHAR *cpBuf,WORD wMaxLen);
  231.  
  232.    "GetStr" reads characters from the file up to and including the  next  line
  233.    separator.
  234.  
  235. BOOL IsOpen(VOID);
  236.  
  237.    "IsOpen" returns TRUE if the file is open.
  238.  
  239. BOOL Load(BCFile *opFile);
  240.  
  241.    "Load"  loads  this  BCFile object's data member values from a file that is
  242.    specified by another BCFile object.  The file specified via opFile must  be
  243.    open  for  reading  in  binary  mode, and its file position must point to a
  244.    location  previously  stored  with  BCFile::Save.   It  returns   TRUE   if
  245.    successful.
  246.  
  247. BOOL LoadBool(BOOL  blBool);
  248.  
  249.    "LoadBool"  reads  a BOOL from the file and assigns the value to the blBool
  250.    reference.  It returns TRUE if successful.
  251.  
  252. BOOL LoadByte(BYTE  bByte);
  253.  
  254.    "LoadByte" reads a byte from the file and assigns the  byte  value  to  the
  255.    bByte reference.  It returns TRUE if successful.
  256.  
  257. BOOL LoadCoord(COORD  coCoord);
  258.  
  259.    "LoadCoord"  reads  a  COORD  from  the  file  and assigns the value to the
  260.    coCOORD reference.  It returns TRUE if successful.
  261.  
  262. BOOL LoadDblWord(DWORD  dwDblWord);
  263.  
  264.    "LoadDblWord" reads a double word (4 bytes) from the file and assigns it to
  265.    the dwDblWord reference.  It returns TRUE if successful.
  266.  
  267. BOOL LoadDouble(DOUBLE  dDouble);
  268.  
  269.    "LoadDouble" reads a DOUBLE from the file and assigns  it  to  the  dDouble
  270.    reference.  It returns TRUE if successful.
  271.  
  272. BOOL LoadFarBlk(VOID HUGE *lpBlk,LONG lSize);
  273.  
  274.    "LoadFarBlk" reads data from a file into a far or huge block of memory.  It
  275.    returns TRUE if lSize bytes were successfully read into lpBlk.
  276.  
  277. BOOL LoadFloat(FLOAT  fFloat);
  278.  
  279.    "LoadFloat"  reads  a  FLOAT  from  a  file  and  assigns  it to the fFloat
  280.    reference.  It returns TRUE if successful.
  281.  
  282. BOOL LoadInt(INT  iInt);
  283.  
  284.    "LoadInt" reads an INT from a file and assigns it to  the  iInt  reference.
  285.    It returns TRUE if successful.
  286.  
  287. LONG LoadLength(VOID);
  288.  
  289.    "LoadLength"  reads  a  variable-length length field previously stored with
  290.    SaveLength.  See SaveLength below for the format.  It  returns  the  length
  291.    value or -1L if an error occurred.
  292.  
  293. BOOL LoadLong(LONG  lLong);
  294.  
  295.    "LoadLong"  reads a LONG from a file and assigns it to the lLong reference.
  296.    It returns TRUE if successful.
  297.  
  298. BOOL LoadPtr(VOID * pPtr);
  299.  
  300.    "LoadPtr" reads a VOID pointer from a file  and  assigns  it  to  the  pPtr
  301.    reference.   The  pointer  must  have  been  saved  from a program having a
  302.    corresponding memory model.  The actual value of the pointer is useless  in
  303.    any  program  instance  other  than  the  instance  that saved the pointer,
  304.    although it may be useful to  know  whether  the  pointer  is  0.   LoadPtr
  305.    returns TRUE if successful.
  306.  
  307. BOOL LoadString(CHAR *cpString);
  308.  
  309.    "LoadString"  reads  a  string  from  the  file, copying it into the buffer
  310.    pointed to by cpString.  The string is stored in the  file  as  a  variable
  311.    length  length field (see SaveLength) followed by the string bytes (without
  312.    the null terminator).  The cpString argument must be big enough to hold the
  313.    string.  Otherwise, use Loadlength to check the length first, and then  use
  314.    GetBlk,   Read,   or   SetPos  accordingly.   LoadString  returns  TRUE  if
  315.    successful.
  316.  
  317. BOOL LoadStringPtr(CHAR * cpString);
  318.  
  319.    "LoadStringPtr" allocates memory for and reads a string from  the  file  in
  320.    the  same  manner as LoadString.  LoadStringPtr sets the cpString reference
  321.    to point to the allocated memory.  It returns TRUE if successful, or  FALSE
  322.    if an error occurs while allocating the memory or reading the file.
  323.  
  324. BOOL LoadWord(WORD  wWord);
  325.  
  326.    "LoadWord" reads a word (2 bytes) from the file and assigns it to the wWord
  327.    reference.  It returns TRUE if successful.
  328.  
  329. BOOL Open(WORD wOpenMode);
  330.  
  331.    "Open"  opens  the  file  with  the  given mode flags, which are defined in
  332.    CDECLS.H.  The file must not already be open in this object.  Open  returns
  333.    TRUE if the file was successfully opened.
  334.  
  335. BOOL PutBlk(VOID *pBlk,WORD wLen);
  336.  
  337.    "PutBlk"  writes  a  block  of  bytes to the file.  It returns TRUE if wLen
  338.    bytes were successfully written.
  339.  
  340. BOOL PutChr(INT iChr);
  341.  
  342.    "PutChr" writes the  byte  in  iChr  to  the  file.   It  returns  TRUE  if
  343.    successful.
  344.  
  345. BOOL PutChrs(INT iChr,WORD wCnt);
  346.  
  347.    "PutChrs"  writes  wCnt copies of the byte in iChr to the file.  It returns
  348.    TRUE if wCnt bytes were written.
  349.  
  350. BOOL PutStr(CHAR *cpStr);
  351.  
  352.    "PutStr" writes the given string to the file (without the NUL  terminator).
  353.    It returns TRUE if successful.
  354.  
  355. WORD Read(VOID *pBuf,WORD wCnt);
  356.  
  357.    "Read" reads from the file.  It returns the number of bytes read.
  358.  
  359. BOOL Save(BCFile *opFile);
  360.  
  361.    "Save" writes this object to the file represented by another BCFile object,
  362.    which  must  be  open  for  writing  in  binary  mode.   It returns TRUE if
  363.    successful.
  364.  
  365. BOOL SaveBool(BOOL blBool);
  366.  
  367.    "SaveBool" writes a BOOL to the file.  It returns TRUE if successful.
  368.  
  369. BOOL SaveByte(BYTE bByte);
  370.  
  371.    "SaveByte" writes a byte to the file.  It returns TRUE if successful.
  372.  
  373. BOOL SaveCoord(COORD coCoord);
  374.  
  375.    "SaveCoord" writes  a  COORD  value  to  the  file.   It  returns  TRUE  if
  376.    successful.
  377.  
  378. BOOL SaveDblWord(DWORD dwDblWord);
  379.  
  380.    "SaveDblWord" writes a double word (4 bytes) to a file.  It returns TRUE if
  381.    successful.
  382.  
  383. BOOL SaveDouble(DOUBLE dDouble);
  384.  
  385.    "SaveDouble" writes a DOUBLE to the file.  It returns TRUE if successful.
  386.  
  387. BOOL SaveFarBlk(VOID HUGE *lpBlk,LONG lSize);
  388.  
  389.    "SaveFarBlk"  writes  a  far or huge block of data to the file.  It returns
  390.    TRUE if successful.
  391.  
  392. BOOL SaveFloat(FLOAT fFloat);
  393.  
  394.    "SaveFloat" writes  a  FLOAT  value  to  the  file.   It  returns  TRUE  if
  395.    successful.
  396.  
  397. BOOL SaveInt(INT iInt);
  398.  
  399.    "SaveInt" writes an INT value to the file.  It returns TRUE if successful.
  400.  
  401. BOOL SaveLong(LONG lLong);
  402.  
  403.    "SaveLong" writes a LONG value to the file.  It returns TRUE if successful.
  404.  
  405. BOOL SaveLength(DWORD dwLen);
  406.  
  407.    "SaveLength"  writes  a  variable-length  length  field  to  the file.  Its
  408.    objective is to use the fewest bytes possible to hold the length value.  It
  409.    breaks up the length value into up to five bytes, each with 7 bits  of  the
  410.    length  value  and a bit flag.  If the flag bit is set, it means that there
  411.    is at least one more byte following the byte.  These length fragment  bytes
  412.    are  stored with the bytes holding the most significant parts of the length
  413.    first.  Therefore, with this scheme, if the length is less than 128 it  can
  414.    be  stored  with  one  byte;  if less than 16384, two bytes; etc., up to 32
  415.    bits.  SaveLength returns TRUE if successful.
  416.  
  417. BOOL SavePtr(VOID *pPtr);
  418.  
  419.    "SavePtr" writes pointer value to the file.  The number  of  bytes  written
  420.    depends on the program's memory model.  SavePtr returns TRUE if successful.
  421.  
  422. BOOL SaveString(CHAR *cpString);
  423.  
  424.    "SaveString"  writes  a  string to the file.  It stores first the length of
  425.    the string using SaveLength, followed by the string bytes (write  the  null
  426.    terminator).  The cpString argument must point to a null-terminated string.
  427.    SaveString returns TRUE if successful.
  428.  
  429. BOOL SaveStringPtr(CHAR *cpString);
  430.  
  431.    "SaveStringPtr" writes a string to the file.  It is the same as SaveString.
  432.  
  433. BOOL SaveWord(WORD wWord);
  434.  
  435.    "SaveWord"  writes  a  word  (2  bytes)  to  the  file.  It returns TRUE if
  436.    successful.
  437.  
  438. VOID SetModule(BCModule *opMod);
  439.  
  440.    "SetModule" specifies the BCModule object that owns the file.
  441.  
  442. LONG SetPos(LONG lPos,WORD wMode);
  443.  
  444.    "SetPos" moves the current  position  in  the  file.   The  wMode  argument
  445.    specifies  whether  lPos  is  relative  to  the  beginning, end, or current
  446.    position of the file.  (Use the constant  values  listed  after  the  class
  447.    declaration above.)  It returns -1L upon error.
  448.  
  449. WORD Write(VOID *pBuf,WORD wCnt);
  450.  
  451.    "Write" writes to the file.  It returns the number of bytes written.
  452.  
  453.  
  454.                                   EXAMPLE
  455.  
  456. BCFile oFile("MyName");
  457.  
  458. if (oFile.Open(BC_WRITE_OPEN))
  459. {
  460.     if (!oFile.PutStr("Hello, file.\n"))
  461.         DispMsg("Error writing file.");
  462.  
  463.     oFile.Close();
  464. }
  465. else
  466.     DispMsg("Unable to open file.");
  467.  
  468.                          === End of BCFILE.DOC ===
  469.