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.4 2002/12/19 03:35:43 robertj
28 * Fixed missing set of lastWriteCount in Write() function.
30 * Revision 1.3 2002/11/06 22:47:25 robertj
31 * Fixed header comment (copyright etc)
33 * Revision 1.2 2002/06/27 03:53:35 robertj
34 * Cleaned up documentation and added Compare() function.
36 * Revision 1.1 2002/06/26 09:03:16 craigs
44 #pragma implementation "memfile.h"
47 #include <ptclib/memfile.h>
51 //////////////////////////////////////////////////////////////////////////////
53 PMemoryFile::PMemoryFile()
59 PMemoryFile::PMemoryFile(const PBYTEArray
& ndata
)
66 PObject::Comparison
PMemoryFile::Compare(const PObject
& obj
) const
68 PAssert(obj
.IsDescendant(Class()), PInvalidCast
);
69 return data
.Compare(((const PMemoryFile
&)obj
).data
);
73 BOOL
PMemoryFile::Read(void * buf
, PINDEX len
)
75 if ((position
+ len
) > data
.GetSize())
76 len
= data
.GetSize() - position
;
81 ::memcpy(buf
, position
+ (const BYTE
* )data
, len
);
86 return lastReadCount
!= 0;
90 BOOL
PMemoryFile::Write(const void * buf
, PINDEX len
)
92 memcpy(data
.GetPointer(position
+len
) + position
, buf
, len
);
99 off_t
PMemoryFile::GetLength() const
101 return data
.GetSize();
105 BOOL
PMemoryFile::SetLength(off_t len
)
107 return data
.SetSize(len
);
111 BOOL
PMemoryFile::SetPosition(off_t pos
, FilePositionOrigin origin
)
115 if (pos
> data
.GetSize())
121 if (pos
< -position
|| pos
> (data
.GetSize() - position
))
127 if (pos
< -data
.GetSize())
129 position
= data
.GetSize() - pos
;
136 off_t
PMemoryFile::GetPosition() const
142 // End of File ///////////////////////////////////////////////////////////////