rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWFileManager Class Reference
[File System]

Allocates and deallocates storage in a disk file, much like a "freestore" manager. More...

#include <rw/filemgr.h>

Inheritance diagram for RWFileManager:
RWFile

List of all members.

Public Member Functions

 RWFileManager (const char *filename, const char *mode=rwnil)
 ~RWFileManager ()
RWoffset allocate (RWspace s)
void deallocate (RWoffset t)
RWoffset endData () const
RWoffset start () const

Detailed Description

Class RWFileManager allocates and deallocates storage in a disk file, much like a "freestore" manager. It does this by maintaining a linked list of free space within the file.

Note:
Class RWFileManager inherits class RWFile as a public base class; hence all the public member functions of RWFile are visible to RWFileManager. They are not listed here.

If a file is managed by an RWFileManager, then reading or writing to unallocated space in the file has undefined results. In particular, overwriting the end of allocated space is a common problem which usually results in corrupted data. One way to encounter this problem is to use binaryStoreSize() to discover the amount of space needed to store an RWCollection. For most purposes, the storage size of an RWCollection is found using the RWCollectable method recursiveStoreSize() .

Synopsis

 typedef long     RWoffset ;
 typedef unsigned long   RWspace;  // (typically)
 #include <rw/filemgr.h>
 RWFileManager f("file.dat");

Persistence

None


Constructor & Destructor Documentation

RWFileManager::RWFileManager ( const char *  filename,
const char *  mode = rwnil 
)

Constructs an RWFileManager for the file with path name filename using mode mode. The mode is as given by the Standard C Library function fopen(). If mode is zero (the default), then the constructor attempts to open an existing file with the given filename for update (mode "rb+"). If this is not possible, then it attempts to create a new file with the given filename (mode "wb+"). If the file exists and is not empty, then the constructor assumes it contains an existing file manager; other contents cause the function to throw an exception of type RWExternalErr. If no file exists or if an existing file is empty, then the constructor attempts to create the file (if necessary) and initialize it with a new file manager. The resultant object should be checked for validity using function isValid(). RWFileErr is a possible exception that could be thrown.

RWFileManager::~RWFileManager (  ) 

Empty Destructor.


Member Function Documentation

RWoffset RWFileManager::allocate ( RWspace  s  ) 

Allocates s bytes of storage in the file. Returns the offset to the start of the storage location. The very first allocation for the file is considered "special" and can be returned at any later time by the function start(). RWFileErr is a possible exception that could be thrown.

void RWFileManager::deallocate ( RWoffset  t  ) 

Deallocates (frees) the storage space starting at offset t. This space must have been previously allocated by a call to allocate(). The very first allocation ever made in the file is considered "special" and cannot be deallocated. RWFileErr is a possible exception that could be thrown.

RWoffset RWFileManager::endData (  )  const [inline]

Returns an offset just past the end of the file.

RWoffset RWFileManager::start (  )  const [inline]

Returns the offset of the first space ever allocated for data in this file. If no space has ever been allocated, returns RWNIL. This is typically used to "get started" and find the rest of the data in the file.

 All Classes Functions Variables Typedefs Enumerations Enumerator Friends

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.