Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

PLearn::IntVecFile Class Reference

#include <IntVecFile.h>

Collaboration diagram for PLearn::IntVecFile:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 IntVecFile ()
 Default constructor, you must then call open.

 IntVecFile (const string &the_filename, bool readwrite=false)
 IntVecFile (const IntVecFile &other)
 The copy constructor opens the file a second time in readonly mode only.

void open (const string &the_filename, bool readwrite=false)
void close ()
int get (int i) const
void put (int i, int value)
TVec< intgetVec () const
int length () const
int operator[] (int i) const
void append (int value)
void append (const TVec< int > &vec)
 ~IntVecFile ()

Protected Member Functions

void writeFileSignature ()
 write magic signature

void getVersionAndSize ()
 store in data members

void seek_to_index (int index) const
 seek depending on version


Protected Attributes

string filename
FILE * f
int length_
int version_number_
 0 if old version, 1 if < current version

char endianness_
 either 'L' or 'B'


Static Protected Attributes

const char signature []
 magic signature

const int header_size []
 index array by version number


Detailed Description

IntVecFile is a class to handle a simple linear file of integers with random access.

There are two versions of the on-disk file format. The "old" version 0, where integers are stored in the file in plain little-endian binary representation, with no header at all. The "length" of the vector is inferred directly from the size of the file.

The version 1 has the following layout. The file starts with the magic header {0xDE, 0xAD, 0xBE, 0xEF}. Following is a single character: 'L' for little-endian, and 'B' for big-endian file. Finally, three bytes {0x00, 0x00, 0x01} (version 1) of the file format. As with version 0, the length of the vector is inferred from the size of the file.

Random access in both read and write are possible. And it is possible to write beyond length(), in which case length() will be updated to reflect the change

Definition at line 77 of file IntVecFile.h.


Constructor & Destructor Documentation

PLearn::IntVecFile::IntVecFile  )  [inline]
 

Default constructor, you must then call open.

Definition at line 92 of file IntVecFile.h.

References PLearn::byte_order(), endianness_, f, filename, length_, and version_number_.

PLearn::IntVecFile::IntVecFile const string the_filename,
bool  readwrite = false
[inline]
 

Definition at line 96 of file IntVecFile.h.

References f, and open.

PLearn::IntVecFile::IntVecFile const IntVecFile other  ) 
 

The copy constructor opens the file a second time in readonly mode only.

Definition at line 62 of file IntVecFile.cc.

References filename, and open.

PLearn::IntVecFile::~IntVecFile  ) 
 

Definition at line 119 of file IntVecFile.cc.

References close().


Member Function Documentation

void PLearn::IntVecFile::append const TVec< int > &  vec  ) 
 

Definition at line 138 of file IntVecFile.cc.

References PLearn::byte_order(), PLearn::TVec< T >::data(), endianness_, PLearn::endianswap(), f, PLearn::TVec< T >::length(), length(), length_, and seek_to_index().

void PLearn::IntVecFile::append int  value  )  [inline]
 

Definition at line 112 of file IntVecFile.h.

References append(), and length().

Referenced by append(), PLearn::filter(), PLearn::VVMatrix::generateFilterIndexFile(), PLearn::VVMatrix::generateVMatIndex(), PLearn::grep(), and PLearn::FilteredVMatrix::openIndex().

void PLearn::IntVecFile::close  ) 
 

Definition at line 112 of file IntVecFile.cc.

References f.

Referenced by PLearn::VVMatrix::generateFilterIndexFile(), open(), PLearn::FilteredVMatrix::openIndex(), and ~IntVecFile().

int PLearn::IntVecFile::get int  i  )  const
 

Definition at line 94 of file IntVecFile.cc.

References BIG_ENDIAN_ORDER, endianness_, f, PLearn::fread_int(), length(), PLERROR, and seek_to_index().

TVec< int > PLearn::IntVecFile::getVec  )  const
 

Definition at line 124 of file IntVecFile.cc.

References PLearn::byte_order(), PLearn::TVec< T >::data(), endianness_, PLearn::endianswap(), f, length(), PLERROR, and seek_to_index().

Referenced by PLearn::VVMatrix::generateVMatIndex().

void PLearn::IntVecFile::getVersionAndSize  )  [protected]
 

store in data members

< unbelievable (bis)

Definition at line 171 of file IntVecFile.cc.

References BIG_ENDIAN_ORDER, endianness_, f, filename, PLearn::filesize(), header_size, length_, LITTLE_ENDIAN_ORDER, PLERROR, signature, and version_number_.

Referenced by open().

int PLearn::IntVecFile::length  )  const [inline]
 

Definition at line 110 of file IntVecFile.h.

References length_.

Referenced by append(), PLearn::SelectRowsFileIndexVMatrix::build_(), PLearn::VVMatrix::generateVMatIndex(), get(), PLearn::FilteredVMatrix::getNewRow(), getVec(), and PLearn::FilteredVMatrix::openIndex().

void PLearn::IntVecFile::open const string the_filename,
bool  readwrite = false
 

Definition at line 69 of file IntVecFile.cc.

References close(), f, PLearn::file_exists(), filename, getVersionAndSize(), PLearn::isfile(), PLERROR, and writeFileSignature().

Referenced by PLearn::SelectRowsFileIndexVMatrix::build_(), and PLearn::FilteredVMatrix::openIndex().

int PLearn::IntVecFile::operator[] int  i  )  const [inline]
 

Definition at line 111 of file IntVecFile.h.

References operator[]().

Referenced by operator[]().

void PLearn::IntVecFile::put int  i,
int  value
 

Definition at line 104 of file IntVecFile.cc.

References BIG_ENDIAN_ORDER, endianness_, f, PLearn::fwrite_int(), length_, and seek_to_index().

Referenced by PLearn::fullyRebalance2Classes(), and PLearn::rebalanceNClasses().

void PLearn::IntVecFile::seek_to_index int  index  )  const [protected]
 

seek depending on version

Definition at line 213 of file IntVecFile.cc.

References f, header_size, and version_number_.

Referenced by append(), get(), getVec(), and put().

void PLearn::IntVecFile::writeFileSignature  )  [protected]
 

write magic signature

< write without

Definition at line 155 of file IntVecFile.cc.

References PLearn::byte_order(), endianness_, f, length_, signature, and version_number_.

Referenced by open().


Member Data Documentation

char PLearn::IntVecFile::endianness_ [protected]
 

either 'L' or 'B'

Definition at line 85 of file IntVecFile.h.

Referenced by append(), get(), getVec(), getVersionAndSize(), IntVecFile(), put(), and writeFileSignature().

FILE* PLearn::IntVecFile::f [protected]
 

Definition at line 81 of file IntVecFile.h.

Referenced by append(), close(), get(), getVec(), getVersionAndSize(), IntVecFile(), open(), put(), seek_to_index(), and writeFileSignature().

string PLearn::IntVecFile::filename [protected]
 

Definition at line 80 of file IntVecFile.h.

Referenced by getVersionAndSize(), IntVecFile(), and open().

const int PLearn::IntVecFile::header_size [static, protected]
 

Initial value:

{ 0, 2 }
index array by version number

Definition at line 56 of file IntVecFile.cc.

Referenced by getVersionAndSize(), and seek_to_index().

int PLearn::IntVecFile::length_ [protected]
 

Definition at line 82 of file IntVecFile.h.

Referenced by append(), getVersionAndSize(), IntVecFile(), length(), put(), and writeFileSignature().

const char PLearn::IntVecFile::signature [static, protected]
 

Initial value:

{ 0xDE, 0xAD, 0xBE, 0xEF, 0x00 }
magic signature

Definition at line 52 of file IntVecFile.cc.

Referenced by getVersionAndSize(), and writeFileSignature().

int PLearn::IntVecFile::version_number_ [protected]
 

0 if old version, 1 if < current version

Definition at line 83 of file IntVecFile.h.

Referenced by getVersionAndSize(), IntVecFile(), seek_to_index(), and writeFileSignature().


The documentation for this class was generated from the following files:
Generated on Tue Aug 17 16:23:11 2004 for PLearn by doxygen 1.3.7