EDoc::ManagedFile Class Reference

#include <include/EDoc/ManagedFile.h>


Detailed Description

Represents a file that can have some sort of cleanup action associated with it when it is no longer being used.

This implements an internal reference counting pattern where when no more copies of this managed file exist it will perform a cleanup action. This cleanup action is done on calling the virtual destructor of: ManagedFileCleanupIFace::~ManagedFileCleanupIFace() a derived class for ManagedFileCleanupIFace will implement various actions that need to be performed in order to cleanup the file correctly. This may include: Do nothing. Delete temporary file, Write temporary file into archive before delete.

Definition at line 42 of file ManagedFile.h.

Public Member Functions

 ManagedFile (std::list< std::string > identifier_in)
 Create a new managed file that is identified by the given list of archives.
 ManagedFile (std::string identifier_in)
 Create a new managed file for the given filename.
 ManagedFile (std::list< std::string > identifier_in, std::string work_file_name_in, ManagedFileCleanupIFace *cleanup_in)
 Create a new managed file that is operating on a given temporary file and has a given cleanup callback that needs to be called when we are finsihed using it.
 ManagedFile (const ManagedFile &right)
 Copy constructor.
ManagedFileoperator= (const ManagedFile &right)
 Assignment operator.
virtual ~ManagedFile ()
 Destructor.
const std::string & GetWorkFileName () const
 Retruns the name of the file that is to be used for reading/writing operations.
const std::list< std::string > & GetIdentifier () const
 Returns the identifier for this file.
const std::string & GetName () const
 Returns the name of the final file this represents without any archive context.
std::string GetFileNameRep () const
 Returns a string that represents the name of the file including its archive context.

Private Member Functions

void IncRef ()
 Increment the reference count to the cleanup instance.
void DecRef ()
 Decrement the reference count to the cleanup instance and perform any cleanup operations if necessary when the reference count reaches 0.

Private Attributes

ManagedFileCleanupIFacecleanup
 Reference to object that implementes operations to perform to close/cleanup the file.
std::string work_file_name
 Reference to a temporary file that all work is to be performed on.
std::list< std::string > identifier
 List of identifiers used to identify this file within an abrbitrary list of archives.


Constructor & Destructor Documentation

EDoc::ManagedFile::ManagedFile ( std::list< std::string >  identifier_in  )  [explicit]

Create a new managed file that is identified by the given list of archives.

If the list contains just a single member then that is a direct filename, otheriwse the list contains the identifiers for recursive archives. For example if this was managing a file called Blah.edc inside a zipfile call foo.zip which itself was part of another zip file bar.zip you would pass the following:

  1. bar.zip
  2. foo.zip
  3. Blah.edc

Definition at line 30 of file ManagedFile.cpp.

References IncRef().

EDoc::ManagedFile::ManagedFile ( std::string  identifier_in  )  [explicit]

Create a new managed file for the given filename.

This is just a wrapper around the above constructor.

Definition at line 37 of file ManagedFile.cpp.

References identifier, and IncRef().

EDoc::ManagedFile::ManagedFile ( std::list< std::string >  identifier_in,
std::string  work_file_name_in,
EDoc::ManagedFileCleanupIFace cleanup_in 
)

Create a new managed file that is operating on a given temporary file and has a given cleanup callback that needs to be called when we are finsihed using it.

Note:
EDoc++ data included.

Definition at line 44 of file ManagedFile.cpp.

References IncRef().

EDoc::ManagedFile::ManagedFile ( const ManagedFile right  ) 

Copy constructor.

Note:
EDoc++ data included.

Definition at line 55 of file ManagedFile.cpp.

References IncRef().

EDoc::ManagedFile::~ManagedFile (  )  [virtual]

Destructor.

If this is the last reference to the particular file being managed then it will perform any cleanup operations that may have been associated with the file. For example this could include adding it to a zip archive or deleteing a temporary file etc.

Definition at line 79 of file ManagedFile.cpp.

References DecRef().


Member Function Documentation

EDoc::ManagedFile::operator= ( const ManagedFile right  ) 

Assignment operator.

Note:
EDoc++ data included.

Definition at line 63 of file ManagedFile.cpp.

References cleanup, DecRef(), identifier, IncRef(), and work_file_name.

EDoc::ManagedFile::GetWorkFileName (  )  const [inline]

Retruns the name of the file that is to be used for reading/writing operations.

This will often be a temporary file which will later be merged into an archive.

Definition at line 104 of file ManagedFile.h.

References identifier, and work_file_name.

Referenced by EDoc::GetAllFiles(), EDocBFD::BFDArchive::HandlesType(), EDoc::DirectoryArchive::HandlesType(), EDoc::Persistence::Persistence(), EDocBFD::BFDArchive::ReadExtractAll(), EDocBFD::BFDArchive::WriteOpen(), and EDoc::DirectoryArchive::WriteOpen().

EDoc::ManagedFile::GetIdentifier (  )  const [inline]

Returns the identifier for this file.

Note:
EDoc++ data included.

Definition at line 119 of file ManagedFile.h.

References identifier.

Referenced by EDoc::GetAllFiles(), EDocBFD::HandleEDocSection(), EDocBFD::BFDArchive::WriteOpen(), and EDoc::DirectoryArchive::WriteOpen().

EDoc::ManagedFile::GetName (  )  const [inline]

Returns the name of the final file this represents without any archive context.

Note:
EDoc++ data included.

Definition at line 128 of file ManagedFile.h.

References identifier.

Referenced by EDoc::Persistence::ReadExtract().

EDoc::ManagedFile::GetFileNameRep (  )  const

Returns a string that represents the name of the file including its archive context.

This is used for displaying data ot a user.

Definition at line 109 of file ManagedFile.cpp.

References EDOC_FOREACH_CONST, and identifier.

Referenced by EDoc::Persistence::GetFilenameRep(), EDocBFD::ProcessReadBFD(), and EDocBFD::BFDArchive::ReadExtractAll().

EDoc::ManagedFile::IncRef (  )  [private]

Increment the reference count to the cleanup instance.

Note:
EDoc++ data included.

Definition at line 84 of file ManagedFile.cpp.

References cleanup, and EDoc::ManagedFileCleanupIFace::ref_count.

Referenced by ManagedFile(), and operator=().

EDoc::ManagedFile::DecRef (  )  [private]

Decrement the reference count to the cleanup instance and perform any cleanup operations if necessary when the reference count reaches 0.

Note:
EDoc++ data included.

Definition at line 92 of file ManagedFile.cpp.

References cleanup, EDOC_Finest, EDoc::Erase(), identifier, EDoc::ManagedFileCleanupIFace::ref_count, and work_file_name.

Referenced by operator=(), and ~ManagedFile().


Field Documentation

ManagedFileCleanupIFace* EDoc::ManagedFile::cleanup [private]

Reference to object that implementes operations to perform to close/cleanup the file.

Definition at line 165 of file ManagedFile.h.

Referenced by DecRef(), IncRef(), and operator=().

std::string EDoc::ManagedFile::work_file_name [private]

Reference to a temporary file that all work is to be performed on.

Definition at line 171 of file ManagedFile.h.

Referenced by DecRef(), GetWorkFileName(), and operator=().

std::list<std::string> EDoc::ManagedFile::identifier [private]

List of identifiers used to identify this file within an abrbitrary list of archives.

Definition at line 177 of file ManagedFile.h.

Referenced by DecRef(), GetFileNameRep(), GetIdentifier(), GetName(), GetWorkFileName(), ManagedFile(), and operator=().


The documentation for this class was generated from the following files:
Generated on Tue Jan 20 18:26:09 2009 for EDoc-0.2.1 by  doxygen 1.5.1