NCBI C++ ToolKit
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
CWriteDB_File Class Referenceabstract

Search Toolkit Book for CWriteDB_File

CWriteDB_IndexFile class. More...

#include <objtools/blast/seqdb_writer/writedb_files.hpp>

+ Inheritance diagram for CWriteDB_File:
+ Collaboration diagram for CWriteDB_File:

Public Member Functions

 CWriteDB_File (const string &basename, const string &extension, int index, Uint8 max_file_size, bool always_create)
 Constructor. More...
 
void Create ()
 Create and open the file. More...
 
unsigned int Write (const CTempString &data)
 Write contents of a string to the file. More...
 
unsigned int Write (const char *data, int length)
 
unsigned int WriteInt4 (int data)
 Write an Int4 (in bigendian order) to the file. More...
 
unsigned int WriteInt8 (Int8 data)
 Write an Int8 (in bigendian order) to the file. More...
 
unsigned int WriteWithNull (const CTempString &data)
 Write contents of a string to the file, appending a NUL. More...
 
void Close ()
 Close the file, flushing any remaining data to disk. More...
 
virtual void RenameSingle ()
 Rename this file, disincluding the volume index. More...
 
virtual void RenameFileIndex (unsigned int num_digits)
 
const stringGetFilename () const
 Get the current filename for this file. More...
 
- Public Member Functions inherited from CObject
 CObject (void)
 Constructor. More...
 
 CObject (const CObject &src)
 Copy constructor. More...
 
virtual ~CObject (void)
 Destructor. More...
 
CObjectoperator= (const CObject &src) THROWS_NONE
 Assignment operator. More...
 
bool CanBeDeleted (void) const THROWS_NONE
 Check if object can be deleted. More...
 
bool IsAllocatedInPool (void) const THROWS_NONE
 Check if object is allocated in memory pool (not system heap) More...
 
bool Referenced (void) const THROWS_NONE
 Check if object is referenced. More...
 
bool ReferencedOnlyOnce (void) const THROWS_NONE
 Check if object is referenced only once. More...
 
void AddReference (void) const
 Add reference to object. More...
 
void RemoveReference (void) const
 Remove reference to object. More...
 
void ReleaseReference (void) const
 Remove reference without deleting object. More...
 
virtual void DoNotDeleteThisObject (void)
 Mark this object as not allocated in heap – do not delete this object. More...
 
virtual void DoDeleteThisObject (void)
 Mark this object as allocated in heap – object can be deleted. More...
 
void * operator new (size_t size)
 Define new operator for memory allocation. More...
 
void * operator new[] (size_t size)
 Define new[] operator for 'array' memory allocation. More...
 
void operator delete (void *ptr)
 Define delete operator for memory deallocation. More...
 
void operator delete[] (void *ptr)
 Define delete[] operator for memory deallocation. More...
 
void * operator new (size_t size, void *place)
 Define new operator. More...
 
void operator delete (void *ptr, void *place)
 Define delete operator. More...
 
void * operator new (size_t size, CObjectMemoryPool *place)
 Define new operator using memory pool. More...
 
void operator delete (void *ptr, CObjectMemoryPool *place)
 Define delete operator. More...
 
virtual void DebugDump (CDebugDumpContext ddc, unsigned int depth) const
 Define method for dumping debug information. More...
 
- Public Member Functions inherited from CDebugDumpable
 CDebugDumpable (void)
 
virtual ~CDebugDumpable (void)
 
void DebugDumpText (ostream &out, const string &bundle, unsigned int depth) const
 
void DebugDumpFormat (CDebugDumpFormatter &ddf, const string &bundle, unsigned int depth) const
 
void DumpToConsole (void) const
 

Static Public Member Functions

static string MakeShortName (const string &base, int index)
 Construct the short name for a volume. More...
 
- Static Public Member Functions inherited from CObject
static NCBI_XNCBI_EXPORT void ThrowNullPointerException (void)
 Define method to throw null pointer exception. More...
 
static NCBI_XNCBI_EXPORT void ThrowNullPointerException (const type_info &type)
 
static EAllocFillMode GetAllocFillMode (void)
 
static void SetAllocFillMode (EAllocFillMode mode)
 
static void SetAllocFillMode (const string &value)
 Set mode from configuration parameter value. More...
 
- Static Public Member Functions inherited from CDebugDumpable
static void EnableDebugDump (bool on)
 

Protected Types

typedef ofstream TFile
 Underlying 'output file' type used here. More...
 

Protected Member Functions

Uint8 x_DefaultByteLimit ()
 The default value for max_file_size. More...
 
virtual void x_Flush ()=0
 This should flush any unwritten data to disk. More...
 
void x_MakeFileName ()
 Build the filename for this file. More...
 
- Protected Member Functions inherited from CObject
virtual void DeleteThis (void)
 Virtual method "deleting" this object. More...
 

Protected Attributes

bool m_Created
 True if the file has already been opened. More...
 
string m_Nul
 For convenience, a string containing one NUL character. More...
 
string m_BaseName
 Database base name for all files. More...
 
string m_Extension
 File extension for this file. More...
 
int m_Index
 Volume index. More...
 
unsigned int m_Offset
 Stream position. More...
 
Uint8 m_MaxFileSize
 Maximum file size in bytes. More...
 
bool m_UseIndex
 True if filenames should use volume index. More...
 
string m_Fname
 Current filename for output file. More...
 
TFile m_RealFile
 Actual stream implementing the output file. More...
 

Additional Inherited Members

- Public Types inherited from CObject
enum  EAllocFillMode { eAllocFillNone = 1 , eAllocFillZero , eAllocFillPattern }
 Control filling of newly allocated memory. More...
 
typedef CObjectCounterLocker TLockerType
 Default locker type for CRef. More...
 
typedef atomic< Uint8TCounter
 Counter type is CAtomiCounter. More...
 
typedef Uint8 TCount
 Alias for value type of counter. More...
 
- Static Public Attributes inherited from CObject
static const TCount eCounterBitsCanBeDeleted = 1 << 0
 Define possible object states. More...
 
static const TCount eCounterBitsInPlainHeap = 1 << 1
 Heap signature was found. More...
 
static const TCount eCounterBitsPlaceMask
 Mask for 'in heap' state flags. More...
 
static const int eCounterStep = 1 << 2
 Skip over the "in heap" bits. More...
 
static const TCount eCounterValid = TCount(1) << (sizeof(TCount) * 8 - 2)
 Minimal value for valid objects (reference counter is zero) Must be a single bit value. More...
 
static const TCount eCounterStateMask
 Valid object, and object in heap. More...
 

Detailed Description

CWriteDB_IndexFile class.

This manufactures blast database index files from input data.

Definition at line 57 of file writedb_files.hpp.

Member Typedef Documentation

◆ TFile

typedef ofstream CWriteDB_File::TFile
protected

Underlying 'output file' type used here.

Definition at line 167 of file writedb_files.hpp.

Constructor & Destructor Documentation

◆ CWriteDB_File()

CWriteDB_File::CWriteDB_File ( const string basename,
const string extension,
int  index,
Uint8  max_file_size,
bool  always_create 
)

Constructor.

The filename is constructed from basename, extension, and index, but might be changed if the RenameSingle() method is called. If zero is specified for maximum file size, a default size is provided by this class. The maximum file size is not enforced by this class, instead each derived class must do its own enforcement.

Parameters
basenameDatabase base name, shared by all files. [in]
extensionFile name extension for this file. [in]
indexVolume index used in filename. [in]
max_file_sizeFile size limit (in bytes). [in]
always_createIf true the file will be created now. [in]

Definition at line 158 of file writedb_files.cpp.

References _ASSERT, Create(), m_MaxFileSize, m_Nul, m_Offset, m_UseIndex, x_DefaultByteLimit(), and x_MakeFileName().

Member Function Documentation

◆ Close()

void CWriteDB_File::Close ( void  )

Close the file, flushing any remaining data to disk.

Definition at line 259 of file writedb_files.cpp.

References m_Created, m_RealFile, and x_Flush().

Referenced by CWriteDB_GiMask::AddGiMask(), CWriteDB_Isam::Close(), CWriteDB_Column::Close(), CWriteDB_GiMask::Close(), CWriteDB_Volume::Close(), and CWriteDB_OidList::Close().

◆ Create()

void CWriteDB_File::Create ( void  )

Create and open the file.

This method must be called before the first time that data is written to the file. If the constructor is passed 'true' for always_create, this method will be called during construction. It is an error to call this method more than once (including via the constructor) or to not call it but to call Write. The rationale for making this explicit is to permit some files to be created optionally, such as ISAM files, which should only be created if the corresponding ID types are found.

Definition at line 197 of file writedb_files.cpp.

References _ASSERT, m_Created, m_Fname, m_RealFile, and out().

Referenced by CWriteDB_GiMaskOffset::AddGIs(), CWriteDB_GiMaskIndex::AddGIs(), CWriteDB_File(), CWriteDB_ColumnData::WriteBlob(), CWriteDB_GiMaskData::WriteMask(), CWriteDB_OidList::x_CreateMaskFile(), CWriteDB_IsamIndex::x_Flush(), CWriteDB_ColumnData::x_Flush(), CWriteDB_ColumnIndex::x_Flush(), and CWriteDB_GiIndex::x_Flush().

◆ GetFilename()

const string& CWriteDB_File::GetFilename ( void  ) const
inline

Get the current filename for this file.

The filename is returned. The data returned by this method reflects changes made by RenameSingle(), so it is probably best to call it after that method has been called (if it will be called).

Returns
The filename.

Definition at line 157 of file writedb_files.hpp.

References m_Fname.

Referenced by CWriteDB_Isam::ListFiles(), CWriteDB_GiMask::ListFiles(), CWriteDB_Volume::ListFiles(), CWriteDB_Column::ListFiles(), and CWriteDB_Volume::RenameFileIndex().

◆ MakeShortName()

string CWriteDB_File::MakeShortName ( const string base,
int  index 
)
static

Construct the short name for a volume.

Volume names consist of the database base name, ".", and the volume index in decimal. The volume index is normally two digits, but if more than 100 volumes are needed, the filename will use three or more index digits as needed.

Parameters
baseBase name to use.
indexVolume index.
Returns
A short name.

Definition at line 235 of file writedb_files.cpp.

Referenced by CWriteDB_Volume::CWriteDB_Volume(), CMakeProfileDBApp::x_InitRPSDbInfo(), and x_MakeFileName().

◆ RenameFileIndex()

void CWriteDB_File::RenameFileIndex ( unsigned int  num_digits)
virtual

◆ RenameSingle()

void CWriteDB_File::RenameSingle ( )
virtual

◆ Write() [1/2]

unsigned int CWriteDB_File::Write ( const char *  data,
int  length 
)

Definition at line 224 of file writedb_files.cpp.

References _ASSERT, data, m_Created, m_Offset, and m_RealFile.

◆ Write() [2/2]

unsigned int CWriteDB_File::Write ( const CTempString data)

◆ WriteInt4()

unsigned int CWriteDB_File::WriteInt4 ( int  data)
inline

Write an Int4 (in bigendian order) to the file.

Parameters
dataString to write.
Returns
File offset after write.

Definition at line 103 of file writedb_files.hpp.

References data, m_Offset, m_RealFile, and s_WriteInt4().

Referenced by CWriteDB_OidList::x_CreateMaskFile(), CWriteDB_GiIndex::x_Flush(), CWriteDB_IsamIndex::x_FlushNumericIndex(), CWriteDB_IsamIndex::x_FlushStringIndex(), and CWriteDB_IsamIndex::x_WriteHeader().

◆ WriteInt8()

unsigned int CWriteDB_File::WriteInt8 ( Int8  data)
inline

Write an Int8 (in bigendian order) to the file.

Parameters
dataString to write.
Returns
File offset after write.

Definition at line 113 of file writedb_files.hpp.

References data, m_Offset, m_RealFile, and s_WriteInt8BE().

Referenced by CWriteDB_IsamIndex::x_FlushNumericIndex().

◆ WriteWithNull()

unsigned int CWriteDB_File::WriteWithNull ( const CTempString data)
inline

Write contents of a string to the file, appending a NUL.

Parameters
dataString to write.
Returns
File offset after write.

Definition at line 123 of file writedb_files.hpp.

References data, m_Nul, and Write().

Referenced by CWriteDB_SequenceFile::AddSequence(), and CWriteDB_SequenceFile::CWriteDB_SequenceFile().

◆ x_DefaultByteLimit()

Uint8 CWriteDB_File::x_DefaultByteLimit ( )
inlineprotected

The default value for max_file_size.

Returns
The max file size used if otherwise unspecified.

Definition at line 174 of file writedb_files.hpp.

Referenced by CWriteDB_File().

◆ x_Flush()

virtual void CWriteDB_File::x_Flush ( )
protectedpure virtual

This should flush any unwritten data to disk.

This method must be implemented by derived classes to flush any unwritten data to disk. In the cases of sequence and header files, it will normally do nothing, because such files are written as the data is available. For index (pin/nin) and ISAM files, this method does most of the disk I/O.

Implemented in CWriteDB_OidList, CWriteDB_GiIndex, CWriteDB_GiMaskOffset, CWriteDB_GiMaskData, CWriteDB_ColumnIndex, CWriteDB_ColumnData, CWriteDB_FileAutoFlush, CWriteDB_IsamData, CWriteDB_IsamIndex, CWriteDB_SequenceFile, CWriteDB_HeaderFile, and CWriteDB_IndexFile.

Referenced by Close().

◆ x_MakeFileName()

void CWriteDB_File::x_MakeFileName ( )
protected

Build the filename for this file.

Definition at line 247 of file writedb_files.cpp.

References m_BaseName, m_Extension, m_Fname, m_Index, m_UseIndex, and MakeShortName().

Referenced by CWriteDB_File(), and RenameSingle().

Member Data Documentation

◆ m_BaseName

string CWriteDB_File::m_BaseName
protected

Database base name for all files.

Definition at line 194 of file writedb_files.hpp.

Referenced by RenameFileIndex(), x_MakeFileName(), and CWriteDB_IndexFile::x_MakeLmdbName().

◆ m_Created

bool CWriteDB_File::m_Created
protected

◆ m_Extension

string CWriteDB_File::m_Extension
protected

File extension for this file.

Definition at line 195 of file writedb_files.hpp.

Referenced by RenameFileIndex(), and x_MakeFileName().

◆ m_Fname

string CWriteDB_File::m_Fname
protected

Current filename for output file.

Definition at line 203 of file writedb_files.hpp.

Referenced by Create(), GetFilename(), RenameFileIndex(), RenameSingle(), and x_MakeFileName().

◆ m_Index

int CWriteDB_File::m_Index
protected

Volume index.

Definition at line 196 of file writedb_files.hpp.

Referenced by RenameFileIndex(), CWriteDB_IndexFile::x_Flush(), and x_MakeFileName().

◆ m_MaxFileSize

Uint8 CWriteDB_File::m_MaxFileSize
protected

◆ m_Nul

string CWriteDB_File::m_Nul
protected

For convenience, a string containing one NUL character.

Definition at line 170 of file writedb_files.hpp.

Referenced by CWriteDB_File(), WriteWithNull(), and CWriteDB_IndexFile::x_Flush().

◆ m_Offset

unsigned int CWriteDB_File::m_Offset
protected

Stream position.

Definition at line 197 of file writedb_files.hpp.

Referenced by CWriteDB_SequenceFile::CanFit(), CWriteDB_File(), Write(), WriteInt4(), and WriteInt8().

◆ m_RealFile

TFile CWriteDB_File::m_RealFile
protected

Actual stream implementing the output file.

Definition at line 204 of file writedb_files.hpp.

Referenced by Close(), Create(), Write(), WriteInt4(), WriteInt8(), and CWriteDB_IndexFile::x_Flush().

◆ m_UseIndex

bool CWriteDB_File::m_UseIndex
protected

True if filenames should use volume index.

Definition at line 202 of file writedb_files.hpp.

Referenced by CWriteDB_File(), RenameSingle(), and x_MakeFileName().


The documentation for this class was generated from the following files:
Modified on Mon May 06 04:49:33 2024 by modify_doxy.py rev. 669887