1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 inline void RFileBuf::Reset(TInt aSize)
18 /** Frees the intermediate buffer and changes the size of any future intermediate
19 buffer to the specified value.
21 The intermediate buffer must not contain any outstanding write data, otherwise
22 the function raises a STORE-File 6 panic.
24 @param aSize The size of any future intermediate buffer. */
25 {Reset();iSize=aSize;}
26 inline void RFileBuf::Detach()
27 /** Detaches the file from this stream buffer.
29 The intermediate buffer's read and write marks are not changed, and the stream
30 positions are not changed. This means that the contents of the file should
31 not change while it is detached.
36 inline void RFileBuf::Reattach(RFile& aFile)
37 /** Re-attaches the specified file to this stream buffer.
39 The intermediate buffer's read and write marks are not changed, and the stream
40 positions are not changed.
42 The file should be the one that was detached using the Detach() function.
44 @param aFile The file to be re-attached.
48 inline RFile& RFileBuf::File() const
49 /** Gets a reference to the file attached to this stream buffer.
51 @return The file attached to this stream buffer. */
52 {return MUTABLE_CAST(RFile&,iFile);}
54 // Class RFileWriteStream
55 inline RFileWriteStream::RFileWriteStream(const MExternalizer<TStreamRef>& anExter)
56 : RWriteStream(anExter)
60 inline const TUidType& CFileStore::Type() const
61 /** Gets the UID type of the file store.
63 @return The UID type object containing the file store type.
66 inline void CFileStore::Reset()
67 /** Frees the file store’s buffer space.
69 The buffer space is automatically re-allocated when needed.
71 This function should only be used immediately after a successful call to CommitL()
74 @see CStreamStore::CommitL()
75 @see CStreamStore::RevertL() */
77 inline void CFileStore::Reset(TInt aSize)
78 /** Frees the file store’s buffer space and changes the size of future buffer
81 The buffer space is automatically re-allocated when needed, using the new
84 This function should only be used immediately after a successful call to CommitL()
87 @param aSize The size of future buffer space allocations.
88 @see CStreamStore::CommitL()
89 @see CStreamStore::RevertL() */
91 inline void CFileStore::Detach()
92 /** Detaches the file store from its associated file.
94 In effect, the file store gives up ownership of the file.
96 Detaching is useful in cases where a file needs to be closed and later re-opened;
97 for example, to give up a write lock for backup purposes.
99 It is very important that the contents of the file should not change while
105 inline void CFileStore::Reattach(RFile& aFile)
106 /** Reattaches a file to the file store. The file should be the one that was detached
107 using the Detach() function.
109 @param aFile The file to be associated with this file store.
111 {iBuf.Reattach(aFile);}
112 inline RFile& CFileStore::File() const
113 /** Gets a reference to the file associated with this file store.
115 This function is called prior to detaching the file store.
117 @return A reference to the associated file.
119 {return iBuf.File();}
120 inline TStreamExchange& CFileStore::Host() const
121 {return MUTABLE_CAST(TStreamExchange&,iHost);}
122 inline TBool CFileStore::IsHost(const MStreamBuf* aBuf) const
123 {return aBuf==&iBuf;}
124 inline void CFileStore::SetSizeL(TInt aSize)
125 {iBuf.SetSizeL(aSize);}
127 // Class CDirectFileStore
128 inline CDirectFileStore* CDirectFileStore::OpenL(RFs& aFs,const TDesC& aName,TUint aFileMode)
129 /** Opens a file containing a direct file store, and constructs a direct file store
132 @param aFs Handle to a file server session.
133 @param aName The full path name of the file containing the store.
134 @param aFileMode The mode in which the file is to be accessed. The mode is
135 defined by the TFileMode type.
136 @return A pointer to the new direct file store object.
138 {return STATIC_CAST(CDirectFileStore*,CFileStore::OpenL(aFs,aName,aFileMode,KDirectFileStoreFactoryFunction));}
139 inline CDirectFileStore* CDirectFileStore::OpenLC(RFs& aFs,const TDesC& aName,TUint aFileMode)
140 /** Opens a file containing a direct file store, constructs a direct file store
141 object, and places the pointer onto the cleanup stack.
143 @param aFs Handle to a file server session.
144 @param aName The full path name of the file containing the store.
145 @param aFileMode The mode in which the file is to be accessed. The mode is
146 defined by the TFileMode type.
147 @return A pointer to the new direct file store object.
149 {return STATIC_CAST(CDirectFileStore*,CFileStore::OpenLC(aFs,aName,aFileMode,KDirectFileStoreFactoryFunction));}
150 inline CDirectFileStore* CDirectFileStore::CreateL(RFs& aFs,const TDesC& aName,TUint aFileMode)
151 /** Creates a new file and constructs a new direct file store object to be associated
154 @param aFs Handle to a file server session.
155 @param aName The full path name of the new file. A file with this name must
156 not already exist, otherwise the function leaves.
157 @param aFileMode The mode in which the file is to be accessed. The mode is
158 defined by the TFileMode type.
159 @return A pointer to the new direct file store object
161 {return STATIC_CAST(CDirectFileStore*,CFileStore::CreateL(aFs,aName,aFileMode,&DoNewL));}
162 inline CDirectFileStore* CDirectFileStore::CreateLC(RFs& aFs,const TDesC& aName,TUint aFileMode)
163 /** Creates a new file and constructs a new direct file store object to be associated
164 with this file, and places the pointer onto the cleanup stack.
166 @param aFs Handle to a file server session.
167 @param aName The full path name of the new file. A file with this name must
168 not already exist, otherwise the function leaves.
169 @param aFileMode The mode in which the file is to be accessed. The mode is
170 defined by the TFileMode type.
171 @return A pointer to the new direct file store object
173 {return STATIC_CAST(CDirectFileStore*,CFileStore::CreateLC(aFs,aName,aFileMode,&DoNewL));}
174 inline CDirectFileStore* CDirectFileStore::ReplaceL(RFs& aFs,const TDesC& aName,TUint aFileMode)
175 /** Creates a file and constructs a direct file store object to be associated with
178 The file replaces any existing file of the same name.
180 @param aFs Handle to a file server session.
181 @param aName The full path name of the file to be replaced.
182 @param aFileMode The mode in which the file is to be accessed. The mode is
183 defined by the TFileMode type.
184 @return A pointer to the new direct file store object.
186 {return STATIC_CAST(CDirectFileStore*,CFileStore::ReplaceL(aFs,aName,aFileMode,&DoNewL));}
187 inline CDirectFileStore* CDirectFileStore::ReplaceLC(RFs& aFs,const TDesC& aName,TUint aFileMode)
188 /** Creates a file, constructs a direct file store object to be associated with
189 it, and places the pointer onto the cleanup stack.
191 The file replaces any existing file of the same name.
193 @param aFs Handle to a file server session.
194 @param aName The full path name of the file to be replaced.
195 @param aFileMode The mode in which the file is to be accessed. The mode is
196 defined by the TFileMode type.
197 @return A pointer to the new direct file store object.
199 {return STATIC_CAST(CDirectFileStore*,CFileStore::ReplaceLC(aFs,aName,aFileMode,&DoNewL));}
200 inline CDirectFileStore* CDirectFileStore::TempL(RFs& aFs,const TDesC& aPath,TFileName& aName,TUint aFileMode)
201 /** Creates a temporary file and constructs a direct file store object to be associated
204 The new file is created in the specified path and a unique file name is generated
207 Note that the store framework does not delete a temporary file after it is
210 @param aFs Handle to a file server session.
211 @param aPath The path where the new file is to be created.
212 @param aName On return, contains the full path name of the new file.
213 @param aFileMode The mode in which the new file is to be accessed. The mode
214 is defined by the TFileMode type.
215 @return A pointer to the new direct file store object.
217 {return STATIC_CAST(CDirectFileStore*,CFileStore::TempL(aFs,aPath,aName,aFileMode,&DoNewL));}
218 inline CDirectFileStore* CDirectFileStore::TempLC(RFs& aFs,const TDesC& aPath,TFileName& aName,TUint aFileMode)
219 /** Creates a temporary file, constructs a direct file store object to be associated
220 with it, and places the pointer onto the cleanup stack.
222 The new file is created in the specified path and a unique file name is generated
225 Note that the store framework does not delete a temporary file after it is
228 @param aFs Handle to a file server session.
229 @param aPath The path where the new file is to be created.
230 @param aName On return, contains the full path name of the new file.
231 @param aFileMode The mode in which the new file is to be accessed. The mode
232 is defined by the TFileMode type.
233 @return A pointer to the new direct file store object.
235 {return STATIC_CAST(CDirectFileStore*,CFileStore::TempLC(aFs,aPath,aName,aFileMode,&DoNewL));}
236 inline CDirectFileStore* CDirectFileStore::FromL(RFile& aFile)
237 /** Constructs a direct file store object from an already opened file.
239 The file must already be open before calling this function.
241 Note that ownership of the file passes to the store. The referenced RFile
242 is cleared and is no longer valid.
244 @param aFile A reference to the opened file.
245 @return A pointer to the new direct file store object. */
246 {return STATIC_CAST(CDirectFileStore*,CFileStore::FromL(aFile,KDirectFileStoreFactoryFunction));}
247 inline CDirectFileStore* CDirectFileStore::FromLC(RFile& aFile)
248 /** Constructs a direct file store object from an already opened file, and places
249 the pointer onto the cleanup stack.
251 The file must already be open before calling this function.
253 Note that ownership of the file passes to the store. The referenced RFile
254 is cleared and is no longer valid.
256 @param aFile A reference to the opened file.
257 @return A pointer to the new direct file store object. */
258 {return STATIC_CAST(CDirectFileStore*,CFileStore::FromLC(aFile,KDirectFileStoreFactoryFunction));}
259 inline CDirectFileStore* CDirectFileStore::NewL(RFile& aFile)
260 /** Constructs a new direct file store object in an already opened file.
262 The file must already be open before calling the function. The existing content
263 of the file is discarded.
265 Note that ownership of the file passes to the store. The referenced RFile
266 is cleared and is no longer valid:
268 @param aFile A reference to the opened file.
269 @return A pointer to the new direct file store object. */
270 {return STATIC_CAST(CDirectFileStore*,CFileStore::NewL(aFile,&DoNewL));}
271 inline CDirectFileStore* CDirectFileStore::NewLC(RFile& aFile)
272 /** Constructs a new direct file store object in an already opened file and places
273 the pointer onto the cleanup stack.
275 The file must already be open before calling the function. The existing content
276 of the file is discarded.
278 Note that ownership of the file passes to the store. The referenced RFile
279 is cleared and is no longer valid:
281 @param aFile A reference to the opened file.
282 @return A pointer to the new direct file store object. */
283 {return STATIC_CAST(CDirectFileStore*,CFileStore::NewLC(aFile,&DoNewL));}
285 // Class CPermanentFileStore
286 inline CPermanentFileStore* CPermanentFileStore::OpenL(RFs& aFs,const TDesC& aName,TUint aFileMode)
287 /** Opens a file containing a permanent file store, and constructs a permanent
290 @param aFs Handle to a file server session.
291 @param aName The full path name of the file containing the store.
292 @param aFileMode The mode in which the file is to be accessed. The mode is
293 defined by the TFileMode type.
294 @return A pointer to the new permanent file store object.
296 {return STATIC_CAST(CPermanentFileStore*,CFileStore::OpenL(aFs,aName,aFileMode,KPermanentFileStoreFactoryFunction));}
297 inline CPermanentFileStore* CPermanentFileStore::OpenLC(RFs& aFs,const TDesC& aName,TUint aFileMode)
298 /** Opens a file containing a permanent file store, constructs a permanent file
299 store object, and places the pointer onto the cleanup stack.
301 @param aFs Handle to a file server session.
302 @param aName The full path name of the file containing the store.
303 @param aFileMode The mode in which the file is to be accessed. The mode is
304 defined by the TFileMode type.
305 @return A pointer to the new permanent file store object.
307 {return STATIC_CAST(CPermanentFileStore*,CFileStore::OpenLC(aFs,aName,aFileMode,KPermanentFileStoreFactoryFunction));}
308 inline CPermanentFileStore* CPermanentFileStore::CreateL(RFs& aFs,const TDesC& aName,TUint aFileMode)
309 /** Creates a new file and constructs a new permanent file store object to be associated
312 @param aFs Handle to a file server session.
313 @param aName The full path name of the new file. A file with this name must
314 not already exist, otherwise the function leaves.
315 @param aFileMode The mode in which the new file is to be accessed. This mode
316 is defined by the TFileMode type.
317 @return A pointer to the new permanent file store object.
319 {return STATIC_CAST(CPermanentFileStore*,CFileStore::CreateL(aFs,aName,aFileMode,&DoNewL));}
320 inline CPermanentFileStore* CPermanentFileStore::CreateLC(RFs& aFs,const TDesC& aName,TUint aFileMode)
321 /** Creates a new file and constructs a new permanent file store object to be associated
322 with this file, and places the pointer onto the cleanup stack.
324 @param aFs Handle to a file server session.
325 @param aName The full path name of the new file. A file with this name must
326 not already exist, otherwise the function leaves.
327 @param aFileMode The mode in which the new file is to be accessed. This mode
328 is defined by the TFileMode type.
329 @return A pointer to the new permanent file store object.
331 {return STATIC_CAST(CPermanentFileStore*,CFileStore::CreateLC(aFs,aName,aFileMode,&DoNewL));}
332 inline CPermanentFileStore* CPermanentFileStore::ReplaceL(RFs& aFs,const TDesC& aName,TUint aFileMode)
333 /** Creates a file, constructs a permanent file store object to be associated with
336 This file replaces any existing file of the same name.
338 @param aFs Handle to a file server session.
339 @param aName The full path name of the file to be replaced.
340 @param aFileMode The mode in which the file is to be accessed. The mode is
341 defined by the TFileMode type.
342 @return A pointer to the new permanent file store object.
344 {return STATIC_CAST(CPermanentFileStore*,CFileStore::ReplaceL(aFs,aName,aFileMode,&DoNewL));}
345 inline CPermanentFileStore* CPermanentFileStore::ReplaceLC(RFs& aFs,const TDesC& aName,TUint aFileMode)
346 /** Creates a file, constructs a permanent file store object to be associated with
347 it, and places the pointer onto the cleanup stack.
349 This file replaces any existing file of the same name.
351 @param aFs Handle to a file server session.
352 @param aName The full path name of the file to be replaced.
353 @param aFileMode The mode in which the file is to be accessed. The mode is
354 defined by the TFileMode type.
355 @return A pointer to the new permanent file store object.
357 {return STATIC_CAST(CPermanentFileStore*,CFileStore::ReplaceLC(aFs,aName,aFileMode,&DoNewL));}
358 inline CPermanentFileStore* CPermanentFileStore::TempL(RFs& aFs,const TDesC& aPath,TFileName& aName,TUint aFileMode)
359 /** Creates a temporary file and constructs a permanent file store object to be
362 The new file is created in the specified path and a unique file name is generated
365 Note that the store framework does not delete a temporary file after it is
368 @param aFs Handle to a file server session.
369 @param aPath The path where the new file is to be created.
370 @param aName On return, contains the full path name of the new file.
371 @param aFileMode The mode in which the file is to be accessed. The mode is
372 defined by the TFileMode type.
373 @return A pointer to the new permanent file store object.
375 {return STATIC_CAST(CPermanentFileStore*,CFileStore::TempL(aFs,aPath,aName,aFileMode,&DoNewL));}
376 inline CPermanentFileStore* CPermanentFileStore::TempLC(RFs& aFs,const TDesC& aPath,TFileName& aName,TUint aFileMode)
377 /** Creates a temporary file, constructs a permanent file store object to be associated
378 with it, and places the pointer onto the cleanup stack.
380 The new file is created in the specified path and a unique file name is generated
383 Note that the store framework does not delete a temporary file after it is
386 @param aFs Handle to a file server session.
387 @param aPath The path where the new file is to be created.
388 @param aName On return, contains the full path name of the new file.
389 @param aFileMode The mode in which the file is to be accessed. The mode is
390 defined by the TFileMode type.
391 @return A pointer to the new permanent file store object.
393 {return STATIC_CAST(CPermanentFileStore*,CFileStore::TempLC(aFs,aPath,aName,aFileMode,&DoNewL));}
394 inline CPermanentFileStore* CPermanentFileStore::FromL(RFile& aFile)
395 /** Constructs a permanent file store object from an already opened file.
397 The file must already be open before calling this function.
399 Note that ownership of the file passes to the store. The referenced RFile
400 is cleared and is no longer valid.
402 @param aFile A reference to the opened file.
403 @return A pointer to the new permanent file store object. */
404 {return STATIC_CAST(CPermanentFileStore*,CFileStore::FromL(aFile,KPermanentFileStoreFactoryFunction));}
405 inline CPermanentFileStore* CPermanentFileStore::FromLC(RFile& aFile)
406 /** Constructs a permanent file store object from an already opened file, and places
407 the pointer onto the cleanup stack.
409 The file must already be open before calling this function.
411 Note that ownership of the file passes to the store. The referenced RFile
412 is cleared and is no longer valid.
414 @param aFile A reference to the opened file.
415 @return A pointer to the new permanent file store object. */
416 {return STATIC_CAST(CPermanentFileStore*,CFileStore::FromLC(aFile,KPermanentFileStoreFactoryFunction));}
417 inline CPermanentFileStore* CPermanentFileStore::NewL(RFile& aFile)
418 /** Constructs a new permanent file store object in an already opened file.
420 The file must already be open before calling this function. The existing content
421 of the file is discarded.
423 Note that ownership of the file passes to the store. The referenced RFile
424 is cleared and is no longer valid.
426 @param aFile A reference to the opened file.
427 @return A pointer to the new permanent file store object. */
428 {return STATIC_CAST(CPermanentFileStore*,CFileStore::NewL(aFile,&DoNewL));}
429 inline CPermanentFileStore* CPermanentFileStore::NewLC(RFile& aFile)
430 /** Constructs a new permanent file store object in an already opened file and
431 places the pointer onto the cleanup stack.
433 The file must already be open before calling this function.The existing content
434 of the file is discarded.
436 Note that ownership of the file passes to the store. The referenced RFile
437 is cleared and is no longer valid.
439 @param aFile A reference to the opened file.
440 @return A pointer to the new permanent file store object. */
441 {return STATIC_CAST(CPermanentFileStore*,CFileStore::NewLC(aFile,&DoNewL));}
443 // Class RFilePagePool
444 inline TInt RFilePagePool::Open(RFs& aFs,const TDesC& aName,TUint aFileMode)
445 /** Opens a file to use for the page pool.
447 @param aFs A file server session
448 @param aName The name of the file
449 @param aFileMode The mode in which the file is opened. For more information,
450 see the TFileMode enumeration.
451 @return KErrNone if successful, otherwise another of the system-wide error
454 {return iFile.Open(aFs,aName,aFileMode);}
455 inline TInt RFilePagePool::Create(RFs& aFs,const TDesC& aName,TUint aFileMode)
456 /** Creates a new file for the page pool.
458 @param aFs A file server session
459 @param aName The name of the file. Any path components which are not specified
460 here are taken from the session path.
461 @param aFileMode The mode in which the file is opened. For more information
462 see the TFileMode enumeration.
463 @return KErrNone if successful, otherwise another of the system-wide error
466 {return iFile.Create(aFs,aName,aFileMode);}
467 inline TInt RFilePagePool::Replace(RFs& aFs,const TDesC& aName,TUint aFileMode)
468 /** Creates or opens a file for the page pool.
470 If there is an existing file with the same name, this function overwrites
471 it. If the file does not already exist, it is created.
473 @param aFs A file server session.
474 @param aName The name of the file. Any path components which are not specified
475 here are taken from the session path.
476 @param aFileMode The mode in which the file is opened. For more information
477 see the TFileMode enumeration.
478 @return KErrNone if successful, otherwise another of the system-wide error
481 {return iFile.Replace(aFs,aName,aFileMode);}
482 inline TInt RFilePagePool::Temp(RFs& aFs,const TDesC& aPath,TFileName& aName,TUint aFileMode)
483 /** Creates and opens a file for the page pool with a unique name.
485 @param aFs A file server session.
486 @param aPath The directory in which the file should be created.
487 @param aName On return, contains the full path and name of the file. The filename
488 is guaranteed to be unique within the directory specified by aPath.
489 @param aFileMode The mode in which the file is opened. For more information
490 see the TFileMode enumeration.
491 @return KErrNone if successful, otherwise another of the system-wide error
493 {return iFile.Temp(aFs,aPath,aName,aFileMode);}
494 inline void RFilePagePool::Attach(RFile& aFile)
495 /** Sets an existing file to be used for the page pool.
497 @param aFile File to use for the page pool */
499 inline void RFilePagePool::Detach()
500 /** Ends the use of the file for the page pool, but does not close the file. */
502 inline RFile& RFilePagePool::File() const
503 {return MUTABLE_CAST(RFile&,iFile);}