sfile.h
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:7k
源码类别:

IP电话/视频会议

开发平台:

Visual C++

  1. /*
  2.  * sfile.h
  3.  *
  4.  * Structured file I/O channel class.
  5.  *
  6.  * Portable Windows Library
  7.  *
  8.  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
  9.  *
  10.  * The contents of this file are subject to the Mozilla Public License
  11.  * Version 1.0 (the "License"); you may not use this file except in
  12.  * compliance with the License. You may obtain a copy of the License at
  13.  * http://www.mozilla.org/MPL/
  14.  *
  15.  * Software distributed under the License is distributed on an "AS IS"
  16.  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  17.  * the License for the specific language governing rights and limitations
  18.  * under the License.
  19.  *
  20.  * The Original Code is Portable Windows Library.
  21.  *
  22.  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
  23.  *
  24.  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
  25.  * All Rights Reserved.
  26.  *
  27.  * Contributor(s): ______________________________________.
  28.  *
  29.  * $Log: sfile.h,v $
  30.  * Revision 1.15  1999/03/09 02:59:51  robertj
  31.  * Changed comments to doc++ compatible documentation.
  32.  *
  33.  * Revision 1.14  1999/02/16 08:11:10  robertj
  34.  * MSVC 6.0 compatibility changes.
  35.  *
  36.  * Revision 1.13  1998/09/24 07:24:01  robertj
  37.  * Moved structured fiel into separate module so don't need silly implementation file for GNU C.
  38.  *
  39.  * Revision 1.12  1998/09/23 06:21:23  robertj
  40.  * Added open source copyright license.
  41.  *
  42.  * Revision 1.11  1996/01/23 13:15:38  robertj
  43.  * Mac Metrowerks compiler support.
  44.  *
  45.  * Revision 1.10  1995/06/17 11:13:19  robertj
  46.  * Documentation update.
  47.  *
  48.  * Revision 1.9  1995/03/14 12:42:34  robertj
  49.  * Updated documentation to use HTML codes.
  50.  *
  51.  * Revision 1.8  1995/01/14  06:19:39  robertj
  52.  * Documentation
  53.  *
  54.  * Revision 1.7  1994/08/23  11:32:52  robertj
  55.  * Oops
  56.  *
  57.  * Revision 1.6  1994/08/22  00:46:48  robertj
  58.  * Added pragma fro GNU C++ compiler.
  59.  *
  60.  * Revision 1.5  1994/04/20  12:17:44  robertj
  61.  * PFilePath split
  62.  *
  63.  * Revision 1.4  1994/01/03  04:42:23  robertj
  64.  * Mass changes to common container classes and interactors etc etc etc.
  65.  *
  66.  * Revision 1.3  1993/08/21  01:50:33  robertj
  67.  * Made Clone() function optional, default will assert if called.
  68.  *
  69.  * Revision 1.2  1993/07/14  12:49:16  robertj
  70.  * Fixed RCS keywords.
  71.  *
  72.  */
  73. #define _PSTRUCTUREDFILE
  74. #ifdef __GNUC__
  75. #pragma interface
  76. #endif
  77. /**A class representing a a structured file that is portable accross CPU
  78.    architectures (as in the XDR protocol).
  79.    
  80.    This differs from object serialisation in that the access is always to a
  81.    disk file and is random access. It would primarily be used for database
  82.    type applications.
  83.  */
  84. class PStructuredFile : public PFile
  85. {
  86.   PCLASSINFO(PStructuredFile, PFile);
  87.   private:
  88.     BOOL Read(void * buf, PINDEX len) { return PFile::Read(buf, len); }
  89.     BOOL Write(const void * buf, PINDEX len) { return PFile::Write(buf, len); }
  90.   public:
  91.   /**@name Construction */
  92.   //@{
  93.     /**Create a structured file object but do not open it. It does not
  94.        initially have a valid file name. However, an attempt to open the file
  95.        using the #PFile::Open()# function will generate a unique
  96.        temporary file.
  97.        
  98.        The initial structure size is one byte.
  99.      */
  100.     PStructuredFile();
  101.     /**Create a unique temporary file name, and open the file in the specified
  102.        mode and using the specified options. Note that opening a new, unique,
  103.        temporary file name in ReadOnly mode will always fail. This would only
  104.        be usefull in a mode and options that will create the file.
  105.        The #PChannel::IsOpen()# function may be used after object
  106.        construction to determine if the file was successfully opened.
  107.      */
  108.     PStructuredFile(
  109.       OpenMode mode,          /// Mode in which to open the file.
  110.       int opts = ModeDefault  /// #OpenOptions enum# for open operation.
  111.     );
  112.       
  113.     /**Create a structured file object with the specified name and open it in
  114.        the specified mode and with the specified options.
  115.        The #PChannel::IsOpen()# function may be used after object
  116.        construction to determine if the file was successfully opened.
  117.      */
  118.     PStructuredFile(
  119.       const PFilePath & name,    /// Name of file to open.
  120.       OpenMode mode = ReadWrite, /// Mode in which to open the file.
  121.       int opts = ModeDefault     /// #OpenOptions enum# for open operation.
  122.     );
  123.   //@}
  124.   /**@name Structured I/O functions */
  125.   //@{
  126.     /**Read a sequence of bytes into the specified buffer, translating the
  127.        structure according to the specification made in the
  128.        #SetStructure()# function.
  129.        @return
  130.        TRUE if the structure was successfully read.
  131.      */
  132.     BOOL Read(
  133.       void * buffer   /// Pointer to structure to receive data.
  134.     );
  135.       
  136.     /**Write a sequence of bytes into the specified buffer, translating the
  137.        structure according to the specification made in the
  138.        #SetStructure()# function.
  139.        @return
  140.        TRUE if the structure was successfully written.
  141.      */
  142.     BOOL Write(
  143.       const void * buffer   /// Pointer to structure to write data from.
  144.     );
  145.   //@}
  146.   /**@name Structure definition functions */
  147.   //@{
  148.     /**Get the size of each structure in the file.
  149.        @return
  150.        number of bytes in a structure.
  151.      */
  152.     PINDEX GetStructureSize() { return structureSize; }
  153.     /// All element types in a structure
  154.     enum ElementType {
  155.       /// Element is a single character.
  156.       Character,    
  157.       /// Element is a 16 bit integer.
  158.       Integer16,    
  159.       /// Element is a 32 bit integer.
  160.       Integer32,    
  161.       /// Element is a 64 bit integer.
  162.       Integer64,    
  163.       /// Element is a 32 bit IEE floating point number.
  164.       Float32,      
  165.       /// Element is a 64 bit IEE floating point number.
  166.       Float64,      
  167.       /// Element is a 80 bit IEE floating point number.
  168.       Float80,      
  169.       NumElementTypes
  170.     };
  171.     /// Elements in the structure definition.
  172.     struct Element {
  173.       /// Type of element in structure.
  174.       ElementType type;   
  175.       /// Count of elements of this type.
  176.       PINDEX      count;  
  177.     };
  178.     /** Set the structure of each record in the file. */
  179.     void SetStructure(
  180.       Element * structure,  /// Array of structure elements
  181.       PINDEX numElements    /// Number of structure elements in structure.
  182.     );
  183.   //@}
  184.   protected:
  185.   // Member variables
  186.     /// Number of bytes in structure.
  187.     PINDEX structureSize;
  188.     /// Array of elements in the structure.
  189.     Element * structure;
  190.     /// Number of elements in the array.
  191.     PINDEX numElements;
  192. #ifdef DOC_PLUS_PLUS
  193. };
  194. #endif
  195. // Class declaration continued in platform specific header file ///////////////