4 * memory file I/O channel class.
6 * Portable Windows Library
8 * Copyright (c) 2002 Equivalence Pty. Ltd.
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/
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
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Contributor(s): ______________________________________.
27 * Revision 1.5 2004/04/03 08:22:21 csoutheren
28 * Remove pseudo-RTTI and replaced with real RTTI
30 * Revision 1.4 2002/12/19 03:35:43 robertj
31 * Fixed missing set of lastWriteCount in Write() function.
33 * Revision 1.3 2002/11/06 22:47:25 robertj
34 * Fixed header comment (copyright etc)
36 * Revision 1.2 2002/06/27 03:53:35 robertj
37 * Cleaned up documentation and added Compare() function.
39 * Revision 1.1 2002/06/26 09:03:16 craigs
47 #pragma implementation "memfile.h"
50 #include <ptclib/memfile.h>
54 //////////////////////////////////////////////////////////////////////////////
56 PMemoryFile::PMemoryFile()
62 PMemoryFile::PMemoryFile(const PBYTEArray
& ndata
)
69 PObject::Comparison
PMemoryFile::Compare(const PObject
& obj
) const
71 PAssert(PIsDescendant(&obj
, PMemoryFile
), PInvalidCast
);
72 return data
.Compare(((const PMemoryFile
&)obj
).data
);
76 BOOL
PMemoryFile::Read(void * buf
, PINDEX len
)
78 if ((position
+ len
) > data
.GetSize())
79 len
= data
.GetSize() - position
;
84 ::memcpy(buf
, position
+ (const BYTE
* )data
, len
);
89 return lastReadCount
!= 0;
93 BOOL
PMemoryFile::Write(const void * buf
, PINDEX len
)
95 memcpy(data
.GetPointer(position
+len
) + position
, buf
, len
);
102 off_t
PMemoryFile::GetLength() const
104 return data
.GetSize();
108 BOOL
PMemoryFile::SetLength(off_t len
)
110 return data
.SetSize(len
);
114 BOOL
PMemoryFile::SetPosition(off_t pos
, FilePositionOrigin origin
)
118 if (pos
> data
.GetSize())
124 if (pos
< -position
|| pos
> (data
.GetSize() - position
))
130 if (pos
< -data
.GetSize())
132 position
= data
.GetSize() - pos
;
139 off_t
PMemoryFile::GetPosition() const
145 // End of File ///////////////////////////////////////////////////////////////