PTLib  Version 2.10.11
memfile.h
Go to the documentation of this file.
1 /*
2  * memfile.h
3  *
4  * WAV file I/O channel class.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 2002 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
23  * Equivalence Pty Ltd
24  *
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 26949 $
30  * $Author: rjongbloed $
31  * $Date: 2012-02-07 20:27:07 -0600 (Tue, 07 Feb 2012) $
32  */
33 
34 #ifndef PTLIB_PMEMFILE_H
35 #define PTLIB_PMEMFILE_H
36 
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40 
41 
44 class PMemoryFile : public PFile
45 {
46  PCLASSINFO(PMemoryFile, PFile);
47  public:
52  PMemoryFile();
53 
57  const PBYTEArray & data
58  );
59 
62  ~PMemoryFile();
64 
65 
75  const PObject & obj
76  ) const;
78 
79 
93  virtual PBoolean Open(
94  OpenMode mode = ReadWrite, // Mode in which to open the file.
95  int opts = ModeDefault // Options for open operation.
96  );
97 
108  virtual PBoolean Open(
109  const PFilePath & name, // Name of file to open.
110  OpenMode mode = ReadWrite, // Mode in which to open the file.
111  int opts = ModeDefault // <code>OpenOptions</code> enum# for open operation.
112  );
113 
118  virtual PBoolean Close();
119 
131  virtual PBoolean Read(
132  void * buf,
133  PINDEX len
134  );
135 
145  virtual PBoolean Write(
146  const void * buf,
147  PINDEX len
148  );
150 
151 
160  virtual off_t GetLength() const;
161 
168  virtual PBoolean SetLength(
169  off_t len
170  );
171 
182  virtual PBoolean SetPosition(
183  off_t pos,
184  FilePositionOrigin origin = Start
185  );
186 
193  virtual off_t GetPosition() const;
195 
196 
201  const PBYTEArray & GetData() const { return m_data; }
203 
204 
205  protected:
207  off_t m_position;
208 };
209 
210 
211 #endif // PTLIB_PMEMFILE_H
212 
213 
214 // End of File ///////////////////////////////////////////////////////////////
Comparison Compare(const PObject &obj) const
Determine the relative rank of the two objects.
This class represents a disk file.
Definition: file.h:60
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write to the memory file channel.
~PMemoryFile()
Destroy the memory file.
This class is used to allow a block of memory to substitute for a disk file.
Definition: memfile.h:44
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
Comparison
Result of the comparison operation performed by the Compare() function.
Definition: object.h:1184
const PBYTEArray & GetData() const
Get the memory data the file has operated with.
Definition: memfile.h:201
virtual off_t GetPosition() const
Get the current active position in the file for the next read or write operation. ...
BOOL PBoolean
Definition: object.h:102
virtual PBoolean SetLength(off_t len)
Set the size of the file, padding with 0 bytes if it would require expanding the file, or truncating it if being made shorter.
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the memory file channel.
Array of unsigned characters.
Definition: array.h:670
off_t m_position
Definition: memfile.h:207
FilePositionOrigin
Options for the origin in setting the file position.
Definition: file.h:457
virtual off_t GetLength() const
Get the current size of the file.
virtual PBoolean SetPosition(off_t pos, FilePositionOrigin origin=Start)
Set the current active position in the file for the next read or write operation. ...
File options depend on the OpenMode parameter.
Definition: file.h:95
PMemoryFile()
Create a new, empty, memory file.
virtual PBoolean Close()
Close the channel, shutting down the link to the data source.
PBYTEArray m_data
Definition: memfile.h:206
Set position relative to start of file.
Definition: file.h:459
virtual PBoolean Open(OpenMode mode=ReadWrite, int opts=ModeDefault)
Open the current file in the specified mode and with the specified options.
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
OpenMode
When a file is opened, it may restrict the access available to operations on the object instance...
Definition: file.h:77