PTLib  Version 2.10.11
sfile.h
Go to the documentation of this file.
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  * $Revision: 24177 $
30  * $Author: rjongbloed $
31  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
32  */
33 
34 #ifndef PTLIB_STRUCTUREDFILE_H
35 #define PTLIB_STRUCTUREDFILE_H
36 
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40 
41 
49 class PStructuredFile : public PFile
50 {
51  PCLASSINFO(PStructuredFile, PFile);
52 
53  private:
54  PBoolean Read(void * buf, PINDEX len) { return PFile::Read(buf, len); }
55  PBoolean Write(const void * buf, PINDEX len) { return PFile::Write(buf, len); }
56 
57  public:
68 
78  OpenMode mode,
79  int opts = ModeDefault
80  );
81 
89  const PFilePath & name,
90  OpenMode mode = ReadWrite,
91  int opts = ModeDefault
92  );
94 
104  PBoolean Read(
105  void * buffer
106  );
107 
115  PBoolean Write(
116  const void * buffer
117  );
119 
127  PINDEX GetStructureSize() { return structureSize; }
128 
130  enum ElementType {
146  };
147 
149  struct Element {
153  PINDEX count;
154  };
155 
157  void SetStructure(
158  Element * structure,
159  PINDEX numElements
160  );
162 
163  protected:
164  // Member variables
167 
170 
172  PINDEX numElements;
173 
174 
175 // Include platform dependent part of class
176 #ifdef _WIN32
177 #include "msos/ptlib/sfile.h"
178 #else
179 #include "unix/ptlib/sfile.h"
180 #endif
181 };
182 
183 
184 #endif // PTLIB_STRUCTUREDFILE_H
185 
186 
187 // End Of File ///////////////////////////////////////////////////////////////
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the file channel.
Element is a 64 bit IEE floating point number.
Definition: sfile.h:142
This class represents a disk file.
Definition: file.h:60
Element * structure
Array of elements in the structure.
Definition: sfile.h:169
Element is a 16 bit integer.
Definition: sfile.h:134
ElementType type
Type of element in structure.
Definition: sfile.h:151
Elements in the structure definition.
Definition: sfile.h:149
Element is a 80 bit IEE floating point number.
Definition: sfile.h:144
This class describes a full description for a file on the particular platform.
Definition: filepath.h:65
File can be both read and written.
Definition: file.h:80
Definition: sfile.h:145
ElementType
All element types in a structure.
Definition: sfile.h:130
Element is a 32 bit IEE floating point number.
Definition: sfile.h:140
BOOL PBoolean
Definition: object.h:102
PINDEX structureSize
Number of bytes in structure.
Definition: sfile.h:166
PINDEX numElements
Number of elements in the array.
Definition: sfile.h:172
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write to the file channel.
PINDEX count
Count of elements of this type.
Definition: sfile.h:153
void SetStructure(Element *structure, PINDEX numElements)
Set the structure of each record in the file.
Element is a single character.
Definition: sfile.h:132
File options depend on the OpenMode parameter.
Definition: file.h:95
PStructuredFile()
Create a structured file object but do not open it.
Element is a 32 bit integer.
Definition: sfile.h:136
A class representing a a structured file that is portable accross CPU architectures (as in the XDR pr...
Definition: sfile.h:49
PINDEX GetStructureSize()
Get the size of each structure in the file.
Definition: sfile.h:127
Element is a 64 bit integer.
Definition: sfile.h:138
OpenMode
When a file is opened, it may restrict the access available to operations on the object instance...
Definition: file.h:77